[BUG] configfs: slab-use-after-free in configfs_drop_dentry() on rmdir

From: Farhad Alemi

Date: Tue May 26 2026 - 23:42:42 EST


Hello Andreas and the configfs team,

I am reporting a configfs use-after-free found by syzkaller.

Summary:
A configfs config-item rmdir(2) can land in configfs_drop_dentry() with
sd->s_dentry pointing at a dentry whose RCU grace period has not yet
elapsed. The spin_lock(&dentry->d_lock) at fs/configfs/inode.c:209 then
reads freed slab memory and KASAN reports a slab-use-after-free.

The race is between an earlier openat path (via lookup_open ->
d_alloc_parallel) that allocates a child dentry, hits an error and
takes the dput()/__dentry_kill()/call_rcu() free path, and a later
rmdir on the same config item that walks the children via
detach_attrs() and grabs &dentry->d_lock before the RCU grace period
elapses.

Observed on:
- Linux v6.17.8 x86_64, QEMU Q35
- KASAN enabled; panic_on_warn set
- The only local dirty file in my tree is drivers/tty/serial/serial_core.c,
containing a local ttyS0 console guard for the fuzzing harness. It is
unrelated to fs/configfs/.
- Trigger does not require a crafted on-disk state; configfs is in-memory.
However, the syz reproducer uses fault injection (CONFIG_FAULT_INJECTION)
to force the openat error path on the Nth allocation. Without fault
injection the race is plausibly still reachable but timing-dependent.

Impact:
A configfs config-item rmdir races with a still-pending dentry RCU free
and KASAN reports a UAF read in the spin_lock:

BUG: KASAN: slab-use-after-free in __raw_spin_lock
include/linux/spinlock_api_smp.h:133 [inline]
BUG: KASAN: slab-use-after-free in _raw_spin_lock+0x33/0x40
kernel/locking/spinlock.c:154
Read of size 1 at addr ffff888133d5a538 by task syz.2.275/4076

Allocator (openat path):

__d_alloc+0x3b/0x7b0 fs/dcache.c:1690
d_alloc_parallel+0xeb/0x1620 fs/dcache.c:2549
lookup_open fs/namei.c:3638 [inline]
open_last_lookups fs/namei.c:3815 [inline]
path_openat+0xa6b/0x3890 fs/namei.c:4051
do_filp_open+0x232/0x490 fs/namei.c:4081
do_sys_openat2+0x134/0x1e0 fs/open.c:1437
__x64_sys_openat+0x13d/0x170 fs/open.c:1463

Free path (RCU dput, softirq):

kmem_cache_free+0x18f/0x3f0 mm/slub.c:4812
rcu_do_batch kernel/rcu/tree.c:2605 [inline]
rcu_core+0xd1e/0x1800 kernel/rcu/tree.c:2861

Crashing path (rmdir):

_raw_spin_lock+0x33/0x40 kernel/locking/spinlock.c:154
configfs_drop_dentry+0x5c/0x150 fs/configfs/inode.c:209
detach_attrs+0x22b/0x2f0 fs/configfs/dir.c:588
configfs_detach_item fs/configfs/dir.c:870 [inline]
configfs_detach_group fs/configfs/dir.c:917 [inline]
configfs_rmdir+0x652/0x9f0 fs/configfs/dir.c:1551
vfs_rmdir+0x3c2/0x530 fs/namei.c:4469
do_rmdir+0x275/0x540 fs/namei.c:4524
__x64_sys_rmdir+0x4c/0x60 fs/namei.c:4541

Expected behavior:
configfs_drop_dentry()'s read of sd->s_dentry and the subsequent
spin_lock(&dentry->d_lock) need to be safe against a concurrent
RCU-deferred dentry free. Plausible directions: hold the parent's
i_lock around the sd->s_dentry read + spin_lock; rcu_read_lock() to
keep the slab from being recycled while we attempt to lock; or have
configfs hold an explicit reference on sd->s_dentry while it lives in
the children list.

Reproducer:
A generated C reproducer was not produced for this seed. The syz
program is attached as reproducer.syz; the salient operation sequence
is:

1. mkdir + mount configfs
2. openat the null_blk backend ("nullb")
3. mkdirat a new config item under nullb
4. openat one of its attributes with fault injection (fail_nth=7),
which takes the dput()/RCU-free path on the freshly-allocated
dentry
5. additional openat + write syscalls (incidental to the race)
6. rmdir the config item, which reaches configfs_drop_dentry()
before the RCU grace period for step 4's freed dentry has
elapsed

The console report is attached as crash-report.txt.

