syzbot
KCSAN: data-race in __seccomp_filter / bpf_sk_storage_free
Status:
upstream: reported on 2026/11/19 02:53
Subsystems:
net
Labels:
prio:low
race:harmful
[Documentation on labels]
Reported-by: syzbot+dbe9d09c93ae0bb86ae1@syzkaller.appspotmail.com
First crash: 2d01h, last: 2d01h
✨ AI-generated root cause summary:
Commit 378b7708194f moved __migrate_disable() and __migrate_enable() inline from kernel/sched/core.c (where KCSAN instrumentation is disabled via KCSAN_SANITIZE := n) into include/linux/sched.h. In __migrate_disable(), this_rq_pinned()++ is updated with only preemption disabled (via guard(preempt)()), without disabling hardware interrupts. When an interrupt fires on the same CPU while a task is executing __migrate_disable(), the interrupt exit path invokes softirqs (such as RCU core callbacks running deferred_put_nlk_sk -> bpf_sk_storage_free), which calls rcu_read_lock_dont_migrate() -> migrate_disable(), resulting in an uninstrumented/non-IRQ-safe nested read-modify-write on CPU 0's rq->nr_pinned that triggers KCSAN.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
Involved Functions, Data Structures, and Files
- Files:
include/linux/sched.h, kernel/sched/core.c, net/core/bpf_sk_storage.c
- Functions:
__migrate_disable(), migrate_disable(), __migrate_enable(), migrate_enable(), bpf_sk_storage_free(), rcu_read_lock_dont_migrate()
- Structs and Fields:
struct rq::nr_pinned (accessed via macro this_rq_pinned()), struct task_struct::migration_disabled
Technical Mechanism
-
Inlining of migrate_{disable,enable}:
Commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline") moved the definitions of __migrate_disable() and __migrate_enable() from kernel/sched/core.c into the header include/linux/sched.h.
In kernel/sched/Makefile, KCSAN instrumentation is explicitly turned off for scheduler core files (KCSAN_SANITIZE := n). However, once __migrate_disable() was made an inline function in include/linux/sched.h, every compilation unit calling migrate_disable() (such as kernel/seccomp.c and net/core/bpf_sk_storage.c) compiled and inlined these functions with KCSAN instrumentation enabled.
-
Concurrency Between Task and Softirq / Interrupt Contexts:
Inside include/linux/sched.h, __migrate_disable() is implemented as follows:
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;
}
guard(preempt)() only disables preemption (preempt_disable()), but does not disable local hardware interrupts or softirqs.
-
Trigger Sequence Leading to KCSAN Report:
- Task Context: Task 6079 enters
__seccomp_filter() -> seccomp_run_filters() -> bpf_prog_run_pin_on_cpu() -> migrate_disable(). Because p->migration_disabled is 0, it disables preemption and performs a plain C read-modify-write on this_rq_pinned()++ (which accesses runqueues.nr_pinned on CPU 0 at address 0xffff888237c2ccf0).
- Watchpoint Setup: KCSAN instruments the memory access to
this_rq_pinned() and sets up a watchpoint delay (delay_tsc).
- Interrupt and Softirq Preemption: While Task 6079 is executing at line 2495, an APIC timer interrupt (
sysvec_apic_timer_interrupt) fires on CPU 0. On return from interrupt, __irq_exit_rcu() processes pending softirqs via handle_softirqs().
- Nested
migrate_disable() in Softirq: RCU softirq processing runs RCU callback batches (rcu_core() -> rcu_do_batch()), invoking deferred socket destruction (deferred_put_nlk_sk() -> sk_free() -> __sk_destruct() -> bpf_sk_storage_free()). bpf_sk_storage_free() calls rcu_read_lock_dont_migrate(), which under CONFIG_PREEMPT_RCU calls migrate_disable().
- Data Race Detection: In softirq context on the same CPU,
__migrate_disable() is entered and performs a read-modify-write access to the exact same per-CPU rq->nr_pinned memory address (0xffff888237c2ccf0) while the interrupted task's access is still active, causing KCSAN to report a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.