From: Alexandru Hossu <hossu.alexandru@gmail.com>
To: gregkh@linuxfoundation.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
error27@gmail.com, luka.gejak@linux.dev, stable@vger.kernel.org
Subject: [PATCH v4 2/2] staging: rtl8723bs: fix OOB reads in OnAssocRsp() IE parsing
Date: Tue, 5 May 2026 19:22:14 +0200 [thread overview]
Message-ID: <20260505172214.3650398-3-hossu.alexandru@gmail.com> (raw)
In-Reply-To: <20260505172214.3650398-1-hossu.alexandru@gmail.com>
Three out-of-bounds read paths in OnAssocRsp():
1. Missing minimum frame length check before fixed field reads.
Before entering the IE loop the function reads capability, status,
and AID from fixed offsets relative to pframe + WLAN_HDR_A3_LEN
(at offsets +0, +2, and +4 respectively, so 6 bytes total). There
is no check that pkt_len is large enough to cover these fields. A
malicious AP can send a truncated Association Response frame shorter
than WLAN_HDR_A3_LEN + 6 bytes, causing out-of-bounds reads and
loading garbage into MLME state variables.
2. IE header and payload may extend past the packet end.
The IE loop advances by pIE->length + 2 per iteration but only
guards on i < pkt_len. When the last IE has only one byte left in
the frame, the loop reads pIE->length from pframe[pkt_len], one
byte past the receive buffer. Even when the header bytes are in
bounds, pIE->length can point the data window past pkt_len, silently
passing a truncated IE to the handler functions.
3. WMM OUI comparison reads 6 bytes past a possibly short IE payload.
For WLAN_EID_VENDOR_SPECIFIC, the code calls memcmp(pIE->data,
WMM_PARA_OUI, 6) without checking that pIE->length is at least 6.
An attacker can craft a vendor-specific IE at the end of the frame
with pIE->length smaller than 6. The existing IE bounds check only
confirms the declared payload fits within pkt_len, not that it is
large enough for the 6-byte OUI comparison.
Fix all three:
- Return _FAIL immediately if pkt_len < WLAN_HDR_A3_LEN + 6.
- Add two guards in the IE loop: break if fewer than sizeof(*pIE)
bytes remain, and break if the declared IE payload extends past
pkt_len.
- Guard the WMM OUI comparison with pIE->length >= 6.
Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")
Cc: stable@vger.kernel.org
Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
---
Changes in v4:
- Add pkt_len < WLAN_HDR_A3_LEN + 6 check before reading the three
fixed fields (capability, status, AID) to prevent OOB reads from
truncated frames. Caught by sashiko review of v3.
- Add pIE->length >= 6 guard before the 6-byte WMM OUI memcmp to
prevent reading past a short IE payload. Caught by sashiko.
Changes in v2:
- Add IE header bounds check: break if i + sizeof(*pIE) > pkt_len.
- Add IE payload bounds check: break if the declared IE data extends
past pkt_len.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 5f00fe282d1b..84cc814f069c 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -1379,6 +1379,9 @@ unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame)
timer_delete_sync(&pmlmeext->link_timer);
+ if (pkt_len < WLAN_HDR_A3_LEN + 6)
+ return _FAIL;
+
/* status */
status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2));
if (status > 0) {
@@ -1400,11 +1403,16 @@ unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame)
/* to handle HT, WMM, rate adaptive, update MAC reg */
/* for not to handle the synchronous IO in the tasklet */
for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
+ if (i + sizeof(*pIE) > pkt_len)
+ break;
pIE = (struct ndis_80211_var_ie *)(pframe + i);
+ if (i + sizeof(*pIE) + pIE->length > pkt_len)
+ break;
switch (pIE->element_id) {
case WLAN_EID_VENDOR_SPECIFIC:
- if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
+ if (pIE->length >= 6 &&
+ !memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
WMM_param_handler(padapter, pIE);
break;
--
2.53.0
next prev parent reply other threads:[~2026-05-05 17:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 9:16 [PATCH v3 0/2] staging: rtl8723bs: fix OOB write in HT_caps_handler and OOB read in OnAssocRsp Alexandru Hossu
2026-04-28 9:16 ` [PATCH v3 1/2] staging: rtl8723bs: fix OOB write in HT_caps_handler() Alexandru Hossu
2026-04-28 10:17 ` Luka Gejak
2026-04-28 9:16 ` [PATCH v3 2/2] staging: rtl8723bs: fix OOB read in OnAssocRsp() IE loop Alexandru Hossu
2026-04-28 10:17 ` Luka Gejak
2026-05-04 14:13 ` [PATCH v3 0/2] staging: rtl8723bs: fix OOB write in HT_caps_handler and OOB read in OnAssocRsp Greg KH
2026-05-05 17:22 ` [PATCH v4 0/2] staging: rtl8723bs: fix OOB write and read in HT_caps_handler and OnAssocRsp Alexandru Hossu
2026-05-05 17:22 ` [PATCH v4 1/2] staging: rtl8723bs: fix OOB write and read in HT_caps_handler() Alexandru Hossu
2026-05-05 17:22 ` Alexandru Hossu [this message]
2026-05-11 12:35 ` [PATCH v4 0/2] staging: rtl8723bs: fix OOB write and read in HT_caps_handler and OnAssocRsp Greg KH
2026-05-11 12:36 ` Greg KH
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=20260505172214.3650398-3-hossu.alexandru@gmail.com \
--to=hossu.alexandru@gmail.com \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=luka.gejak@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