linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Buesch <mb@bu3sch.de>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, linville@tuxdriver.com
Subject: Re: [PATCH RFC] cfg80211: Add ies_allocated check before copying ies
Date: Sun, 26 Apr 2009 10:40:10 +0200	[thread overview]
Message-ID: <200904261040.10838.mb@bu3sch.de> (raw)
In-Reply-To: <1240734752.17781.3.camel@johannes.local>

On Sunday 26 April 2009 10:32:32 Johannes Berg wrote:
> On Sat, 2009-04-25 at 22:36 +0200, Michael Buesch wrote:
> > I don't fully understand the code, but let's imagine the following situation:
> > 
> > - cfg80211_bss_update was called and the ie was stored to allocated space.
> > - The information_elements pointer is changed to the allocated space.
> > - cfg80211_bss_update is called again, but now the ie fits into the
> >   space after the "found" structure.
> > - But the information_elements pointer still points to the allocated space.
> >   So it may overrun the buffer and crash.
> > 
> > Is this scenario possible?
> > If yes, please consider the following patch.
> 
> Yeah, looks like a bug, good catch. I don't think the fix is correct
> though -- you lose the data in this case.
> 
> I think it should simply be:
> 
> >  			size_t ielen = res->pub.len_information_elements;
> >  
> > -			if (ksize(found) >= used + ielen) {
> > +			if (!found->ies_allocated && ksize(found) >= used + ielen) {
> >  				memcpy(found->pub.information_elements,
> >  				       res->pub.information_elements, ielen);
> >  				found->pub.len_information_elements = ielen;
> > 
> 
> so that the else branch gets a chance to reallocate if necessary, would
> you agree?

Yeah I first also considered this option, but I thought that the code likes to
prefer putting the stuff into the "found" tail, if it fits.
But yes, your fix is perfectly fine. If it was allocated once, it will always be
allocated (and grown) from then on.
It won't shrink the buffer anymore for future ies that are smaller, but I guess that's OK.

-- 
Greetings, Michael.

  reply	other threads:[~2009-04-26  8:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-25 20:36 [PATCH RFC] cfg80211: Add ies_allocated check before copying ies Michael Buesch
2009-04-26  8:32 ` Johannes Berg
2009-04-26  8:40   ` Michael Buesch [this message]
2009-04-26  8:45     ` Johannes Berg

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=200904261040.10838.mb@bu3sch.de \
    --to=mb@bu3sch.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.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).