linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: "Luis R. Rodriguez" <mcgrof@gmail.com>
Cc: "John W. Linville" <linville@tuxdriver.com>,
	"André Goddard Rosa" <andre.goddard@gmail.com>,
	"Jiri Kosina" <jkosina@suse.cz>,
	linux-wireless@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] prism54: call BUG_ON() earlier
Date: Mon, 12 Jul 2010 19:37:14 +0200	[thread overview]
Message-ID: <20100712173714.GD5658@bicker> (raw)
In-Reply-To: <AANLkTikJ9Ae2HRIwdcc8oVgAc2zoVHUL7ZY9k2QO2QpS@mail.gmail.com>

On Mon, Jul 12, 2010 at 10:06:55AM -0700, Luis R. Rodriguez wrote:
> On Sat, Jul 10, 2010 at 1:53 AM, Dan Carpenter <error27@gmail.com> wrote:
> > This test is off by one because strlen() doesn't include the NULL
> > terminator.
> >
> > Signed-off-by: Dan Carpenter <error27@gmail.com>
> >
> > diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
> > index 8d1190c..1051268 100644
> > --- a/drivers/net/wireless/prism54/isl_ioctl.c
> > +++ b/drivers/net/wireless/prism54/isl_ioctl.c
> > @@ -2067,7 +2067,7 @@ send_simple_event(islpci_private *priv, const char *str)
> >        memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
> >        if (!memptr)
> >                return;
> > -       BUG_ON(n > IW_CUSTOM_MAX);
> > +       BUG_ON(n >= IW_CUSTOM_MAX);
> >        wrqu.data.pointer = memptr;
> >        wrqu.data.length = n;
> >        strcpy(memptr, str);
> >
> 
> send_simple_event() never passes a NULL terminated string though. What
> does this fix today? If nothing then better leave as-is.
> 
>   Luis

It doesn't fix any bugs in the current code, but it's a necessary clean
up.

        memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
	                 ^^^^^^^^^^^^^
	This is the size of memptr.

        if (!memptr)
                return;
        BUG_ON(n > IW_CUSTOM_MAX);

	^^^^^^^^^^^^^^^^^^^^^^^^^^
	This is an off-by-one check.

        wrqu.data.pointer = memptr;
        wrqu.data.length = n;
        strcpy(memptr, str);
	^^^^^^^^^^^^^^^^^^^^

	This would be a silent memory corruption.

In the current code we only use short event strings so the check isn't
needed.  But we should either correct the check or remove it.

regards,
dan carpenter



  reply	other threads:[~2010-07-12 17:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-10  8:53 [patch] prism54: call BUG_ON() earlier Dan Carpenter
2010-07-12 17:06 ` Luis R. Rodriguez
2010-07-12 17:37   ` Dan Carpenter [this message]
2010-07-12 17:48     ` 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=20100712173714.GD5658@bicker \
    --to=error27@gmail.com \
    --cc=andre.goddard@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=mcgrof@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 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).