* [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits
@ 2026-11-19 20:26 syzbot
2026-11-19 20:53 ` Marco Elver
0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2026-11-19 20:26 UTC (permalink / raw)
To: arnd, binbin.wu, bp, chao.gao, dapeng1.mi, dave.hansen, ebiggers,
hpa, linux-kernel, mingo, seanjc, syzkaller-bugs, tglx, x86
Hello,
syzbot found the following issue on:
HEAD commit: 666539eecdf4 Merge tag 'assoc-array-fixes-v2'
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14b3c5be580000
kernel config: https://syzkaller.appspot.com/x/.config?x=b949a9d3c1d44ceb
dashboard link: https://syzkaller.appspot.com/bug?extid=b07ec23d35be305855be
compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/a943b9915869/disk-666539ee.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/9bfd839d7ea5/vmlinux-666539ee.xz
kernel image: https://storage.googleapis.com/syzbot-assets/0f20b9720a71/bzImage-666539ee.xz
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 analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=b07ec23d35be305855be
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+b07ec23d35be305855be@syzkaller.appspotmail.com
==================================================================
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
==================================================================
---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits
2026-11-19 20:26 [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits syzbot
@ 2026-11-19 20:53 ` Marco Elver
2026-11-19 21:11 ` Dave Hansen
0 siblings, 1 reply; 3+ messages in thread
From: Marco Elver @ 2026-11-19 20:53 UTC (permalink / raw)
To: syzbot
Cc: arnd, binbin.wu, bp, chao.gao, dapeng1.mi, dave.hansen, ebiggers,
hpa, linux-kernel, mingo, seanjc, syzkaller-bugs, tglx, x86
On Thu, 19 Nov 2026 at 21:26, syzbot
<syzbot+b07ec23d35be305855be@syzkaller.appspotmail.com> wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 666539eecdf4 Merge tag 'assoc-array-fixes-v2'
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=14b3c5be580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=b949a9d3c1d44ceb
> dashboard link: https://syzkaller.appspot.com/bug?extid=b07ec23d35be305855be
> compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8
>
> Unfortunately, I don't have any reproducer for this issue yet.
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/a943b9915869/disk-666539ee.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/9bfd839d7ea5/vmlinux-666539ee.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/0f20b9720a71/bzImage-666539ee.xz
>
> 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.
The above analysis is confusing. There's a better analysis it did
(https://syzkaller.appspot.com/ai_job?id=45f623b0-666c-486c-a73c-ede5e8eb0ba4):
> CPU0 (task in execve) CPU0 (preempt / softirq)
>
> // Task previously enabled dynamic xfeature:
> // xfd_state == 0, TIF_NEED_FPU_LOAD == 0
> fpu_flush_thread()
> fpstate_reset(fpu) // NO fpregs_lock()!
> fpu->fpstate = &fpu->__fpstate
> __fpstate_reset(fpu->fpstate)
> fpstate->xfeatures = default_features
> fpstate->xfd = init_fpstate.xfd // != 0
>
> <PREEMPT or SOFTIRQ>
> __switch_to() -> switch_fpu()
> (or kernel_fpu_begin_mask())
> // !TIF_NEED_FPU_LOAD is true
> update_fpu_state_and_flag(fpu, current)
> save_fpregs_to_fpstate(fpu)
> os_xsave(fpu->fpstate)
> xfd_validate_state(fpstate, mask, false)
> xstate_op_valid():
> fpstate->xfd != xfd_state (0)
> fpstate->xfd == current->fpu->fpstate->xfd
> -> returns false!
> WARN_ON_ONCE(1) // Kernel warning
> full analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=b07ec23d35be305855be
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+b07ec23d35be305855be@syzkaller.appspotmail.com
>
> ==================================================================
> 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
> ==================================================================
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits
2026-11-19 20:53 ` Marco Elver
@ 2026-11-19 21:11 ` Dave Hansen
0 siblings, 0 replies; 3+ messages in thread
From: Dave Hansen @ 2026-11-19 21:11 UTC (permalink / raw)
To: Marco Elver, syzbot
Cc: arnd, binbin.wu, bp, chao.gao, dapeng1.mi, dave.hansen, ebiggers,
hpa, linux-kernel, mingo, seanjc, syzkaller-bugs, tglx, x86,
Bae, Chang Seok
[-- Attachment #1: Type: text/plain, Size: 172 bytes --]
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?
[-- Attachment #2: [PATCH 3/4] x86/fpu: Reset the fpstate on exec() under fpregs_lock().eml --]
[-- Type: message/rfc822, Size: 4290 bytes --]
From: Dave Hansen <dave.hansen@linux.intel.com>
To: dave.hansen@intel.com
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Subject: [PATCH 3/4] x86/fpu: Reset the fpstate on exec() under fpregs_lock()
Date: Thu, 19 Nov 2026 13:07:33 -0800
Message-ID: <20261119210733.7A3C75E4@davehans-spike.ostc.intel.com>
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();
/*
_
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 21:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 20:26 [syzbot] [kernel?] KCSAN: data-race in fpu_flush_thread / skb_copy_bits syzbot
2026-11-19 20:53 ` Marco Elver
2026-11-19 21:11 ` Dave Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox