KASAN: invalid-free in hwsim_update_pib

Status: upstream: reported C repro on 2026/11/12 17:20
Subsystems: wpan
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+8a8482d4c33cc58babb4@syzkaller.appspotmail.com
First crash: 4d00h, last: 1d12h
✨ AI-generated root cause summary:

In drivers/net/ieee802154/mac802154_hwsim.c, hwsim_del() frees the simulated hardware's physical layer information base (phy->pib) via kfree_rcu() prior to unregistering the hardware via ieee802154_unregister_hw(). During ieee802154_unregister_hw(), slave network interfaces are closed, and an ongoing scan is aborted through mac802154_slave_close() -> mac802154_abort_scan_locked() -> drv_set_channel() -> hwsim_hw_channel(). hwsim_hw_channel() accesses the already-queued phy->pib and calls hwsim_update_pib(), which invokes kfree_rcu() on the exact same PIB object a second time, causing a double-free and use-after-free.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit ddfe51b0a0f5:

Root Cause Analysis

Involved Functions, Structures, and Source Files


Bug Mechanism and Lifecycle Invariant Violation

In the IEEE 802.15.4 hardware simulator driver (mac802154_hwsim), radio state such as channel, page, and filtering parameters is held in a dynamically allocated struct hwsim_pib object referenced by phy->pib. Driver callbacks such as .set_channel (hwsim_hw_channel()), .set_promiscuous_mode (hwsim_set_promiscuous_mode()), and .set_hw_addr_filt (hwsim_hw_addr_filt()) dereference phy->pib and call hwsim_update_pib() to allocate a new PIB object and retire the old one via kfree_rcu(pib_old, rcu).

Under the driver lifecycle model, driver-private data structures accessed by device callbacks must remain valid until the core stack has finished unregistering the hardware via ieee802154_unregister_hw(phy->hw).

When deleting a radio instance via HWSIM_CMD_DEL_RADIO (hwsim_del_radio_nl() -> hwsim_del()), hwsim_del() executes the following sequence:

static void hwsim_del(struct hwsim_phy *phy)
{
	...
	pib = rcu_dereference(phy->pib);
	rcu_read_unlock();

	kfree_rcu(pib, rcu);

	ieee802154_unregister_hw(phy->hw);
	ieee802154_free_hw(phy->hw);
}
  1. Premature Free: hwsim_del() reads pib = rcu_dereference(phy->pib) and invokes kfree_rcu(pib, rcu) to enqueue the PIB object for RCU deferred freeing. Crucially, this is done before ieee802154_unregister_hw(phy->hw), and phy->pib is not updated or cleared.
  2. Synchronous Device Teardown Callback: ieee802154_unregister_hw() proceeds to call ieee802154_remove_interfaces(), which invokes unregister_netdevice(). This forces running slave interfaces to close via mac802154_slave_close().
  3. Aborting In-Progress Scan: If a scan operation is active on the interface, mac802154_slave_close() calls mac802154_abort_scan_locked() -> mac802154_scan_cleanup_locked(). To restore the radio's channel, mac802154_scan_cleanup_locked() calls drv_set_channel() -> hwsim_hw_channel().
  4. Second kfree_rcu Invocation (Double Free): hwsim_hw_channel() reads phy->pib (which still points to the PIB object currently in the RCU grace-period queue) and invokes hwsim_update_pib(). Inside hwsim_update_pib():
    pib_old = rcu_replace_pointer(phy->pib, pib,
                                  lockdep_is_held(&phy->pib_lock));
    spin_unlock_bh(&phy->pib_lock);
    kfree_rcu(pib_old, rcu);
    
    pib_old is the exact same pointer passed to kfree_rcu() in step 1. Calling kfree_rcu() / kvfree_call_rcu() on the already-queued object triggers KASAN's double-free detection in kfree_rcu_sheaf / kvfree_call_rcu.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
d9e3c0b1 repro-c Reproduced: ✅ ❓ KASAN: invalid-free in hwsim_update_pib 2026/11/11 00:04 2026/11/11 00:04 2026/11/11 01:06 d3056657
e9eb84b0 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: invalid-free in hwsim_update_pib 2026/11/08 17:04 2026/11/08 17:04 2026/11/08 17:15 5cecaf1f
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [wpan?] KASAN: invalid-free in hwsim_update_pib 0 (1) 2026/11/12 17:20
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/11/11 04:45 22m retest repro git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 793807ca13bf3072fc6d16ce6d90e9ab9beff2a5 report job log log
▶ ▼ Cause bisection attempts (1)
Created Duration User Patch Repo Result
2026/11/11 05:30 0m bisect git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git error

