Re: [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits

From: Dave Hansen

Date: Thu Nov 19 2026 - 16:11:22 EST


I'm not fond of the changelog or comments as-is, but the attached fix
looks sane-adjacent to me.

Chang, any chance you'd want to dig in and make sure this is a real issue?
--- Begin Message ---
Written by Claude, Anthropic's AI model, at Dave Hansen's direction.

switch_fpu() and kernel_fpu_begin() save live registers through
fpu->fpstate, using its xfeatures as the XSAVES mask, whenever
TIF_NEED_FPU_LOAD is clear. Code that changes the fpstate pointer or
its contents therefore does so under fpregs_lock(), which disables
preemption and softirqs and makes irq_fpu_usable() refuse hardirq FPU
use.

fpu_flush_thread() does not. It calls fpstate_reset() before taking
fpregs_lock() and before setting TIF_NEED_FPU_LOAD. At exec() the
registers are normally still live, so a preemption, softirq or hardirq
kernel_fpu_begin() in that window saves them through a pointer and
mask that fpstate_reset() is in the middle of writing. KCSAN reports
this as a data race between __fpstate_reset() and os_xsave().

It is harmless today. The embedded fpstate is only ever written with
the same default values, so the racing stores change nothing. With a
dynamically allocated fpstate the save lands in the embedded one using
its default mask, which is correctly sized, and exec() is about to
discard the state anyway. The worst outcome is a WARN from
xfd_validate_state() under CONFIG_X86_DEBUG_FPU because the hardware
XFD no longer matches the new fpstate's xfd.

Move the fpstate_reset() call into fpu_reset_fpstate_regs(), inside
its existing fpregs_lock() region. The vfree() of the old fpstate stays
outside the locked region since it may sleep.

No functional change intended on non-debug kernels. Compile tested
only.

---

b/arch/x86/kernel/fpu/core.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff -puN arch/x86/kernel/fpu/core.c~fpu-flush-thread-fpregs-lock arch/x86/kernel/fpu/core.c
--- a/arch/x86/kernel/fpu/core.c~fpu-flush-thread-fpregs-lock 2026-11-19 12:52:10.079375387 -0800
+++ b/arch/x86/kernel/fpu/core.c 2026-11-19 13:03:51.610146974 -0800
@@ -824,6 +824,12 @@ static void fpu_reset_fpstate_regs(void)
fpregs_lock();
__fpu_invalidate_fpregs_state(fpu);
/*
+ * Resetting the fpstate is only safe with preemption disabled.
+ * Otherwise a context switch could save the registers into it
+ * halfway through. Do it here, under the lock, not in the caller.
+ */
+ fpstate_reset(fpu);
+ /*
* This does not change the actual hardware registers. It just
* resets the memory image and sets TIF_NEED_FPU_LOAD so a
* subsequent return to usermode will reload the registers from the
@@ -882,7 +888,6 @@ void fpu_flush_thread(void)
struct fpu *fpu = x86_task_fpu(current);
struct fpstate *old_fps = fpu->fpstate;

- fpstate_reset(fpu);
fpu_reset_fpstate_regs();

/*
_

--- End Message ---