Skip to contentSkip to conversation

wifi: mac80211: validate minstrel HT tx status rates

PATCH Superseded Ren Wei 2 participants 3 messages May 25 – May 26 1 message not in the archive mac80211

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 wifi: mac80211: validate minstrel HT tx status rates

In reply to a message not in the archive

From: Yuqi Xu <[email protected]>

minstrel_ht_tx_status() accepts both legacy tx status entries and rate_info-based status entries, then turns the reported HT/VHT rate into a minstrel group and rate index.

The validation helpers only checked that the entry was present and had tries recorded. They did not verify that the reported HT stream count, VHT NSS, VHT bandwidth encoding, and MCS value were representable by minstrel_ht's rate tables. As a result, malformed tx status metadata could produce group or rate indices outside the tables that minstrel_ht_get_stats() and minstrel_ht_ri_get_stats() index.

Teach the existing tx status validation path to enforce the exact constraints used by minstrel HT's tables for both status formats. Reject HT rates beyond the supported stream groups, and reject VHT rates with unsupported bandwidth encodings, invalid NSS values, or MCS values outside the table.

This keeps the fix at the existing trust boundary and leaves the stats lookup path unchanged.

Fixes ec8aa669b839 ("mac80211: add the minstrel_ht rate control algorithm")
Assisted-by Codex:GPT-5.4
---
 net/mac80211/rc80211_minstrel_ht.c | 47 +++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 4 deletions(-)
net/mac80211/rc80211_minstrel_ht.c +43 -4
index b73ef3adfcc5..a35d42c77ac5 100644
@@ -323,6 +323,43 @@ minstrel_ht_is_legacy_group(int group)
 	       group == MINSTREL_OFDM_GROUP;
 }
 
+static bool
+minstrel_ht_txstat_valid_rate(struct ieee80211_tx_rate *rate)
+{
+	unsigned int bw;
+
+	if (rate->flags & IEEE80211_TX_RC_MCS)
+		return rate->idx < MINSTREL_MAX_STREAMS * 8;
+
+	if (!(rate->flags & IEEE80211_TX_RC_VHT_MCS))
+		return true;
+
+	bw = !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) +
+	     2 * !!(rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH);
+
+	return !(rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) &&
+	       bw <= BW_80 &&
+	       ieee80211_rate_get_vht_nss(rate) <= MINSTREL_MAX_STREAMS &&
+	       ieee80211_rate_get_vht_mcs(rate) < MCS_GROUP_RATES;
+}
+
+static bool
+minstrel_ht_ri_txstat_valid_rate(struct rate_info *rate)
+{
+	if (rate->flags & RATE_INFO_FLAGS_MCS)
+		return rate->mcs < MINSTREL_MAX_STREAMS * 8;
+
+	if (!(rate->flags & RATE_INFO_FLAGS_VHT_MCS))
+		return true;
+
+	return (rate->bw == RATE_INFO_BW_20 ||
+		rate->bw == RATE_INFO_BW_40 ||
+		rate->bw == RATE_INFO_BW_80) &&
+	       rate->nss >= 1 &&
+	       rate->nss <= MINSTREL_MAX_STREAMS &&
+	       rate->mcs < MCS_GROUP_RATES;
+}
+
 /*
  * Look up an MCS group index based on mac80211 rate information
  */
@@ -1205,8 +1242,9 @@ minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
 	if (!rate->count)
 		return false;
 
-	if (rate->flags & IEEE80211_TX_RC_MCS ||
-	    rate->flags & IEEE80211_TX_RC_VHT_MCS)
+	if (rate->flags & IEEE80211_TX_RC_MCS ||
+	    rate->flags & IEEE80211_TX_RC_VHT_MCS)
+		return minstrel_ht_txstat_valid_rate(rate);
 
 	for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++)
@@ -1235,8 +1273,9 @@ minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp,
 	if (!rate_status->try_count)
 		return false;
 
-	if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
-	    rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
+	if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
+	    rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
+		return minstrel_ht_ri_txstat_valid_rate(&rate_status->rate_idx);
 
 	for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++) {
Signature · 1 line
2.54.0
#2 lore raw

net/mac80211/rc80211_minstrel_ht.c minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi, · line 1209

Quoted 6 lines · Ren Wei
net/mac80211/rc80211_minstrel_ht.c +0 -2
@@ -1205,8 +1242,9 @@ minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
        if (!rate->count)
                return false;
 
-       if (rate->flags & IEEE80211_TX_RC_MCS ||
-           rate->flags & IEEE80211_TX_RC_VHT_MCS)

Miss a line?
- return true;

net/mac80211/rc80211_minstrel_ht.c minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp, · line 1239

Quoted 11 lines
net/mac80211/rc80211_minstrel_ht.c +3 -2
+       if (rate->flags & IEEE80211_TX_RC_MCS ||
+           rate->flags & IEEE80211_TX_RC_VHT_MCS)
+               return minstrel_ht_txstat_valid_rate(rate);
 
        for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++)
@@ -1235,8 +1273,9 @@ minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp,
        if (!rate_status->try_count)
                return false;
 
-       if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
-           rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)

Miss a line?

- return true;

Quoted 8 lines
net/mac80211/rc80211_minstrel_ht.c +3 -1
+       if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
+           rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
+               return minstrel_ht_ri_txstat_valid_rate(&rate_status->rate_idx);
 
        for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++) {
--

2.54.0

author
#3 lore raw
Quoted 28 lines · Ping-Ke Shih

net/mac80211/rc80211_minstrel_ht.c minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi, · line 1209

Quoted 6 lines · Ren Wei
net/mac80211/rc80211_minstrel_ht.c +0 -2
@@ -1205,8 +1242,9 @@ minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
        if (!rate->count)
                return false;
 
-       if (rate->flags & IEEE80211_TX_RC_MCS ||
-           rate->flags & IEEE80211_TX_RC_VHT_MCS)

Miss a line?

(quoted diff) +0 -1
- 		return true;

net/mac80211/rc80211_minstrel_ht.c minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp, · line 1239

Quoted 13 lines
net/mac80211/rc80211_minstrel_ht.c +3 -2
+       if (rate->flags & IEEE80211_TX_RC_MCS ||
+           rate->flags & IEEE80211_TX_RC_VHT_MCS)
+               return minstrel_ht_txstat_valid_rate(rate);
 
        for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++)
@@ -1235,8 +1273,9 @@ minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp,
        if (!rate_status->try_count)
                return false;
 
-       if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
-           rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)

Miss a line?

(quoted diff) +0 -1
-		return true;
Quoted 8 lines
Quoted 8 lines
net/mac80211/rc80211_minstrel_ht.c +3 -1
+       if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
+           rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
+               return minstrel_ht_ri_txstat_valid_rate(&rate_status->rate_idx);
 
        for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++) {
--

2.54.0

Yes, you're right, and I'm very sorry about this.

After generating the patch, we adjusted this part after finding an issue, but I made a mistake in that follow-up change and ended up changing it incorrectly here.

What should have been replaced in both places was the old return true; line with the helper-based return.

I'll fix it in the next revision. Thank you for catching this, and sorry for the trouble.