Skip to content

Commit a2c2f08

Browse files
Hou Taotytso
authored andcommitted
ext4: limit the number of blocks in one ADD_RANGE TLV
Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the newly-added blocks, but the limit on the max value of ee_len field is ignored, and it can lead to BUG_ON as shown below when running command "fallocate -l 128M file" on a fast_commit-enabled fs: kernel BUG at fs/ext4/ext4_extents.h:199! invalid opcode: 0000 [#1] SMP PTI CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200 Call Trace: ? ext4_fc_write_inode+0xf2/0x150 ext4_fc_commit+0x93b/0xa00 ? ext4_fallocate+0x1ad/0x10d0 ext4_sync_file+0x157/0x340 ? ext4_sync_file+0x157/0x340 vfs_fsync_range+0x49/0x80 do_fsync+0x3d/0x70 __x64_sys_fsync+0x14/0x20 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae Simply fixing it by limiting the number of blocks in one EXT4_FC_TAG_ADD_RANGE TLV. Fixes: aa75f4d ("ext4: main fast-commit commit path") Cc: [email protected] Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 948ca5f commit a2c2f08

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/ext4/fast_commit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
892892
sizeof(lrange), (u8 *)&lrange, crc))
893893
return -ENOSPC;
894894
} else {
895+
unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ?
896+
EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN;
897+
898+
/* Limit the number of blocks in one extent */
899+
map.m_len = min(max, map.m_len);
900+
895901
fc_ext.fc_ino = cpu_to_le32(inode->i_ino);
896902
ex = (struct ext4_extent *)&fc_ext.fc_ex;
897903
ex->ee_block = cpu_to_le32(map.m_lblk);

0 commit comments

Comments
 (0)