KCSAN: data-race in sk_filter_trim_cap / tracing_gen_ctx_irq_test

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

A data race occurs between __migrate_disable() in include/linux/sched.h and migration_disable_value() in kernel/trace/trace.c. In __migrate_disable(), guard(preempt)() disables preemption but leaves hardware interrupts enabled while performing an unmarked write to p->migration_disabled (p->migration_disabled = 1). When a hardware interrupt fires on the same CPU while the write is taking place, interrupt exit paths triggering tracing (such as trace_write_msr) call tracing_gen_ctx_irq_test(), which performs an unmarked read via migration_disable_value() (return current->migration_disabled). This data race surfaced to KCSAN when migrate_disable() was moved from kernel/sched/core.c (where KCSAN_SANITIZE := n disabled instrumentation) to include/linux/sched.h as an inline function, exposing its accesses to KCSAN instrumentation in callers such as sk_filter_trim_cap().

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

Root Cause Analysis

1. Functions, Structs, Fields, and Files Involved

2. Mechanism and Trigger

  1. Unmarked writes with hardware interrupts enabled: In include/linux/sched.h:2479, __migrate_disable() updates p->migration_disabled:

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

    While guard(preempt)() disables kernel preemption on the CPU, hardware interrupts remain enabled throughout the execution of __migrate_disable(). The write p->migration_disabled = 1; (at line 2496) is performed as an unmarked plain store.

  2. Asynchronous unmarked read from hardirq tracing context on the same CPU: While task 5403 was executing the plain store in __migrate_disable(), an APIC timer interrupt (sysvec_apic_timer_interrupt) arrived on the same CPU (CPU 0), interrupting the task. During interrupt exit processing (irqentry_exit $\to$ __hrtimer_rearm_deferred $\to$ lapic_next_event $\to$ native_apic_msr_write), writing the lapic MSR triggered the trace_write_msr tracepoint (arch/x86/include/asm/msr-trace.h). The tracepoint buffer allocation path (trace_event_buffer_reserve $\to$ tracing_gen_ctx_dec $\to$ tracing_gen_ctx_irq_test) samples the current migration disable counter to pack into the trace entry:

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

    migration_disable_value() reads current->migration_disabled via a plain, unmarked load. Because the interrupted thread was in the middle of modifying p->migration_disabled, KCSAN detected the concurrent unmarked read and write to the same memory location (0xffff8881017e95b8).

  3. Why the data race surfaced: Previously, migrate_disable() and migrate_enable() resided in kernel/sched/core.c. In kernel/sched/Makefile, KCSAN_SANITIZE := n disables KCSAN instrumentation for all scheduler core compilation units, masking any data races occurring within them. Commit 378b7708194f ("sched: Make migrate_{en,dis}able() inline") moved migrate_disable() to include/linux/sched.h as an inline function so callers (such as sk_filter_trim_cap() in net/core/filter.c) could inline it directly. These calling files are compiled with full KCSAN instrumentation enabled, exposing the missing concurrency markings (data_race() or READ_ONCE() / WRITE_ONCE()) between the process-context modifications and the interrupt-context trace sampling.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
4349d0f9 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ✅ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ✅ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in sk_filter_trim_cap / tracing_gen_ctx_irq_test 2026/11/18 07:14 2026/11/18 07:14 2026/11/18 07:28 eb4895d7
d7e021e0 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in sk_filter_trim_cap / tracing_gen_ctx_irq_test 2026/11/18 07:14 2026/11/18 07:14 2026/11/18 07:28 eb4895d7

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

