All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Buesch <mb@bu3sch.de>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Luciano Coelho <luciano.coelho@nokia.com>,
	linville@tuxdriver.org, linux-wireless@vger.kernel.org,
	kalle.valo@nokia.com, vidhya.govindan@nokia.com, nbd@openwrt.org
Subject: Re: [PATCH v2] mac80211: minstrel: avoid accessing negative indices in rix_to_ndx()
Date: Fri, 3 Jul 2009 12:10:29 +0200	[thread overview]
Message-ID: <200907031210.29648.mb@bu3sch.de> (raw)
In-Reply-To: <1246609742.16770.54.camel@johannes.local>

On Friday 03 July 2009 10:29:02 Johannes Berg wrote:
> On Fri, 2009-07-03 at 08:25 +0300, Luciano Coelho wrote:
> > If rix is not found in mi->r[], i will become -1 after the loop.  This value
> > is eventually used to access arrays, so we were accessing arrays with a
> > negative index, which is obviously not what we want to do.  This patch fixes
> > this potential problem.
> 
> This seems odd -- are you or are you not saying that this can happen in
> normal operation?
> 
> > @@ -66,7 +66,7 @@ rix_to_ndx(struct minstrel_sta_info *mi, int rix)
> >  	for (i = rix; i >= 0; i--)
> >  		if (mi->r[i].rix == rix)
> >  			break;
> > -	WARN_ON(mi->r[i].rix != rix);
> > +	WARN_ON(i < 0);
> >  	return i;
> 
> If it can, this warning seems wrong.

Well, the old WARN_ON seems wrong anyway, because it accesses the array
out of bounds. In case the loop did not find the entry, the warn on will look like this:

WARN_ON(mi->r[-1].rix != rix);

So I do think it's correct to replace the WARN_ON with WARN_ON(i < 0), if this can't
happen in normal operation. If it can happen in normal op, the warning should be removed
and the callers of rix_to_ndx() need to be checked.

-- 
Greetings, Michael.

      parent reply	other threads:[~2009-07-03 10:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-03  5:25 [PATCH v2] mac80211: minstrel: avoid accessing negative indices in rix_to_ndx() Luciano Coelho
2009-07-03  8:29 ` Johannes Berg
2009-07-03  8:44   ` Luciano Coelho
2009-07-03 10:10   ` Michael Buesch [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=200907031210.29648.mb@bu3sch.de \
    --to=mb@bu3sch.de \
    --cc=johannes@sipsolutions.net \
    --cc=kalle.valo@nokia.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.org \
    --cc=luciano.coelho@nokia.com \
    --cc=nbd@openwrt.org \
    --cc=vidhya.govindan@nokia.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.