FS: nilfs2: potential integer overflow in nilfs_ioctl_clean_segments()
PATCH 1/1 FS: nilfs2: potential integer overflow in nilfs_ioctl_clean_segments()
There is a potential integer overflow in nilfs_ioctl_clean_segments(). When a large argv[n].v_nmembs is passed from the userspace, the subsequent call to vmalloc() will allocate a buffer smaller than expected, which leads to out-of-bound access in nilfs_ioctl_move_blocks() and lfs_clean_segments().
The following check does not prevent the overflow because nsegs is also controlled by the userspace and could be very large.
if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) goto out_free;
This patch clamps argv[n].v_nmembs to UINT_MAX / argv[n].v_size, and returns -EINVAL when overflow.
--- fs/nilfs2/ioctl.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
fs/nilfs2/ioctl.c +3 -0
@@ -625,6 +625,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) goto out_free; +if (argv[n].v_nmembs >=UINT_MAX / argv[n].v_size) + goto out_free; + len = argv[n].v_size * argv[n].v_nmembs; base = (void __user *)(unsigned long )argv[n].v_base;if (len ==0 ) {
Signature · 6 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Haogang Chen
There is a potential integer overflow in
nilfs_ioctl_clean_segments(). When a large argv[n].v_nmembs is passed from the userspace, the subsequent call tovmalloc()will allocate a buffer smaller than expected, which leads to out-of-bound access innilfs_ioctl_move_blocks()andlfs_clean_segments().The following check does not prevent the overflow because nsegs is also controlled by the userspace and could be very large.
Quoted 7 lines
if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) goto out_free;This patch clamps argv[n].v_nmembs to
UINT_MAX/ argv[n].v_size, and returns-EINVALwhen overflow.Signed-off-by Haogang Chen <[email protected]>
Ahh, that makes sense.
I will apply your patch.
Thanks,
Ryusuke Konishi
Quoted 25 lines
--- fs/nilfs2/ioctl.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)fs/nilfs2/ioctl.c +3
-0@@ -625,6 +625,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) goto out_free; +if (argv[n].v_nmembs >=UINT_MAX / argv[n].v_size) + goto out_free; + len = argv[n].v_size * argv[n].v_nmembs; base = (void __user *)(unsigned long )argv[n].v_base;if (len ==0 ) {Signature · 6 lines
1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html