KCSAN: data-race in ns_capable / selinux_inode_permission

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

A KCSAN data-race false positive was reported on task_struct::flags (&current->flags) during ns_capable_common(), which executes 'current->flags |= PF_SUPERPRIV'. Under CONFIG_KCSAN_INTERRUPT_WATCHER=y and PREEMPT(lazy), kcsan_setup_watchpoint() leaves preemption and interrupts enabled during delay_access(); an interrupt firing during udelay() can lead to an instrumented load of current->flags on the interrupt exit / lazy preemption path, consuming the task's own watchpoint while in_task() is true for the same PID on CPU 0. Furthermore, because release_report() only clears ai.size and does not zero other_infos[watchpoint_idx].stack_entries, print_report() reads past num_stack_entries when other_skipnr == other_info->num_stack_entries, printing zero stack frames but pulling the stale function symbol 'selinux_inode_permission' from an earlier watchpoint into the report title.

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

Root Cause Analysis

1. Raced Location and Triggering Code Path

The memory location reported in the KCSAN splat is 0xffff888101d7116c:

  • In the active kernel build, struct task_struct slab objects are 64-byte (0x40) cacheline-aligned. Task 3294's task_struct is allocated at 0xffff888101d71140.
  • The flags field of struct task_struct (include/linux/sched.h) resides at byte offset 0x2c (bit offset 352): $$\text{Address} = \text{0xffff888101d71140} + \text{0x2c} = \text{0xffff888101d7116c}$$
  • The read-write access occurs in kernel/capability.c:343 within ns_capable_common():
    capable = security_capable(current_cred(), ns, cap, opts);
    if (capable == 0) {
        current->flags |= PF_SUPERPRIV;
        return true;
    }
    
    This executes an unmarked 4-byte read-modify-write operation setting PF_SUPERPRIV on current->flags.

2. Mechanism of the Same-Task "Self-Race" Artifact

Both accesses in the KCSAN report specify by task 3294 on cpu 0 (in_task() == true and task_pid_nr(current) == 3294). The race is a false-positive artifact of KCSAN runtime handling under CONFIG_KCSAN_INTERRUPT_WATCHER=y and PREEMPT(lazy):

  1. Watchpoint Setup without Disabling Preemption or Interrupts: When ns_capable_common() performs current->flags |= PF_SUPERPRIV, KCSAN's instrumentation invokes check_access(). Because should_watch() evaluates to true, it calls kcsan_setup_watchpoint() (kernel/kcsan/core.c:528).

    • With CONFIG_KCSAN_INTERRUPT_WATCHER=y enabled, interrupt_watcher is true, so kcsan_setup_watchpoint() does not call local_irq_save() nor does it disable preemption; it only increments ctx->disable_scoped.
    • The watchpoint on 0xffff888101d7116c is inserted into watchpoints[], and the thread enters delay_access() -> udelay() (kernel/kcsan/core.c:622).
  2. Interrupt and Preemption / Exit Re-entry: During the busy-wait in udelay(), hardware interrupts remain enabled. A hardware interrupt (e.g., timer interrupt) occurs on CPU 0.

    • Once hardirq/softirq processing finishes, the interrupt context is left (in_task() becomes true again for task 3294).
    • Under PREEMPT(lazy), on the interrupt return path (irqentry_exit_cond_resched() / preempt_schedule_irq()), kernel scheduling or entry/exit routines perform an instrumented read of current->flags (for example checking flags such as PF_EXITING, PF_MEMALLOC, etc.).
    • Since ctx->disable_count == 0, KCSAN instrumentation is fully active and executes find_watchpoint(). This matches the active watchpoint previously inserted by task 3294 on its own &current->flags.
    • kcsan_found_watchpoint() successfully consumes the watchpoint via try_consume_watchpoint() and records the access information into other_infos[watchpoint_idx].
    • When the interrupted context resumes in udelay(), consume_watchpoint(watchpoint) in kcsan_setup_watchpoint() returns false, triggering kcsan_report_known_origin() for a data race where both accesses belong to task 3294 on CPU 0.