read to 0xffff8881017e95b8 of 2 bytes by task 5403 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]
 tracing_gen_ctx_dec include/linux/trace_events.h:218 [inline]
 trace_event_buffer_reserve+0xe4/0x180 kernel/trace/trace_events.c:720
 do_trace_event_raw_event_msr_trace_class arch/x86/include/asm/msr-trace.h:21 [inline]
 trace_event_raw_event_msr_trace_class+0x85/0x170 arch/x86/include/asm/msr-trace.h:21
 __do_trace_write_msr arch/x86/include/asm/msr-trace.h:45 [inline]
 trace_write_msr arch/x86/include/asm/msr-trace.h:45 [inline]
 do_trace_write_msr+0xc1/0xe0 arch/x86/lib/msr.c:128
 native_write_msr arch/x86/include/asm/msr.h:140 [inline]
 wrmsrq arch/x86/include/asm/msr.h:199 [inline]
 native_apic_msr_write+0x4a/0x50 arch/x86/include/asm/apic.h:208
 apic_write arch/x86/include/asm/apic.h:405 [inline]
 lapic_next_event+0x11/0x20 arch/x86/kernel/apic/apic.c:418
 clockevents_program_event+0x22e/0x340 kernel/time/clockevents.c:372
 tick_program_event+0x79/0xc0 kernel/time/tick-oneshot.c:48
 hrtimer_rearm_event kernel/time/hrtimer.c:710 [inline]
 hrtimer_rearm kernel/time/hrtimer.c:2181 [inline]
 __hrtimer_rearm_deferred+0x569/0x660 kernel/time/hrtimer.c:2201
 hrtimer_rearm_deferred_tif include/linux/hrtimer_rearm.h:58 [inline]
 hrtimer_rearm_deferred include/linux/hrtimer_rearm.h:67 [inline]
 irqentry_hrtimer_rearm_deferred include/linux/irq-entry-common.h:471 [inline]
 irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:509 [inline]
 irqentry_exit_to_kernel_mode include/linux/irq-entry-common.h:546 [inline]
 irqentry_exit+0x5bc/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
 rdtsc_ordered arch/x86/include/asm/tsc.h:57 [inline]
 delay_tsc+0x5b/0xa0 arch/x86/lib/delay.c:70
 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_save_cb include/linux/filter.h:1104 [inline]
 sk_filter_trim_cap+0x1d0/0x580 net/core/filter.c:168
 sk_filter include/linux/filter.h:1226 [inline]
 unix_dgram_sendmsg+0x63a/0x1050 net/unix/af_unix.c:2184
 unix_seqpacket_sendmsg+0xd1/0x120 net/unix/af_unix.c:2550
 sock_sendmsg_nosec net/socket.c:800 [inline]
 __sock_sendmsg net/socket.c:818 [inline]
 ____sys_sendmsg+0x50f/0x550 net/socket.c:2713
 ___sys_sendmsg+0x1c8/0x220 net/socket.c:2770
 __sys_sendmmsg+0x1a0/0x310 net/socket.c:2859
 __do_sys_sendmmsg net/socket.c:2886 [inline]
 __se_sys_sendmmsg net/socket.c:2883 [inline]
 __x64_sys_sendmmsg+0x57/0x70 net/socket.c:2883
 x64_sys_call+0x1fb4/0x2550 arch/x86/include/generated/asm/syscalls_64.h:308
 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 0xffff8881017e95b8 of 2 bytes by task 5403 on cpu 0:
 __migrate_disable include/linux/sched.h:2496 [inline]
 migrate_disable include/linux/sched.h:2512 [inline]
 bpf_prog_run_save_cb include/linux/filter.h:1104 [inline]
 sk_filter_trim_cap+0x1d0/0x580 net/core/filter.c:168
 sk_filter include/linux/filter.h:1226 [inline]
 unix_dgram_sendmsg+0x63a/0x1050 net/unix/af_unix.c:2184
 unix_seqpacket_sendmsg+0xd1/0x120 net/unix/af_unix.c:2550
 sock_sendmsg_nosec net/socket.c:800 [inline]
 __sock_sendmsg net/socket.c:818 [inline]
 ____sys_sendmsg+0x50f/0x550 net/socket.c:2713
 ___sys_sendmsg+0x1c8/0x220 net/socket.c:2770
 __sys_sendmmsg+0x1a0/0x310 net/socket.c:2859
 __do_sys_sendmmsg net/socket.c:2886 [inline]
 __se_sys_sendmmsg net/socket.c:2883 [inline]
 __x64_sys_sendmmsg+0x57/0x70 net/socket.c:2883
 x64_sys_call+0x1fb4/0x2550 arch/x86/include/generated/asm/syscalls_64.h:308
 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: 5403 Comm: syz.2.728 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 02:25 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in sk_filter_trim_cap / tracing_gen_ctx_irq_test
* Struck through repros no longer work on HEAD.