2022-07-20 01:26:29

by Sasha Levin

[permalink] [raw]
Subject: [PATCH AUTOSEL 5.4 06/16] wifi: mac80211: do not wake queues on a vif that is being stopped

From: Felix Fietkau <[email protected]>

[ Upstream commit f856373e2f31ffd340e47e2b00027bd4070f74b3 ]

When a vif is being removed and sdata->bss is cleared, __ieee80211_wake_txqs
can still be called on it, which crashes as soon as sdata->bss is being
dereferenced.
To fix this properly, check for SDATA_STATE_RUNNING before waking queues,
and take the fq lock when setting it (to ensure that __ieee80211_wake_txqs
observes the change when running on a different CPU)

Signed-off-by: Felix Fietkau <[email protected]>
Acked-by: Toke Høiland-Jørgensen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
net/mac80211/iface.c | 2 ++
net/mac80211/util.c | 3 +++
2 files changed, 5 insertions(+)

diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index ddc001ad9055..48bda8aaa90a 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -803,7 +803,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
bool cancel_scan;
struct cfg80211_nan_func *func;

+ spin_lock_bh(&local->fq.lock);
clear_bit(SDATA_STATE_RUNNING, &sdata->state);
+ spin_unlock_bh(&local->fq.lock);

cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
if (cancel_scan)
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index c1c117fdf318..8ae0186091b6 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -250,6 +250,9 @@ static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
local_bh_disable();
spin_lock(&fq->lock);

+ if (!test_bit(SDATA_STATE_RUNNING, &sdata->state))
+ goto out;
+
if (sdata->vif.type == NL80211_IFTYPE_AP)
ps = &sdata->bss->ps;

--
2.35.1


2022-07-20 02:06:03

by Ben Greear

[permalink] [raw]
Subject: Re: [PATCH AUTOSEL 5.4 06/16] wifi: mac80211: do not wake queues on a vif that is being stopped

I think this one had a regression and needs another init-lock-early patch to keep from causing
problems?

It certainly broke my 5.17-ish kernel...

Thanks,
Ben

On 7/19/22 6:17 PM, Sasha Levin wrote:
> From: Felix Fietkau <[email protected]>
>
> [ Upstream commit f856373e2f31ffd340e47e2b00027bd4070f74b3 ]
>
> When a vif is being removed and sdata->bss is cleared, __ieee80211_wake_txqs
> can still be called on it, which crashes as soon as sdata->bss is being
> dereferenced.
> To fix this properly, check for SDATA_STATE_RUNNING before waking queues,
> and take the fq lock when setting it (to ensure that __ieee80211_wake_txqs
> observes the change when running on a different CPU)
>
> Signed-off-by: Felix Fietkau <[email protected]>
> Acked-by: Toke Høiland-Jørgensen <[email protected]>
> Link: https://lore.kernel.org/r/[email protected]
> Signed-off-by: Johannes Berg <[email protected]>
> Signed-off-by: Sasha Levin <[email protected]>
> ---
> net/mac80211/iface.c | 2 ++
> net/mac80211/util.c | 3 +++
> 2 files changed, 5 insertions(+)
>
> diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
> index ddc001ad9055..48bda8aaa90a 100644
> --- a/net/mac80211/iface.c
> +++ b/net/mac80211/iface.c
> @@ -803,7 +803,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
> bool cancel_scan;
> struct cfg80211_nan_func *func;
>
> + spin_lock_bh(&local->fq.lock);
> clear_bit(SDATA_STATE_RUNNING, &sdata->state);
> + spin_unlock_bh(&local->fq.lock);
>
> cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
> if (cancel_scan)
> diff --git a/net/mac80211/util.c b/net/mac80211/util.c
> index c1c117fdf318..8ae0186091b6 100644
> --- a/net/mac80211/util.c
> +++ b/net/mac80211/util.c
> @@ -250,6 +250,9 @@ static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
> local_bh_disable();
> spin_lock(&fq->lock);
>
> + if (!test_bit(SDATA_STATE_RUNNING, &sdata->state))
> + goto out;
> +
> if (sdata->vif.type == NL80211_IFTYPE_AP)
> ps = &sdata->bss->ps;
>
>


--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com

2022-07-20 06:01:51

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH AUTOSEL 5.4 06/16] wifi: mac80211: do not wake queues on a vif that is being stopped

On Tue, 2022-07-19 at 18:58 -0700, Ben Greear wrote:
> I think this one had a regression and needs another init-lock-early patch to keep from causing
> problems?
>

Yes, for now we should drop it from all stable trees. We'll re-assess
the situation later if it's needed there or not, I guess.

johannes