syzbot
KCSAN: data-race in sk_filter_trim_cap / tracing_gen_ctx_irq_test
Status:
moderation: reported on 2026/11/19 00:09
Subsystems:
trace
Labels:
race:benign
prio:high
[Documentation on labels]
Reported-by: syzbot+17ee253fabddf8af01f2@syzkaller.appspotmail.com
First crash: 1d22h, last: 1d22h
✨ AI-generated root cause summary:
A data race occurs between __migrate_disable() in include/linux/sched.h and migration_disable_value() in kernel/trace/trace.c. In __migrate_disable(), guard(preempt)() disables preemption but leaves hardware interrupts enabled while performing an unmarked write to p->migration_disabled (p->migration_disabled = 1). When a hardware interrupt fires on the same CPU while the write is taking place, interrupt exit paths triggering tracing (such as trace_write_msr) call tracing_gen_ctx_irq_test(), which performs an unmarked read via migration_disable_value() (return current->migration_disabled). This data race surfaced to KCSAN when migrate_disable() was moved from kernel/sched/core.c (where KCSAN_SANITIZE := n disabled instrumentation) to include/linux/sched.h as an inline function, exposing its accesses to KCSAN instrumentation in callers such as sk_filter_trim_cap().
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, Fields, and Files Involved
2. Mechanism and Trigger
-
Unmarked writes with hardware interrupts enabled:
In include/linux/sched.h:2479, __migrate_disable() updates p->migration_disabled:
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;
}
While guard(preempt)() disables kernel preemption on the CPU, hardware interrupts remain enabled throughout the execution of __migrate_disable(). The write p->migration_disabled = 1; (at line 2496) is performed as an unmarked plain store.
-
Asynchronous unmarked read from hardirq tracing context on the same CPU:
While task 5403 was executing the plain store in __migrate_disable(), an APIC timer interrupt (sysvec_apic_timer_interrupt) arrived on the same CPU (CPU 0), interrupting the task.
During interrupt exit processing (irqentry_exit $\to$ __hrtimer_rearm_deferred $\to$ lapic_next_event $\to$ native_apic_msr_write), writing the lapic MSR triggered the trace_write_msr tracepoint (arch/x86/include/asm/msr-trace.h).
The tracepoint buffer allocation path (trace_event_buffer_reserve $\to$ tracing_gen_ctx_dec $\to$ tracing_gen_ctx_irq_test) samples the current migration disable counter to pack into the trace entry:
static unsigned short migration_disable_value(void)
{
#if defined(CONFIG_SMP)
return current->migration_disabled;
#else
return 0;
#endif
}
migration_disable_value() reads current->migration_disabled via a plain, unmarked load. Because the interrupted thread was in the middle of modifying p->migration_disabled, KCSAN detected the concurrent unmarked read and write to the same memory location (0xffff8881017e95b8).
-
Why the data race surfaced:
Previously, migrate_disable() and migrate_enable() resided in kernel/sched/core.c. In kernel/sched/Makefile, KCSAN_SANITIZE := n disables KCSAN instrumentation for all scheduler core compilation units, masking any data races occurring within them. Commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline") moved migrate_disable() to include/linux/sched.h as an inline function so callers (such as sk_filter_trim_cap() in net/core/filter.c) could inline it directly. These calling files are compiled with full KCSAN instrumentation enabled, exposing the missing concurrency markings (data_race() or READ_ONCE() / WRITE_ONCE()) between the process-context modifications and the interrupt-context trace sampling.
Sample crash report:
* Struck through repros no longer work on HEAD.