KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb

Status: moderation: reported on 2026/11/22 01:33
Subsystems: net
Labels: prio:high race:benign
[Documentation on labels]
Reported-by: syzbot+546c8ecb3500c4a66783@syzkaller.appspotmail.com
First crash: 4d23h, last: 4d08h
✨ 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:

A KCSAN data-race report is triggered on current->migration_disabled between a process-context BPF execution and an incoming softirq packet receive filter on the same CPU. Commit 378b7708194f moved __migrate_disable() and __migrate_enable() as static inlines into include/linux/sched.h, exposing plain C accesses to p->migration_disabled to KCSAN instrumentation outside kernel/sched/ (where KCSAN_SANITIZE := n). When task 5152 in bpf_flow_dissect runs __migrate_enable(), it performs an unannotated read of p->migration_disabled; during this access, a hardware interrupt on the same CPU triggers NET_RX_SOFTIRQ, where packet_rcv invokes bpf_prog_run_clear_cb() -> bpf_prog_run_pin_on_cpu() -> __migrate_disable(), performing an unannotated write (p->migration_disabled++) to the interrupted task's migration_disabled field.

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

Technical Summary and Root Cause Analysis

1. Mechanism and Call Flow

The bug report is a KCSAN data race detected on current->migration_disabled (a 2-byte unsigned short field in struct task_struct, here at address 0xffff8881046d0478) occurring entirely on the same CPU (CPU 0) between process context and an interrupt/softirq context.

The two racing sides operate as follows:

  1. Process Context (Reader):

    • Task 5152 executes a flow dissector BPF program via the sys_bpf(BPF_PROG_TEST_RUN) path (bpf_prog_test_run_flow_dissector() -> bpf_flow_dissect()).
    • bpf_flow_dissect() invokes bpf_prog_run_pin_on_cpu(prog, ctx) (include/linux/filter.h:831), which wraps the program execution in migrate_disable() and migrate_enable().
    • In migrate_enable() -> __migrate_enable() (include/linux/sched.h:2444), the task performs a plain C read to check if nesting is present:
      if (p->migration_disabled > 1) { // line 2457
          p->migration_disabled--;
          return;
      }
      
    • Task 5152 reads p->migration_disabled (which has a value of 1). Under KCSAN instrumentation, reading this location sets up a watchpoint and introduces an artificial micro-delay (kcsan_setup_watchpoint() -> delay_access() -> udelay()) while interrupts remain enabled.
  2. Softirq Context (Writer):

    • During that window on CPU 0, a hardware interrupt arrives (common_interrupt()).
    • Upon completing the hard IRQ handler, softirqs are processed before return to the task (__irq_exit_rcu() -> handle_softirqs() -> net_rx_action()).
    • Incoming packet processing reaches an AF_PACKET socket: packet_rcv() calls run_filter() (net/packet/af_packet.c:2111), which calls bpf_prog_run_clear_cb().
    • bpf_prog_run_clear_cb() invokes bpf_prog_run_pin_on_cpu() (include/linux/filter.h:1119), which calls migrate_disable().
    • In migrate_disable() -> __migrate_disable() (include/linux/sched.h:2479), p = current evaluates to the interrupted task on CPU 0 (Task 5152):
      if (p->migration_disabled) {
          p->migration_disabled++; // line 2490 - plain C write to 2-byte field
          return;
      }
      
    • This concurrent write from the softirq to the same memory location triggers KCSAN's watchpoint.

2. Root Cause

  1. Inlining of Scheduler Migration Helpers: Previously, migrate_disable() and migrate_enable() were implemented as out-of-line functions in kernel/sched/core.c. In kernel/sched/Makefile, KCSAN instrumentation is explicitly disabled (KCSAN_SANITIZE := n). Commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline") moved __migrate_disable() and __migrate_enable() into include/linux/sched.h as static inline functions so they could be inlined at call sites to reduce BPF trampoline overhead. This exposed plain C loads and stores of p->migration_disabled to KCSAN instrumentation across arbitrary subsystems (filter.h, af_packet.c, flow_dissector.c, etc.).

  2. Interrupt / Softirq Reentrancy on current->migration_disabled: BPF execution helpers like bpf_prog_run_pin_on_cpu() and bpf_prog_run_clear_cb() wrap BPF executions in migrate_disable() / migrate_enable(). While this is necessary for migratable/preemptible contexts (such as PREEMPT_RT or preemptible process context under rcu_read_lock()), these functions are also called in non-threaded softirq context (NET_RX_SOFTIRQ), where preemption and migration are already disabled. When invoked in softirq on !PREEMPT_RT, current remains the interrupted task, and __migrate_disable() / __migrate_enable() manipulate current->migration_disabled without annotations (READ_ONCE()/WRITE_ONCE(), data_race(), or __no_kcsan) or local interrupt disablement.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
bfcc66f9 bisect-cause ❓ KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb 2026/11/18 00:54 2026/11/18 00:54 2026/11/18 01:26 ca622473
f9ffa01c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ✅ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ✅ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb 2026/11/18 00:51 2026/11/18 00:51 2026/11/18 01:22 ca622473
cb593db1 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb 2026/11/18 00:49 2026/11/18 00:49 2026/11/18 01:57 ca622473

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

write to 0xffff8881046d0478 of 2 bytes by interrupt on cpu 0:
 __migrate_disable include/linux/sched.h:2490 [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+0x77/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
 __preempt_count_add arch/x86/include/asm/preempt.h:98 [inline]
 delay_tsc+0x4b/0xa0 arch/x86/lib/delay.c:77
 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:2457 [inline]
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_run_pin_on_cpu include/linux/filter.h:838 [inline]
 bpf_flow_dissect+0x162/0x360 net/core/flow_dissector.c:1024
 bpf_prog_test_run_flow_dissector+0x25d/0x360 net/bpf/test_run.c:1565
 bpf_prog_test_run+0x21b/0x360 kernel/bpf/syscall.c:4860
 __sys_bpf+0x914/0xc50 kernel/bpf/syscall.c:6478
 __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 0xffff8881046d0478 of 2 bytes by task 5152 on cpu 0:
 __migrate_enable include/linux/sched.h:2457 [inline]
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_run_pin_on_cpu include/linux/filter.h:838 [inline]
 bpf_flow_dissect+0x162/0x360 net/core/flow_dissector.c:1024
 bpf_prog_test_run_flow_dissector+0x25d/0x360 net/bpf/test_run.c:1565
 bpf_prog_test_run+0x21b/0x360 kernel/bpf/syscall.c:4860
 __sys_bpf+0x914/0xc50 kernel/bpf/syscall.c:6478
 __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: 5152 Comm: syz.0.776 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 17:17 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb
2026/11/17 10:29 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb
2026/11/17 02:05 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in bpf_flow_dissect / bpf_prog_run_clear_cb
* Struck through repros no longer work on HEAD.