Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [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

* RE: [PATCH v2] wifi: rtlwifi: fix P2P NoA bounds check using truncated length
  2026-11-30 20:57 ` [PATCH v2] wifi: rtlwifi: fix P2P NoA bounds check using truncated length Tanuj Sharma
@ 2026-12-01  2:59   ` Ping-Ke Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Ping-Ke Shih @ 2026-12-01  2:59 UTC (permalink / raw)
  To: Tanuj Sharma, rtl8821cerfe2@gmail.com
  Cc: security@kernel.org, kvalo@kernel.org,
	linux-wireless@vger.kernel.org, stable@vger.kernel.org

Tanuj Sharma <ertanuj96@gmail.com> wrote:
> 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")

I think Fixes should be:

Fixes: 26634c4b1868 ("rtlwifi Modify existing bits to match vendor version 2013.02.07")

> Signed-off-by: Tanuj Sharma <ertanuj96@gmail.com>

Otherwise, looks good to me.

Acked-by: Ping-Ke Shih <pkshih@realtek.com>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01  2:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <d2a222a066a1419a89d1c8b2c119066a@realtek.com>
2026-11-30 20:57 ` [PATCH v2] wifi: rtlwifi: fix P2P NoA bounds check using truncated length Tanuj Sharma
2026-12-01  2:59   ` Ping-Ke Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox