* [PATCH wireless v2] wifi: nxpwifi: bound the pairwise-cipher OUI walk to the IE length
@ 2026-11-20 21:28 Paulneja
0 siblings, 0 replies; only message in thread
From: Paulneja @ 2026-11-20 21:28 UTC (permalink / raw)
To: Jeff Chen, Johannes Berg
Cc: Francesco Dolcini, linux-wireless, linux-kernel, stable
nxpwifi_search_oui_in_ie() walks as many 4-byte cipher suites as the
pairwise count in the RSN or WPA element of a beacon says, without
checking the count against the element length. An AP can send a short
element with a large count and make the walk read up to 1020 bytes past
the end of the kmemdup()ed beacon buffer.
Pass the number of element bytes available at the suite list and reject
a count that does not fit, as commit e667aee1c192 ("wifi: mwifiex: bound
the pairwise-cipher OUI walk to the IE length") did for mwifiex.
Fixes: 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")
Cc: stable@vger.kernel.org
Signed-off-by: Paulneja <paulnejacontacto@gmail.com>
---
Notes:
v2: shortened the commit message and dropped the Assisted-by tag, as Jeff
asked. No code change.
An LLM was used to locate the bug and to draft the patch. I reviewed it by
hand against struct ie_body and struct ieee80211_vendor_ie and against the
mwifiex fix.
Testing: no IW61x hardware here. The three functions were run verbatim in a
userspace harness under AddressSanitizer with a short RSN element and a
pairwise count of 255. It reports a heap-buffer-overflow read before the
patch and is clean after it. scan.o builds without warnings with W=1.
drivers/net/wireless/nxp/nxpwifi/scan.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/nxp/nxpwifi/scan.c b/drivers/net/wireless/nxp/nxpwifi/scan.c
index 4eeba6700aa7..33779e21336b 100644
--- a/drivers/net/wireless/nxp/nxpwifi/scan.c
+++ b/drivers/net/wireless/nxp/nxpwifi/scan.c
@@ -79,12 +79,20 @@ _dbg_security_flags(int log_level, const char *func, const char *desc,
/* Parse a WPA/RSN element and check whether its PTK list contains the OUI */
static u8
-nxpwifi_search_oui_in_ie(struct ie_body *iebody, u8 *oui)
+nxpwifi_search_oui_in_ie(struct ie_body *iebody, u8 *oui, int ie_len)
{
+ const size_t ptk_body_offset = offsetof(struct ie_body, ptk_body);
u8 count;
+ /* ie_len is the number of element bytes available at iebody */
+ if (ie_len < 0 || (size_t)ie_len < ptk_body_offset)
+ return NXPWIFI_OUI_NOT_PRESENT;
+
count = iebody->ptk_cnt[0];
+ if (ptk_body_offset + count * sizeof(iebody->ptk_body) > (size_t)ie_len)
+ return NXPWIFI_OUI_NOT_PRESENT;
+
/*
* PTK may contain multiple OUIs; iterate through the list and compare
* each one
@@ -113,10 +121,13 @@ nxpwifi_is_rsn_oui_present(struct nxpwifi_bssdescriptor *bss_desc,
__be32 oui = cpu_to_be32(cipher);
if (bss_desc->bcn_rsn_ie) {
+ int ie_len = (int)bss_desc->bcn_rsn_ie->datalen -
+ RSN_GTK_OUI_OFFSET;
+
iebody = (struct ie_body *)
(((u8 *)bss_desc->bcn_rsn_ie->data) +
RSN_GTK_OUI_OFFSET);
- ret = nxpwifi_search_oui_in_ie(iebody, (u8 *)&oui);
+ ret = nxpwifi_search_oui_in_ie(iebody, (u8 *)&oui, ie_len);
if (ret)
return ret;
}
@@ -132,9 +143,15 @@ nxpwifi_is_wpa_oui_present(struct nxpwifi_bssdescriptor *bss_desc, u32 cipher)
__be32 oui = cpu_to_be32(cipher);
if (bss_desc->bcn_wpa_ie) {
+ /* data[] starts after the OUI and OUI type */
+ int ie_len = (int)bss_desc->bcn_wpa_ie->vend_hdr.len -
+ (int)sizeof(bss_desc->bcn_wpa_ie->vend_hdr.oui) -
+ (int)sizeof(bss_desc->bcn_wpa_ie->vend_hdr.oui_type) -
+ WPA_GTK_OUI_OFFSET;
+
iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +
WPA_GTK_OUI_OFFSET);
- ret = nxpwifi_search_oui_in_ie(iebody, (u8 *)&oui);
+ ret = nxpwifi_search_oui_in_ie(iebody, (u8 *)&oui, ie_len);
if (ret)
return ret;
}
base-commit: dcf495789037ab78d8ddf5844239cf85d92ac5f1
--
2.56.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 21:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 21:28 [PATCH wireless v2] wifi: nxpwifi: bound the pairwise-cipher OUI walk to the IE length Paulneja
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®