KCSAN: data-race in bpf_map_copy_value / bpf_prog_run_clear_cb

Status: moderation: reported on 2026/11/20 00:05
Subsystems: net
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+e2387bdd52c8babb3419@syzkaller.appspotmail.com
First crash: 2d23h, last: 2d07h
✨ AI-generated root cause summary:

In __migrate_disable() (inlined in include/linux/sched.h), guard(preempt)() is used to disable preemption while modifying the runqueue counter this_rq_pinned() (rq->nr_pinned). However, disabling preemption does not mask interrupts or softirqs. If a hardware interrupt arrives on the same CPU while a task is running __migrate_disable() (e.g. from bpf_disable_instrumentation()), softirq handling can invoke BPF socket filter helpers like bpf_prog_run_pin_on_cpu(), which also call migrate_disable() on the interrupted task. This causes reentrant, unsynchronized read-modify-write accesses to rq->nr_pinned, triggering a KCSAN data-race warning.

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

Technical Root Cause Analysis

1. Involved Files, Functions, and Structures

  • Files:
  • Structures and Fields:
    • struct rq: nr_pinned field (offset RQ_nr_pinned, accessed via this_rq_pinned()), tracking tasks on the per-CPU runqueue that have migration disabled.
    • struct task_struct: migration_disabled nesting counter.

2. Triggering Mechanism and Race Sequence

  1. Task Context (__sys_bpf -> bpf_map_copy_value): A user task (PID 4653) on CPU 0 performs a BPF syscall operation (generic_map_lookup_batch -> bpf_map_copy_value), which calls bpf_disable_instrumentation(). This invokes migrate_disable() -> __migrate_disable().

    In __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;
    }
    

    At line 2494, guard(preempt)() increments the preemption disable count (PREEMPT_OFFSET), preventing task rescheduling on this CPU. At line 2495, the code performs an unannotated read-modify-write (this_rq_pinned()++) to 0xffff888237c2ccf0 (rq->nr_pinned on CPU 0).

  2. Interrupt and Softirq Interruption: Disabling preemption (preempt_disable()) does not mask hardware interrupts (HARDIRQ_MASK) or software interrupts (SOFTIRQ_MASK). While PID 4653 is in __migrate_disable() at line 2495 (instrumented by KCSAN with a watchpoint), a hardware interrupt occurs on CPU 0.

    Upon IRQ exit (__irq_exit_rcu()), softirqs are processed on CPU 0 (handle_softirqs() -> net_rx_action()). During NAPI network packet polling, packet_rcv() in net/packet/af_packet.c calls run_filter(), which invokes bpf_prog_run_clear_cb().

  3. Reentrant Call in Softirq Context: bpf_prog_run_clear_cb() delegates to bpf_prog_run_pin_on_cpu(), which unconditionally calls migrate_disable().

    Because softirqs run in the context of the interrupted task, current is still PID 4653. The softirq re-enters __migrate_disable() on CPU 0 and accesses the exact same runqueue counter this_rq_pinned() (rq->nr_pinned).

  4. Sanitizer Detection: Historically, migrate_disable() resided out-of-line in kernel/sched/core.c, where KCSAN instrumentation is disabled (KCSAN_SANITIZE := n). Inlining __migrate_disable() into include/linux/sched.h exposed the plain C read-modify-write on this_rq_pinned() to KCSAN when called from instrumented subsystems (such as kernel/bpf/ and net/). KCSAN flags the concurrent, unsynchronized read-write access between task context and the interrupt/softirq context on CPU 0 as a data race.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
d350b783 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in bpf_map_copy_value / bpf_prog_run_clear_cb 2026/11/19 09:24 2026/11/19 09:24 2026/11/19 10:10 2006bdcc
aebe315b assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in bpf_map_copy_value / bpf_prog_run_clear_cb 2026/11/19 09:21 2026/11/19 09:21 2026/11/19 10:04 2006bdcc

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

read-write to 0xffff888237c2ccf0 of 4 bytes by interrupt on cpu 0:
 __migrate_disable include/linux/sched.h:2495 [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+0xa3/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
 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_disable include/linux/sched.h:2495 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_copy_value+0xc5/0x500 kernel/bpf/syscall.c:317
 generic_map_lookup_batch+0x674/0x980 kernel/bpf/syscall.c:2192
 bpf_map_do_batch+0x1cb/0x3b0 kernel/bpf/syscall.c:5845
 __sys_bpf+0x4c1/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-write to 0xffff888237c2ccf0 of 4 bytes by task 4653 on cpu 0:
 __migrate_disable include/linux/sched.h:2495 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_copy_value+0xc5/0x500 kernel/bpf/syscall.c:317
 generic_map_lookup_batch+0x674/0x980 kernel/bpf/syscall.c:2192
 bpf_map_do_batch+0x1cb/0x3b0 kernel/bpf/syscall.c:5845
 __sys_bpf+0x4c1/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: 0 UID: 0 PID: 4653 Comm: syz.4.476 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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