From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch] USB: usbtest: prevent a divide by zero bug
Date: Tue, 20 Nov 2012 17:44:04 +0000 [thread overview]
Message-ID: <20121120174404.GA4082@breakpoint.cc> (raw)
In-Reply-To: <20121117150610.GA19951@elgon.mountain>
On Sat, Nov 17, 2012 at 09:10:56PM +0300, Dan Carpenter wrote:
> On Sat, Nov 17, 2012 at 06:48:55PM +0100, walter harms wrote:
> >
> >
> > Am 17.11.2012 16:06, schrieb Dan Carpenter:
> > > If param->length is zero, then this could lead to a divide by zero bug
> > > later in the function when we do: size %= max;
> > >
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > >
> > > diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> > > index f10bd97..7667b12 100644
> > > --- a/drivers/usb/misc/usbtest.c
> > > +++ b/drivers/usb/misc/usbtest.c
> > > @@ -423,6 +423,9 @@ alloc_sglist(int nents, int max, int vary)
> > > unsigned i;
> > > unsigned size = max;
> > >
> > > + if (max = 0)
> > > + return NULL;
> > > +
> >
> > maybe you should be more defensive and check from (max <= 0)
> >
>
> Nah... Testing for = 0 is ok.
The parameter comes from user. -1 is hardly possible because the parameter is
defined as unsigned and only alloc_sglist() parameters are signed. Could you
please convert the int to unsigned so it matches the original source of the
parameter?
Passing -1 from user space leads to
|WARNING: at /home/bigeasy/work/new/TI/linux/mm/page_alloc.c:2403
|__alloc_pages_nodemask+0x24d/0x6d0()
aka ENOMEM so it is not that big of deal.
0 on the hand is more critical.
> regards,
> dan carpenter
Sebastian
prev parent reply other threads:[~2012-11-20 17:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-17 15:06 [patch] USB: usbtest: prevent a divide by zero bug Dan Carpenter
2012-11-17 17:48 ` walter harms
2012-11-17 18:10 ` Dan Carpenter
2012-11-20 17:44 ` Sebastian Andrzej Siewior [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=20121120174404.GA4082@breakpoint.cc \
--to=sebastian@breakpoint.cc \
--cc=kernel-janitors@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.