From: Dan Carpenter <dan.carpenter@oracle.com>
To: Wenliang Fan <fanwlexca@gmail.com>
Cc: gregkh <gregkh@linuxfoundation.org>,
klmckinney1 <klmckinney1@gmail.com>,
tulinizer <tulinizer@gmail.com>,
devel <devel@driverdev.osuosl.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drivers/staging/bcm: Integer overflow
Date: Fri, 20 Dec 2013 12:12:55 +0300 [thread overview]
Message-ID: <20131220091255.GR5443@mwanda> (raw)
In-Reply-To: <CAPLUJPaJiiaervQTPoYES3C9mvTx2gGGXizrEMN3GA6jY=b0Mw@mail.gmail.com>
On Fri, Dec 20, 2013 at 04:51:45PM +0800, Wenliang Fan wrote:
> Thanks for your advice.
> But the variable 'psFlash2xReadWrite->offset' in '
> *drivers/staging/bcm/nvm.c*:validateFlash2xReadWrite()' is also comes from
> user space, which would cause an integer overflow in the following line:
>
> if ((uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes) <=
> uiSectEndOffset)
>
> in '*drivers/staging/bcm/**nvm.c*: validateFlash2xReadWrite()',
> and another integer overflow in the following line:
>
>
> ReadOffset = ReadOffset + ReadBytes; (or WriteOffset = WriteOffset +
> WriteBytes;)
>
> in '*drivers/staging/bcm/**Bcmchar.c*: bcm_char_ioctl()'.
>
Alright, fine. But the new check is messy. Do it like this:
/* these are user controlled and can lead to integer overflows */
if (psFlash2xReadWrite->offset > uiSectEndOffset)
return false;
if (uiNumOfBytes > uiSectEndOffset)
return false;
if (uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes > uiSectEndOffset)
return false;
return true;
That way each step is simpler to understand. People are too fond of
compound conditions... *grumble*.
regards,
dan carpenter
next prev parent reply other threads:[~2013-12-20 9:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-20 7:13 [PATCH] drivers/staging/bcm: Integer overflow Wenliang Fan
2013-12-20 8:16 ` Dan Carpenter
[not found] ` <CAPLUJPaJiiaervQTPoYES3C9mvTx2gGGXizrEMN3GA6jY=b0Mw@mail.gmail.com>
2013-12-20 9:12 ` Dan Carpenter [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-12-20 10:19 Wenliang Fan
2013-12-20 10:45 ` Dan Carpenter
2013-12-20 11:07 Wenliang Fan
2013-12-20 11:18 ` Dan Carpenter
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=20131220091255.GR5443@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=fanwlexca@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=klmckinney1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tulinizer@gmail.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 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.