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 --- 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;