From: Anvik Loitongbam <permissiontogallop@gmail.com>
To: Jes Sorensen <Jes.Sorensen@gmail.com>
Cc: linux-wireless@vger.kernel.org,
Anvik Loitongbam <permissiontogallop@gmail.com>
Subject: [PATCH] wifi: rtl8xxxu: validate firmware size before parsing
Date: Sat, 21 Nov 2026 22:35:59 +0530 [thread overview]
Message-ID: <20261121170559.149274-1-permissiontogallop@gmail.com> (raw)
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;
next reply other threads:[~2026-11-21 17:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 17:05 Anvik Loitongbam [this message]
2026-11-22 3:08 ` [PATCH] wifi: rtl8xxxu: validate firmware size before parsing Ping-Ke Shih
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=20261121170559.149274-1-permissiontogallop@gmail.com \
--to=permissiontogallop@gmail.com \
--cc=Jes.Sorensen@gmail.com \
--cc=linux-wireless@vger.kernel.org \
/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