diff mbox series

[v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters

Message ID 20250315161253.19399-1-m.lobanov@rosa.ru (mailing list archive)
State Superseded
Delegated to: Johannes Berg
Headers show
Series [v3] wifi: mac80211: check basic rates validity in sta_link_apply_parameters | expand

Checks

Context Check Description
wifibot/fixes_present success Fixes tag not required for -next series
wifibot/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
wifibot/tree_selection success Guessed tree name to be wireless-next
wifibot/ynl success Generated files up to date; no warnings/errors; no diff in generated;
wifibot/build_32bit success Errors and warnings before: 0 this patch: 0
wifibot/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
wifibot/build_clang success Errors and warnings before: 0 this patch: 0
wifibot/build_clang_rust success No Rust files in patch. Skipping build
wifibot/build_tools success No tools touched, skip
wifibot/check_selftest success No net selftest shell script
wifibot/checkpatch warning WARNING: line length of 87 exceeds 80 columns
wifibot/deprecated_api success None detected
wifibot/header_inline success No static functions without inline keyword in header files
wifibot/kdoc success Errors and warnings before: 0 this patch: 0
wifibot/source_inline success Was 0 now: 0
wifibot/verify_fixes success Fixes tag looks correct
wifibot/verify_signedoff success Signed-off-by tag matches author and committer

Commit Message

Mikhail Lobanov March 15, 2025, 4:12 p.m. UTC
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(-)

Comments

Johannes Berg March 17, 2025, 7:25 a.m. UTC | #1
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
diff mbox series

Patch

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)