Bug 219136 - ext4: dax: overflowing extents beyond inode size when partially writing
Summary: ext4: dax: overflowing extents beyond inode size when partially writing
Status: NEW
Alias: None
Product: File System
Classification: Unclassified
Component: ext4 (show other bugs)
Hardware: All Linux
: P3 normal
Assignee: fs_ext4@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-07 12:52 UTC by Zhihao Cheng
Modified: 2024-08-07 12:53 UTC (History)
0 users

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments
diff (1.05 KB, patch)
2024-08-07 12:53 UTC, Zhihao Cheng
Details | Diff
test.sh (317 bytes, application/x-shellscript)
2024-08-07 12:53 UTC, Zhihao Cheng
Details

Description Zhihao Cheng 2024-08-07 12:52:24 UTC
The dax_iomap_rw() does two things in each iteration: map written blocks
    and copy user data to blocks. If the process is killed by user(See signal
    handling in dax_iomap_iter()), the copied data will be returned and added
    on inode size, which means that the length of written extents may exceed
    the inode size, then fsck will fail. An example is given as:
    
    dd if=/dev/urandom of=file bs=4M count=1
     dax_iomap_rw
      iomap_iter // round 1
       ext4_iomap_begin
        ext4_iomap_alloc // allocate 0~2M extents(written flag)
      dax_iomap_iter // copy 2M data
      iomap_iter // round 2
       iomap_iter_advance
        iter->pos += iter->processed // iter->pos = 2M
       ext4_iomap_begin
        ext4_iomap_alloc // allocate 2~4M extents(written flag)
      dax_iomap_iter
       fatal_signal_pending
      done = iter->pos - iocb->ki_pos // done = 2M
     ext4_handle_inode_extension
      ext4_update_inode_size // inode size = 2M
    
    fsck reports: Inode 13, i_size is 2097152, should be 4194304.  Fix?

Reproducer:
1. Apply diff and compile kernel
2. ./test.sh
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: e2c71b4e-3315-4463-8613-ea3f40bf1efb
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

./test.sh: line 18:  1559 Terminated              dd if=/dev/urandom of=$MNT/file bs=4M count=1
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Inode 13, i_size is 2097152, should be 4194304.  Fix? no

Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/pmem2: ********** WARNING: Filesystem still has errors **********

/dev/pmem2: 13/131072 files (0.0% non-contiguous), 27308/524288 blocks
Comment 1 Zhihao Cheng 2024-08-07 12:53:00 UTC
Created attachment 306683 [details]
diff
Comment 2 Zhihao Cheng 2024-08-07 12:53:24 UTC
Created attachment 306684 [details]
test.sh

Note You need to log in before you can comment on or make changes to this bug.