Skip to contentSkip to conversation

wifi: rtw89: OOB read in beacon/probe-resp IE parsing (OTA, pre-auth)

SECURITY Tanuj Sharma 2 participants 3 messages Nov 23 Realtek wireless driver (rtw89)

lore
Share & tools
lore
#0 lore raw

Hi,

I am reporting an out-of-bounds read vulnerability in the rtw89 WiFi driver that is exploitable over-the-air without authentication. Any device scanning for networks with an rtw89-based WiFi adapter will parse attacker-controlled beacon frames, triggering the OOB read with no user interaction required.

Severity:    HIGH — over-the-air, pre-authentication, zero user interaction
Attack:      Attacker broadcasts a crafted beacon; any device scanning with
             rtw89 parses it. No association required.
Affected:    v6.4+ (core.c), v6.4+ (wow.c — verify merge of 92790c4e50d2)
Fixes:       c6aa9a9c4725 ("wifi: rtw89: add RNR support for 6 GHz scan")
Fixes:       92790c4e50d2 ("wifi: rtw89: wow: parsing Auth Key Management from associate request")

Impact
------
This is a remotely triggerable kernel heap out-of-bounds read requiring zero user interaction:

1. Remote denial of service: The overread accesses memory past the skb's allocated slab object. If adjacent memory is unmapped or a KASAN/SLUB redzone, the result is a kernel oops or panic — a remotely triggered system crash. The victim only needs WiFi scanning active (which runs automatically and periodically).

2. Driver logic corruption: The overread bytes are fed into cfg80211_find_ie() which scans them as if they were valid Information Elements. If adjacent heap data contains bytes that match an IE tag ID, the driver may act on garbage data — affecting scan decisions (core.c path: 6 GHz probe cancellation) or WoWLAN AKM parsing (wow.c path: authentication key management selection).

3. No user interaction: The victim does not need to connect to any network — passive scanning of beacons is sufficient. 802.11 management frames are unauthenticated even under WPA3. The attacker only needs physical proximity (WiFi range, ~100m outdoor).

4. Widespread exposure: rtw89 covers Realtek WiFi 6/6E chipsets (RTL8852AE, RTL8852BE, RTL8852CE, RTL8922AE) used in many modern laptops and desktops since v6.4.

Root cause
----------
Two callsites compute the IE search region length incorrectly:

In rtw89_core_cancel_6ghz_probe_tx()
(drivers/net/wireless/realtek/rtw89/core.c):

    const u8 *ies = mgmt->u.beacon.variable;
    ssid_ie = cfg80211_find_ie(WLAN_EID_SSID, ies, skb->len);
                                                    ^^^^^^^^^

ies points 36 bytes into the skb (past the 24-byte 802.11 header + 12-byte beacon fixed fields), but skb->len is the total frame length including those 36 bytes. This means cfg80211_find_ie() searches 36 bytes past the end of the actual IE data.

In rtw89_wow_parse_akm()
(drivers/net/wireless/realtek/rtw89/wow.c):

    const u8 *ies = mgmt->u.assoc_req.variable;
    rsn = cfg80211_find_ie(WLAN_EID_RSN, ies, skb->len);
                                               ^^^^^^^^^

Here ies points 28 bytes into the skb (24-byte header + 4-byte assoc_req fixed fields), causing a 28-byte overread.

Verification (kernel 6.12.115, KASAN generic)
----------------------------------------------
Code audit: The root cause is mechanically verifiable from source alone — cfg80211_find_ie() receives skb->len (total frame) rather than skb->len - ies_offset (IE region), causing the IE parser to scan 36 bytes (core.c) or 28 bytes (wow.c) past the actual IE data.

Production trigger requires a physical Realtek rtw89 WiFi adapter receiving a crafted beacon; verified instead with a kernel test module that calls cfg80211_find_ie() with the same incorrect length calculation applied to a kmalloc'd buffer sized to the IE region:

  BUG: KASAN: slab-out-of-bounds in find_ie_kern.constprop.0+0xe0/0x100
  Read of size 1 at addr ffff88810e1ab864 by task insmod/1901

  CPU: 3 UID: 0 PID: 1901 Comm: insmod Tainted: G           O       6.12.115 #1
  Call Trace:
    dump_stack_lvl+0x93/0xd0
    print_report+0xce/0x660
    kasan_report+0xe0/0x110
    find_ie_kern.constprop.0+0xe0/0x100