3. Why selinux_inode_permission Appears in the Bug Title with Zero Stack Frames

An inspection of selinux_inode_permission() and its inlined callees (current_sid(), selinux_task(), task_avdcache_permnoaudit(), inode_security_rcu(), task_avdcache_search(), and task_avdcache_update()) reveals that it never reads or writes current->flags.

The appearance of selinux_inode_permission in the report title is caused by an out-of-bounds/stale array read in kernel/kcsan/report.c:

  1. other_infos (kernel/kcsan/report.c:45) is a statically allocated array indexed by watchpoint slot (watchpoint - watchpoints).
  2. When a previous, unrelated watchpoint report is released via release_report() (kernel/kcsan/report.c:502), KCSAN resets other_info->ai.size = 0, but does not zero out other_info->stack_entries[].
  3. When prepare_report_producer() records the new watchpoint consumer via stack_trace_save(), if stack capture unwinds 0 frames or if all captured frames are skipped as runtime infrastructure, other_info->num_stack_entries equals other_skipnr (num_stack_entries - other_skipnr == 0).
  4. At kernel/kcsan/report.c:455, print_stack_trace(other_info->stack_entries + other_skipnr, other_info->num_stack_entries - other_skipnr, ...) prints 0 entries, producing the empty space in the report.
  5. However, at kernel/kcsan/report.c:416:
    other_frame = other_info->stack_entries[other_skipnr];
    
    There is no bounds check ensuring other_skipnr < other_info->num_stack_entries. It reads past num_stack_entries, retrieving whatever stale return address was left in other_infos[watchpoint_idx].stack_entries[other_skipnr] by an earlier watchpoint event that traversed selinux_inode_permission.
  6. print_report() uses other_frame to format the report header:
    pr_err("BUG: KCSAN: %s in %ps / %ps\n", ...);
    
    producing "data-race in ns_capable / selinux_inode_permission".

4. Concurrency Invariants on task_struct::flags

According to the kernel threading model documented in include/linux/sched.h:1838-1848:

  • Per-task flags (tsk->flags, PF_*) are strictly owned and written by current (the task itself).
  • Asynchronous cross-task modifications are prohibited and instead handled via atomic_flags (PFA_*).
  • Because only current modifies its own tsk->flags, task-local RMW operations such as current->flags |= PF_SUPERPRIV do not race with other threads in real-world kernel operation.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
acddbca0 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in ns_capable / selinux_inode_permission 2026/11/18 18:32 2026/11/18 18:32 2026/11/18 19:01 2006bdcc
d1793dd0 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in ns_capable / selinux_inode_permission 2026/11/18 18:18 2026/11/18 18:18 2026/11/18 19:31 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in ns_capable / selinux_inode_permission

read to 0xffff888101d7116c of 4 bytes by task 3294 on cpu 0:

read-write to 0xffff888101d7116c of 4 bytes by task 3294 on cpu 0:
 ns_capable_common kernel/capability.c:343 [inline]
 ns_capable+0x80/0xb0 kernel/capability.c:362
 do_ipt_set_ctl+0x60/0x970 net/ipv4/netfilter/ip_tables.c:1623
 nf_setsockopt+0x199/0x1b0 net/netfilter/nf_sockopt.c:101
 ip_setsockopt+0x102/0x110 net/ipv4/ip_sockglue.c:1424
 tcp_setsockopt+0x98/0xb0 net/ipv4/tcp.c:4190
 sock_common_setsockopt+0x69/0x80 net/core/sock.c:4117
 do_sock_setsockopt+0x137/0x170 net/socket.c:2399
 __sys_setsockopt net/socket.c:2424 [inline]
 __do_sys_setsockopt net/socket.c:2430 [inline]
 __se_sys_setsockopt net/socket.c:2427 [inline]
 __x64_sys_setsockopt+0xc2/0x130 net/socket.c:2427
 x64_sys_call+0x248f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:55
 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: 3294 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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