KCSAN: data-race in trace_call_bpf / tracing_gen_ctx_irq_test

Status: moderation: reported on 2026/11/21 00:00
Subsystems: trace
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+4bd54b4245740188f1cb@syzkaller.appspotmail.com
First crash: 3d16h, last: 3d16h
✨ AI-generated root cause summary:

A KCSAN data race occurs on current->migration_disabled (2 bytes) between __migrate_disable() in include/linux/sched.h and migration_disable_value() in kernel/trace/trace.c. __migrate_disable() only disables preemption via guard(preempt)(), which does not block interrupts or softirqs, and updates p->migration_disabled without WRITE_ONCE(). When an interrupt/softirq fires on the same CPU and emits a trace/perf event, tracing_gen_ctx_irq_test() calls migration_disable_value(), which performs an unmarked plain read of current->migration_disabled without READ_ONCE().

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

Root Cause Analysis

The KCSAN report is caused by an unmarked concurrent write and read to the 2-byte unsigned short field task_struct::migration_disabled (include/linux/sched.h) on the same CPU between task context and interrupt/softirq context:

  1. Write side (task context): In trace_call_bpf() (kernel/trace/bpf_trace.c:147) -> bpf_prog_run_array() (include/linux/bpf.h:2796) -> migrate_disable() -> __migrate_disable() (include/linux/sched.h:2479-2497), the task updates its own migration-disable counter:

    • Line 2490: p->migration_disabled++; (if already non-zero)
    • Line 2494-2496: guard(preempt)(); this_rq_pinned()++; p->migration_disabled = 1;

    Here, guard(preempt)() only disables task preemption; it does not disable hardirqs or softirqs. Similarly, __migrate_enable() (include/linux/sched.h:2444-2477) modifies p->migration_disabled without WRITE_ONCE().

  2. Read side (interrupt / softirq context on the same CPU): While CPU 0 is inside __migrate_disable(), an APIC timer interrupt (sysvec_apic_timer_interrupt) fires and runs softirq processing (__irq_exit_rcu() -> handle_softirqs() -> rcu_core_si() -> rcu_core() -> rcu_do_batch() -> radix_tree_node_rcu_free() -> kmem_cache_free()). During softirq execution on CPU 0, current still points to the interrupted task (p).

    kmem_cache_free() triggers the kmem_cache_free tracepoint (perf_trace_kmem_cache_free() -> perf_trace_run_bpf_submit() -> perf_tp_event() -> perf_trace_buf_update()), which calls tracing_gen_ctx() -> tracing_gen_ctx_flags() -> tracing_gen_ctx_irq_test() (kernel/trace/trace.c:1747) -> migration_disable_value() (kernel/trace/trace.c:1715-1722):

    static unsigned short migration_disable_value(void)
    {
    #if defined(CONFIG_SMP)
        return current->migration_disabled;
    #else
        return 0;
    #endif
    }
    

    tracing_gen_ctx_irq_test() clamps the returned value via min_t(unsigned int, migration_disable_value(), 0xf) << 4, and tracing_generic_entry_update() (include/linux/trace_events.h:181) stores it in the upper nibble of struct trace_entry::preempt_count.

  3. Missing memory access annotations: Because __migrate_disable() (and __migrate_enable()) writes to p->migration_disabled with plain C assignments/increments and migration_disable_value() reads current->migration_disabled with a plain C load from interrupt context, KCSAN flags the unsynchronized 2-byte access to task_struct::migration_disabled. Using READ_ONCE() in migration_disable_value() and WRITE_ONCE() when updating p->migration_disabled in __migrate_disable()/__migrate_enable() (or marking the trace-context read appropriately) resolves the KCSAN data race.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
25e6edf2 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in trace_call_bpf / tracing_gen_ctx_irq_test 2026/11/19 20:01 2026/11/19 20:01 2026/11/19 20:08 229865fb
50763e1f assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in trace_call_bpf / tracing_gen_ctx_irq_test 2026/11/19 20:01 2026/11/19 20:01 2026/11/19 20:02 229865fb

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

read to 0xffff888101deebf8 of 2 bytes by interrupt on cpu 0:
 migration_disable_value kernel/trace/trace.c:1718 [inline]
 tracing_gen_ctx_irq_test+0xdd/0x110 kernel/trace/trace.c:1747
 tracing_gen_ctx_flags include/linux/trace_events.h:204 [inline]
 tracing_gen_ctx include/linux/trace_events.h:211 [inline]
 perf_trace_buf_update+0x33/0xa0 kernel/trace/trace_event_perf.c:428
 perf_tp_event+0xaf/0x1650 kernel/events/core.c:11621
 perf_trace_run_bpf_submit+0xac/0x110 kernel/events/core.c:11554
 do_perf_trace_kmem_cache_free include/trace/events/kmem.h:117 [inline]
 perf_trace_kmem_cache_free+0x131/0x170 include/trace/events/kmem.h:117
 __do_trace_kmem_cache_free include/trace/events/kmem.h:117 [inline]
 trace_kmem_cache_free include/trace/events/kmem.h:117 [inline]
 kmem_cache_free+0x350/0x3b0 mm/slub.c:6756
 radix_tree_node_rcu_free+0x69/0x80 lib/radix-tree.c:304
 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_prog_run_array include/linux/bpf.h:2796 [inline]
 trace_call_bpf+0xee/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
 bpf_free_scev+0x19e/0x280 kernel/bpf/scev.c:1714
 bpf_check+0x709/0x20e0 kernel/bpf/verifier.c:24318
 bpf_prog_load+0xf64/0x10c0 kernel/bpf/syscall.c:3172
 __sys_bpf+0xbce/0xc50 kernel/bpf/syscall.c:6460
 __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 0xffff888101deebf8 of 2 bytes by task 22906 on cpu 0:
 __migrate_disable include/linux/sched.h:2496 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_prog_run_array include/linux/bpf.h:2796 [inline]
 trace_call_bpf+0xee/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
 bpf_free_scev+0x19e/0x280 kernel/bpf/scev.c:1714
 bpf_check+0x709/0x20e0 kernel/bpf/verifier.c:24318
 bpf_prog_load+0xf64/0x10c0 kernel/bpf/syscall.c:3172
 __sys_bpf+0xbce/0xc50 kernel/bpf/syscall.c:6460
 __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: 22906 Comm: syz.4.4266 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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