* [PATCH v2] wifi: rtlwifi: fix P2P NoA bounds check using truncated length
[not found] <d2a222a066a1419a89d1c8b2c119066a@realtek.com>
@ 2026-11-30 20:57 ` Tanuj Sharma
2026-12-01 2:59 ` Ping-Ke Shih
0 siblings, 1 reply; 2+ messages in thread
From: Tanuj Sharma @ 2026-11-30 20:57 UTC (permalink / raw)
To: pkshih, rtl8821cerfe2; +Cc: security, kvalo, linux-wireless, stable
Both rtl_p2p_noa_ie() and rtl_p2p_action_ie() parse P2P sub-elements
whose length field is 16 bits (little-endian at bytes 1-2 of each
sub-element header). The code reads the full 16-bit value into noa_len:
noa_len = le16_to_cpu(*((__le16 *)&ie[1]));
but the bounds check only uses the low byte:
if (ie + 3 + ie[1] > end)
When the high byte (ie[2]) is non-zero, the bounds check passes with a
smaller value than the actual length, allowing the inner NOA descriptor
loop to read up to 26 bytes past the validated region. Use noa_len in the
bounds check to match the actual length used for parsing.
Additionally, the while loop condition 'ie + 1 < end' only guarantees
ie[0] and ie[1] are readable, but the le16_to_cpu read accesses both
ie[1] and ie[2]. Change the condition to 'ie + 2 < end' to ensure the
full 3-byte sub-element header (attribute ID + 16-bit length) is
accessible before reading.
Cc: stable@vger.kernel.org
Fixes: 8c55dedb795b ("rtlwifi: Fix potential overflow on P2P code")
Signed-off-by: Tanuj Sharma <ertanuj96@gmail.com>
---
Changes in v2:
- Use 'ie + 2 < end' instead of 'ie + 3 <= end' for the while loop
condition to match the existing coding style (Ping-Ke Shih)
drivers/net/wireless/realtek/rtlwifi/ps.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtlwifi/ps.c b/drivers/net/wireless/realtek/rtlwifi/ps.c
index 6241e4fed4f64..807d88fc5c6bc 100644
--- a/drivers/net/wireless/realtek/rtlwifi/ps.c
+++ b/drivers/net/wireless/realtek/rtlwifi/ps.c
@@ -720,9 +720,9 @@ static void rtl_p2p_noa_ie(struct ieee80211_hw *hw, void *data,
return;
find_p2p_ie = true;
/*to find noa ie*/
- while (ie + 1 < end) {
+ while (ie + 2 < end) {
noa_len = le16_to_cpu(*((__le16 *)&ie[1]));
- if (ie + 3 + ie[1] > end)
+ if (ie + 3 + noa_len > end)
return;
if (ie[0] == 12) {
@@ -815,9 +815,9 @@ static void rtl_p2p_action_ie(struct ieee80211_hw *hw, void *data,
rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "action frame find P2P IE.\n");
/*to find noa ie*/
- while (ie + 1 < end) {
+ while (ie + 2 < end) {
noa_len = le16_to_cpu(*(__le16 *)&ie[1]);
- if (ie + 3 + ie[1] > end)
+ if (ie + 3 + noa_len > end)
return;
if (ie[0] == 12) {
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread