From: Dan Carpenter <dan.carpenter@oracle.com>
To: William Kucharski <william.kucharski@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Keith Busch <keith.busch@intel.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Kees Cook <keescook@chromium.org>,
YueHaibing <yuehaibing@huawei.com>,
linux-mm@kvack.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] mm/gup_benchmark: prevent integer overflow in ioctl
Date: Thu, 1 Nov 2018 10:16:13 +0300 [thread overview]
Message-ID: <20181101071613.7x3smxwz5wo57n2m@mwanda> (raw)
In-Reply-To: <CF4F3932-68A1-4D92-9E4F-6DCD3A3A0447@oracle.com>
On Thu, Nov 01, 2018 at 12:38:22AM -0600, William Kucharski wrote:
>
>
> > On Oct 25, 2018, at 12:15 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > The concern here is that "gup->size" is a u64 and "nr_pages" is unsigned
> > long. On 32 bit systems we could trick the kernel into allocating fewer
> > pages than expected.
> >
> > Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > mm/gup_benchmark.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
> > index debf11388a60..5b42d3d4b60a 100644
> > --- a/mm/gup_benchmark.c
> > +++ b/mm/gup_benchmark.c
> > @@ -27,6 +27,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
> > int nr;
> > struct page **pages;
> >
> > + if (gup->size > ULONG_MAX)
> > + return -EINVAL;
> > +
> > nr_pages = gup->size / PAGE_SIZE;
> > pages = kvcalloc(nr_pages, sizeof(void *), GFP_KERNEL);
> > if (!pages)
>
> Given gup->size is in bytes, if your goal is to avoid an overflow of nr_pages on 32-bit
> systems, shouldn't you be checking something like:
>
> if ((gup_size / PAGE_SIZE) > ULONG_MAX)
My patch lets people allocate 4MB. (U32_MAX / 4096 * sizeof(void *)).
Surely, that's enough? I liked my check because it avoids the divide so
it's faster and it is a no-op on 64bit systems.
regards,
dan carpenter
next prev parent reply other threads:[~2018-11-01 7:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-25 6:15 [PATCH] mm/gup_benchmark: prevent integer overflow in ioctl Dan Carpenter
2018-10-25 7:32 ` Kirill A. Shutemov
2018-11-01 6:38 ` William Kucharski
2018-11-01 7:16 ` Dan Carpenter [this message]
2018-11-01 8:28 ` William Kucharski
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=20181101071613.7x3smxwz5wo57n2m@mwanda \
--to=dan.carpenter@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=keith.busch@intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=sfr@canb.auug.org.au \
--cc=william.kucharski@oracle.com \
--cc=yuehaibing@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).