[PATCH wireless 3/3] wifi: mwifiex: validate ext scan event envelope and TLV lengths

From: Elkin Cruz

Date: Wed Nov 25 2026 - 16:02:06 EST


In mwifiex_handle_event_ext_scan_report(), event_scan is cast from buf
without first verifying that adapter->event_skb contains at least
sizeof(*event_scan) bytes, and scan_resp_size is not validated against
the remaining event buffer length before dumping memory.

Additionally, under TLV_TYPE_BSS_SCAN_INFO, scan_info_tlv was assigned
before checking whether the TLV length matches the expected structure
size, causing invalid pointers to be retained on short TLVs.

Validate the event_skb length and scan_resp_size upfront, and verify the
TLV size before assigning scan_info_tlv. Break out of the switch on a
malformed TLV_TYPE_BSS_SCAN_INFO so the loop skips that TLV while
keeping bytes_left accounting consistent.

Fixes: 21f58d200388 ("mwifiex: implement extended scan feature")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---
drivers/net/wireless/marvell/mwifiex/scan.c | 27 ++++++++++++++-------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
index 53aa16c1df33..52543532367b 100644
--- a/drivers/net/wireless/marvell/mwifiex/scan.c
+++ b/drivers/net/wireless/marvell/mwifiex/scan.c
@@ -2627,9 +2627,21 @@ int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
u64 fw_tsf = 0;
s32 rssi = 0;
struct mwifiex_event_scan_result *event_scan = buf;
- u8 num_of_set = event_scan->num_of_set;
- u8 *scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
- u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
+ u8 num_of_set;
+ u8 *scan_resp;
+ u16 scan_resp_size;
+
+ if (adapter->event_skb->len < sizeof(*event_scan))
+ return -EINVAL;
+
+ num_of_set = event_scan->num_of_set;
+ scan_resp = buf + sizeof(struct mwifiex_event_scan_result);
+ scan_resp_size = le16_to_cpu(event_scan->buf_size);
+
+ if (scan_resp_size > adapter->event_skb->len - sizeof(*event_scan)) {
+ ret = -EINVAL;
+ goto check_next_scan;
+ }

if (num_of_set > MWIFIEX_MAX_AP) {
mwifiex_dbg(adapter, ERROR,
@@ -2690,14 +2702,11 @@ int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
}
switch (type) {
case TLV_TYPE_BSS_SCAN_INFO:
+ if (len != sizeof(struct mwifiex_ie_types_bss_scan_info) -
+ sizeof(struct mwifiex_ie_types_header))
+ break;
scan_info_tlv =
(struct mwifiex_ie_types_bss_scan_info *)tlv;
- if (len !=
- sizeof(struct mwifiex_ie_types_bss_scan_info) -
- sizeof(struct mwifiex_ie_types_header)) {
- bytes_left_for_tlv = 0;
- continue;
- }
break;
default:
break;
--
2.56.1.839.g22a8290db9-goog