KASAN: slab-use-after-free Read in kernfs_find_ns

Status: moderation: reported on 2026/11/23 15:14
Subsystems: kernfs
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+731166a269181b232095@syzkaller.appspotmail.com
First crash: 6d12h, last: 6d12h
✨ AI cause bisection: introduced by (AI job) :
commit 4e0f7b9070726a34bbd87a74e407d4cced6d49ab
Author: Parav Pandit <parav@mellanox.com>
Date: Tue Feb 26 11:56:13 2019 +0000

  RDMA/core: Implement compat device/sysfs tree in net namespace

✨ AI-generated root cause summary:

In drivers/infiniband/core/device.c, remove_one_compat_dev() unlocks device->compat_devs_mutex immediately after erasing the compat device (cdev) from the xarray, performing device_del(&cdev->dev) outside the lock. When device unregistration races with network namespace teardown (rdma_dev_exit_net), rdma_dev_exit_net() calls remove_one_compat_dev(), observes NULL from xa_erase(), and completes without waiting for device_del() to finish. Consequently, cleanup_net() frees struct net while device_del() is still executing, causing device_remove_class_symlinks() -> sysfs_delete_link() -> kernfs_ns_id() to read ns->ns_id from the freed struct net, triggering a slab-use-after-free.

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

Technical Root Cause Analysis

1. Involved Subsystems, Files, and Entities

  • Source File: drivers/infiniband/core/device.c
  • Functions: remove_one_compat_dev(), remove_compat_devs(), disable_device(), rdma_dev_exit_net(), rdma_init_coredev()
  • Structs & Fields:
    • struct ib_device (device->compat_devs, device->compat_devs_mutex)
    • struct ib_core_device (cdev->rdma_net, cdev->dev)
    • struct net (net->ns.ns_id)
    • struct kernfs_node (sd->ns)
    • struct class ib_class (ib_class.namespace, ib_class.ns_type)

2. Lifecycle and Invariants

RDMA devices support compat devices in network namespaces other than the device's primary namespace.

  • In add_one_compat_dev() (drivers/infiniband/core/device.c:993), rdma_init_coredev() associates the compat device (cdev) with the target namespace via write_pnet(&coredev->rdma_net, read_pnet(&rnet->net)). Compat devices do not increment the reference count of struct net.
  • Because cdev->dev.class = &ib_class defines .namespace = net_namespace (drivers/infiniband/core/device.c:550), sysfs directory and symlink kernfs nodes for cdev->dev store targ->sd->ns = to_ns_common(net) (&net->ns).
  • Removal of compat devices can be triggered in two paths:
    1. When an RDMA device is unregistered: __ib_unregister_device() $\rightarrow$ disable_device() $\rightarrow$ remove_compat_devs() $\rightarrow$ remove_one_compat_dev().
    2. When a network namespace exits: cleanup_net() $\rightarrow$ rdma_dev_exit_net() $\rightarrow$ remove_one_compat_dev().

Because cdev does not take a reference on struct net, the invariant requires that all sysfs nodes referencing net (cdev->dev) are fully deleted (device_del(&cdev->dev)) before rdma_dev_exit_net() returns and allows cleanup_net() to free struct net.


3. Root Cause and Trigger Mechanism

In remove_one_compat_dev() (drivers/infiniband/core/device.c:1027-1039):

static void remove_one_compat_dev(struct ib_device *device, u32 id)
{
	struct ib_core_device *cdev;

	mutex_lock(&device->compat_devs_mutex);
	cdev = xa_erase(&device->compat_devs, id);
	mutex_unlock(&device->compat_devs_mutex);
	if (cdev) {
		ib_free_port_attrs(cdev);
		device_del(&cdev->dev);
		put_device(&cdev->dev);
	}
}

remove_one_compat_dev() releases device->compat_devs_mutex immediately after erasing cdev from device->compat_devs, invoking device_del(&cdev->dev) outside the lock.

