KCSAN: data-race in __blk_flush_plug / perf_prepare_sample

Status: moderation: reported on 2026/11/20 00:08
Subsystems: perf
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+e01554782fff4caed19b@syzkaller.appspotmail.com
First crash: 2d21h, last: 2d12h
✨ AI-generated root cause summary:

A KCSAN data race occurs between task context and an asynchronous interrupt on the same CPU: __blk_flush_plug() performs an unmarked read-modify-write on current->flags (current->flags &= ~PF_BLOCK_TS;) while an APIC timer interrupt calls perf_sample_regs_user() -> is_user_task(), which executes an unmarked read of task->flags (task->flags & (PF_KTHREAD | PF_USER_WORKER)). Under the Linux Kernel Memory Model (LKMM), concurrent unmarked writes and reads without annotations such as READ_ONCE() or atomic bit operations constitute a data race. In practice, this race is benign because the interrupt handler only inspects immutable task flags on disjoint bit positions without modifying the field.

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

Technical Mechanism and Root Cause

1. Functions, Structs, and Fields Involved

  • struct task_struct::flags (include/linux/sched.h): An unsigned int (32-bit) field containing process-level flags (PF_*), traditionally intended to be read and written exclusively by current (with specific exceptions like fork/ptrace).
  • __blk_flush_plug() (block/blk-core.c:1285): Called during block plug flushing (in this report, via blk_finish_plug() during memory reclaim under direct allocation). It clears the plug timestamp valid bit:
    current->flags &= ~PF_BLOCK_TS;
    
  • is_user_task() (include/linux/sched.h:1874): Called from perf_sample_regs_user() (kernel/events/core.c:7947) during perf event sample generation:
    static __always_inline bool is_user_task(struct task_struct *task)
    {
        return task->mm && !(task->flags & (PF_KTHREAD | PF_USER_WORKER));
    }
    

2. Triggering Mechanism and Race Condition

The bug is detected by Kernel Concurrency Sanitizer (KCSAN) on the same CPU (CPU 1) between task execution context and an asynchronous interrupt handler:

  1. Task Context Write: A task on CPU 1 enters __blk_flush_plug(). At line 1285, it executes current->flags &= ~PF_BLOCK_TS;. This is an unmarked C read-modify-write operation on current->flags.
  2. KCSAN Watchpoint Setup: Prior to / around the access, KCSAN sets up a watchpoint on the 4-byte address of current->flags and delays execution (delay_access() / udelay()).
  3. Interrupt Context Read: While the task context is suspended in the delay window, a local APIC timer interrupt (sysvec_apic_timer_interrupt) triggers on CPU 1. The interrupt handler executes hrtimer_interrupt() -> perf_swevent_hrtimer() -> perf_prepare_sample() -> perf_sample_regs_user(), which invokes is_user_task(current).
  4. Data Race: is_user_task() issues an unmarked 32-bit load of current->flags to check the bits PF_KTHREAD (0x00200000) and PF_USER_WORKER (0x00004000). Because one access is a write/read-modify-write and the other is a read to the same 4-byte memory location without synchronization primitives (such as READ_ONCE() / WRITE_ONCE() or atomic bit operations), KCSAN reports a data-race violation under the Linux Kernel Memory Model (LKMM).

3. Invariants and Practical Consequence

  • The block plug code introduced PF_BLOCK_TS (0x20000000) into task->flags as a fast flag to determine whether cached plug timestamps need invalidation upon task switch (finish_task_switch()).
  • Under normal kernel conventions, task->flags is updated non-atomically because only current writes it. However, asynchronous interrupt handlers on the same CPU can run at any instruction boundary and inspect current->flags.
  • In practice, this race is benign: the interrupt reader only checks PF_KTHREAD and PF_USER_WORKER, which are initialized during process/thread creation and never change over the thread's lifetime, while __blk_flush_plug() only modifies bit 29 (PF_BLOCK_TS). Furthermore, the interrupt handler does not write current->flags, preventing lost updates, and aligned 32-bit memory accesses are single-copy atomic on modern architectures (such as x86-64).
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
7c30314d assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __blk_flush_plug / perf_prepare_sample 2026/11/19 15:12 2026/11/19 15:12 2026/11/19 15:37 9aa3e232
ecf5bfd3 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __blk_flush_plug / perf_prepare_sample 2026/11/19 14:42 2026/11/19 14:42 2026/11/19 14:56 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in __blk_flush_plug / perf_prepare_sample

