[PATCH v7 1/2] staging: rtl8723bs: fix Challenge Text IE length checks in OnAuthClient() and OnAuth()

From: Alexandru Hossu

Date: Tue May 05 2026 - 17:14:16 EST


Two functions process Challenge Text IEs without verifying that the IE
length matches the 128-byte buffer:

1. OnAuthClient() shared key path (STA mode).

rtw_get_ie() returns the raw IE length from the received frame,
which can be up to 255. This length is used directly in memcpy()
into chg_txt[128] with no bounds check, allowing a heap overflow of
up to 127 bytes when a rogue AP sends an Auth seq=2 frame with a
Challenge Text IE longer than 128 bytes.

2. OnAuth() sequence 3 path (AP mode).

When a STA completes shared-key authentication, OnAuth() calls
rtw_get_ie() to find the Challenge Text IE, checks only that the
IE is present and has nonzero length, then calls
memcmp((p + 2), pstat->chg_txt, 128). If a rogue STA sends a
Challenge Text IE shorter than 128 bytes, memcmp reads past the
end of the IE payload into adjacent packet data, causing an
out-of-bounds read.

IEEE 802.11 mandates the Challenge Text element carries exactly 128
bytes of challenge data. Add len != sizeof(pmlmeinfo->chg_txt) and
ie_len != sizeof(pstat->chg_txt) guards to reject any element whose
length field does not match.

Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Alexandru Hossu <hossu.alexandru@xxxxxxxxx>
---
Changes in v7:
- No code changes from v6; dropping Reviewed-by: Dan Carpenter because
patch 2/2 changes code from the reviewed version.

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 5f00fe282d1b..dd3c94d314d8 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -802,7 +802,7 @@ unsigned int OnAuth(struct adapter *padapter, union recv_frame *precv_frame)
p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_, WLAN_EID_CHALLENGE, (int *)&ie_len,
len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);

- if (!p || ie_len <= 0) {
+ if (!p || ie_len != sizeof(pstat->chg_txt)) {
status = WLAN_STATUS_CHALLENGE_FAIL;
goto auth_fail;
}
@@ -891,7 +891,7 @@ unsigned int OnAuthClient(struct adapter *padapter, union recv_frame *precv_fram
p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, WLAN_EID_CHALLENGE, (int *)&len,
pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);

- if (!p)
+ if (!p || len != sizeof(pmlmeinfo->chg_txt))
goto authclnt_fail;

memcpy(pmlmeinfo->chg_txt, p + 2, len);
--
2.53.0