When IB device unregistration races with network namespace teardown:

  1. Device unregistration thread (e.g. nldev_dellink): Calls remove_one_compat_dev(device, rnet->id). It acquires compat_devs_mutex, erases cdev = xa_erase(&device->compat_devs, id), drops compat_devs_mutex, and enters device_del(&cdev->dev).
  2. Netns cleanup thread (cleanup_net workqueue): rdma_dev_exit_net(net) iterates over devices and invokes remove_one_compat_dev(dev, rnet->id) for the same device and namespace ID. It takes compat_devs_mutex, but xa_erase() returns NULL because the entry was already erased by the device unregistration thread. It drops compat_devs_mutex and returns immediately without synchronizing or waiting for the in-progress device_del(&cdev->dev).
  3. rdma_dev_exit_net() finishes its device iteration and returns.
  4. cleanup_net() finishes ops_exit_list(net) and calls net_complete_free(net) $\rightarrow$ kmem_cache_free(net_namespace, net), deallocating the struct net slab object.
  5. Device unregistration thread: Still executing device_del(&cdev->dev), it proceeds to device_remove_class_symlinks(&cdev->dev) $\rightarrow$ sysfs_delete_link(&sp->subsys.kobj, &dev->kobj, dev_name(dev)). In sysfs_delete_link(), ns = targ->sd->ns is retrieved from cdev->dev.kobj.sd->ns (which points to &net->ns of the now-freed struct net), and passed to kernfs_remove_by_name_ns(..., ns) $\rightarrow$ kernfs_find_ns() $\rightarrow$ kernfs_name_hash(name, ns) $\rightarrow$ kernfs_ns_id(ns).
  6. kernfs_ns_id() dereferences ns->ns_id (offset 488 within the freed struct net), causing the reported slab use-after-free read.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
c08ebd8f repro-c Reproduced: ✅ ❓ KASAN: slab-use-after-free Read in kernfs_find_ns 2026/11/19 17:07 2026/11/19 17:07 2026/11/19 18:36 229865fb
da36c11b bisect-cause IsRelease: ❌ ❓ KASAN: slab-use-after-free Read in kernfs_find_ns 2026/11/19 15:10 2026/11/19 15:10 2026/11/19 16:00 9aa3e232
b6063d36 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: slab-use-after-free Read in kernfs_find_ns 2026/11/19 14:23 2026/11/19 14:23 2026/11/19 15:05 2006bdcc
▶ ▼ Similar bugs (7)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream general protection fault in kernfs_find_ns kernfs 2 2 1820d 1815d 0/29 auto-closed as invalid on 2022/03/29 00:22
linux-5.15 KASAN: slab-out-of-bounds Read in kernfs_find_ns 17 2 399d 407d 0/3 auto-obsoleted due to no activity on 2026/01/28 00:39
android-54 general protection fault in kernfs_find_ns 2 1 2012d 2012d 0/2 auto-closed as invalid on 2021/09/18 09:16
android-5-10 general protection fault in kernfs_find_ns 2 syz, C error 174 2h59m 1170d 0/2 upstream: reported C repro on 2023/09/09 18:30
linux-5.15 KASAN: global-out-of-bounds Read in kernfs_find_ns 17 1 541d 541d 0/3 auto-obsoleted due to no activity on 2025/09/08 00:48
android-54 general protection fault in kernfs_find_ns (2) 2 syz, C 21 601d 1855d 0/2 upstream: reported C repro on 2021/10/24 20:02
linux-6.1 KASAN: use-after-free Read in kernfs_find_ns origin:lts-only 19 syz, C 2 32d 113d 0/3 upstream: reported C repro on 2026/08/01 21:32
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/11/19 18:37 30m retest repro git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git f1715c0c04606ebbe832cc760abf49dfd6f2ae1f no crash job log log