Sample crash report:
==================================================================
BUG: KASAN: double-free in kfree_rcu_sheaf mm/slab_common.c:1693 [inline]
BUG: KASAN: double-free in kvfree_call_rcu+0x9c/0x440 mm/slab_common.c:2056
Free of addr ffff888077e0ab80 by task syz-executor416/6057

CPU: 1 UID: 0 PID: 6057 Comm: syz-executor416 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_address_description+0x55/0x1e0 mm/kasan/report.c:378
 print_report+0x58/0x70 mm/kasan/report.c:482
 kasan_report_invalid_free+0xea/0x110 mm/kasan/report.c:557
 check_slab_allocation+0xbc/0xe0 mm/kasan/common.c:-1
 kasan_slab_pre_free include/linux/kasan.h:202 [inline]
 __kfree_rcu_sheaf+0x126/0x690 mm/slub.c:6299
 kfree_rcu_sheaf mm/slab_common.c:1693 [inline]
 kvfree_call_rcu+0x9c/0x440 mm/slab_common.c:2056
 hwsim_update_pib+0x276/0x400 drivers/net/ieee802154/mac802154_hwsim.c:119
 hwsim_hw_channel+0x178/0x2b0 drivers/net/ieee802154/mac802154_hwsim.c:131
 drv_set_channel+0xfe/0x280 net/mac802154/driver-ops.h:240
 mac802154_scan_cleanup_locked+0x116/0x280 net/mac802154/scan.c:72
 mac802154_abort_scan_locked+0xa3/0xe0 net/mac802154/scan.c:92
 mac802154_slave_close+0xc9/0x2e0 net/mac802154/iface.c:306
 __dev_close_many+0x361/0x6e0 net/core/dev.c:1836
 netif_close_many+0x249/0x660 net/core/dev.c:1862
 unregister_netdevice_many_notify+0x7aa/0x1dc0 net/core/dev.c:12729
 unregister_netdevice_many net/core/dev.c:12831 [inline]
 unregister_netdevice_queue+0x2f5/0x340 net/core/dev.c:12627
 unregister_netdevice include/linux/netdevice.h:3511 [inline]
 ieee802154_remove_interfaces+0x162/0x1a0 net/mac802154/iface.c:714
 ieee802154_unregister_hw+0x62/0xe0 net/mac802154/main.c:284
 hwsim_del+0x49c/0x500 drivers/net/ieee802154/mac802154_hwsim.c:1016
 hwsim_del_radio_nl+0x110/0x150 drivers/net/ieee802154/mac802154_hwsim.c:361
 genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114
 genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
 genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209
 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2585
 genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
 netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
 netlink_unicast+0x8ef/0xa80 net/netlink/af_netlink.c:1362
 netlink_sendmsg+0x7f0/0xb20 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
 __sock_sendmsg net/socket.c:818 [inline]
 __sys_sendto+0x408/0x5a0 net/socket.c:2283
 __do_sys_sendto net/socket.c:2290 [inline]
 __se_sys_sendto net/socket.c:2286 [inline]
 __x64_sys_sendto+0xde/0x100 net/socket.c:2286
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x00007f8868cf0b77
Code: 48 89 fa 4c 89 df e8 98 1d 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffeb08d8fe0 EFLAGS: 00000202 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 000055555ef33400 RCX: 00007f8868cf0b77
RDX: 000000000000001c RSI: 00007ffeb08d91e0 RDI: 0000000000000003
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000032
R13: 00007ffeb08d9040 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 13:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3f/0x90 mm/kasan/common.c:79
 poison_kmalloc_redzone mm/kasan/common.c:412 [inline]
 __kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:429
 kasan_kmalloc include/linux/kasan.h:267 [inline]
 __kmalloc_cache_noprof+0x31c/0x600 mm/slub.c:5678
 _kmalloc_noprof include/linux/slab.h:991 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 hwsim_update_pib+0x7e/0x400 drivers/net/ieee802154/mac802154_hwsim.c:103
 hwsim_set_promiscuous_mode+0x196/0x2e0 drivers/net/ieee802154/mac802154_hwsim.c:326
 drv_set_promiscuous_mode+0x154/0x2d0 net/mac802154/driver-ops.h:127
 drv_start+0x4db/0x1000 net/mac802154/driver-ops.h:167
 mac802154_scan_worker+0x8e6/0xe60 net/mac802154/scan.c:248
 process_one_work kernel/workqueue.c:3511 [inline]
 process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3594
 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3675
 kthread+0x38b/0x480 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Last potentially related work creation:
 kasan_save_stack+0x3e/0x60 mm/kasan/common.c:57
 __kasan_record_aux_stack+0xc5/0xe0 mm/kasan/generic.c:561
 __kfree_rcu_sheaf+0x136/0x690 mm/slub.c:6304
 kfree_rcu_sheaf mm/slab_common.c:1693 [inline]
 kvfree_call_rcu+0x9c/0x440 mm/slab_common.c:2056
 hwsim_del+0x476/0x500 drivers/net/ieee802154/mac802154_hwsim.c:1014
 hwsim_del_radio_nl+0x110/0x150 drivers/net/ieee802154/mac802154_hwsim.c:361
 genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114
 genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
 genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209
 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2585
 genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
 netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
 netlink_unicast+0x8ef/0xa80 net/netlink/af_netlink.c:1362
 netlink_sendmsg+0x7f0/0xb20 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
 __sock_sendmsg net/socket.c:818 [inline]
 __sys_sendto+0x408/0x5a0 net/socket.c:2283
 __do_sys_sendto net/socket.c:2290 [inline]
 __se_sys_sendto net/socket.c:2286 [inline]
 __x64_sys_sendto+0xde/0x100 net/socket.c:2286
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff888077e0ab80
 which belongs to the cache kmalloc-64 of size 64
