KCSAN: data-race in perf_callchain / v2_read_file_info

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

A KCSAN data race was reported between an interrupt context reading task->flags and task context modifying current->flags on the same CPU. In task context, memalloc_flags_restore() performs an unmarked read-modify-write (current->flags &= ~flags) to clear PF_MEMALLOC_NOFS; when interrupted on the same CPU by an APIC timer interrupt, the perf subsystem executes perf_callchain() -> is_user_task(current), which performs an unmarked plain read of task->flags to test PF_KTHREAD and PF_USER_WORKER. Because neither the reader in is_user_task() nor the updater in memalloc_flags_restore() uses READ_ONCE()/WRITE_ONCE() or data_race(), KCSAN flags the concurrent access as a data race.

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

Technical Analysis of Root Cause

1. Raced Object and Memory Location

The memory access reported by KCSAN is to 0xffff88810280a2ac (4 bytes), which corresponds to the flags field (unsigned int flags, at byte offset 0x2c / 352 bits) of struct task_struct for the current task (PID: 3515).

2. Call Paths and Contexts Involved

  • Task Context (read-write on CPU 1): During a mount operation, v2_read_file_info() (fs/quota/quota_v2.c:191) restores filesystem memory allocation flags by calling memalloc_nofs_restore(memalloc):

    // include/linux/sched/mm.h:401
    static inline void memalloc_nofs_restore(unsigned int flags)
    {
        memalloc_flags_restore(flags);
    }
    
    // include/linux/sched/mm.h:339-342
    static inline void memalloc_flags_restore(unsigned flags)
    {
        current->flags &= ~flags;
    }
    

    memalloc_flags_restore() performs an unmarked C read-modify-write on current->flags to clear dynamic allocation flags (in this case, PF_MEMALLOC_NOFS). Note that v2_read_file_info() is merely an incidental caller; any task-context caller of memalloc_flags_{save,restore}() or other plain current->flags mutators can encounter this race.

  • Interrupt Context (read on CPU 1): With CONFIG_KCSAN_INTERRUPT_WATCHER enabled, kcsan_setup_watchpoint() leaves local IRQs enabled while inserting a delay on the watchpoint for &current->flags. During this window, an APIC timer interrupt occurs on the same CPU: sysvec_apic_timer_interrupt $\to$ hrtimer_interrupt $\to$ perf_swevent_hrtimer $\to$ perf_prepare_sample $\to$ perf_callchain (kernel/events/core.c:8742). In perf_callchain(), the helper is_user_task(current) (include/linux/sched.h:1874) is executed to determine if user space callchains should be recorded:

    // include/linux/sched.h:1872-1875
    static __always_inline bool is_user_task(struct task_struct *task)
    {
        return task->mm && !(task->flags & (PF_KTHREAD | PF_USER_WORKER));
    }
    

    This performs an unmarked plain load of task->flags (current->flags).

3. Root Cause Mechanism

The task->flags field contains per-task flags that are modified synchronously by current itself. However, interrupt and NMI handlers running on the same CPU (such as perf sampling current) can asynchronously inspect current->flags.

While some callers that inspect current->flags from asynchronous contexts use marked access (for example, current_gfp_context() in include/linux/sched/mm.h:250 explicitly uses READ_ONCE(current->flags)), is_user_task() uses a plain, unmarked load:

task->flags & (PF_KTHREAD | PF_USER_WORKER)

Simultaneously, memalloc_flags_{save,restore}() mutate current->flags via plain read-modify-write operations (current->flags |= flags; and current->flags &= ~flags;) without READ_ONCE() or WRITE_ONCE().

When an interrupt arrives while the task is modifying current->flags, KCSAN detects the concurrent plain load against the active watchpoint on current->flags.

To eliminate the KCSAN data-race report and prevent any theoretical compiler load/store tearing, is_user_task() should use READ_ONCE(task->flags) (or data_race()), and memalloc_flags_{save,restore}() should access current->flags using marked operations (READ_ONCE()/WRITE_ONCE()).

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
e80dfe8a assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in perf_callchain / v2_read_file_info 2026/11/19 04:07 2026/11/19 04:07 2026/11/19 04:31 2006bdcc
bcb2fb4d assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in perf_callchain / v2_read_file_info 2026/11/19 04:06 2026/11/19 04:06 2026/11/19 04:27 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in perf_callchain / v2_read_file_info

