mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters
@ 2025-03-15 16:12 Mikhail Lobanov
  2025-03-17  7:25 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Mikhail Lobanov @ 2025-03-15 16:12 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Mikhail Lobanov, Shaul Triebitz, Christophe Jaillet,
	linux-wireless, linux-kernel, lvc-project

When userspace sets supported rates for a new station via
NL80211_CMD_NEW_STATION, it might send a list that's empty
or contains only invalid values. Currently, we process these
values in sta_link_apply_parameters() without checking the result of
ieee80211_parse_bitrates(), which can lead to an empty rates bitmap.

A similar issue was addressed for NL80211_CMD_SET_BSS in commit
ce04abc3fcc6 ("wifi: mac80211: check basic rates validity").
This patch applies the same approach in sta_link_apply_parameters()
for NL80211_CMD_NEW_STATION, ensuring there is at least one valid
rate by inspecting the result of ieee80211_parse_bitrates().

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: b95eb7f0eee4 ("wifi: cfg80211/mac80211: separate link params from station params")
Signed-off-by: Mikhail Lobanov <m.lobanov@rosa.ru>
---
v2: Fixed the patch subject to provide a complete description.
v3: added the missing if as Christophe Jaillet (christophe.jaillet@wanadoo.fr) noticed.

 net/mac80211/cfg.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 9351c64608a9..b4d18172da16 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1909,10 +1909,11 @@ static int sta_link_apply_parameters(struct ieee80211_local *local,
 
 	if (params->supported_rates &&
 	    params->supported_rates_len) {
-		ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
-					 sband, params->supported_rates,
-					 params->supported_rates_len,
-					 &link_sta->pub->supp_rates[sband->band]);
+		if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
+					      sband, params->supported_rates,
+					      params->supported_rates_len,
+					      &link_sta->pub->supp_rates[sband->band]))
+			return -EINVAL;
 	}
 
 	if (params->ht_capa)
-- 
2.47.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters
  2025-03-15 16:12 [PATCH v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters Mikhail Lobanov
@ 2025-03-17  7:25 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2025-03-17  7:25 UTC (permalink / raw)
  To: Mikhail Lobanov
  Cc: Shaul Triebitz, Christophe Jaillet, linux-wireless, linux-kernel,
	lvc-project

On Sat, 2025-03-15 at 19:12 +0300, Mikhail Lobanov wrote:
> When userspace sets supported rates for a new station via
> NL80211_CMD_NEW_STATION, it might send a list that's empty
> or contains only invalid values. Currently, we process these
> values in sta_link_apply_parameters() without checking the result of
> ieee80211_parse_bitrates(), which can lead to an empty rates bitmap.
> 
> A similar issue was addressed for NL80211_CMD_SET_BSS in commit
> ce04abc3fcc6 ("wifi: mac80211: check basic rates validity").
> This patch applies the same approach in sta_link_apply_parameters()
> for NL80211_CMD_NEW_STATION, ensuring there is at least one valid
> rate by inspecting the result of ieee80211_parse_bitrates().
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Fixes: b95eb7f0eee4 ("wifi: cfg80211/mac80211: separate link params from station params")
> Signed-off-by: Mikhail Lobanov <m.lobanov@rosa.ru>
> ---
> v2: Fixed the patch subject to provide a complete description.
> v3: added the missing if as Christophe Jaillet (christophe.jaillet@wanadoo.fr) noticed.
> 
>  net/mac80211/cfg.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
> index 9351c64608a9..b4d18172da16 100644
> --- a/net/mac80211/cfg.c
> +++ b/net/mac80211/cfg.c
> @@ -1909,10 +1909,11 @@ static int sta_link_apply_parameters(struct ieee80211_local *local,
>  
>  	if (params->supported_rates &&
>  	    params->supported_rates_len) {
> -		ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
> -					 sband, params->supported_rates,
> -					 params->supported_rates_len,
> -					 &link_sta->pub->supp_rates[sband->band]);
> +		if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
> +					      sband, params->supported_rates,
> +					      params->supported_rates_len,
> +					      &link_sta->pub->supp_rates[sband->band]))
> +			return -EINVAL;
>  	}

Seems you could remove the braces, and put it all into a single if
statement?

 if (... && ... && !parse(...))
     return -EINVAL;

I think?

johannes

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-17  7:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-15 16:12 [PATCH v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters Mikhail Lobanov
2025-03-17  7:25 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®