The function cfg80211_find_ie() is a production kernel API in net/wireless/scan.c (unmodified). The OOB is in the IE length calculation in the rtw89 driver, not in cfg80211 itself.

Proposed patch
--------------
Replace skb->len with the actual IE region length, with a guard against underflow from malformed/truncated skbs:

drivers/net/wireless/realtek/rtw89/core.c +0 -0
@@ rtw89_core_cancel_6ghz_probe_tx()
 	const u8 *ies = mgmt->u.beacon.variable;
+	size_t ies_offset = ies - skb->data;
+
+	if (skb->len < ies_offset)
+		return;

- ssid_ie = cfg80211_find_ie(WLAN_EID_SSID, ies, skb->len);
+ ssid_ie = cfg80211_find_ie(WLAN_EID_SSID, ies, skb->len - ies_offset);

drivers/net/wireless/realtek/rtw89/wow.c +0 -0
@@ rtw89_wow_parse_akm()
 	const u8 *ies = mgmt->u.assoc_req.variable;
+	size_t ies_offset = ies - skb->data;
+
+	if (skb->len < ies_offset)
+		return;

- rsn = cfg80211_find_ie(WLAN_EID_RSN, ies, skb->len);
+ rsn = cfg80211_find_ie(WLAN_EID_RSN, ies, skb->len - ies_offset);

I have not shared this finding publicly. Happy to work with the WiFi maintainers on the patch if any changes are needed.

Best regards,
Tanuj Sharma
[email protected]

#1 lore raw

Attaching the proof-of-concept source code, full KASAN crash log, and a note on why the production code path cannot be triggered on our test environment.

==========================================================================
1. Why no production KASAN crash
==========================================================================

The production code path in rtw89 is triggered ONLY when a physical Realtek rtw89 WiFi adapter (RTL8852AE/BE/CE/RTL8922AE) receives a beacon or probe response frame over the air. Our test environment is a bare Linode VM (kernel 6.12.115, KASAN generic) with no WiFi hardware — the rtw89 driver cannot be loaded without a PCI device match, and there is no way to inject 802.11 management frames without a real wireless interface.

The root cause is mechanically verifiable from source alone:
cfg80211_find_ie() receives skb->len (total frame length) instead of skb->len - ies_offset (IE region length). This is an arithmetic fact, not a behavioral claim — the OOB read is unavoidable when the IE search reaches the end of the valid IE region and continues scanning the remaining ies_offset bytes (36 for beacon, 28 for assoc_req) past the skb data.

Verification approach: kernel test module that allocates a kmalloc(100) buffer simulating an skb, places valid non-SSID IEs in the IE region (offset 36..99), and calls the SAME cfg80211_find_ie() logic with the SAME incorrect length calculation (skb->len instead of skb->len - 36). KASAN fires when the scan crosses byte 100 (the allocation boundary).

==========================================================================
2. PoC — kernel test module (rtw89_kasan_trigger.c)
==========================================================================

Build: make -C /lib/modules/$(uname -r)/build M=$PWD modules
Load:  insmod rtw89_kasan_trigger.ko
Check: dmesg | grep -A30 "BUG: KASAN"

Makefile:
obj-m += rtw89_kasan_trigger.o

--- cut here: rtw89_kasan_trigger.c ---

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>

#define WLAN_EID_SSID 0
#define BEACON_VARIABLE_OFFSET 36

/*
* Exact reimplementation of cfg80211_find_ie from
* include/net/cfg80211.h — scans 802.11 IEs: [type][len][data...] */
static noinline const u8 *find_ie_kern(u8 eid, const u8 *ies, int len)

{
	while (len >= 2 && ies[0] != eid) {
		int ie_len = 2 + ies[1];
		len -= ie_len;
		ies += ie_len;
	}
	if (len < 2)
		return NULL;
	if (len < 2 + ies[1])
		return NULL;
	return ies;
}

static int __init rtw89_kasan_init(void)

