KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid

Status: moderation: reported on 2026/11/19 00:03
Subsystems: lsm
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+32f5a9784b5443d09ccb@syzkaller.appspotmail.com
First crash: 2d19h, last: 2d04h
✨ AI-generated root cause summary:

In ns_capable_common() (kernel/capability.c), when a capability check succeeds, current->flags |= PF_SUPERPRIV performs an unsynchronized, plain read-modify-write on current->flags. When KCSAN instruments this access with CONFIG_KCSAN_INTERRUPT_WATCHER=y, it installs a watchpoint and delays execution via udelay() without disabling interrupts or preemption. During this delay, an asynchronous event (such as preemption or scheduler/PSI hooks) on the same CPU in task context reads task_struct::flags, consuming the watchpoint. When stack unwinding for the reading context yields no non-KCSAN frames, KCSAN reports a data-race between 0x0 and capable_wrt_inode_uidgid.

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

Root Cause Analysis

1. Functions, Structs, and Fields Involved

  • File: kernel/capability.c
  • Function: ns_capable_common() (invoked via ns_capable() and capable_wrt_inode_uidgid())
  • Structure and Field: struct task_struct::flags (offset 0x2c / byte 44 in the 64-byte slab-aligned task object 0xffff888104b41140, accessing address 0xffff888104b4116c)
  • Flag: PF_SUPERPRIV (0x00000100 defined in include/linux/sched.h)

2. Technical Mechanism and Trigger

  1. Unsynchronized Read-Modify-Write in Capability Checks: In kernel/capability.c:343:

    static bool ns_capable_common(struct user_namespace *ns, int cap, unsigned int opts)
    {
        int capable;
        ...
        capable = security_capable(current_cred(), ns, cap, opts);
        if (capable == 0) {
            current->flags |= PF_SUPERPRIV;
            return true;
        }
        return false;
    }
    

    When a capability check succeeds during operations such as chown (chown_common -> notify_change -> shmem_setattr -> setattr_prepare -> chgrp_ok -> capable_wrt_inode_uidgid), ns_capable_common() sets PF_SUPERPRIV on current->flags using a plain C bitwise OR (|=).

  2. KCSAN Watchpoint Setup: Because current->flags |= PF_SUPERPRIV is compiled into a 4-byte read-modify-write (__tsan_read_write4), KCSAN selects this access and enters kcsan_setup_watchpoint() (kernel/kcsan/core.c):

    • A watchpoint is installed for the 4 bytes at 0xffff888104b4116c.
    • With CONFIG_KCSAN_INTERRUPT_WATCHER=y enabled, interrupt_watcher is true; therefore, local interrupts are not disabled, and preemption remains enabled.
    • The task executes delay_access(), looping in udelay(kcsan_udelay_task) to artificially widen the race window.
  3. Concurrent Access and Watchpoint Trigger:

    • While task 3283 is delaying inside udelay(), an asynchronous event (e.g., preemption via preempt_schedule_irq() entering __schedule(), or a tracing/PSI hook such as psi_task_switch()) occurs on CPU 1.
    • Because in_task() remains true while current is still task 3283 during schedule preemption or task-context hooks, KCSAN records the reader identity as task 3283 on cpu 1.
    • The reader inspects task_struct::flags (a plain 4-byte read), triggering kcsan_found_watchpoint().
  4. Empty Stack Trace and 0x0 Symbol:

    • The reading access is consumed via kcsan_report_set_info(). Because plain reads are not scoped accesses (KCSAN_ACCESS_SCOPED is not set), ai.ip is initialized to 0.
    • When saving the reader's stack trace (stack_trace_save(..., skipnr=2) in prepare_report_producer()), stack unwinding across the scheduler/interrupt boundary either yields only KCSAN runtime frames or fails to unwind.
    • get_stack_skipnr() in sanitize_stack_entries() skips all captured frames, resulting in other_frame = 0 (0x0) and 0 frames printed under the read stack.
    • Finally, print_report() formats the bug header as data-race in 0x0 / capable_wrt_inode_uidgid.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
a5dccfca assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid 2026/11/18 23:31 2026/11/18 23:31 2026/11/19 00:35 2006bdcc
4d84b736 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid 2026/11/18 23:26 2026/11/18 23:26 2026/11/18 23:50 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid

read to 0xffff888104b4116c of 4 bytes by task 3283 on cpu 1:

read-write to 0xffff888104b4116c of 4 bytes by task 3283 on cpu 1:
 ns_capable_common kernel/capability.c:343 [inline]
 ns_capable kernel/capability.c:362 [inline]
 capable_wrt_inode_uidgid+0xa2/0x190 kernel/capability.c:495
 chgrp_ok fs/attr.c:132 [inline]
 setattr_prepare+0x4bc/0x710 fs/attr.c:198
 shmem_setattr+0x3b/0x7a0 mm/shmem.c:1562
 notify_change+0x857/0x8d0 fs/attr.c:556
 chown_common+0x2df/0x450 fs/open.c:825
 do_fchownat+0x100/0x210 fs/open.c:853
 __do_sys_chown fs/open.c:873 [inline]
 __se_sys_chown fs/open.c:871 [inline]
 __x64_sys_chown+0x47/0x60 fs/open.c:871
 x64_sys_call+0x6d4/0x2550 arch/x86/include/generated/asm/syscalls_64.h:93
 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: 1 UID: 0 PID: 3283 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 17:14 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid
2026/11/17 11:41 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid
2026/11/17 10:18 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid
2026/11/17 02:29 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / capable_wrt_inode_uidgid
* Struck through repros no longer work on HEAD.