[PATCH] wifi: rtw89: fix OOB read past firmware buffer when duplicating elements
From: Falconet3
Date: Sat Nov 21 2026 - 19:06:32 EST
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!From: Falconet3 <Falconet3@xxxxxxxxx>
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@xxxxxxxxx>
---
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