syzbot
KCSAN: data-race in bpf_map_copy_value / bpf_prog_run_clear_cb
Status:
moderation: reported on 2026/11/20 00:05
Subsystems:
net
Labels:
race:benign
prio:low
[Documentation on labels]
Reported-by: syzbot+e2387bdd52c8babb3419@syzkaller.appspotmail.com
First crash: 2d23h, last: 2d07h
✨ AI-generated root cause summary:
In __migrate_disable() (inlined in include/linux/sched.h), guard(preempt)() is used to disable preemption while modifying the runqueue counter this_rq_pinned() (rq->nr_pinned). However, disabling preemption does not mask interrupts or softirqs. If a hardware interrupt arrives on the same CPU while a task is running __migrate_disable() (e.g. from bpf_disable_instrumentation()), softirq handling can invoke BPF socket filter helpers like bpf_prog_run_pin_on_cpu(), which also call migrate_disable() on the interrupted task. This causes reentrant, unsynchronized read-modify-write accesses to rq->nr_pinned, triggering a KCSAN data-race warning.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
1. Involved Files, Functions, and Structures
- Files:
- Structures and Fields:
struct rq: nr_pinned field (offset RQ_nr_pinned, accessed via this_rq_pinned()), tracking tasks on the per-CPU runqueue that have migration disabled.
struct task_struct: migration_disabled nesting counter.
2. Triggering Mechanism and Race Sequence
-
Task Context (__sys_bpf -> bpf_map_copy_value):
A user task (PID 4653) on CPU 0 performs a BPF syscall operation (generic_map_lookup_batch -> bpf_map_copy_value), which calls bpf_disable_instrumentation(). This invokes migrate_disable() -> __migrate_disable().
In __migrate_disable() (include/linux/sched.h:2479):
static inline void __migrate_disable(void)
{
struct task_struct *p = current;
if (p->migration_disabled) {
p->migration_disabled++;
return;
}
guard(preempt)();
this_rq_pinned()++;
p->migration_disabled = 1;
}
At line 2494, guard(preempt)() increments the preemption disable count (PREEMPT_OFFSET), preventing task rescheduling on this CPU. At line 2495, the code performs an unannotated read-modify-write (this_rq_pinned()++) to 0xffff888237c2ccf0 (rq->nr_pinned on CPU 0).
-
Interrupt and Softirq Interruption:
Disabling preemption (preempt_disable()) does not mask hardware interrupts (HARDIRQ_MASK) or software interrupts (SOFTIRQ_MASK). While PID 4653 is in __migrate_disable() at line 2495 (instrumented by KCSAN with a watchpoint), a hardware interrupt occurs on CPU 0.
Upon IRQ exit (__irq_exit_rcu()), softirqs are processed on CPU 0 (handle_softirqs() -> net_rx_action()). During NAPI network packet polling, packet_rcv() in net/packet/af_packet.c calls run_filter(), which invokes bpf_prog_run_clear_cb().
-
Reentrant Call in Softirq Context:
bpf_prog_run_clear_cb() delegates to bpf_prog_run_pin_on_cpu(), which unconditionally calls migrate_disable().
Because softirqs run in the context of the interrupted task, current is still PID 4653. The softirq re-enters __migrate_disable() on CPU 0 and accesses the exact same runqueue counter this_rq_pinned() (rq->nr_pinned).
-
Sanitizer Detection:
Historically, migrate_disable() resided out-of-line in kernel/sched/core.c, where KCSAN instrumentation is disabled (KCSAN_SANITIZE := n). Inlining __migrate_disable() into include/linux/sched.h exposed the plain C read-modify-write on this_rq_pinned() to KCSAN when called from instrumented subsystems (such as kernel/bpf/ and net/). KCSAN flags the concurrent, unsynchronized read-write access between task context and the interrupt/softirq context on CPU 0 as a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.