KCSAN: data-race in bpf_map_update_value / bpf_sk_storage_free

Status: upstream: reported on 2026/11/19 01:15
Subsystems: net
Labels: prio:low race:harmful
[Documentation on labels]
Reported-by: syzbot+30dc80192107a6515bb5@syzkaller.appspotmail.com
First crash: 1d08h, last: 1d08h
✨ AI-generated root cause summary:

A KCSAN data race occurs between task context and softirq context on the 2-byte field current->migration_disabled. While a syscall thread in bpf_map_update_value() calls migrate_disable() -> __migrate_disable(), it disables preemption via guard(preempt)() and performs a plain store to current->migration_disabled = 1. Preempt disable does not mask hardware interrupts, allowing a timer interrupt on the same CPU to run softirq RCU callbacks on irq exit, which invokes socket destruction (__sk_destruct() -> bpf_sk_storage_free()). In bpf_sk_storage_free(), rcu_read_lock_dont_migrate() unnecessarily invokes migrate_disable() in softirq context, re-entering __migrate_disable() and reading current->migration_disabled concurrently with the interrupted plain store.

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

Technical Root Cause Analysis

1. Mechanism and Call Flow

The reported KCSAN bug is a data race on current->migration_disabled (a 16-bit integer located in struct task_struct) between a task-context write and an interrupt/softirq-context read on the same CPU:

  1. Task Context (Writer): A task executing the bpf() syscall (bpf_map_update_value) calls bpf_disable_instrumentation() (include/linux/bpf.h:2875), which invokes migrate_disable() -> __migrate_disable() (include/linux/sched.h:2479). In __migrate_disable(), because p->migration_disabled is initially 0:

    • It acquires guard(preempt)(), which disables preemption (preempt_disable()).
    • It increments this_rq_pinned()++.
    • It writes p->migration_disabled = 1; (include/linux/sched.h:2496).
  2. Interrupt and Softirq Interruption (Reader): guard(preempt)() only disables preemption; it does not mask hardware interrupts (local_irq_save) or bottom halves. While the write to p->migration_disabled = 1 is being executed (where KCSAN inserts a watchpoint delay), a hardware timer interrupt (sysvec_apic_timer_interrupt) triggers on CPU 1. On IRQ exit, __irq_exit_rcu() (kernel/softirq.c:780) determines that irq_count() == HARDIRQ_OFFSET && local_softirq_pending() and invokes pending softirqs via invoke_softirq() -> __do_softirq(). Within RCU_SOFTIRQ (rcu_core_si -> rcu_core -> rcu_do_batch), deferred socket destruction is invoked (deferred_put_nlk_sk -> sk_free -> __sk_free -> sk_destruct -> __sk_destruct -> bpf_sk_storage_free).

  3. Re-entrancy into __migrate_disable(): In net/core/bpf_sk_storage.c:52, bpf_sk_storage_free() calls rcu_read_lock_dont_migrate(). When CONFIG_PREEMPT_RCU is enabled, rcu_read_lock_dont_migrate() (include/linux/rcupdate.h:986) calls migrate_disable(). Because the softirq runs in the context of the interrupted task, current is still the same task_struct. __migrate_disable() executes:

    if (p->migration_disabled) {
        ...
    }
    

    This performs an un-annotated, non-atomic 2-byte read on p->migration_disabled (include/linux/sched.h:2483), directly racing with the interrupted thread's store to p->migration_disabled = 1 (include/linux/sched.h:2496).

2. Violated Invariants & Underlying Defect

  1. Unnecessary migrate_disable() in bpf_sk_storage_free(): Socket destruction (__sk_destruct) frequently occurs in softirq or RCU callback contexts where migration is inherently impossible (interrupt/softirq execution cannot be migrated to another CPU). Furthermore, bpf_local_storage no longer relies on per-CPU busy counters. Similar local storage destructors (bpf_task_storage_free and bpf_cgrp_storage_free) use standard rcu_read_lock() / rcu_read_unlock(). bpf_sk_storage_free() unnecessarily invoked rcu_read_lock_dont_migrate().
  2. Lack of IRQ / Softirq Re-entrancy Protection in __migrate_disable(): __migrate_disable() only disables preemption, leaving current->migration_disabled susceptible to concurrent reads and writes if any code executed in hardirq/softirq context on the same CPU also calls migrate_disable().
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
56a86a8f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in bpf_map_update_value / bpf_sk_storage_free 2026/11/18 23:56 2026/11/18 23:56 2026/11/19 00:12 2006bdcc
d7d99fbb assessment-kcsan Benign: ❌ ❓ KCSAN: data-race in bpf_map_update_value / bpf_sk_storage_free 2026/11/18 23:55 2026/11/18 23:55 2026/11/19 01:15 2006bdcc
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [net?] KCSAN: data-race in bpf_map_update_value / bpf_sk_storage_free 0 (1) 2026/11/19 01:15

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

read to 0xffff888101d295b8 of 2 bytes by interrupt on cpu 1:
 __migrate_disable include/linux/sched.h:2483 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 rcu_read_lock_dont_migrate include/linux/rcupdate.h:990 [inline]
 bpf_sk_storage_free+0x2b/0x210 net/core/bpf_sk_storage.c:52
 __sk_destruct+0x12e/0x4d0 net/core/sock.c:2398
 sk_destruct net/core/sock.c:2448 [inline]
 __sk_free+0x23c/0x280 net/core/sock.c:2459
 sk_free+0x55/0x90 net/core/sock.c:2470
 deferred_put_nlk_sk+0x89/0xc0 net/netlink/af_netlink.c:712
 rcu_do_batch kernel/rcu/tree.c:2650 [inline]
 rcu_core+0x76e/0xcb0 kernel/rcu/tree.c:2919
 rcu_core_si+0xd/0x20 kernel/rcu/tree.c:2936
 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_disable include/linux/sched.h:2496 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_update_value+0x1cf/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

write to 0xffff888101d295b8 of 2 bytes by task 12002 on cpu 1:
 __migrate_disable include/linux/sched.h:2496 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_disable_instrumentation include/linux/bpf.h:2875 [inline]
 bpf_map_update_value+0x1cf/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: 12002 Comm: syz.0.4076 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 17:20 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in bpf_map_update_value / bpf_sk_storage_free
* Struck through repros no longer work on HEAD.