read to 0xffff888101de22ac of 4 bytes by interrupt on cpu 1:
 is_user_task include/linux/sched.h:1874 [inline]
 perf_sample_regs_user kernel/events/core.c:7947 [inline]
 perf_prepare_sample+0x3d5/0x1550 kernel/events/core.c:8844
 __perf_event_output kernel/events/core.c:9070 [inline]
 perf_event_output_forward+0x61/0x170 kernel/events/core.c:9091
 __perf_event_overflow+0x62f/0x950 kernel/events/core.c:10980
 perf_event_overflow kernel/events/core.c:11004 [inline]
 perf_swevent_hrtimer+0x293/0x320 kernel/events/core.c:12424
 __run_hrtimer kernel/time/hrtimer.c:2079 [inline]
 __hrtimer_run_queues+0x1f8/0x540 kernel/time/hrtimer.c:2136
 hrtimer_interrupt+0x27b/0x870 kernel/time/hrtimer.c:2255
 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1051 [inline]
 __sysvec_apic_timer_interrupt+0x5f/0x1f0 arch/x86/kernel/apic/apic.c:1068
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x6f/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 __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
 __blk_flush_plug+0x26e/0x2b0 block/blk-core.c:1285
 blk_finish_plug+0x47/0x70 block/blk-core.c:1301
 lru_gen_shrink_lruvec mm/vmscan.c:5427 [inline]
 shrink_lruvec mm/vmscan.c:6199 [inline]
 shrink_node_memcgs mm/vmscan.c:6438 [inline]
 shrink_node+0x9f6/0x4600 mm/vmscan.c:6482
 shrink_zones mm/vmscan.c:6701 [inline]
 do_try_to_free_pages+0x310/0xb80 mm/vmscan.c:6763
 try_to_free_mem_cgroup_pages+0x201/0x450 mm/vmscan.c:7044
 try_charge_memcg+0x460/0xc50 mm/memcontrol.c:2776
 try_charge mm/memcontrol.c:2924 [inline]
 obj_cgroup_charge_pages mm/memcontrol.c:3225 [inline]
 __memcg_kmem_charge_page+0x1bd/0x3e0 mm/memcontrol.c:3269
 __alloc_frozen_pages_noprof+0x1ff/0x3d0 mm/page_alloc.c:5514
 alloc_pages_mpol+0xaf/0x1d0 mm/mempolicy.c:2513
 alloc_frozen_pages_noprof mm/mempolicy.c:2584 [inline]
 alloc_pages_noprof+0x94/0x160 mm/mempolicy.c:2604
 vm_area_alloc_pages mm/vmalloc.c:3801 [inline]
 __vmalloc_area_node mm/vmalloc.c:3948 [inline]
 __vmalloc_node_range_noprof+0xa35/0x10b0 mm/vmalloc.c:4152
 __bpf_map_area_alloc kernel/bpf/syscall.c:404 [inline]
 bpf_map_area_alloc+0xfa/0x140 kernel/bpf/syscall.c:411
 dev_map_init_map kernel/bpf/devmap.c:154 [inline]
 dev_map_alloc+0x13d/0x350 kernel/bpf/devmap.c:173
 map_create_alloc kernel/bpf/syscall.c:1553 [inline]
 map_create+0xb14/0x1050 kernel/bpf/syscall.c:1663
 __sys_bpf+0x8e0/0xc50 kernel/bpf/syscall.c:6437
 __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-write to 0xffff888101de22ac of 4 bytes by task 13850 on cpu 1:
 __blk_flush_plug+0x26e/0x2b0 block/blk-core.c:1285
 blk_finish_plug+0x47/0x70 block/blk-core.c:1301
 lru_gen_shrink_lruvec mm/vmscan.c:5427 [inline]
 shrink_lruvec mm/vmscan.c:6199 [inline]
 shrink_node_memcgs mm/vmscan.c:6438 [inline]
 shrink_node+0x9f6/0x4600 mm/vmscan.c:6482
 shrink_zones mm/vmscan.c:6701 [inline]
 do_try_to_free_pages+0x310/0xb80 mm/vmscan.c:6763
 try_to_free_mem_cgroup_pages+0x201/0x450 mm/vmscan.c:7044
 try_charge_memcg+0x460/0xc50 mm/memcontrol.c:2776
 try_charge mm/memcontrol.c:2924 [inline]
 obj_cgroup_charge_pages mm/memcontrol.c:3225 [inline]
 __memcg_kmem_charge_page+0x1bd/0x3e0 mm/memcontrol.c:3269
 __alloc_frozen_pages_noprof+0x1ff/0x3d0 mm/page_alloc.c:5514
 alloc_pages_mpol+0xaf/0x1d0 mm/mempolicy.c:2513
 alloc_frozen_pages_noprof mm/mempolicy.c:2584 [inline]
 alloc_pages_noprof+0x94/0x160 mm/mempolicy.c:2604
 vm_area_alloc_pages mm/vmalloc.c:3801 [inline]
 __vmalloc_area_node mm/vmalloc.c:3948 [inline]
 __vmalloc_node_range_noprof+0xa35/0x10b0 mm/vmalloc.c:4152
 __bpf_map_area_alloc kernel/bpf/syscall.c:404 [inline]
 bpf_map_area_alloc+0xfa/0x140 kernel/bpf/syscall.c:411
 dev_map_init_map kernel/bpf/devmap.c:154 [inline]
 dev_map_alloc+0x13d/0x350 kernel/bpf/devmap.c:173
 map_create_alloc kernel/bpf/syscall.c:1553 [inline]
 map_create+0xb14/0x1050 kernel/bpf/syscall.c:1663
 __sys_bpf+0x8e0/0xc50 kernel/bpf/syscall.c:6437
 __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: 13850 Comm: syz.1.2653 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 13:26 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __blk_flush_plug / perf_prepare_sample
2026/11/17 13:26 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __blk_flush_plug / perf_prepare_sample
2026/11/17 03:45 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __blk_flush_plug / perf_prepare_sample
* Struck through repros no longer work on HEAD.