* [PATCH] wifi: rtw89: fix OOB read past firmware buffer when duplicating elements
@ 2026-11-22 0:06 Falconet3
2026-11-22 1:31 ` Ping-Ke Shih
0 siblings, 1 reply; 2+ messages in thread
From: Falconet3 @ 2026-11-22 0:06 UTC (permalink / raw)
To: pkshih; +Cc: linux-wireless, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 169 bytes --]
Fix for an OOB read (up to 31 bytes past the firmware buffer) introduced in v7.4-rc1 by the fw-element copy-on-parse rework. Patch attached, applies to v7.4-rc3. Thanks!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-wifi-rtw89-fix-OOB-read-in-fw-element-dup.patch --]
[-- Type: text/x-patch; name=0001-wifi-rtw89-fix-OOB-read-in-fw-element-dup.patch, Size: 2685 bytes --]
From: Falconet3 <Falconet3@proton.me>
Date: Sat, 21 Nov 2026 21:00:00 +0000
Subject: [PATCH] wifi: rtw89: fix OOB read past firmware buffer when duplicating elements
Since v7.4-rc1, rtw89 copies firmware elements at parse time so the
struct firmware can be released after probe
(rtw89_fw_elem_dup_if_needed(), fw.c:168). The copy length is
sizeof(*elm) + le32_to_cpu(elm->size) (the element header is 32 bytes,
fw.h:4646), but the element walk in __rtw89_fw_recognize_elements()
only validates "offset + elm_size < firmware->size" (fw.c:1678),
omitting the header size.
A crafted firmware element with offset + elm_size == firmware->size - 1
therefore passes the check, and devm_kmemdup()/vmalloc+memcpy in
__rtw89_fw_elem_dup_if_needed() (fw.c:141-160, called from fw.c:1361,
1417, 1524, 1536, 1562) reads up to sizeof(struct rtw89_fw_element_hdr)-1
= 31 bytes past the end of firmware->data.
Impact: heap/vmalloc OOB read of up to 31 bytes at driver probe,
copied into a persistent devm_ buffer; on exact-size vmalloc firmware
buffers the read can hit the guard page (probe-time oops/DoS).
Threat model: malicious/replaced firmware file (root or supply chain).
Affects v7.4-rc1..v7.4-rc3 only (in v7.3.5 and earlier the handlers
stored pointers into the firmware instead of copying, fw.c:1346).
Fix the walk to validate header + body, overflow-safe.
Fix was verified with git apply --check against v7.4-rc3; not
build-tested and no reproducer available in this environment.
Fixes: FILL-IN-SHA ("wifi: rtw89: ...")
Assisted-by: LLM Mistral Vibe
Signed-off-by: Falconet3 <Falconet3@proton.me>
---
drivers/net/wireless/realtek/rtw89/fw.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 0000000..0000000 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -1668,6 +1668,7 @@ static int __rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev,
const struct rtw89_fw_element_handler *handler;
const struct rtw89_fw_element_hdr *hdr;
u32 elm_size;
u32 elem_id;
+ u32 end;
int ret;
@@ -1674,8 +1675,10 @@ static int __rtw89_fw_recognize_elements(struct rtw89_dev *rtwdev,
while (offset + sizeof(*hdr) < firmware->size) {
hdr = (const struct rtw89_fw_element_hdr *)(firmware->data + offset);
elm_size = le32_to_cpu(hdr->size);
- if (offset + elm_size >= firmware->size) {
+ if (check_add_overflow(offset, (u32)sizeof(*hdr), &end) ||
+ check_add_overflow(end, elm_size, &end) ||
+ end > firmware->size) {
rtw89_warn(rtwdev, "firmware element size exceeds\n");
break;
}
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 1:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 0:06 [PATCH] wifi: rtw89: fix OOB read past firmware buffer when duplicating elements Falconet3
2026-11-22 1:31 ` 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
all inboxes | Powered by JetHome®