Sample crash report:
smc: removing ib device rxe0
smbdirect: ib_dev[rxe0] removed
==================================================================
BUG: KASAN: slab-use-after-free in kernfs_ns_id fs/kernfs/dir.c:321 [inline]
BUG: KASAN: slab-use-after-free in kernfs_name_hash fs/kernfs/dir.c:334 [inline]
BUG: KASAN: slab-use-after-free in kernfs_find_ns+0x116/0x800 fs/kernfs/dir.c:915
Read of size 8 at addr ffff888038ebd168 by task syz.0.0/5354

CPU: 0 UID: 0 PID: 5354 Comm: syz.0.0 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
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+0x117/0x150 mm/kasan/report.c:595
 kernfs_ns_id fs/kernfs/dir.c:321 [inline]
 kernfs_name_hash fs/kernfs/dir.c:334 [inline]
 kernfs_find_ns+0x116/0x800 fs/kernfs/dir.c:915
 kernfs_remove_by_name_ns+0x5c/0x140 fs/kernfs/dir.c:1793
 device_remove_class_symlinks+0x178/0x190 drivers/base/core.c:3551
 device_del+0x400/0x8f0 drivers/base/core.c:3953
 remove_one_compat_dev drivers/infiniband/core/device.c:1036 [inline]
 remove_compat_devs drivers/infiniband/core/device.c:1047 [inline]
 disable_device+0x248/0x330 drivers/infiniband/core/device.c:1339
 __ib_unregister_device+0x2c9/0x400 drivers/infiniband/core/device.c:1571
 ib_unregister_device_and_put+0xb8/0xf0 drivers/infiniband/core/device.c:1636
 nldev_dellink+0x3a4/0x440 drivers/infiniband/core/nldev.c:1905
 rdma_nl_rcv_msg drivers/infiniband/core/netlink.c:-1 [inline]
 rdma_nl_rcv_skb drivers/infiniband/core/netlink.c:239 [inline]
 rdma_nl_rcv+0x6ef/0xa40 drivers/infiniband/core/netlink.c:259
 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_sendmsg+0x49f/0x790 net/socket.c:2713
 ___sys_sendmsg+0x2f8/0x3d0 net/socket.c:2770
 __sys_sendmsg net/socket.c:2802 [inline]
 __do_sys_sendmsg net/socket.c:2807 [inline]
 __se_sys_sendmsg net/socket.c:2805 [inline]
 __x64_sys_sendmsg+0x1b1/0x290 net/socket.c:2805
 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:0x7f7bccda94d9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f7bcdbfcfe8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f7bcd026180 RCX: 00007f7bccda94d9
RDX: 0000000000000000 RSI: 0000200000000580 RDI: 0000000000000004
RBP: 00007f7bcce38136 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f7bcd026218 R14: 00007f7bcd026180 R15: 00007ffe0b26c528
 </TASK>

Allocated by task 5352:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
 unpoison_slab_object mm/kasan/common.c:351 [inline]
 __kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:377
 kasan_slab_alloc include/linux/kasan.h:253 [inline]
 slab_post_alloc_hook mm/slub.c:4720 [inline]
 slab_alloc_node mm/slub.c:5033 [inline]
 kmem_cache_alloc_noprof+0x2b4/0x600 mm/slub.c:5047
 net_alloc net/core/net_namespace.c:494 [inline]
 copy_net_ns+0x1de/0x780 net/core/net_namespace.c:571
 create_new_namespaces+0x3f0/0x6b0 kernel/nsproxy.c:132
 unshare_nsproxy_namespaces+0x144/0x190 kernel/nsproxy.c:234
 ksys_unshare+0x532/0x890 kernel/fork.c:3306
 __do_sys_unshare kernel/fork.c:3372 [inline]
 __se_sys_unshare kernel/fork.c:3370 [inline]
 __x64_sys_unshare+0x38/0x50 kernel/fork.c:3370
 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

