linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Eliad Peller <eliad@wizery.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: Re: [PATCH 01/11] mac80211: add TX fastpath
Date: Mon, 20 Apr 2015 10:47:13 +0200	[thread overview]
Message-ID: <1429519633.2439.11.camel@sipsolutions.net> (raw)
In-Reply-To: <CAB3XZEeraicUA4Vo4tT93yFn7uN4-FapHOu_5wVutBvtJZP+jQ@mail.gmail.com> (sfid-20150420_102521_690840_0A3A15BD)

Hey, somebody is reviewing my patches :-)

> > +       build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
> > +       if (!build.key)
> > +               build.key = rcu_access_pointer(sdata->default_unicast_key);
> don't you need rcu_dereference here? (and you don't seem to be inside
> rcu section here)

It's a bit complicated.

I used to think I don't need it, but perhaps I do to avoid accessing bad
memory in this function.

The thing is that this function is going to be called immediately
whenever those pointers change, so that the RCU handling of the fast_tx
struct itself should prevent the TX path from accessing a bad key
pointer.

However, it seems possible that we go into this function on another CPU
for unrelated reasons, and if that CPU then stalls after getting the key
pointer but before assigning the fast_tx pointer, then it might
overwrite the assignment or clearing from the CPU processing the key
change.

So indeed it looks like this isn't safe as is right now.

To fix that, I think I can hold the lock longer, so that the lifetime of
the key and the fast_tx pointer are more closely correlated. If I
acquire the spinlock before checking for the key, then the CPU that
invalidates the key pointer cannot race in this way with another caller,
since the key pointer would (for this purpose) be protected by the lock.
Then either the CPU that deleted the key will have to wait (while the
key is still pretty much valid) and then will overwrite the fast_tx w/o
the key, or the other CPU will have to wait and will find the key
pointer changed/NULL already.

Right? what do you think?

johannes


  reply	other threads:[~2015-04-20  8:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-17 15:15 [PATCH 01/11] mac80211: add TX fastpath Johannes Berg
2015-04-17 15:15 ` [PATCH 02/11] mac80211_hwsim: enable IEEE80211_HW_SUPPORT_FAST_XMIT Johannes Berg
2015-04-17 15:15 ` [PATCH 03/11] mac80211: extend fast-xmit to driver fragmentation Johannes Berg
2015-04-17 15:15 ` [PATCH 04/11] mac80211: extend fast-xmit for more ciphers Johannes Berg
2015-04-17 15:15 ` [PATCH 05/11] mac80211: extend fast-xmit to cover IBSS Johannes Berg
2015-04-17 15:15 ` [PATCH 06/11] wlcore: enable IEEE80211_HW_SUPPORT_FAST_XMIT Johannes Berg
2015-04-17 15:15 ` [PATCH 07/11] ath10k: " Johannes Berg
2015-04-22  9:00   ` Kalle Valo
2015-04-17 15:15 ` [PATCH 08/11] mac80211: allow checksum offload only in fast-xmit Johannes Berg
2015-04-17 15:15 ` [PATCH 09/11] mac80211: enable changing netdev features with ethtool Johannes Berg
2015-04-17 15:15 ` [PATCH 10/11] mac80211: allow drivers to support S/G Johannes Berg
2015-04-17 15:15 ` [PATCH 11/11] mac80211: allow segmentation offloads Johannes Berg
2015-04-20  8:25 ` [PATCH 01/11] mac80211: add TX fastpath Eliad Peller
2015-04-20  8:47   ` Johannes Berg [this message]
2015-04-21  6:54     ` Eliad Peller
2015-04-21  7:06       ` Johannes Berg
2015-04-22 11:00 ` 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=1429519633.2439.11.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=eliad@wizery.com \
    --cc=linux-wireless@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 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).