syzbot
KCSAN: data-race in inet_lookup_run_sk_lookup / tracing_gen_ctx_irq_test
Status:
moderation: reported on 2026/11/20 00:07
Subsystems:
trace
Labels:
prio:high
race:benign
[Documentation on labels]
Reported-by: syzbot+37663b1c84b88e64544a@syzkaller.appspotmail.com
First crash: 2d09h, last: 2d04h
✨ AI-generated root cause summary:
A data race occurs between task context and an interrupt on the same CPU when tracing_gen_ctx_irq_test() reads 'current->migration_disabled' via migration_disable_value() in kernel/trace/trace.c while migrate_disable() or migrate_enable() updates 'p->migration_disabled' in include/linux/sched.h. The task modifies 'p->migration_disabled' using plain C read/write operations without disabling hardware interrupts, and migration_disable_value() reads the field with a plain memory access without READ_ONCE() or data_race(). When a timer interrupt fires on the same CPU while the task is updating the counter and executes a tracing event (e.g., bpf_trace_printk), KCSAN detects concurrent unmarked memory accesses to 'current->migration_disabled'.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Fields Involved
struct task_struct::migration_disabled (include/linux/sched.h:948):
An unsigned short (2 bytes) counter tracking the nesting depth of migrate_disable() calls for a task.
__migrate_disable() and __migrate_enable() (include/linux/sched.h:2444-2497):
Inlined sched functions that increment, decrement, and reset p->migration_disabled in task context.
migration_disable_value() and tracing_gen_ctx_irq_test() (kernel/trace/trace.c:1715-1748):
Ftrace helper functions called during trace event buffer reservations (trace_event_buffer_reserve() -> tracing_gen_ctx()) to encode context flags, preempt depth, and migrate-disable depth into the ring-buffer trace entry header (struct trace_entry::preempt_count).
2. Mechanism of the Data Race
-
Write Side (Task Context):
A task running on CPU 1 (in the report, executing a network socket lookup BPF program via inet_lookup_run_sk_lookup() -> bpf_sk_lookup_run_v4()) enters migrate_enable() / migrate_disable().
Within include/linux/sched.h:
__migrate_disable() updates p->migration_disabled (p->migration_disabled++ or p->migration_disabled = 1).
__migrate_enable() updates p->migration_disabled (p->migration_disabled-- or p->migration_disabled = 0).
These updates are performed via plain, unmarked C read-modify-write and assignment operations. Crucially, hardware interrupts are not disabled on these paths (even during 0 -> 1 and 1 -> 0 transitions, guard(preempt)() only disables preemption, leaving local IRQs enabled).
-
Read Side (Interrupt Context on the Same CPU):
When KCSAN sets a watchpoint on p->migration_disabled and delays execution during an unmarked write, a local APIC timer interrupt (sysvec_apic_timer_interrupt) triggers on CPU 1.
Inside the timer interrupt, an hrtimer fires a perf sampling event (perf_swevent_hrtimer() -> __perf_event_overflow()), which triggers a BPF program calling bpf_trace_printk().
Emitting the trace event requires building the trace entry context via:
trace_event_buffer_reserve()
tracing_gen_ctx()
tracing_gen_ctx_irq_test()
migration_disable_value()
In kernel/trace/trace.c:
static unsigned short migration_disable_value(void)
{
#if defined(CONFIG_SMP)
return current->migration_disabled;
#else
return 0;
#endif
}
migration_disable_value() performs a plain, unmarked C load of current->migration_disabled. Because the interrupted task is the current task on CPU 1, the interrupt reads the exact memory address being watched by KCSAN for the task-context write.
-
Violation:
Because migration_disable_value() performs an unmarked load without READ_ONCE() or data_race(), and __migrate_enable() / __migrate_disable() modify the counter without WRITE_ONCE() or IRQ disabling, KCSAN detects a concurrent unmarked read and write to the same memory location (0xffff888103b1ebf8) across task and interrupt contexts on the same CPU.
Sample crash report:
* Struck through repros no longer work on HEAD.