mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tristan Madani <tristmd@gmail.com>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tristan Madani <tristan@talencesecurity.com>,
	stable@vger.kernel.org
Subject: [PATCH wireless] wifi: rtlwifi: fix OOB reads in IE parsing functions
Date: Fri,  4 Sep 2026 08:49:40 +0000	[thread overview]
Message-ID: <20260904084940.3885379-1-tristmd@gmail.com> (raw)

From: Tristan Madani <tristan@talencesecurity.com>

rtl_find_ie() and rtl_find_221_ie() iterate over information elements
in beacon frames using a loop condition of `while (pos < end)`.  When
only one byte remains (pos == end - 1), the loop body accesses pos[1]
which reads one byte beyond the validated buffer boundary.

In rtl_find_ie(), pos[1] is read in the bounds check expression
`pos + 2 + pos[1] > end` before the result of that check can prevent
the access.

In rtl_find_221_ie(), the situation is worse: when the last byte
happens to be 0xDD (221, vendor-specific IE), the code accesses
pos[1] for the length, pos[2] for the data pointer, and passes both to
rtl_chk_vendor_ouisub() which performs memcmp() on the out-of-bounds
data.  The bounds check `pos + 2 + pos[1] > end` only appears after the
vendor IE has already been fully processed.

Fix both functions by tightening the loop condition to
`while (pos + 2 <= end)`, which ensures that at least the IE id (pos[0])
and length (pos[1]) bytes are within bounds before any access.
Additionally, in rtl_find_221_ie(), move the full IE bounds check before
the vendor-specific processing to prevent accessing IE data that extends
past the buffer.

Fixes: acd48572c396 ("rtlwifi: Change base routines for addition of rtl8192se and rtl8192de")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
 drivers/net/wireless/realtek/rtlwifi/base.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c b/drivers/net/wireless/realtek/rtlwifi/base.c
index 9e98c01bb90e6..9671b9247b571 100644
--- a/drivers/net/wireless/realtek/rtlwifi/base.c
+++ b/drivers/net/wireless/realtek/rtlwifi/base.c
@@ -2373,7 +2373,7 @@ u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
 
 	pos = (u8 *)mgmt->u.beacon.variable;
 	end = data + len;
-	while (pos < end) {
+	while (pos + 2 <= end) {
 		if (pos + 2 + pos[1] > end)
 			return NULL;
 
@@ -2597,17 +2597,17 @@ static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
 
 	pos = (u8 *)mgmt->u.beacon.variable;
 	end = data + len;
-	while (pos < end) {
-		if (pos[0] == 221) {
+	while (pos + 2 <= end) {
+		if (pos + 2 + pos[1] > end)
+			return false;
+
+		if (pos[0] == 221 && pos[1] >= 3) {
 			vendor_ie.length = pos[1];
 			vendor_ie.octet = &pos[2];
 			if (rtl_chk_vendor_ouisub(hw, vendor_ie))
 				return true;
 		}
 
-		if (pos + 2 + pos[1] > end)
-			return false;
-
 		pos += 2 + pos[1];
 	}
 	return false;
-- 
2.47.3


                 reply	other threads:[~2026-09-04  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260904084940.3885379-1-tristmd@gmail.com \
    --to=tristmd@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    --cc=stable@vger.kernel.org \
    --cc=tristan@talencesecurity.com \
    /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

all inboxes | Powered by JetHome®