KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test

Status: moderation: reported on 2026/11/19 00:02
Subsystems: trace
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+f4b3a0c44207d20e9040@syzkaller.appspotmail.com
First crash: 1d22h, last: 1d06h
✨ AI-generated root cause summary:

A data race occurs on task_struct::migration_disabled between __migrate_enable() in include/linux/sched.h and migration_disable_value() in kernel/trace/trace.c. In __migrate_enable(), when migration_disabled > 1, the counter is decremented using an unmarked plain write with preemption and hardware interrupts enabled. If a hardware interrupt fires during the write and initiates preemption on the same CPU, __schedule() executes trace_sched_switch, which invokes tracing_gen_ctx_irq_test() and reads current->migration_disabled via an unmarked plain read in migration_disable_value(). Under LKMM, these concurrent unmarked accesses between thread and interrupt contexts constitute a data race.

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

Root Cause Analysis: KCSAN Data Race on task_struct::migration_disabled

1. Functions, Structs, and Files Involved

  • include/linux/sched.h:
    • __migrate_enable() (lines 2457–2460, 2475) and __migrate_disable() (lines 2483–2491, 2496).
    • Field: struct task_struct::migration_disabled (short / u16, 2 bytes at offset 1144 bytes / bit offset 9152).
  • kernel/trace/trace.c:
    • migration_disable_value() (lines 1715–1722).
    • tracing_gen_ctx_irq_test() (lines 1724–1748).
  • kernel/trace/trace_event_perf.c / kernel/sched/core.c:
    • perf_trace_buf_update(), perf_tp_event(), trace_sched_switch(), and __schedule().

2. Triggering Mechanism and Race Condition

  1. Unmarked Write in Task Context (__migrate_enable):

    • In __migrate_enable(), when a task has nested migrate_disable() calls (p->migration_disabled > 1), it executes:
      if (p->migration_disabled > 1) {
          p->migration_disabled--;
          return;
      }
      
    • Crucially, when p->migration_disabled > 1, migrate_disable() allows the task to remain preemptible (unlike preempt_disable()), and hardware interrupts remain enabled. The decrement p->migration_disabled-- is performed as an unmarked plain C read-modify-write operation.
    • (In the reported trace, bpf_prog_test_run_sk_lookup() nested two migration disable sectionsβ€”first via bpf_test_timer_enter() $\to$ rcu_read_lock_dont_migrate(), and second via BPF_PROG_SK_LOOKUP_RUN_ARRAY() $\to$ migrate_disable(), raising migration_disabled to 2.)
  2. Interruption and Unmarked Read in Tracing / Interrupt Preemption Context (migration_disable_value):

    • While __migrate_enable() is updating p->migration_disabled, an APIC timer interrupt (sysvec_apic_timer_interrupt) fires on the same CPU.
    • On the return path from the interrupt (irqentry_exit $\to$ irqentry_exit_cond_resched $\to$ irqentry_exit_to_kernel_mode_preempt $\to$ preempt_schedule_irq), the kernel determines that the task needs rescheduling and calls __schedule().
    • In __schedule(), the tracepoint trace_sched_switch fires. When perf or ftrace is active, generating trace buffer entry headers invokes tracing_gen_ctx_irq_test(), which calls:
      static unsigned short migration_disable_value(void)
      {
      #if defined(CONFIG_SMP)
          return current->migration_disabled;
      #else
          return 0;
      #endif
      }
      
    • migration_disable_value() performs an unmarked plain load of current->migration_disabled.
  3. Violation of the Linux Kernel Memory Model (LKMM):

    • Under LKMM, concurrent unmarked accesses where at least one access is a write constitute a data race. With CONFIG_KCSAN_INTERRUPT_WATCHER=y, KCSAN detects races between a task context access and an interrupting same-CPU context (such as hardirq/softirq or IRQ-exit preemption).
    • Because neither the read in migration_disable_value() nor the updates in __migrate_enable() / __migrate_disable() use READ_ONCE() or WRITE_ONCE(), KCSAN flags this as an unannotated data race.

3. Suggested Remediation

Annotate concurrent accesses to task_struct::migration_disabled with READ_ONCE() and WRITE_ONCE():

  • Use READ_ONCE(current->migration_disabled) in migration_disable_value() (as well as scheduler inspection helpers like is_migration_disabled()).
  • Use WRITE_ONCE(p->migration_disabled, ...) in __migrate_enable() and __migrate_disable().
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
e57dc2a5 assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test 2026/11/18 11:15 2026/11/18 11:15 2026/11/18 11:36 eb4895d7
b718a69e assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test 2026/11/18 11:09 2026/11/18 11:09 2026/11/18 11:32 eb4895d7

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

read to 0xffff88810469dab8 of 2 bytes by task 4868 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_sched_switch include/trace/events/sched.h:220 [inline]
 perf_trace_sched_switch+0x187/0x1d0 include/trace/events/sched.h:220
 __do_trace_sched_switch include/trace/events/sched.h:220 [inline]
 trace_sched_switch include/trace/events/sched.h:220 [inline]
 __schedule+0xc3d/0xd30 kernel/sched/core.c:7383
 preempt_schedule_irq+0x2c/0x50 kernel/sched/core.c:7666
 irqentry_exit_cond_resched kernel/entry/common.c:145 [inline]
 irqentry_exit_to_kernel_mode_preempt+0x63/0x80 include/linux/irq-entry-common.h:453
 irqentry_exit_to_kernel_mode include/linux/irq-entry-common.h:543 [inline]
 irqentry_exit+0x99/0x640 kernel/entry/common.c:154
 sysvec_apic_timer_interrupt+0x44/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_enable+0x48/0xf0 include/linux/sched.h:2458
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_test_run_sk_lookup+0x5d4/0x790 net/bpf/test_run.c:1658
 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

write to 0xffff88810469dab8 of 2 bytes by task 4868 on cpu 0:
 __migrate_enable+0x48/0xf0 include/linux/sched.h:2458
 migrate_enable include/linux/sched.h:2517 [inline]
 bpf_prog_test_run_sk_lookup+0x5d4/0x790 net/bpf/test_run.c:1658
 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: 4868 Comm: syz.1.595 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 18:06 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test
2026/11/17 13:56 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test
2026/11/17 04:45 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test
2026/11/17 02:45 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test
2026/11/17 02:34 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __migrate_enable / tracing_gen_ctx_irq_test
* Struck through repros no longer work on HEAD.