Novelty check:
I searched syzbot dashboard data across upstream, fixed, invalid, stable,
and Android namespaces, and searched lore.kernel.org for
"configfs_drop_dentry", "detach_attrs" + "UAF", and "configfs_rmdir" +
"KASAN". I did not find an exact match. There are unrelated configfs
default-group / PCI-endpoint race reports, but those have different
code paths and free sites.

I appreciate your time and consideration, and I'm grateful for your
work on this subsystem. I'd be glad to test any candidate patches.

Regards,
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007f48fd005fa0 R14: 00007f48fd005fa0 R15: 0000000000001185
</TASK>
==================================================================
BUG: KASAN: slab-use-after-free in __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
BUG: KASAN: slab-use-after-free in _raw_spin_lock+0x33/0x40 kernel/locking/spinlock.c:154
Read of size 1 at addr ffff888133d5a538 by task syz.2.275/4076

CPU: 1 UID: 0 PID: 4076 Comm: syz.2.275 Not tainted 6.17.8 #1 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+0x1a9/0x280 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xba/0x230 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
__kasan_check_byte+0x2a/0x40 mm/kasan/common.c:568
kasan_check_byte include/linux/kasan.h:399 [inline]
lock_acquire+0x8d/0x350 kernel/locking/lockdep.c:5842
__raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
_raw_spin_lock+0x33/0x40 kernel/locking/spinlock.c:154
spin_lock include/linux/spinlock.h:351 [inline]
configfs_drop_dentry+0x5c/0x150 fs/configfs/inode.c:209
detach_attrs+0x22b/0x2f0 fs/configfs/dir.c:588
configfs_detach_item fs/configfs/dir.c:870 [inline]
configfs_detach_group fs/configfs/dir.c:917 [inline]
configfs_rmdir+0x652/0x9f0 fs/configfs/dir.c:1551
vfs_rmdir+0x3c2/0x530 fs/namei.c:4469
do_rmdir+0x275/0x540 fs/namei.c:4524
__do_sys_rmdir fs/namei.c:4543 [inline]
__se_sys_rmdir fs/namei.c:4541 [inline]
__x64_sys_rmdir+0x4c/0x60 fs/namei.c:4541
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf0/0x390 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f48fcd7778d
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fffbceab7a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
RAX: ffffffffffffffda RBX: 00007f48fd005fa0 RCX: 00007f48fcd7778d
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00002000000002c0
RBP: 00007f48fce1eb3d R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f48fd005fa0 R14: 00007f48fd005fa0 R15: 0000000000001677
</TASK>

