diff mbox series

wifi: mac80211: Don't finalize CSA in IBSS mode if state is disconnected

Message ID 20220814151512.9985-1-code@siddh.me
State New
Headers show
Series wifi: mac80211: Don't finalize CSA in IBSS mode if state is disconnected | expand

Commit Message

Siddh Raman Pant Aug. 14, 2022, 3:15 p.m. UTC
When we are not connected to a channel, sending channel "switch"
announcement doesn't make any sense.

The BSS list is empty in that case. This causes the for loop in
cfg80211_get_bss() to be bypassed, so the function returns NULL
(check line 1424 of net/wireless/scan.c), causing the WARN_ON()
in ieee80211_ibss_csa_beacon() to get triggered (check line 500
of net/mac80211/ibss.c), which was consequently reported on the
syzkaller dashboard.

Thus, check if we have an existing connection before generating
the CSA beacon in ieee80211_ibss_finish_csa().

Fixes: cd7760e62c2a ("mac80211: add support for CSA in IBSS mode")
Bug report: https://syzkaller.appspot.com/bug?id=05603ef4ae8926761b678d2939a3b2ad28ab9ca6
Reported-by: syzbot+b6c9fe29aefe68e4ad34@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org

Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
The fixes commit is old, and syzkaller shows the problem exists for
4.19 and 4.14 as well, so CC'd stable list.

 net/mac80211/ibss.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Siddh Raman Pant Aug. 24, 2022, 8:11 p.m. UTC | #1
On Sun, 14 Aug 2022 20:45:12 +0530  Siddh Raman Pant  wrote:
> When we are not connected to a channel, sending channel "switch"
> announcement doesn't make any sense.
> 
> The BSS list is empty in that case. This causes the for loop in
> cfg80211_get_bss() to be bypassed, so the function returns NULL
> (check line 1424 of net/wireless/scan.c), causing the WARN_ON()
> in ieee80211_ibss_csa_beacon() to get triggered (check line 500
> of net/mac80211/ibss.c), which was consequently reported on the
> syzkaller dashboard.
> 
> Thus, check if we have an existing connection before generating
> the CSA beacon in ieee80211_ibss_finish_csa().
> 
> Fixes: cd7760e62c2a ("mac80211: add support for CSA in IBSS mode")
> Bug report: https://syzkaller.appspot.com/bug?id=05603ef4ae8926761b678d2939a3b2ad28ab9ca6
> Reported-by: syzbot+b6c9fe29aefe68e4ad34@syzkaller.appspotmail.com
> Cc: stable@vger.kernel.org

Tested-by: syzbot+b6c9fe29aefe68e4ad34@syzkaller.appspotmail.com

Syzbot is now booting properly and the test ran successfully.

Thanks,
Siddh

> Signed-off-by: Siddh Raman Pant <code@siddh.me>
> ---
> The fixes commit is old, and syzkaller shows the problem exists for
> 4.19 and 4.14 as well, so CC'd stable list.
> 
>  net/mac80211/ibss.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
> index d56890e3fabb..9b283bbc7bb4 100644
> --- a/net/mac80211/ibss.c
> +++ b/net/mac80211/ibss.c
> @@ -530,6 +530,10 @@ int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata)
>  
>  	sdata_assert_lock(sdata);
>  
> +	/* When not connected/joined, sending CSA doesn't make sense. */
> +	if (ifibss->state != IEEE80211_IBSS_MLME_JOINED)
> +		return -ENOLINK;
> +
>  	/* update cfg80211 bss information with the new channel */
>  	if (!is_zero_ether_addr(ifibss->bssid)) {
>  		cbss = cfg80211_get_bss(sdata->local->hw.wiphy,
> -- 
> 2.35.1
diff mbox series

Patch

diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index d56890e3fabb..9b283bbc7bb4 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -530,6 +530,10 @@  int ieee80211_ibss_finish_csa(struct ieee80211_sub_if_data *sdata)
 
 	sdata_assert_lock(sdata);
 
+	/* When not connected/joined, sending CSA doesn't make sense. */
+	if (ifibss->state != IEEE80211_IBSS_MLME_JOINED)
+		return -ENOLINK;
+
 	/* update cfg80211 bss information with the new channel */
 	if (!is_zero_ether_addr(ifibss->bssid)) {
 		cbss = cfg80211_get_bss(sdata->local->hw.wiphy,