Linux wireless drivers development
 help / color / mirror / Atom feed
From: Josef Schlehofer <pepe.schlehofer@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org,
	Dylan Eskew <dylan.eskew@candelatech.com>
Subject: [PATCH iw] iw: scan: fix crash and over-reads when printing EHT capabilities
Date: Wed, 25 Nov 2026 13:47:31 +0100	[thread overview]
Message-ID: <20261125124731.97143-1-pepe.schlehofer@gmail.com> (raw)

print_eht_capability() takes the HE PHY capabilities from the HE
Capabilities element of the same scan result. Without one, he_cap is
NULL and iw crashes. The MCS fields are read straight from the element,
so a short EHT element is read past its end.

Copy the fields into zeroed buffers, as print_eht_info() does, and
treat missing HE capabilities as zero.

init_context() also reads the extension ID of an empty extension
element and keeps an HE element of any length. Skip empty extension
elements and keep only an HE element long enough to be printed.

Fixes: a6ad3f11ead1 ("iw: scan: add eht capability parsing")
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
Checked with an AddressSanitizer build that feeds print_ies() crafted
elements in exactly sized buffers. On master, an EHT element without an
HE element crashes, and a short EHT element, a one-byte HE element and
an empty extension element at the end are read past their end. With
the patch they are clean, and the output for valid elements (80, 160
and 320 MHz from an AP, 20 MHz-only STA, 30 bytes) does not change.

Without an HE element the MCS maps are now printed as if HE reported
no wider channels. I can skip them instead if you prefer.

It does not depend on my earlier patch "iw: util: fix the EHT PHY
capabilities buffer size", both apply in either order.

 scan.c |  5 ++++-
 util.c | 24 +++++++++++++-----------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/scan.c b/scan.c
index 871f72f..8208dcc 100644
--- a/scan.c
+++ b/scan.c
@@ -2524,9 +2524,12 @@ static void init_context(struct ie_context *ctx,
 			ctx->is_vht_cap = true;
 			break;
 		case EID_EXTENSION:
+			if (pos[1] < 1)
+				break;
 			switch (pos[2]) {
 			case EID_EXT_HE_CAPABILITY:
-				ctx->he_cap = pos + 3;
+				if (pos[1] - 1 >= ext_printers[EID_EXT_HE_CAPABILITY].minlen)
+					ctx->he_cap = pos + 3;
 				break;
 			}
 			break;
diff --git a/util.c b/util.c
index 1bad4ea..4a1cfcf 100644
--- a/util.c
+++ b/util.c
@@ -1982,23 +1982,25 @@ void print_uhr_info(struct nlattr *nl_iftype)
 void print_eht_capability(const uint8_t *ie, int len, const uint8_t *he_cap,
 			  bool from_ap)
 {
-	const void *mac_cap, *phy_cap, *mcs_set, *he_phy_cap;
+	__u8 mac_cap[2] = { 0 };
+	__u32 phy_cap[3] = { 0 };
+	__u8 mcs_set[19] = { 0 };	/* up to 30 bytes minus the 11 fixed ones */
+	__u16 he_phy_cap[6] = { 0 };
 	int mcs_len;
-	int i = 0;
 
-	mac_cap = &ie[i];
-	i += 2;
+	memcpy(mac_cap, ie, sizeof(mac_cap));
+	memcpy(phy_cap, &ie[2], 9);
 
-	phy_cap = &ie[i];
-	i += 9;
-
-	mcs_set = &ie[i];
-	mcs_len = len - i;
+	mcs_len = len - 11;
+	if (mcs_len > (int)sizeof(mcs_set))
+		mcs_len = sizeof(mcs_set);
+	memcpy(mcs_set, &ie[11], mcs_len);
 
-	he_phy_cap = &he_cap[6];
+	if (he_cap)
+		memcpy(&((__u8 *)he_phy_cap)[1], &he_cap[6], 11);
 
 	__print_eht_capa(NL80211_BAND_6GHZ, mac_cap, phy_cap, mcs_set, mcs_len,
-			 NULL, 0, he_phy_cap - 1, from_ap, false);
+			 NULL, 0, he_phy_cap, from_ap, false);
 }
 
 void print_he_capability(const uint8_t *ie, int len)
-- 
2.54.0 (Apple Git-157)


                 reply	other threads:[~2026-11-25 12:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125124731.97143-1-pepe.schlehofer@gmail.com \
    --to=pepe.schlehofer@gmail.com \
    --cc=dylan.eskew@candelatech.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@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