KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable

Status: moderation: reported on 2026/11/18 00:01
Subsystems: lsm
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+1f5a1d1d73fdd1ac852e@syzkaller.appspotmail.com
First crash: 14h07m, last: 14h07m
✨ AI cause bisection: introduced by (AI job) :
commit 22aafe3bcb67472effdea1ccf0df20280192bbaf
Author: Ingo Molnar <mingo@kernel.org>
Date: Wed Apr 9 21:11:26 2025 +0000

  x86/fpu: Remove init_task FPU state dependencies, add debugging warning for PF_KTHREAD tasks

  
✨ AI-generated root cause summary:

In ns_capable_common() (kernel/capability.c:343), 'current->flags |= PF_SUPERPRIV;' executes an unmarked, non-atomic read-modify-write on task_struct::flags. When KCSAN sets a watchpoint on current->flags, an interrupt/softirq (such as handle_softirqs() in kernel/softirq.c) running on the same CPU with in_task() == true reads current->flags, triggering a watchpoint hit. When stack_trace_save() yields no stack frames for the reader, print_report() in kernel/kcsan/report.c accesses other_info->stack_entries[other_skipnr] without bounds checking, reading a stale symbol (bpf_prog_run_clear_cb) left behind from a previous watchpoint slot in the un-zeroed other_infos[] array, producing a misleading bug title and an empty stack trace.

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

Technical Root Cause Breakdown

1. Functions, Structs, and Fields Involved

  • ns_capable_common() (kernel/capability.c:343): Checks process capabilities and performs current->flags |= PF_SUPERPRIV;.
  • struct task_struct::flags (include/linux/sched.h): Per-task flag word located at offset 0x2c (bit offset 352) within task_struct. The address 0xffff88810411802c in the report corresponds directly to &current->flags of task 3296 (0xffff888104118000).
  • handle_softirqs() (kernel/softirq.c:628): Interrupt/softirq entry helper that executes unsigned long old_flags = current->flags; before disabling bottom halves (softirq_handle_begin()).
  • print_report(), release_report(), prepare_report_producer() (kernel/kcsan/report.c): KCSAN reporting infrastructure responsible for managing struct other_info other_infos[].

2. Detailed Technical Mechanism

A. The Underlying Concurrency Race
  1. Watchpoint Setup:

    • task 3296 executes the getsockopt syscall (do_ipt_get_ctl() -> ns_capable() -> ns_capable_common()).
    • Line 343 of kernel/capability.c executes current->flags |= PF_SUPERPRIV;.
    • In KCSAN instrumentation (check_access() -> kcsan_setup_watchpoint()), KCSAN selects this access and installs a watchpoint on 0xffff88810411802c (current->flags).
    • With CONFIG_KCSAN_INTERRUPT_WATCHER=y, local interrupts are kept enabled while the task spins inside delay_access() (udelay()).
  2. The Conflicting Read Access:

    • While task 3296 is spinning in udelay(), an interrupt / softirq fires on CPU 1.
    • When softirqs are handled (e.g. via __do_softirq() / handle_softirqs()), line 628 of kernel/softirq.c reads current->flags:
      unsigned long old_flags = current->flags;
      
    • At this point, softirq_handle_begin() has not yet set SOFTIRQ_OFFSET in preempt_count(). Because neither HARDIRQ_MASK nor SOFTIRQ_OFFSET is set, in_task() (include/linux/preempt.h:160) evaluates to true.
    • prepare_access_info() sets .task_pid = in_task() ? task_pid_nr(current) : -1, recording task_pid = 3296 and cpu_id = 1.
    • This read collides with the active watchpoint installed on &current->flags, triggering kcsan_found_watchpoint().
B. Why the First Stack Trace is Empty and the Title References bpf_prog_run_clear_cb
  1. Unwind Failure:
    • In prepare_report_producer() (kernel/kcsan/report.c:598), KCSAN attempts to save the stack trace of the interrupting access:
      other_info->num_stack_entries = stack_trace_save(other_info->stack_entries, NUM_STACK_ENTRIES, 2);
      
    • When called across the interrupt stack boundary (call_on_irqstack), the ORC unwinder does not find stack frames past the KCSAN runtime frames, resulting in num_stack_entries == 0 (or other_skipnr == other_info->num_stack_entries).
  2. KCSAN Reporting Out-of-Bounds Frame Read:
    • release_report() (kernel/kcsan/report.c:509) only resets other_info->ai.size = 0 when freeing a report slot; it does not zero out other_info->stack_entries[].
    • In print_report():
      other_skipnr = sanitize_stack_entries(other_info->stack_entries,
                                            other_info->num_stack_entries,
                                            other_info->ai.ip, &other_reordered_to);
      other_frame = other_info->stack_entries[other_skipnr];
      
      sanitize_stack_entries() calls get_stack_skipnr(), which returns skip == num_entries. Because there is no check ensuring other_skipnr < other_info->num_stack_entries, other_frame reads stack_entries[other_skipnr], accessing stale residual data from an earlier test report that previously occupied this slot in other_infos[].
    • In this instance, the stale frame left in stack_entries[] was bpf_prog_run_clear_cb.
    • Because other_frame (bpf_prog_run_clear_cb) sorts lexicographically before this_frame (ns_capable), the bug report header prints: BUG: KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable
    • Subsequently, print_stack_trace() is called with num_entries = other_info->num_stack_entries - other_skipnr == 0, outputting zero lines for the first stack trace.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
28a394eb bisect-cause ❓ KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable 2026/11/17 21:04 2026/11/17 21:04 2026/11/17 22:48 ca622473
e53e1504 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable 2026/11/17 20:43 2026/11/17 20:43 2026/11/17 21:05 ca622473
df8b9139 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable 2026/11/17 20:39 2026/11/17 20:39 2026/11/17 21:31 ca622473

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

read to 0xffff88810411802c of 4 bytes by task 3296 on cpu 1:

read-write to 0xffff88810411802c of 4 bytes by task 3296 on cpu 1:
 ns_capable_common kernel/capability.c:343 [inline]
 ns_capable+0x80/0xb0 kernel/capability.c:362
 do_ipt_get_ctl+0x76/0xcb0 net/ipv4/netfilter/ip_tables.c:1654
 nf_getsockopt+0x190/0x1b0 net/netfilter/nf_sockopt.c:116
 ip_getsockopt+0x137/0x180 net/ipv4/ip_sockglue.c:1785
 tcp_getsockopt+0xad/0xe0 net/ipv4/tcp.c:4885
 sock_common_getsockopt+0x60/0x70 net/core/sock.c:4096
 do_sock_getsockopt+0x2ce/0x350 net/socket.c:2505
 __sys_getsockopt net/socket.c:2536 [inline]
 __do_sys_getsockopt net/socket.c:2543 [inline]
 __se_sys_getsockopt net/socket.c:2540 [inline]
 __x64_sys_getsockopt+0x11d/0x1a0 net/socket.c:2540
 x64_sys_call+0x1032/0x2550 arch/x86/include/generated/asm/syscalls_64.h:56
 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: 3296 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 10:50 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in bpf_prog_run_clear_cb / ns_capable
* Struck through repros no longer work on HEAD.