wifi: mwifiex: validate action frame fixed fields
Subsystems (2)
PATCH v2 1/1 wifi: mwifiex: validate action frame fixed fields
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a buffer equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category immediately after that header and, for a public action frame, reads the following action code without verifying that either field is present. A minimal frame therefore reads one or two bytes beyond the RX buffer.
Validate the header and require the category and public action-code fields before reading them. mwifiex parses the firmware four-address layout before removing addr4, so add ETH_ALEN to the standard IEEE80211_MIN_ACTION_SIZE() offsets.
---
Changes in v2:
- Add a local header check and express the action field sizes with IEEE80211_MIN_ACTION_SIZE(), accounting for the firmware layout.
drivers/net/wireless/marvell/mwifiex/util.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/marvell/mwifiex/util.c +9 -0
@@ -313,13 +313,22 @@ mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,u8 category, action_code, *addr2;struct ieee80211_hdr *ieee_hdr = (void *)payload; +if (len <sizeof (*ieee_hdr)) +return -1 ; + stype = (le16_to_cpu (ieee_hdr->frame_control) &IEEE80211_FCTL_STYPE );switch (stype) {case IEEE80211_STYPE_ACTION : +if (len <IEEE80211_MIN_ACTION_SIZE (category) +ETH_ALEN ) +return -1 ; + category = *(payload +sizeof (struct ieee80211_hdr ));switch (category) {case WLAN_CATEGORY_PUBLIC : +if (len <IEEE80211_MIN_ACTION_SIZE (action_code) +ETH_ALEN ) +return -1 ; + action_code = *(payload +sizeof (struct ieee80211_hdr ) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) {
Signature · 1 line
2.50.1 (Apple Git-155)
Francesco Dolcini
reviewerQuoted 36 lines · Zhao Li
mwifiex_process_mgmt_packet()accepts anrx_pkt_lengthas small as a four-address structieee80211_hdrplus the two-byte firmware length prefix. After stripping the prefix,mwifiex_parse_mgmt_packet()can receive a buffer equal tosizeof(struct ieee80211_hdr).For action frames, the parser reads the category immediately after that header and, for a public action frame, reads the following action code without verifying that either field is present. A minimal frame therefore reads one or two bytes beyond the RX buffer.
Validate the header and require the category and public action-code fields before reading them. mwifiex parses the firmware four-address layout before removing addr4, so add
ETH_ALENto the standardIEEE80211_MIN_ACTION_SIZE()offsets.Suggested-by Johannes Berg <[email protected]>Fixes 72e5aa8d2a6d ("mwifiex: support for parsing TDLS discovery frames")Assisted-by Codex:gpt-5Assisted-by Claude:opus-4.8Signed-off-by Zhao Li <[email protected]>---
Changes in v2:
- Add a local header check and express the action field sizes withIEEE80211_MIN_ACTION_SIZE(), accounting for the firmware layout.drivers/net/wireless/marvell/mwifiex/util.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/net/wireless/marvell/mwifiex/util.c +0
-0
drivers/net/wireless/marvell/mwifiex/util.c mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len, · line 318
Quoted 6 lines
drivers/net/wireless/marvell/mwifiex/util.c +3
-0@@ -313,13 +313,22 @@ mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,u8 category, action_code, *addr2;struct ieee80211_hdr *ieee_hdr = (void *)payload; +if (len <sizeof (*ieee_hdr)) +return -1 ; +
I am confused, why is this check needed here, and not done in mwifiex_process_mgmt_packet()?
Quoted 2 lines · Francesco Dolcini
I am confused, why is this check needed here, and not done in
mwifiex_process_mgmt_packet()?
I double-checked the arithmetic and, yes, I made a mistake. The header check is redundant while the other two checks are needed.
mwifiex_process_mgmt_packet() already validates:
if (pkt_len < sizeof(struct ieee80211_hdr) + sizeof(pkt_len)) {After subtracting sizeof(pkt_len), the len passed into mwifiex_parse_mgmt_packet() is at least sizeof(struct ieee80211_hdr). So the if (len < sizeof(*ieee_hdr)) guard is redundant.
The remaining two guards check that the category and action_code bytes are present beyond the header. Keeping these subtype-specific checks in the parser places them next to the corresponding reads.
I will drop the redundant header check and resend as v3.
Thanks,
Zhao
PATCH v3 1/1 wifi: mwifiex: validate action frame fixed fields
In reply to Zhao Limwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a buffer equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A minimal frame therefore reads one or two bytes beyond the RX buffer.
Require the category and public action-code fields before reading them. mwifiex parses the firmware four-address layout before removing addr4, so add ETH_ALEN to the standard IEEE80211_MIN_ACTION_SIZE() offsets.
---
Changes in v3:
- Drop the redundant parser-local header check; the caller already guarantees the complete four-address header after removing the two-byte firmware prefix.
Changes in v2:
- Express the action-field sizes with IEEE80211_MIN_ACTION_SIZE(), accounting for the firmware four-address layout.
--- drivers/net/wireless/marvell/mwifiex/util.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/marvell/mwifiex/util.c +6 -0
@@ -317,9 +317,15 @@ mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,switch (stype) {case IEEE80211_STYPE_ACTION : +if (len <IEEE80211_MIN_ACTION_SIZE (category) +ETH_ALEN ) +return -1 ; + category = *(payload +sizeof (struct ieee80211_hdr ));switch (category) {case WLAN_CATEGORY_PUBLIC : +if (len <IEEE80211_MIN_ACTION_SIZE (action_code) +ETH_ALEN ) +return -1 ; + action_code = *(payload +sizeof (struct ieee80211_hdr ) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) {
Signature · 1 line
2.50.1 (Apple Git-155)
Brian Norris
maintainerHi,
Quoted 14 lines · Zhao Li
mwifiex_process_mgmt_packet()accepts anrx_pkt_lengthas small as a four-address structieee80211_hdrplus the two-byte firmware length prefix. After stripping the prefix,mwifiex_parse_mgmt_packet()can receive a buffer equal tosizeof(struct ieee80211_hdr).For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A minimal frame therefore reads one or two bytes beyond the RX buffer.
Require the category and public action-code fields before reading them. mwifiex parses the firmware four-address layout before removing addr4, so add
ETH_ALENto the standardIEEE80211_MIN_ACTION_SIZE()offsets.
Quoted 9 lines
Suggested-by Johannes Berg <[email protected]>Fixes 72e5aa8d2a6d ("mwifiex: support for parsing TDLS discovery frames")Assisted-by Codex:gpt-5Assisted-by Claude:opus-4.8Signed-off-by Zhao Li <[email protected]>
I think this is another one of those cases where we're working hard to validate against the firmware-reported packet length, but we're not actually checking that the reported length fits within the real skb size (skb->len).
If you want to follow up on that, that could be worth doing in mwifiex_process_mgmt_packet().
Quoted 18 lines
---
Changes in v3:
- Drop the redundant parser-local header check; the caller already guarantees the complete four-address header after removing the two-byte firmware prefix.Changes in v2:
- Express the action-field sizes withIEEE80211_MIN_ACTION_SIZE(), accounting for the firmware four-address layout.--- drivers/net/wireless/marvell/mwifiex/util.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/net/wireless/marvell/mwifiex/util.c +0
-0
drivers/net/wireless/marvell/mwifiex/util.c mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len, · line 320
Quoted 4 lines
drivers/net/wireless/marvell/mwifiex/util.c +1
-0@@ -317,9 +317,15 @@ mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,switch (stype) {case IEEE80211_STYPE_ACTION : +if (len <IEEE80211_MIN_ACTION_SIZE (category) +ETH_ALEN )
IEEE80211_MIN_ACTION_SIZE() sorta implies we're using 'struct ieee80211_mgmt' in here. But we're using 'struct ieee80211_hdr' and the 4-address format, in fact.
That disconnect then means you have to awkwardly account for the extra address by adding ETH_ALEN.
All in all, I kinda prefer the style of v1, where you directly reference the size of the actual things we're using (sizeof(*ieee_hdr)). It has the downside of the open-coded "+ 1" and "+ 2", but that's how the existing parsing works, so IMO it's still better to match that.
(I do see Johannes suggested this in v1, but I'm not sure I agree, now that I see the result.)
drivers/net/wireless/marvell/mwifiex/util.c mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len, · line 329
Quoted 9 lines
drivers/net/wireless/marvell/mwifiex/util.c +5
-0+return -1 ; + category = *(payload +sizeof (struct ieee80211_hdr ));switch (category) {case WLAN_CATEGORY_PUBLIC : +if (len <IEEE80211_MIN_ACTION_SIZE (action_code) +ETH_ALEN ) +return -1 ; + action_code = *(payload + sizeof(struct ieee80211_hdr)
If we end up going back to 'sizeof(*ieee_hdr)' approach, I'd suggest changing this too, for consistency.
Brian
Quoted 5 lines
drivers/net/wireless/marvell/mwifiex/util.c +0
-0+ 1);if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) {Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v4 1/1 wifi: mwifiex: validate action frame fixed fields
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a frame equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A truncated frame can therefore make the parser consume up to two bytes past the firmware-declared frame length. If those bytes look like a TDLS discovery response, the malformed frame can spuriously update peer signal state.
Require the category and public action-code fields before reading them. Use sizeof(*ieee_hdr) so the checks and field accesses directly match the firmware four-address layout being parsed before address4 is removed.
---
Changes in v4:
- Match the actual four-address parser layout with sizeof(*ieee_hdr) + 1 and sizeof(*ieee_hdr) + 2, as suggested by Brian.
- Use sizeof(*ieee_hdr) consistently for the corresponding field reads.
- Audit the firmware-length containment concern: both callers reject an rx_pkt_offset plus rx_pkt_length beyond skb->len before entering this helper, so no redundant check is added here.
- Describe the out-of-frame read and possible TDLS signal-state update precisely.
Changes in v3:
- Drop the redundant parser-local header check; the caller already guarantees the complete four-address header after removing the two-byte firmware prefix.
Changes in v2:
- Express the action-field sizes with IEEE80211_MIN_ACTION_SIZE(), accounting for the firmware four-address layout.
--- drivers/net/wireless/marvell/mwifiex/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/util.c +8 -2
@@ -317,10 +317,16 @@ mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,switch (stype) {case IEEE80211_STYPE_ACTION : - category = *(payload +sizeof (struct ieee80211_hdr )); +if (len <sizeof (*ieee_hdr) +1 ) +return -1 ; + + category = *(payload +sizeof (*ieee_hdr));switch (category) {case WLAN_CATEGORY_PUBLIC : - action_code = *(payload +sizeof (struct ieee80211_hdr ) +if (len <sizeof (*ieee_hdr) +2 ) +return -1 ; + + action_code = *(payload +sizeof (*ieee_hdr) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) { addr2 = ieee_hdr->addr2;
Signature · 1 line
2.50.1 (Apple Git-155)