read to 0xffff88810280a2ac of 4 bytes by interrupt on cpu 1:
 is_user_task include/linux/sched.h:1874 [inline]
 perf_callchain+0xa2/0x270 kernel/events/core.c:8742
 perf_sample_save_callchain include/linux/perf_event.h:1385 [inline]
 perf_prepare_sample+0x1f5/0x1550 kernel/events/core.c:8829
 __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
 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
 memalloc_flags_restore include/linux/sched/mm.h:341 [inline]
 memalloc_nofs_restore include/linux/sched/mm.h:401 [inline]
 v2_read_file_info+0x4dd/0x6d0 fs/quota/quota_v2.c:191
 dquot_load_quota_sb+0x476/0x5c0 fs/quota/dquot.c:2432
 dquot_load_quota_inode+0x213/0x2f0 fs/quota/dquot.c:2469
 ext4_quota_enable fs/ext4/super.c:7321 [inline]
 ext4_enable_quotas+0x2d2/0x400 fs/ext4/super.c:7347
 __ext4_fill_super fs/ext4/super.c:5756 [inline]
 ext4_fill_super+0x32a4/0x3720 fs/ext4/super.c:5899
 get_tree_bdev_flags+0x297/0x300 fs/super.c:1821
 get_tree_bdev+0x1f/0x30 fs/super.c:1844
 ext4_get_tree+0x1c/0x30 fs/ext4/super.c:5931
 vfs_get_tree+0x57/0x1d0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x288/0x730 fs/namespace.c:3986
 path_mount+0x4ad/0xba0 fs/namespace.c:4337
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x28c/0x2e0 fs/namespace.c:4540
 __x64_sys_mount+0x67/0x80 fs/namespace.c:4540
 x64_sys_call+0xc3b/0x2550 arch/x86/include/generated/asm/syscalls_64.h:166
 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 0xffff88810280a2ac of 4 bytes by task 3515 on cpu 1:
 memalloc_flags_restore include/linux/sched/mm.h:341 [inline]
 memalloc_nofs_restore include/linux/sched/mm.h:401 [inline]
 v2_read_file_info+0x4dd/0x6d0 fs/quota/quota_v2.c:191
 dquot_load_quota_sb+0x476/0x5c0 fs/quota/dquot.c:2432
 dquot_load_quota_inode+0x213/0x2f0 fs/quota/dquot.c:2469
 ext4_quota_enable fs/ext4/super.c:7321 [inline]
 ext4_enable_quotas+0x2d2/0x400 fs/ext4/super.c:7347
 __ext4_fill_super fs/ext4/super.c:5756 [inline]
 ext4_fill_super+0x32a4/0x3720 fs/ext4/super.c:5899
 get_tree_bdev_flags+0x297/0x300 fs/super.c:1821
 get_tree_bdev+0x1f/0x30 fs/super.c:1844
 ext4_get_tree+0x1c/0x30 fs/ext4/super.c:5931
 vfs_get_tree+0x57/0x1d0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x288/0x730 fs/namespace.c:3986
 path_mount+0x4ad/0xba0 fs/namespace.c:4337
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x28c/0x2e0 fs/namespace.c:4540
 __x64_sys_mount+0x67/0x80 fs/namespace.c:4540
 x64_sys_call+0xc3b/0x2550 arch/x86/include/generated/asm/syscalls_64.h:166
 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: 3515 Comm: syz.1.6 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
EXT4-fs (loop1): mounted filesystem 00000000-0000-0000-0000-000000000000 r/w without journal. Quota mode: writeback.
ext4 filesystem being mounted at /1/bus supports timestamps until 2038-01-19 (0x7fffffff)
EXT4-fs error (device loop1): ext4_xattr_block_get:608: inode #15: comm syz.1.6: corrupted xattr block 33: e_value size too large
SELinux: inode_doinit_use_xattr:  getxattr returned 117 for dev=loop1 ino=15
EXT4-fs error (device loop1): ext4_xattr_block_get:608: inode #15: comm syz.1.6: corrupted xattr block 33: e_value size too large
SELinux: inode_doinit_use_xattr:  getxattr returned 117 for dev=loop1 ino=15
syz.1.6 (3515) used greatest stack depth: 9856 bytes left

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