* [PATCH] wifi: rtl8xxxu: validate firmware size before parsing
@ 2026-11-21 17:05 Anvik Loitongbam
2026-11-22 3:08 ` Ping-Ke Shih
0 siblings, 1 reply; 2+ messages in thread
From: Anvik Loitongbam @ 2026-11-21 17:05 UTC (permalink / raw)
To: Jes Sorensen; +Cc: linux-wireless, Anvik Loitongbam
rtl8xxxu_load_firmware() copies fw->size bytes and then subtracts the
fixed firmware header size from fw->size without checking that the file
is large enough. A short firmware file with a valid signature makes
fw_size wrap to a huge size_t; the revision logging then reads the
header fields out of bounds, and the download path derives an
out-of-bounds data pointer.
A 2-byte rtlwifi/rtl8192eu_nic.bin containing the 0x92c0 signature,
loaded while the driver probes a Foxin RTL8192EU (0bda:818b) passed
through to a KASAN guest, reproduces it:
BUG: KASAN: slab-out-of-bounds in rtl8xxxu_load_firmware+0x238/0x2ae
Read of size 1
...
The buggy address is located 4 bytes to the right of
allocated 2-byte region
...
kmemdup_noprof
rtl8xxxu_load_firmware
rtl8192eu_load_firmware
rtl8xxxu_probe
Reject firmware smaller than struct rtl8xxxu_firmware_header before
copying or parsing it. With this change the probe fails with -EINVAL
and KASAN reports nothing.
The issue and the initial fix were tested on a Foxin
RTL8192EU (0bda:818b) passed through to a KASAN guest.
I would be happy to provide the reproducer on request.
Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)")
Signed-off-by: Anvik Loitongbam <permissiontogallop@gmail.com>
---
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c
index 3d0c22db30a8..c85b746c8e4e 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
@@ -2124,6 +2124,11 @@ int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, const char *fw_name)
goto exit;
}
+ if (fw->size < sizeof(struct rtl8xxxu_firmware_header)) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
priv->fw_data = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!priv->fw_data) {
ret = -ENOMEM;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH] wifi: rtl8xxxu: validate firmware size before parsing
2026-11-21 17:05 [PATCH] wifi: rtl8xxxu: validate firmware size before parsing Anvik Loitongbam
@ 2026-11-22 3:08 ` Ping-Ke Shih
0 siblings, 0 replies; 2+ messages in thread
From: Ping-Ke Shih @ 2026-11-22 3:08 UTC (permalink / raw)
To: Anvik Loitongbam, Jes Sorensen; +Cc: linux-wireless@vger.kernel.org
Anvik Loitongbam <permissiontogallop@gmail.com> wrote:
> rtl8xxxu_load_firmware() copies fw->size bytes and then subtracts the
> fixed firmware header size from fw->size without checking that the file
> is large enough. A short firmware file with a valid signature makes
> fw_size wrap to a huge size_t; the revision logging then reads the
> header fields out of bounds, and the download path derives an
> out-of-bounds data pointer.
>
> A 2-byte rtlwifi/rtl8192eu_nic.bin containing the 0x92c0 signature,
It looks like you make a fake firmware to trigger KASAN?
> loaded while the driver probes a Foxin RTL8192EU (0bda:818b) passed
> through to a KASAN guest, reproduces it:
>
> BUG: KASAN: slab-out-of-bounds in rtl8xxxu_load_firmware+0x238/0x2ae
> Read of size 1
> ...
> The buggy address is located 4 bytes to the right of
> allocated 2-byte region
> ...
> kmemdup_noprof
> rtl8xxxu_load_firmware
> rtl8192eu_load_firmware
> rtl8xxxu_probe
>
> Reject firmware smaller than struct rtl8xxxu_firmware_header before
> copying or parsing it. With this change the probe fails with -EINVAL
> and KASAN reports nothing.
>
> The issue and the initial fix were tested on a Foxin
> RTL8192EU (0bda:818b) passed through to a KASAN guest.
> I would be happy to provide the reproducer on request.
>
> Fixes: 26f1fad29ad9 ("New driver: rtl8xxxu (mac80211)")
If this isn't a real case, I don't want the tag.
> Signed-off-by: Anvik Loitongbam <permissiontogallop@gmail.com>
Also, the subject has clearly pointed out the purpose of this
commit, so reduce the commit message as what it is actually needed.
Recently, we have a lot of patches to validate boundary. They are
fine to me, but I don't want much commit message, which is not
very useful.
pw-bot: cr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 3:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 17:05 [PATCH] wifi: rtl8xxxu: validate firmware size before parsing Anvik Loitongbam
2026-11-22 3:08 ` 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