Allocated by task 4076:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4206 [inline]
slab_alloc_node mm/slub.c:4255 [inline]
kmem_cache_alloc_lru_noprof+0x1c2/0x3b0 mm/slub.c:4274
__d_alloc+0x3b/0x7b0 fs/dcache.c:1690
d_alloc_parallel+0xeb/0x1620 fs/dcache.c:2549
lookup_open fs/namei.c:3638 [inline]
open_last_lookups fs/namei.c:3815 [inline]
path_openat+0xa6b/0x3890 fs/namei.c:4051
do_filp_open+0x232/0x490 fs/namei.c:4081
do_sys_openat2+0x134/0x1e0 fs/open.c:1437
do_sys_open fs/open.c:1452 [inline]
__do_sys_openat fs/open.c:1468 [inline]
__se_sys_openat fs/open.c:1463 [inline]
__x64_sys_openat+0x13d/0x170 fs/open.c:1463
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf0/0x390 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 15:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2437 [inline]
slab_free mm/slub.c:4710 [inline]
kmem_cache_free+0x18f/0x3f0 mm/slub.c:4812
rcu_do_batch kernel/rcu/tree.c:2605 [inline]
rcu_core+0xd1e/0x1800 kernel/rcu/tree.c:2861
handle_softirqs+0x278/0x870 kernel/softirq.c:579
run_ksoftirqd+0xac/0x110 kernel/softirq.c:968
smpboot_thread_fn+0x546/0xa50 kernel/smpboot.c:160
kthread+0x728/0x8b0 kernel/kthread.c:463
ret_from_fork+0x452/0x7d0 arch/x86/kernel/process.c:148
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:47
kasan_record_aux_stack+0xbd/0xd0 mm/kasan/generic.c:548
__call_rcu_common kernel/rcu/tree.c:3123 [inline]
call_rcu+0x157/0x9e0 kernel/rcu/tree.c:3243
__dentry_kill+0x4d7/0x660 fs/dcache.c:688
dput+0x1a4/0x2b0 fs/dcache.c:911
lookup_open fs/namei.c:3728 [inline]
open_last_lookups fs/namei.c:3815 [inline]
path_openat+0x1536/0x3890 fs/namei.c:4051
do_filp_open+0x232/0x490 fs/namei.c:4081
do_sys_openat2+0x134/0x1e0 fs/open.c:1437
do_sys_open fs/open.c:1452 [inline]
__do_sys_openat fs/open.c:1468 [inline]
__se_sys_openat fs/open.c:1463 [inline]
__x64_sys_openat+0x13d/0x170 fs/open.c:1463
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf0/0x390 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff888133d5a468
which belongs to the cache dentry of size 312
The buggy address is located 208 bytes inside of
freed 312-byte region [ffff888133d5a468, ffff888133d5a5a0)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x133d5a
head: order:1 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
memcg:ffff888137c44901
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff8881016a6640 ffffea0004955500 dead000000000002
raw: 0000000000000000 0000000080150015 00000000f5000000 ffff888137c44901
head: 0200000000000040 ffff8881016a6640 ffffea0004955500 dead000000000002
head: 0000000000000000 0000000080150015 00000000f5000000 ffff888137c44901
head: 0200000000000001 ffffea0004cf5681 00000000ffffffff 00000000ffffffff
head: 00000007f014aaa9 0000000000000000 00000000ffffffff 0000000000000002
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Reclaimable, gfp_mask 0xd20d0(__GFP_RECLAIMABLE|__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 3263, tgid 3263 ((udev-worker)), ts 66383627308, free_ts 59690661564
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x234/0x280 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x2124/0x2290 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x192/0x380 mm/page_alloc.c:5148
alloc_pages_mpol+0xd6/0x330 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2507 [inline]
allocate_slab+0x8f/0x320 mm/slub.c:2675
new_slab mm/slub.c:2729 [inline]
___slab_alloc+0xbdc/0x1400 mm/slub.c:3916
__slab_alloc mm/slub.c:4007 [inline]
__slab_alloc_node mm/slub.c:4082 [inline]
slab_alloc_node mm/slub.c:4243 [inline]
kmem_cache_alloc_lru_noprof+0x280/0x3b0 mm/slub.c:4274
__d_alloc+0x3b/0x7b0 fs/dcache.c:1690
d_alloc_parallel+0xeb/0x1620 fs/dcache.c:2549
__lookup_slow+0x13c/0x420 fs/namei.c:1801
lookup_slow+0x58/0x80 fs/namei.c:1833
walk_component+0x2d7/0x410 fs/namei.c:2137
lookup_last fs/namei.c:2638 [inline]
path_lookupat+0x168/0x440 fs/namei.c:2662
filename_lookup+0x25b/0x5d0 fs/namei.c:2691
vfs_statx+0x11a/0x570 fs/stat.c:353
vfs_fstatat+0x11d/0x170 fs/stat.c:375
page last free pid 2546 tgid 2546 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
free_unref_folios+0xca1/0x1390 mm/page_alloc.c:2952
folios_put_refs+0x46f/0x560 mm/swap.c:999
free_pages_and_swap_cache+0x2ec/0x5b0 mm/swap_state.c:264
__tlb_batch_free_encoded_pages mm/mmu_gather.c:136 [inline]
tlb_batch_pages_flush mm/mmu_gather.c:149 [inline]
tlb_flush_mmu_free mm/mmu_gather.c:397 [inline]
tlb_flush_mmu+0x3ab/0x690 mm/mmu_gather.c:404
tlb_finish_mmu+0xc8/0x1d0 mm/mmu_gather.c:497
vms_clear_ptes+0x45a/0x580 mm/vma.c:1235
vms_complete_munmap_vmas+0x20a/0x890 mm/vma.c:1277
do_vmi_align_munmap+0x3a7/0x490 mm/vma.c:1536
do_vmi_munmap+0x257/0x2e0 mm/vma.c:1584
__vm_munmap+0x270/0x400 mm/vma.c:3155
__do_sys_munmap mm/mmap.c:1080 [inline]
__se_sys_munmap mm/mmap.c:1077 [inline]
__x64_sys_munmap+0x65/0x80 mm/mmap.c:1077
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf0/0x390 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
ffff888133d5a400: 00 00 00 00 00 fc fc fc fc fc fc fc fc fa fb fb
ffff888133d5a480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888133d5a500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888133d5a580: fb fb fb fb fc fc fc fc fc fc fc fc 00 00 00 00
ffff888133d5a600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================

Attachment: reproducer.syz
Description: Binary data