Linux wireless drivers development
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Brian Norris <briannorris@chromium.org>
Cc: Francesco Dolcini <francesco@dolcini.it>,
	linux-wireless@vger.kernel.org,
	 Johannes Berg <johannes@sipsolutions.net>,
	linux-kernel@vger.kernel.org,  llvm@lists.linux.dev,
	irogers@google.com, Elkin Cruz <elkin@google.com>,
	 stable@vger.kernel.org
Subject: [PATCH wireless 3/3] wifi: mwifiex: validate ext scan event envelope and TLV lengths
Date: Wed, 25 Nov 2026 21:00:38 +0000	[thread overview]
Message-ID: <20261125210038.1277960-4-elkin@google.com> (raw)
In-Reply-To: <20261125210038.1277960-1-elkin@google.com>

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@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
 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


      parent reply	other threads:[~2026-11-25 21:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 21:00 [PATCH wireless 0/3] wifi: mwifiex: fix UAF and ext scan TLV bounds checks Elkin Cruz
2026-11-25 21:00 ` [PATCH wireless 1/3] wifi: mwifiex: fix UAF after skb_realloc_headroom() in bridged RX Elkin Cruz
2026-11-25 21:00 ` [PATCH wireless 2/3] wifi: mwifiex: check TLV header size in ext scan report Elkin Cruz
2026-11-25 21:00 ` Elkin Cruz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125210038.1277960-4-elkin@google.com \
    --to=elkin@google.com \
    --cc=briannorris@chromium.org \
    --cc=francesco@dolcini.it \
    --cc=irogers@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox