Skip to content

Commit 481fe17

Browse files
haogangtorvalds
authored andcommitted
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. Signed-off-by: Haogang Chen <haogangchen@gmail.com> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 695c60f commit 481fe17

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎fs/nilfs2/ioctl.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
625625
if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment)
626626
goto out_free;
627627

628+
if (argv[n].v_nmembs >= UINT_MAX / argv[n].v_size)
629+
goto out_free;
630+
628631
len = argv[n].v_size * argv[n].v_nmembs;
629632
base = (void __user *)(unsigned long)argv[n].v_base;
630633
if (len == 0) {

0 commit comments

Comments
 (0)