The buggy address is located 0 bytes inside of
 56-byte region [ffff888077e0ab80, ffff888077e0abb8)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888077e0a000 pfn:0x77e0a
flags: 0xfff00000000200(workingset|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000200 ffff88813ff308c0 ffffea0001ee43d0 ffffea000086b9d0
raw: ffff888077e0a000 0000000000200019 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0xd2c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5010, tgid 5010 (udevd), ts 50265114608
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x1f9/0x250 mm/page_alloc.c:1880
 prep_new_page+0x22/0xb0 mm/page_alloc.c:1888
 get_page_from_freelist+0x22a1/0x22e0 mm/page_alloc.c:3970
 __alloc_frozen_pages_noprof+0x211/0x450 mm/page_alloc.c:5512
 alloc_slab_page mm/slub.c:3384 [inline]
 allocate_slab+0x7d/0x5e0 mm/slub.c:3499
 new_slab mm/slub.c:3550 [inline]
 refill_objects+0x2d5/0x350 mm/slub.c:7524
 refill_sheaf mm/slub.c:2917 [inline]
 __pcs_replace_empty_main+0x2c8/0x6c0 mm/slub.c:4809
 alloc_from_pcs mm/slub.c:4885 [inline]
 slab_alloc_node mm/slub.c:5019 [inline]
 __do_kmalloc_node mm/slub.c:5528 [inline]
 __kmalloc_noprof+0x476/0x710 mm/slub.c:5554
 _kmalloc_noprof include/linux/slab.h:995 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
 tomoyo_encode+0x2ad/0x570 security/tomoyo/realpath.c:80
 tomoyo_realpath_from_path+0x5fd/0x640 security/tomoyo/realpath.c:283
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_check_open_permission+0x229/0x470 security/tomoyo/file.c:776
 security_file_open+0xa9/0x240 security/security.c:2761
 do_dentry_open+0x495/0x1360 fs/open.c:977
 vfs_open_consume+0x4a/0x350 fs/open.c:1131
 do_open fs/namei.c:4851 [inline]
 path_openat+0x16fc/0x20f0 fs/namei.c:5016
 do_file_open+0x23e/0x4a0 fs/namei.c:5045
page last free pid 16 tgid 16 ts 50082662316 stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 __free_pages_prepare mm/page_alloc.c:1422 [inline]
 __free_frozen_pages+0xd1a/0xe10 mm/page_alloc.c:2978
 rcu_do_batch kernel/rcu/tree.c:2651 [inline]
 rcu_core+0x92e/0x1230 kernel/rcu/tree.c:2920
 handle_softirqs+0x265/0x8d0 kernel/softirq.c:669
 run_ksoftirqd+0x36/0x60 kernel/softirq.c:1133
 smpboot_thread_fn+0x5f8/0xb30 kernel/smpboot.c:162
 kthread+0x38b/0x480 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Memory state around the buggy address:
 ffff888077e0aa80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
 ffff888077e0ab00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888077e0ab80: 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc
                   ^
 ffff888077e0ac00: 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc
 ffff888077e0ac80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/11 05:07 git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 793807ca13bf 70ec0380 .config console log report C ci-upstream-linux-next-kasan-gce-root KASAN: invalid-free in hwsim_update_pib
2026/11/10 01:45 linux-next 630059a5a632 70ec0380 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: invalid-free in hwsim_update_pib
2026/11/08 17:04 linux-next ddfe51b0a0f5 5cecaf1f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: invalid-free in hwsim_update_pib
* Struck through repros no longer work on HEAD.