Freed by task 45:
 kasan_save_stack mm/kasan/common.c:57 [inline]
 kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:584
 poison_slab_object mm/kasan/common.c:264 [inline]
 __kasan_slab_free+0x5c/0x80 mm/kasan/common.c:296
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:2780 [inline]
 slab_free mm/slub.c:6630 [inline]
 kmem_cache_free+0x182/0x650 mm/slub.c:6757
 net_complete_free net/core/net_namespace.c:530 [inline]
 cleanup_net+0x5e3/0x810 net/core/net_namespace.c:722
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3578
 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3659
 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

The buggy address belongs to the object at ffff888038ebcf80
 which belongs to the cache net_namespace of size 9920
The buggy address is located 488 bytes inside of
 freed 9920-byte region [ffff888038ebcf80, ffff888038ebf640)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x38eb8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
memcg:ffff888035b4a481
flags: 0x4fff00000000040(head|node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000040 ffff88801dee6000 dead000000000122 0000000000000000
raw: 0000000000000000 0000000200030003 00000000f5000000 ffff888035b4a481
head: 04fff00000000040 ffff88801dee6000 dead000000000122 0000000000000000
head: 0000000000000000 0000000200030003 00000000f5000000 ffff888035b4a481
head: 04fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5297, tgid 5297 (syz-executor), ts 105409296999
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0x1f9/0x250 mm/page_alloc.c:1860
 prep_new_page mm/page_alloc.c:1868 [inline]
 get_page_from_freelist+0x225d/0x22e0 mm/page_alloc.c:3950
 __alloc_frozen_pages_noprof+0x211/0x450 mm/page_alloc.c:5492
 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:7539
 refill_sheaf mm/slub.c:2917 [inline]
 __pcs_replace_empty_main+0x2c8/0x6c0 mm/slub.c:4811
 alloc_from_pcs mm/slub.c:4887 [inline]
 slab_alloc_node mm/slub.c:5021 [inline]
 kmem_cache_alloc_noprof+0x394/0x600 mm/slub.c:5047
 net_alloc net/core/net_namespace.c:494 [inline]
 copy_net_ns+0x1de/0x780 net/core/net_namespace.c:571
 create_new_namespaces+0x3f0/0x6b0 kernel/nsproxy.c:132
 unshare_nsproxy_namespaces+0x144/0x190 kernel/nsproxy.c:234
 ksys_unshare+0x532/0x890 kernel/fork.c:3306
 __do_sys_unshare kernel/fork.c:3372 [inline]
 __se_sys_unshare kernel/fork.c:3370 [inline]
 __x64_sys_unshare+0x38/0x50 kernel/fork.c:3370
 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
page last free pid 5011 tgid 5011 ts 69340115409 stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 __free_pages_prepare mm/page_alloc.c:1402 [inline]
 __free_frozen_pages+0xd1a/0xe10 mm/page_alloc.c:2958
 __slab_free+0x269/0x2c0 mm/slub.c:5926
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x99/0x100 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:361
 kasan_slab_alloc include/linux/kasan.h:253 [inline]
 slab_post_alloc_hook mm/slub.c:4720 [inline]
 slab_alloc_node mm/slub.c:5033 [inline]
 __do_kmalloc_node mm/slub.c:5530 [inline]
 __kmalloc_noprof+0x302/0x710 mm/slub.c:5556
 _kmalloc_noprof include/linux/slab.h:995 [inline]
 tomoyo_realpath_from_path+0xf2/0x640 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x283/0x560 security/tomoyo/file.c:827
 security_inode_getattr+0x12b/0x310 security/security.c:1918
 vfs_getattr fs/stat.c:263 [inline]
 vfs_fstat fs/stat.c:285 [inline]
 __do_sys_newfstat fs/stat.c:555 [inline]
 __se_sys_newfstat+0x133/0x440 fs/stat.c:550
 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

Memory state around the buggy address:
 ffff888038ebd000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888038ebd080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888038ebd100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                          ^
 ffff888038ebd180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888038ebd200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 03:38 upstream 141b164bbe18 a3e64cfc .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-use-after-free Read in kernfs_find_ns
* Struck through repros no longer work on HEAD.