Root Cause Analysis
1. Mechanism and Involved Entities
- Variable / Struct field:
current->migration_disabled (unsigned short at offset in struct task_struct, defined in include/linux/sched.h:948).
- Functions involved:
2. Detailed Technical Breakdown
In kernel/sched/Makefile, KCSAN instrumentation is explicitly disabled for scheduler compilation units (KCSAN_SANITIZE := n). However, __migrate_disable() and __migrate_enable() are defined as static inline functions in include/linux/sched.h (for !MODULE && !COMPILE_OFFSETS). As a result, they are inlined directly into translation units across the kernel (such as kernel/bpf/syscall.c and net/packet/af_packet.c) where KCSAN instrumentation is enabled.
Within __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;
}
- Task Context Read: Task
6754 executing bpf_map_update_value() invokes bpf_disable_instrumentation(), which calls migrate_disable(). Preemption and local interrupts are enabled. Line 2483 performs an unmarked read of p->migration_disabled (evaluating to 0) before guard(preempt)() is acquired.
- Interrupt / Softirq Reentrancy: While KCSAN observes this read (and introduces a watchpoint delay), a hardware interrupt occurs on CPU 1, which upon exit raises and runs
NET_RX_SOFTIRQ (__irq_exit_rcu() -> handle_softirqs() -> net_rx_action()).
- Softirq Context Write: During packet reception,
packet_rcv() calls run_filter(), which calls bpf_prog_run_clear_cb() and subsequently bpf_prog_run_pin_on_cpu(). In non-CONFIG_PREEMPT_RT kernels (here CONFIG_PREEMPT_LAZY=y), bottom halves run in the context of the interrupted task, so current still points to Task 6754.
- In softirq context,
migrate_disable() is invoked on the same current (task 6754). Because the interrupted task had not yet reached line 2496, p->migration_disabled is still 0. The softirq executes lines 2494–2496, performing an unmarked write p->migration_disabled = 1.
- KCSAN flags this concurrent access between the interrupted task context's read at line 2483 and the softirq's write at line 2496 as a data race.
3. Root Cause Defect
Calling migrate_disable() from softirq/BH/atomic contexts is intentional across networking and BPF (e.g., in BPF socket filters, tracepoints, and RCU callbacks). However:
- The accesses to
p->migration_disabled (and this_rq_pinned()) in include/linux/sched.h are plain, unmarked C loads and stores (if (p->migration_disabled), p->migration_disabled++, p->migration_disabled = 1, and p->migration_disabled = 0) rather than being annotated or protected against compiler reordering and interrupt reentrancy.
- Inlining these scheduler functions outside
kernel/sched/core.c exposes these unannotated, reentrant accesses to KCSAN detection in instrumented modules.