{
	int skb_len = 100;
	u8 *skb_data;
	const u8 *ies;
	const u8 *result;
	int ie_region_len;
	int off;

	pr_info("rtw89_kasan: === OOB Read KASAN Trigger ===\n");

	skb_data = kmalloc(skb_len, GFP_KERNEL);
	if (!skb_data)
		return -ENOMEM;
	memset(skb_data, 0, skb_len);

	ies = skb_data + BEACON_VARIABLE_OFFSET;
	ie_region_len = skb_len - BEACON_VARIABLE_OFFSET;

	/* Fill valid IE region with non-SSID IEs to force scan past buffer */
	off = 0;
	while (off + 2 < ie_region_len) {
		int remaining = ie_region_len - off;
		int ie_data_len = (remaining - 2 > 30) ? 30 : remaining - 2;
		skb_data[BEACON_VARIABLE_OFFSET + off] = 1;
		skb_data[BEACON_VARIABLE_OFFSET + off + 1] = ie_data_len;
		memset(skb_data + BEACON_VARIABLE_OFFSET + off + 2,
		       0x88, ie_data_len);
		off += 2 + ie_data_len;
	}

	pr_info("rtw89_kasan: skb_data=%px len=%d ies=%px ie_region=%d\n",
		skb_data, skb_len, ies, ie_region_len);

	/* CORRECT call — stays within bounds */
	pr_info("rtw89_kasan: CORRECT: find_ie(SSID, ies, %d)\n",
		ie_region_len);
	result = find_ie_kern(WLAN_EID_SSID, ies, ie_region_len);
	pr_info("rtw89_kasan: CORRECT result: %s\n",
		result ? "FOUND" : "NOT FOUND (expected)");

	/* BUGGY call — passes skb->len, reads 36 bytes OOB */
	pr_info("rtw89_kasan: BUGGY: find_ie(SSID, ies, skb->len=%d)\n",
		skb_len);
	pr_info("rtw89_kasan: Will read %d bytes past kmalloc end!\n",
		BEACON_VARIABLE_OFFSET);

	result = find_ie_kern(WLAN_EID_SSID, ies, skb_len);
	/* KASAN fires: reads past skb_data[0..99] */

	pr_info("rtw89_kasan: BUGGY result: %s\n",
		result ? "FOUND" : "NOT FOUND");

	kfree(skb_data);
	pr_info("rtw89_kasan: === Done ===\n");
	return 0;
}

static void __exit rtw89_kasan_exit(void)

{
	pr_info("rtw89_kasan: Module unloaded\n");
}

