From 44fb71261a8f9374967f01038f3d24172c7cdf31 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 13 Oct 2019 14:39:04 +0200 Subject: [PATCH] Kernel: Fix accidental restore of bogus FPU state after fork Cloned threads (basically, forked processes) inherit the complete FPU state of their origin thread. There was a bug in the lazy FPU state save/restore mechanism where a cloned thread would believe it had a buffer full of valid FPU state (because the inherited flag said so) but the origin thread had never actually copied any FPU state into it. This patch fixes that by forcing out an FPU state save after doing the initial FPU initialization (FNINIT) in a thread. :^) --- Kernel/Arch/i386/CPU.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index a394405055..a890ede4dd 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -221,6 +221,8 @@ void exception_7_handler(RegisterDump& regs) asm volatile("fxrstor %0" ::"m"(current->fpu_state())); } else { asm volatile("fninit"); + asm volatile("fxsave %0" + : "=m"(g_last_fpu_thread->fpu_state())); current->set_has_used_fpu(true); }