KCSAN: data-race in fpu_flush_thread / skb_copy_bits

Status: upstream: reported on 2026/11/19 20:26
Subsystems: kernel
Labels: race:harmful prio:low
[Documentation on labels]
Reported-by: syzbot+b07ec23d35be305855be@syzkaller.appspotmail.com
First crash: 2d15h, last: 2d15h
✨ AI-generated root cause summary:

In arch/x86/kernel/fpu/core.c, fpu_flush_thread() calls fpstate_reset(x86_task_fpu(current)) before fpu_reset_fpstate_regs() without holding fpregs_lock() and while TIF_NEED_FPU_LOAD may still be clear. Because preemption and softirqs remain enabled, a context switch into __switch_to() -> switch_fpu() (or a softirq using kernel_fpu_begin()) can observe !TIF_NEED_FPU_LOAD and invoke save_fpregs_to_fpstate() -> os_xsave(), reading fpstate->xfd (via xfd_validate_state()) and fpstate->xfeatures concurrently with __fpstate_reset() modifying them. KCSAN reported the same task/CPU with an empty read stack and a stale "skb_copy_bits" frame because preemption occurred inside KCSAN's delay_tsc(), and __switch_to_asm switches %rsp to the next task's stack before __switch_to() calls switch_fpu() while current still points to the outgoing task, causing arch_stack_walk() to fail and return 0 frames.

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

Root Cause

The data race is caused by missing fpregs_lock() synchronization (and premature FPU state modification before TIF_NEED_FPU_LOAD is set) in fpu_flush_thread() (arch/x86/kernel/fpu/core.c:880-884).

During execve() (begin_new_exec() -> flush_thread() -> fpu_flush_thread()):

void fpu_flush_thread(void)
{
	fpstate_reset(x86_task_fpu(current));
	fpu_reset_fpstate_regs();
}
  1. fpstate_reset() runs without fpregs_lock() and while TIF_NEED_FPU_LOAD may still be clear.

    • As documented on fpregs_lock() (arch/x86/include/asm/fpu/api.h:51-72), modifying current's fpu->fpstate requires fpregs_lock() (which disables preemption and softirqs on !PREEMPT_RT kernels) because a context switch or softirq can otherwise observe !TIF_NEED_FPU_LOAD and save CPU FPU registers to fpu->fpstate.
    • fpu_flush_thread() calls fpstate_reset() (arch/x86/kernel/fpu/core.c:616-634) before fpu_reset_fpstate_regs() (arch/x86/kernel/fpu/core.c:820-842), which is the function that acquires fpregs_lock(), invalidates FPU state (__fpu_invalidate_fpregs_state()), resets fpu->fpstate->regs, and sets TIF_NEED_FPU_LOAD.
    • Inside fpstate_reset(), fpu->fpstate is set to &fpu->__fpstate and __fpstate_reset() (arch/x86/kernel/fpu/core.c:590-614) writes fpstate->size, fpstate->xfeatures, fpstate->xfd (arch/x86/kernel/fpu/core.c:609, offset 0x18 within struct fpstate, matching 0xffff888103fc3058), fpstate->user_size, and fpstate->user_xfeatures.
  2. Concurrent access via context switch (switch_fpu()):

Why the KCSAN Report Shows the Same Task/CPU, Empty Read Stack, and skb_copy_bits

  • When KCSAN sets up the watchpoint in __fpstate_reset(), kcsan_setup_watchpoint() -> delay_tsc() (arch/x86/lib/delay.c:75) calls preempt_enable(), allowing task 15366 (dhcpcd-run-hook) to be preempted on CPU 0.
  • In __switch_to_asm (arch/x86/entry/entry_64.S:192), %rsp is switched to the incoming (next) task's kernel stack before jumping to __switch_to().
  • Inside __switch_to() (arch/x86/kernel/process_64.c:619), switch_fpu(prev_p, cpu) executes before raw_cpu_write(current_task, next_p) at line 670. Thus, when os_xsave() hits the watchpoint, current is still task 15366 (in_task() is true, cpu_id == 0), but %rsp already points to next's stack.
  • Consequently, stack_trace_save() in prepare_report_producer() (kernel/kcsan/report.c:598) calls arch_stack_walk(..., current, NULL) -> get_stack_info(state->sp, current, ...), which fails because state->sp is not on current's (prev_p's) stack, returning num_stack_entries = 0.
  • In print_report() (kernel/kcsan/report.c:413-416, 455-457), other_skipnr is 0, print_stack_trace() prints zero frames for the read side, and other_frame = other_info->stack_entries[other_skipnr] reads a stale stack_entries[0] (skb_copy_bits) left behind in other_infos[watchpoint_idx] from an earlier unrelated KCSAN report.

Fix Direction

Acquire fpregs_lock() across both fpstate_reset() and fpu_reset_fpstate_regs() in fpu_flush_thread() (or otherwise invalidate/set TIF_NEED_FPU_LOAD under fpregs_lock() before calling fpstate_reset() so switch_fpu() / kernel_fpu_begin() cannot observe !TIF_NEED_FPU_LOAD while fpu->fpstate is being reset).

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
6394ef20 repro-c 💥 KCSAN: data-race in fpu_flush_thread / skb_copy_bits 2026/11/19 21:10 2026/11/19 21:10 2026/11/19 21:34 229865fb
ef6a2dd3 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in fpu_flush_thread / skb_copy_bits 2026/11/19 20:17 2026/11/19 20:17 2026/11/19 20:26 229865fb
45f623b0 assessment-kcsan Benign: ❌ ❓ KCSAN: data-race in fpu_flush_thread / skb_copy_bits 2026/11/19 20:15 2026/11/19 20:15 2026/11/19 20:22 229865fb
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits 2 (3) 2026/11/19 21:11

Sample crash report:
==================================================================
BUG: KCSAN: data-race in fpu_flush_thread / skb_copy_bits

read to 0xffff888103fc3058 of 8 bytes by task 15366 on cpu 0:

write to 0xffff888103fc3058 of 8 bytes by task 15366 on cpu 0:
 __fpstate_reset arch/x86/kernel/fpu/core.c:-1 [inline]
 fpstate_reset arch/x86/kernel/fpu/core.c:620 [inline]
 fpu_flush_thread+0x128/0x360 arch/x86/kernel/fpu/core.c:882
 flush_thread+0x40/0x80 arch/x86/kernel/process.c:291
 begin_new_exec+0xcd0/0x1260 fs/exec.c:1235
 load_elf_binary+0x5ee/0x1a00 fs/binfmt_elf.c:1010
 search_binary_handler fs/exec.c:1777 [inline]
 exec_binprm fs/exec.c:1809 [inline]
 bprm_execve+0x480/0xaa0 fs/exec.c:1865
 do_execveat_common+0x6ba/0x720 fs/exec.c:1963
 __do_sys_execve fs/exec.c:2036 [inline]
 __se_sys_execve fs/exec.c:2030 [inline]
 __x64_sys_execve+0x5f/0x80 fs/exec.c:2030
 x64_sys_call+0x1cd2/0x2550 arch/x86/include/generated/asm/syscalls_64.h:60
 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: 15366 Comm: dhcpcd-run-hook 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 06:24 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fpu_flush_thread / skb_copy_bits
* Struck through repros no longer work on HEAD.