KCSAN: data-race in bpf_map_update_value / bpf_prog_run_clear_cb

Status: moderation: reported on 2026/11/22 12:51
Subsystems: net
Labels: prio:high race:benign
[Documentation on labels]
Reported-by: syzbot+6e542230780be1d8658c@syzkaller.appspotmail.com
First crash: 5d13h, last: 5d05h
✨ AI-generated root cause summary:

A KCSAN data race occurs between task-context migrate_disable() and softirq-context migrate_disable() accessing current->migration_disabled in include/linux/sched.h. Because __migrate_disable() and __migrate_enable() are defined as static inline functions in include/linux/sched.h, they are inlined into KCSAN-instrumented modules outside the scheduler (which has KCSAN_SANITIZE := n). When task context executes __migrate_disable() with preemption and interrupts enabled, an unmarked read of p->migration_disabled can be interrupted by a softirq (such as packet filtering in run_filter) on the same CPU, which borrows current and performs an unmarked write to p->migration_disabled.

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

Root Cause Analysis

1. Mechanism and Involved Entities

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;
}
  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.
  2. 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()).
  3. 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.
  4. 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.
  5. 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.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
166613cb assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ✅ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ✅ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in bpf_map_update_value / bpf_prog_run_clear_cb 2026/11/18 12:18 2026/11/18 12:18 2026/11/18 12:40 eb4895d7
a6cb4571 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in bpf_map_update_value / bpf_prog_run_clear_cb 2026/11/18 12:02 2026/11/18 12:02 2026/11/18 13:15 eb4895d7

Sample crash report:
==================================================================
BUG: KCSAN: data-race in bpf_map_update_value / bpf_prog_run_clear_cb

write to 0xffff88811c9595b8 of 2 bytes by interrupt on cpu 1:
 __migrate_disable include/linux/sched.h:2496 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_prog_run_pin_on_cpu include/linux/filter.h:836 [inline]
 bpf_prog_run_clear_cb+0xb3/0x290 include/linux/filter.h:1119
 run_filter net/packet/af_packet.c:2111 [inline]
 packet_rcv+0x26e/0xba0 net/packet/af_packet.c:2184
 deliver_skb+0x10b/0x170 net/core/dev.c:2564
 deliver_ptype_list_skb net/core/dev.c:2579 [inline]
 __netif_receive_skb_core+0x13e0/0x19a0 net/core/dev.c:6391
 __netif_receive_skb_list_core+0x112/0x520 net/core/dev.c:6522
 __netif_receive_skb_list net/core/dev.c:6589 [inline]
 netif_receive_skb_list_internal+0x471/0x5e0 net/core/dev.c:6680
 gro_normal_list include/net/gro.h:539 [inline]
 gro_flush_normal include/net/gro.h:547 [inline]
 napi_complete_done+0x19c/0x410 net/core/dev.c:7048
 virtqueue_napi_complete drivers/net/virtio_net.c:736 [inline]
 virtnet_poll+0x1a9a/0x1f60 drivers/net/virtio_net.c:3048
 __napi_poll+0x73/0x350 net/core/dev.c:7997
 napi_poll net/core/dev.c:8060 [inline]
 net_rx_action+0x33f/0x850 net/core/dev.c:8217
 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
 common_interrupt+0x83/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 rdtsc_ordered arch/x86/include/asm/tsc.h:57 [inline]
 delay_tsc+0x5b/0xa0 arch/x86/lib/delay.c:70
 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_disable include/linux/sched.h:2483 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_update_value+0x108/0x570 kernel/bpf/syscall.c:270
 generic_map_update_batch+0x4e6/0x700 kernel/bpf/syscall.c:2125
 bpf_map_do_batch+0x26a/0x3b0 kernel/bpf/syscall.c:5849
 __sys_bpf+0x784/0xc50 kernel/bpf/syscall.c:-1
 __do_sys_bpf kernel/bpf/syscall.c:6582 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:6579 [inline]
 __x64_sys_bpf+0x69/0x80 kernel/bpf/syscall.c:6579
 x64_sys_call+0xf26/0x2550 arch/x86/include/generated/asm/syscalls_64.h:322
 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

read to 0xffff88811c9595b8 of 2 bytes by task 6754 on cpu 1:
 __migrate_disable include/linux/sched.h:2483 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_update_value+0x108/0x570 kernel/bpf/syscall.c:270
 generic_map_update_batch+0x4e6/0x700 kernel/bpf/syscall.c:2125
 bpf_map_do_batch+0x26a/0x3b0 kernel/bpf/syscall.c:5849
 __sys_bpf+0x784/0xc50 kernel/bpf/syscall.c:-1
 __do_sys_bpf kernel/bpf/syscall.c:6582 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:6579 [inline]
 __x64_sys_bpf+0x69/0x80 kernel/bpf/syscall.c:6579
 x64_sys_call+0xf26/0x2550 arch/x86/include/generated/asm/syscalls_64.h:322
 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: 1 UID: 0 PID: 6754 Comm: syz.3.1510 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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