KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf

Status: moderation: reported on 2026/11/17 19:50
Subsystems: bpf net
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+379a7de5ac3d04784c05@syzkaller.appspotmail.com
First crash: 9h44m, last: 9h44m
✨ AI cause bisection: introduced by (AI job) :
commit 378b7708194fff77c9020392067329931c3fcc04
Author: Menglong Dong <menglong8.dong@gmail.com>
Date: Wed Sep 17 06:09:15 2025 +0000

  sched: Make migrate_{en,dis}able() inline

  
✨ AI-generated root cause summary:

Commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline") moved the implementations of __migrate_disable() and __migrate_enable() from kernel/sched/core.c (where KCSAN_SANITIZE := n suppressed KCSAN instrumentation) into include/linux/sched.h. In these inlined functions, reads and writes to current->migration_disabled are plain, unmarked memory operations performed with preemption disabled via guard(preempt)() but with interrupts left enabled. An interrupt/softirq on the same CPU executing a BPF program via bpf_prog_run_save_cb() can interrupt __migrate_enable() and invoke __migrate_disable(), triggering a KCSAN data race report on p->migration_disabled. Because interrupt execution on the same CPU is strictly nested (LIFO) and executes balanced migrate_disable()/migrate_enable() pairs, the counter is restored to its pre-interrupt value before returning to the interrupted task, making this race benign in practice.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Root Cause Analysis

1. Functions, Structs, and Files Involved

  • File: include/linux/sched.h (and kernel/sched/Makefile)
  • Functions: __migrate_enable(), __migrate_disable(), migrate_enable(), migrate_disable()
  • Calling Contexts:
  • Structs & Fields: struct task_struct::migration_disabled (and rq::nr_pinned via this_rq_pinned())

2. Technical Mechanism and Trigger Conditions

In commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline"), the definitions of migrate_disable() and migrate_enable() (via __migrate_disable() and __migrate_enable()) were moved out of kernel/sched/core.c and into include/linux/sched.h to allow inlining at call sites:

// include/linux/sched.h:
static inline void __migrate_enable(void)
{
	struct task_struct *p = current;
    ...
	guard(preempt)();
	if (unlikely(p->cpus_ptr != &p->cpus_mask))
		___migrate_enable();
	barrier();
	p->migration_disabled = 0;
	this_rq_pinned()--;
}

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;
}
  1. Instrumentation Exposure: In kernel/sched/Makefile, KCSAN_SANITIZE := n explicitly disables KCSAN instrumentation on scheduler core source files to prevent instrumentation overhead and false-positive warnings on scheduler synchronization primitives. When __migrate_disable() and __migrate_enable() resided in kernel/sched/core.c, their accesses were not instrumented by KCSAN. Moving them into include/linux/sched.h exposed their unmarked memory accesses to KCSAN instrumentation inside external callers (kernel/trace/bpf_trace.c, net/core/filter.c, etc.).

  2. Unmarked Plain Access with IRQs Enabled: __migrate_enable() uses guard(preempt)() to disable preemption, but interrupts remain enabled. The write p->migration_disabled = 0; (line 2475) is a plain, unannotated C assignment.

  3. Interrupt Arrival and Watchpoint Trigger: While task 4520 is executing __migrate_enable() inside bpf_prog_run_array() after a tracepoint hook, KCSAN sets up a watchpoint on p->migration_disabled at line 2475 and delays execution (udelay()). During this window, an APIC timer interrupt occurs on the same CPU (CPU 0). Upon exiting the interrupt, softirqs are processed (run_timer_softirq), invoking an ARP neighbour timer (neigh_timer_handler() $\to$ arp_solicit()), which transmits an ARP packet. During packet capture/receive processing (packet_rcv_spkt() $\to$ sock_queue_rcv_skb_reason() $\to$ sk_filter_trim_cap()), bpf_prog_run_save_cb() invokes migrate_disable().

    Because softirqs run in the interrupted task's context, current is task 4520. When __migrate_disable() executes if (p->migration_disabled) (line 2483), it performs an unmarked read on task 4520->migration_disabled, colliding with the pending write watchpoint and causing KCSAN to report a data race.


3. Correctness in Real-World Setups

While flagged by KCSAN as an unmarked concurrent access, this pattern is benign in practice:

  • Interrupt/softirq handlers running on the same CPU execute in a strictly nested LIFO manner relative to the interrupted task context.
  • In softirq context, preempt_count() is non-zero, preventing preemption, scheduling, or invocation of migrate_disable_switch().
  • The softirq calls migrate_disable() and migrate_enable() in a strictly balanced pair inside bpf_prog_run_save_cb().
    • If the interrupt occurs before p->migration_disabled = 0; (when p->migration_disabled == 1), the softirq increments it to 2 and decrements it back to 1 before returning. The interrupted task then sets it to 0.
    • If the interrupt occurs after p->migration_disabled = 0;, the softirq sets it to 1 and restores it to 0 before returning.
  • Upon return from the interrupt, the memory state is restored to its exact pre-interrupt value, ensuring neither migration_disabled nor rq->nr_pinned suffers counter corruption or leaks. Marking accesses with READ_ONCE()/WRITE_ONCE() or data_race() (or applying __no_kcsan) silences the warning.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
e7ca96f2 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf 2026/11/17 20:02 2026/11/17 20:02 2026/11/17 21:19 ca622473
72e82f78 bisect-cause ❓ KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf 2026/11/17 19:49 2026/11/17 19:49 2026/11/17 20:02 ca622473
77424251 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf 2026/11/17 19:35 2026/11/17 19:35 2026/11/17 19:49 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf

read to 0xffff88810468dab8 of 2 bytes by interrupt on cpu 0:
 __migrate_disable include/linux/sched.h:2483 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_prog_run_save_cb include/linux/filter.h:1104 [inline]
 sk_filter_trim_cap+0x15b/0x580 net/core/filter.c:168
 sk_filter_reason include/linux/filter.h:1233 [inline]
 sock_queue_rcv_skb_reason+0x25/0x90 net/core/sock.c:531
 sock_queue_rcv_skb include/net/sock.h:2552 [inline]
 packet_rcv_spkt+0x33b/0x3f0 net/packet/af_packet.c:1938
 dev_queue_xmit_nit+0x4c4/0x510 net/core/dev.c:2678
 xmit_one net/core/dev.c:4064 [inline]
 dev_hard_start_xmit+0xb5/0x3d0 net/core/dev.c:4084
 sch_direct_xmit+0x1c4/0x360 net/sched/sch_generic.c:411
 __dev_xmit_skb net/core/dev.c:4419 [inline]
 __dev_queue_xmit+0xe7d/0x2020 net/core/dev.c:5058
 dev_queue_xmit include/linux/netdevice.h:3485 [inline]
 arp_xmit_finish net/ipv4/arp.c:658 [inline]
 NF_HOOK include/linux/netfilter.h:325 [inline]
 arp_xmit+0x5d/0x170 net/ipv4/arp.c:668
 arp_send_dst+0x168/0x1b0 net/ipv4/arp.c:323
 arp_solicit+0x506/0x580 net/ipv4/arp.c:395
 neigh_probe net/core/neighbour.c:1096 [inline]
 neigh_timer_handler+0x6ab/0x8a0 net/core/neighbour.c:1191
 call_timer_fn+0x36/0x280 kernel/time/timer.c:1749
 expire_timers kernel/time/timer.c:1800 [inline]
 __run_timers kernel/time/timer.c:2375 [inline]
 __run_timer_base+0x40c/0x610 kernel/time/timer.c:2387
 run_timer_base kernel/time/timer.c:2396 [inline]
 run_timer_softirq+0x31/0x70 kernel/time/timer.c:2406
 handle_softirqs+0x109/0x310 kernel/softirq.c:669
 __do_softirq kernel/softirq.c:703 [inline]
 invoke_softirq kernel/softirq.c:542 [inline]
 __irq_exit_rcu+0x40/0xf0 kernel/softirq.c:786
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x74/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 native_pause arch/x86/include/asm/vdso/processor.h:13 [inline]
 delay_tsc+0x43/0xa0 arch/x86/lib/delay.c:76
 udelay include/asm-generic/delay.h:64 [inline]
 delay_access kernel/kcsan/core.c:332 [inline]
 kcsan_setup_watchpoint+0x255/0x3f0 kernel/kcsan/core.c:622
 __migrate_enable include/linux/sched.h:2475 [inline]
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_run_array include/linux/bpf.h:2805 [inline]
 trace_call_bpf+0x2e7/0x420 kernel/trace/bpf_trace.c:147
 perf_trace_run_bpf_submit+0x4e/0x110 kernel/events/core.c:11549
 do_perf_trace_kfree include/trace/events/kmem.h:97 [inline]
 perf_trace_kfree+0xc3/0x100 include/trace/events/kmem.h:97
 __do_trace_kfree include/trace/events/kmem.h:97 [inline]
 trace_kfree include/trace/events/kmem.h:97 [inline]
 kfree+0x351/0x3b0 mm/slub.c:6909
 ___sys_recvmsg+0x16d/0x3a0 net/socket.c:2979
 do_recvmmsg+0x1e4/0x550 net/socket.c:3073
 __sys_recvmmsg net/socket.c:3147 [inline]
 __do_sys_recvmmsg net/socket.c:3170 [inline]
 __se_sys_recvmmsg net/socket.c:3163 [inline]
 __x64_sys_recvmmsg+0xe5/0x170 net/socket.c:3163
 x64_sys_call+0x77f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:300
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffff88810468dab8 of 2 bytes by task 4520 on cpu 0:
 __migrate_enable include/linux/sched.h:2475 [inline]
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_run_array include/linux/bpf.h:2805 [inline]
 trace_call_bpf+0x2e7/0x420 kernel/trace/bpf_trace.c:147
 perf_trace_run_bpf_submit+0x4e/0x110 kernel/events/core.c:11549
 do_perf_trace_kfree include/trace/events/kmem.h:97 [inline]
 perf_trace_kfree+0xc3/0x100 include/trace/events/kmem.h:97
 __do_trace_kfree include/trace/events/kmem.h:97 [inline]
 trace_kfree include/trace/events/kmem.h:97 [inline]
 kfree+0x351/0x3b0 mm/slub.c:6909
 ___sys_recvmsg+0x16d/0x3a0 net/socket.c:2979
 do_recvmmsg+0x1e4/0x550 net/socket.c:3073
 __sys_recvmmsg net/socket.c:3147 [inline]
 __do_sys_recvmmsg net/socket.c:3170 [inline]
 __se_sys_recvmmsg net/socket.c:3163 [inline]
 __x64_sys_recvmmsg+0xe5/0x170 net/socket.c:3163
 x64_sys_call+0x77f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:300
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 4520 Comm: syz.3.215 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 12:03 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in sk_filter_trim_cap / trace_call_bpf
* Struck through repros no longer work on HEAD.