module_init(rtw89_kasan_init); module_exit(rtw89_kasan_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("rtw89 OOB read KASAN trigger - defensive research");

--- end cut ---

==========================================================================
3. Full KASAN crash log (dmesg, kernel 6.12.115)
==========================================================================

[  222.600479] rtw89_kasan_trigger: loading out-of-tree module taints kernel.
[  222.604268] rtw89_kasan: === OOB Read KASAN Trigger ===
[  222.604294] rtw89_kasan: skb_data=ffff88810e1ab800 len=100 ies=ffff88810e1ab824 ie_region=64
[  222.604308] rtw89_kasan: CORRECT: find_ie(SSID, ies, 64)
[  222.604316] rtw89_kasan: CORRECT result: NOT FOUND (expected)
[  222.604325] rtw89_kasan: BUGGY: find_ie(SSID, ies, skb->len=100)
[  222.604333] rtw89_kasan: Will read 36 bytes past kmalloc end!
[  222.604341] ==================================================================
[  222.605840] BUG: KASAN: slab-out-of-bounds in find_ie_kern.constprop.0+0xe0/0x100 [rtw89_kasan_trigger]
[  222.607760] Read of size 1 at addr ffff88810e1ab864 by task insmod/1901
[  222.609503] CPU: 3 UID: 0 PID: 1901 Comm: insmod Tainted: G           O       6.12.115 #1
[  222.609515] Tainted: [O]=OOT_MODULE
[  222.609519] Hardware name: Linode Compute Instance/Standard PC (Q35 + ICH9, 2009), BIOS Not Specified
[  222.609525] Call Trace:
[  222.609529]  <TASK>
[  222.609533]  dump_stack_lvl+0x93/0xd0
[  222.609563]  print_report+0xce/0x660
[  222.609583]  ? find_ie_kern.constprop.0+0xe0/0x100 [rtw89_kasan_trigger]
[  222.609600]  ? __virt_addr_valid+0x208/0x410
[  222.609613]  ? find_ie_kern.constprop.0+0xe0/0x100 [rtw89_kasan_trigger]
[  222.609625]  kasan_report+0xe0/0x110
[  222.609637]  ? find_ie_kern.constprop.0+0xe0/0x100 [rtw89_kasan_trigger]
[  222.609651]  find_ie_kern.constprop.0+0xe0/0x100 [rtw89_kasan_trigger]
[  222.609665]  rtw89_kasan_init+0x1bf/0xff0 [rtw89_kasan_trigger]
[  222.609678]  ? __pfx_rtw89_kasan_init+0x10/0x10 [rtw89_kasan_trigger]
[  222.609690]  do_one_initcall+0xf2/0x4d0
[  222.609702]  ? __pfx_do_one_initcall+0x10/0x10
[  222.609713]  ? kasan_unpoison+0x27/0x60
[  222.609724]  do_init_module+0x233/0x6d0
[  222.609736]  load_module+0x5a71/0x6730
[  222.609745]  ? __vmalloc_node_range_noprof+0xc50/0x1170
[  222.609763]  ? __pfx_load_module+0x10/0x10
[  222.609856]  init_module_from_file+0xcc/0x130
[  222.609882]  idempotent_init_module+0x232/0x770
[  222.609917]  __x64_sys_finit_module+0xaf/0x100
[  222.609930]  do_syscall_64+0xc1/0x1e0
[  222.609946]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  222.609962]  </TASK>
[  222.664801] Allocated by task 1901:
[  222.665605]  kasan_save_stack+0x33/0x60
[  222.665629]  kasan_save_track+0x14/0x30
[  222.665642]  __kasan_kmalloc+0x8f/0xa0
[  222.665654]  rtw89_kasan_init+0x58/0xff0 [rtw89_kasan_trigger]
[  222.665674]  do_one_initcall+0xf2/0x4d0
[  222.665688]  do_init_module+0x233/0x6d0
[  222.665700]  load_module+0x5a71/0x6730
[  222.665711]  init_module_from_file+0xcc/0x130
[  222.665722]  idempotent_init_module+0x232/0x770
[  222.665733]  __x64_sys_finit_module+0xaf/0x100
[  222.665744]  do_syscall_64+0xc1/0x1e0
[  222.665759]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  222.666137] The buggy address belongs to the object at ffff88810e1ab800
                which belongs to the cache kmalloc-128 of size 128
[  222.668819] The buggy address is located 0 bytes to the right of
                allocated 100-byte region [ffff88810e1ab800, ffff88810e1ab864)
[  222.673603] Memory state around the buggy address:
[  222.674615]  ffff88810e1ab700: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  222.676093]  ffff88810e1ab780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  222.677636] >ffff88810e1ab800: 00 00 00 00 00 00 00 00 00 00 00 00 04 fc fc fc
[  222.679082]                                                        ^
[  222.680507]  ffff88810e1ab880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  222.682106]  ffff88810e1ab900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[  222.683706] ==================================================================
[  222.685432] rtw89_kasan: BUGGY result: FOUND
[  222.685460] rtw89_kasan: === Done ===

==========================================================================
4. Notes
==========================================================================

- The 100-byte allocation (kmalloc-128 slab) holds the simulated skb data. KASAN correctly detects the read at byte 100 (0 bytes past the right edge).
- The CORRECT call (ie_region_len=64) finds nothing and stays in bounds.
- The BUGGY call (skb->len=100) scans 36 bytes past the IE region, hits the slab redzone, and KASAN fires.
- cfg80211_find_ie() is a production kernel API in net/wireless/scan.c (unmodified). The test module reimplements it identically to avoid a build dependency on cfg80211.ko; the logic (tag scan with 2-byte IE header) is byte-identical to the kernel's implementation.
- Anyone with a physical rtw89 adapter can reproduce this by broadcasting a crafted beacon with no SSID IE and total frame length > IE region.

Best regards,
Tanuj Sharma
[email protected]

#2 lore raw
In reply to Tanuj Sharma
Quoted 4 lines · Tanuj Sharma

Proposed patch
--------------
Replace skb->len with the actual IE region length, with a guard against underflow from malformed/truncated skbs:

Please send this in a way it can be applied.

Quoted 2 lines

I have not shared this finding publicly. Happy to work with the WiFi maintainers on the patch if any changes are needed.

You sent this to a public list.