* [PATCH] mac80211: Fix race between ieee80211_rx_bss_put and lookup routines.
@ 2008-04-23 7:47 Pavel Emelyanov
[not found] ` <480EE983.4020209-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Emelyanov @ 2008-04-23 7:47 UTC (permalink / raw)
To: Johannes Berg, John W. Linville; +Cc: Linux Netdev List, linux-wireless
The put routine first decrements the users counter and then
(if it is zero) locks the sta_bss_lock and removes one from
the list and the hash.
Thus, any of ieee80211_sta_config_auth, ieee80211_rx_bss_get
or ieee80211_rx_mesh_bss_get can race with it by finding a
bss that is about to get kfree-ed.
Using atomic_dec_and_lock in ieee80211_rx_bss_put takes care
of this race.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 6b75cb6..dac3c2a 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -2248,10 +2248,13 @@ static void ieee80211_rx_bss_put(struct net_device *dev,
struct ieee80211_sta_bss *bss)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- if (!atomic_dec_and_test(&bss->users))
+
+ local_bh_disable();
+ if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
+ local_bh_enable();
return;
+ }
- spin_lock_bh(&local->sta_bss_lock);
__ieee80211_rx_bss_hash_del(dev, bss);
list_del(&bss->list);
spin_unlock_bh(&local->sta_bss_lock);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mac80211: Fix race between ieee80211_rx_bss_put and lookup routines.
[not found] ` <480EE983.4020209-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
@ 2008-04-23 7:53 ` Johannes Berg
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2008-04-23 7:53 UTC (permalink / raw)
To: Pavel Emelyanov
Cc: John W. Linville, Linux Netdev List,
linux-wireless-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]
On Wed, 2008-04-23 at 11:47 +0400, Pavel Emelyanov wrote:
> The put routine first decrements the users counter and then
> (if it is zero) locks the sta_bss_lock and removes one from
> the list and the hash.
>
> Thus, any of ieee80211_sta_config_auth, ieee80211_rx_bss_get
> or ieee80211_rx_mesh_bss_get can race with it by finding a
> bss that is about to get kfree-ed.
>
> Using atomic_dec_and_lock in ieee80211_rx_bss_put takes care
> of this race.
Good catch, thanks.
> Signed-off-by: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
Acked-by: Johannes Berg <johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>
I think we will need this in -stable (different file, same contents)
> ---
>
> diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
> index 6b75cb6..dac3c2a 100644
> --- a/net/mac80211/mlme.c
> +++ b/net/mac80211/mlme.c
> @@ -2248,10 +2248,13 @@ static void ieee80211_rx_bss_put(struct net_device *dev,
> struct ieee80211_sta_bss *bss)
> {
> struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
> - if (!atomic_dec_and_test(&bss->users))
> +
> + local_bh_disable();
> + if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
> + local_bh_enable();
> return;
> + }
>
> - spin_lock_bh(&local->sta_bss_lock);
> __ieee80211_rx_bss_hash_del(dev, bss);
> list_del(&bss->list);
> spin_unlock_bh(&local->sta_bss_lock);
>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-23 8:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-23 7:47 [PATCH] mac80211: Fix race between ieee80211_rx_bss_put and lookup routines Pavel Emelyanov
[not found] ` <480EE983.4020209-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2008-04-23 7:53 ` Johannes Berg
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).