From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH rtw-next v2 3/4] wifi: rtw89: fw: check C2H event length
Date: Wed, 2 Dec 2026 17:05:06 +0800 [thread overview]
Message-ID: <20261202090507.1613331-4-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261202090507.1613331-1-maoyixie.tju@gmail.com>
Nothing checks the length field of the C2H header against the skb. If
the header claims more data than arrived, the debug prints of the LPS
report handler read up to 16 KB past the skb data, even with the debug
mask off.
Drop such events in rtw89_fw_c2h_cmd_handle(). In the LPS report
handler, check that the skb holds the counts before reading them.
Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.
v2: Check the length in rtw89_fw_c2h_cmd_handle() with unlikely()
(Ping-Ke Shih). Keep the size check in rtw89_phy_c2h_lps_rpt().
drivers/net/wireless/realtek/rtw89/fw.c | 3 +++
drivers/net/wireless/realtek/rtw89/phy.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 89559454ebe2..2eb77d4c29de 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -9701,6 +9701,9 @@ static void rtw89_fw_c2h_cmd_handle(struct rtw89_dev *rtwdev,
if (!test_bit(RTW89_FLAG_RUNNING, rtwdev->flags))
return;
+ if (unlikely(len > skb->len))
+ return;
+
switch (category) {
case RTW89_C2H_CAT_TEST:
break;
diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
index 133b591ffa7f..139f5a9abc32 100644
--- a/drivers/net/wireless/realtek/rtw89/phy.c
+++ b/drivers/net/wireless/realtek/rtw89/phy.c
@@ -3449,6 +3449,9 @@ rtw89_phy_c2h_lps_rpt(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len)
const __le16 *addr;
const u8 *info;
+ if (c2h->len < sizeof(*c2h_rpt))
+ return;
+
/* elements size of BBCR/BBMCUCR/RFCR are 6/6/10 bytes respectively */
cr_len = c2h_rpt->cnt_bbcr * 6 +
c2h_rpt->cnt_bbmcucr * 6 +
--
2.34.1
next prev parent reply other threads:[~2026-12-02 9:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:05 [PATCH rtw-next v2 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 2/4] wifi: rtw89: pci: validate hardware index of BD ring Maoyi Xie
2026-12-02 9:05 ` Maoyi Xie [this message]
2026-12-02 9:05 ` [PATCH rtw-next v2 4/4] wifi: rtw89: phy: check cur_idx of TAS power report Maoyi Xie
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=20261202090507.1613331-4-maoyixie.tju@gmail.com \
--to=maoyixie.tju@gmail.com \
--cc=linux-wireless@vger.kernel.org \
--cc=pkshih@realtek.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