From: Ryusuke Konishi <konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
To: haogangchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] FS: nilfs2: potential integer overflow in nilfs_ioctl_clean_segments()
Date: Fri, 02 Dec 2011 00:33:12 +0900 (JST) [thread overview]
Message-ID: <20111202.003312.179955221.ryusuke@osrg.net> (raw)
In-Reply-To: <1322708399-26919-1-git-send-email-haogangchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On Wed, 30 Nov 2011 21:59:59 -0500, Haogang Chen wrote:
> 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Ahh, that makes sense.
I will apply your patch.
Thanks,
Ryusuke Konishi
> ---
> fs/nilfs2/ioctl.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
> index 41d6743..b805df9 100644
> --- a/fs/nilfs2/ioctl.c
> +++ b/fs/nilfs2/ioctl.c
> @@ -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) {
> --
> 1.7.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2011-12-01 15:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-01 2:59 [PATCH] FS: nilfs2: potential integer overflow in nilfs_ioctl_clean_segments() Haogang Chen
[not found] ` <1322708399-26919-1-git-send-email-haogangchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-12-01 15:33 ` Ryusuke Konishi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111202.003312.179955221.ryusuke@osrg.net \
--to=konishi.ryusuke-zyj7fxus5i5l9jvzuh4aog@public.gmane.org \
--cc=haogangchen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox