KCSAN: data-race in d_set_mounted / link_path_walk (5)

Status: moderation: reported on 2026/11/18 06:03
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+a65e0540b9e3aaa72ed5@syzkaller.appspotmail.com
First crash: 1d04h, last: 11h31m
✨ AI-generated root cause summary:

A KCSAN data race occurs on the 4-byte dentry->d_flags field between d_set_mounted() and link_path_walk(). During path traversal in link_path_walk(), the lockless reader checks parent->d_flags & DCACHE_OP_HASH (BIT 0) using a plain read without holding parent->d_lock. Concurrently, a mounting task in d_set_mounted() sets dentry->d_flags |= DCACHE_MOUNTED (BIT 15) using a plain read-modify-write while holding dentry->d_lock. Because immutable operation flags (like DCACHE_OP_HASH) and dynamically mutable state flags (like DCACHE_MOUNTED) share the single 32-bit d_flags word, the concurrent unannotated read and write constitute a data race under the Linux Kernel Memory Model.

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

Technical Root Cause Analysis

1. Functions, Structs, and Fields Involved


2. Mechanism and Lifecycle Violation

In the VFS directory cache subsystem, dentry->d_flags is a shared 32-bit integer that stores two distinct categories of bitflags:

  1. Static / Immutable Operation Flags: Flags such as DCACHE_OP_HASH (BIT(0)), DCACHE_OP_COMPARE (BIT(1)), DCACHE_OP_REVALIDATE (BIT(2)), etc. These are assigned at dentry allocation/initialization time (__d_alloc() via sb->s_d_flags or d_set_d_op()) before the dentry is published, reflecting filesystem-specific operations (d_op). Once published, these bits are immutable for the lifetime of the dentry.
  2. Dynamic / Mutable State Flags: Flags such as DCACHE_MOUNTED (BIT(15)), DCACHE_LRU_LIST (BIT(18)), DCACHE_REFERENCED (BIT(6)), DCACHE_CANT_MOUNT (BIT(8)), etc., which are updated at runtime under dentry->d_lock.

The data race is triggered by the following sequence:

  • Task 7833 (Read): While resolving a pathname in link_path_walk() (e.g. during an openat syscall), the task traverses path components. When processing a normal path component, it accesses the current directory dentry (struct dentry *parent = nd->path.dentry;) locklessly without holding parent->d_lock (to avoid high contention during path traversal). At fs/namei.c:2632, it checks whether the filesystem implements a custom hashing callback:

    if (unlikely(parent->d_flags & DCACHE_OP_HASH)) {
        err = parent->d_op->d_hash(parent, &nd->last);
        ...
    }
    

    This is executed as a plain C read (testl $1, (%rax)).

  • Task 7827 (Write): Concurrently, another thread calls mount() targeting that directory dentry. In d_set_mounted() (fs/dcache.c:1653), the task holds dentry->d_lock and marks the dentry as a mountpoint:

    dentry->d_flags |= DCACHE_MOUNTED;
    

    This is executed as a plain C read-modify-write (orl $0x8000, (%rdi)).

Because both immutable flags (DCACHE_OP_HASH) and mutable state flags (DCACHE_MOUNTED) occupy the same 32-bit word, and neither the read in link_path_walk() nor the write in d_set_mounted() uses marked memory accesses (READ_ONCE() / WRITE_ONCE() or data_race()), KCSAN flags this concurrent unannotated read and write to the same 4-byte memory address (0xffff8881004103c0) as a data race under the Linux Kernel Memory Model.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
4024bf98 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in d_set_mounted / link_path_walk (5) 2026/11/18 06:11 2026/11/18 06:11 2026/11/18 06:27 eb4895d7
c35e5ace assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in d_set_mounted / link_path_walk (5) 2026/11/18 05:55 2026/11/18 05:55 2026/11/18 06:02 ca622473
▶ ▼ Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in d_set_mounted / link_path_walk (4) fs 6 2 2019d 2042d 0/29 auto-closed as invalid on 2021/06/12 19:25
upstream KCSAN: data-race in d_set_mounted / link_path_walk (2) fs 6 1 2145d 2145d 0/29 auto-closed as invalid on 2021/02/07 03:59
upstream KCSAN: data-race in d_set_mounted / link_path_walk (3) fs 6 1 2082d 2082d 0/29 auto-closed as invalid on 2021/04/10 08:08
upstream KCSAN: data-race in d_set_mounted / link_path_walk fs 6 1 2265d 2265d 0/29 auto-closed as invalid on 2020/10/09 14:20

Sample crash report:
==================================================================
BUG: KCSAN: data-race in d_set_mounted / link_path_walk

write to 0xffff8881004103c0 of 4 bytes by task 7827 on cpu 1:
 d_set_mounted+0x144/0x1e0 fs/dcache.c:1653
 get_mountpoint+0x197/0x380 fs/namespace.c:948
 attach_recursive_mnt+0x1ea/0x17c0 fs/namespace.c:2676
 graft_tree fs/namespace.c:2940 [inline]
 do_add_mount fs/namespace.c:3897 [inline]
 do_new_mount_fc fs/namespace.c:3929 [inline]
 do_new_mount+0x650/0x730 fs/namespace.c:3986
 path_mount+0x4ad/0xba0 fs/namespace.c:4337
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x28c/0x2e0 fs/namespace.c:4540
 __x64_sys_mount+0x67/0x80 fs/namespace.c:4540
 x64_sys_call+0xc3b/0x2550 arch/x86/include/generated/asm/syscalls_64.h:166
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff8881004103c0 of 4 bytes by task 7833 on cpu 0:
 link_path_walk+0x487/0xde0 fs/namei.c:2632
 path_openat+0x142/0x11e0 fs/namei.c:5012
 do_file_open+0x16c/0x290 fs/namei.c:5045
 do_sys_openat2+0xa1/0x140 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0xf2/0x120 fs/open.c:1460
 x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 7833 Comm: modprobe Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 19:19 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in d_set_mounted / link_path_walk
2026/11/17 02:48 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in d_set_mounted / link_path_walk
* Struck through repros no longer work on HEAD.