f2fs: check output position in move range ioctl
cover f2fs: check output position in move range ioctl
If a negative value is provided as the output position to the F2FS_IOC_MOVE_RANGE ioctl, f2fs_get_dnode_of_data may hit a memory bug like the following:
BUG: unable to handle page fault for address: ffffed10b30435a4 [...] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009) ... [...] Call Trace: f2fs_get_dnode_of_data+0xa68/0xde0 [...] f2fs_reserve_block+0x3b/0x230 f2fs_get_new_data_page+0xf0/0x8b0 ? f2fs_get_lock_data_page+0x1f0/0x1f0 ? rwsem_down_write_slowpath+0x8d0/0x8d0 ? rwsem_down_read_slowpath+0x830/0x830 ? ___might_sleep+0xba/0xd0 ? f2fs_get_lock_data_page+0x17a/0x1f0 __exchange_data_block+0x11bf/0x24d0 ? f2fs_ioc_release_volatile_write+0x170/0x170 ? __might_sleep+0x31/0xd0 ? ___might_sleep+0xba/0xd0 ? rwsem_down_read_slowpath+0x830/0x830 ? __init_rwsem+0xa0/0xa0 f2fs_ioctl+0x469c/0x6980
I am reletively inexperienced with F2FS, so I may have missed something, but I think a simple check of the output position to ensuring that it isn't a negative value should resolve this issue. The simple test reproducer I wrote no longer triggers the memmory error after the patch. Comments and feedback would be appreciated :-)
Cheers,
- Dan
Dan Robertson (1):
f2fs: check output position in move range ioctl
fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 1/1 f2fs: check output position in move range ioctl
When the move range ioctl is used, check the output position and ensure that it is a non-negative value. Without this check f2fs_get_dnode_of_data may hit a memmory bug.
--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)
fs/f2fs/file.c +2 -0
@@ -2798,6 +2798,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } ret = -EINVAL ; +if (pos_out <0 ) + goto out_unlock;if (pos_in + len > src->i_size || pos_in + len < pos_in) goto out_unlock;if (len ==0 )
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 3 lines · Dan Robertson
When the move range ioctl is used, check the output position and ensure that it is a non-negative value. Without this check
f2fs_get_dnode_of_datamay hit a memmory bug.
Nice catch!
Quoted 11 lines
Signed-off-by Dan Robertson <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +0
-0
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2802
Quoted 5 lines
fs/f2fs/file.c +2
-0@@ -2798,6 +2798,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } ret = -EINVAL ; +if (pos_out <0 ) + goto out_unlock;
IMO, it would be better to check both pos_in and pos_out out of inode lock coverage, maybe after encryption flag check?
Thanks,
Quoted 6 lines
fs/f2fs/file.c +0
-0if (pos_in + len > src->i_size || pos_in + len < pos_in) goto out_unlock;if (len ==0 )
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
A message that is not in the archive (sent off-list or not yet received): 20200821125404.GA20793@nessie
Quoted 10 lines · Dan Robertson
Quoted 6 lines · Chao Yu
Quoted 3 lines · Dan Robertson
When the move range ioctl is used, check the output position and ensure that it is a non-negative value. Without this check
f2fs_get_dnode_of_datamay hit a memmory bug.Nice catch!
I noticed that the
pos_outvalue is unsigned in thefile_move_rangestructure, butf2fs_file_move_rangeuses the signedloff_t. Would a better fix be to
singed loff_t looks good to me, as it keeps line with position variable's type in vfs.
Thanks,
Quoted 27 lines
change the
pos_outargument to an unsigned type or ensure that it is cast to an unsigned type before we shift it right byF2FS_BLKSIZE_BITS? This also would remove the bug, as the index would no longer be negative for theget_node_pathcall inf2fs_get_dnode_of_data, and therefore we should calculate the correct offset.Quoted 14 lines
Quoted 14 lines
Signed-off-by Dan Robertson <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +0
-0@@ -2798,6 +2798,8 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, }Quoted 6 lines
fs/f2fs/file.c static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, · line 2802
Quoted 3 lines
fs/f2fs/file.c +2
-0ret = -EINVAL ; +if (pos_out <0 ) + goto out_unlock;IMO, it would be better to check both
pos_inandpos_outout of inode lock coverage, maybe after encryption flag check?
Quoted 7 lines
Yeah that makes sense. If the
pos_incheck is the right direction, I'll move the check, test it, and set a second patchset version.Cheers,
- Dan
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel