From 6608812e4b24ceff1b84c095b24e7c249085e317 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Wed, 2 Mar 2022 21:41:37 +0330 Subject: [PATCH] Kernel: Over-align the FPUState on the stack in sigreturn The stack is misaligned at this point for some reason, this is a hack that makes the resulting object "correctly" aligned, thus avoiding a KUBSAN error. --- Kernel/Syscalls/sigaction.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/sigaction.cpp b/Kernel/Syscalls/sigaction.cpp index 570f07cd2e..31a355e0ec 100644 --- a/Kernel/Syscalls/sigaction.cpp +++ b/Kernel/Syscalls/sigaction.cpp @@ -89,7 +89,10 @@ ErrorOr Process::sys$sigreturn([[maybe_unused]] RegisterState& register #if ARCH(I386) || ARCH(X86_64) // The FPU state is at the top here, pop it off and restore it. - Thread::current()->fpu_state() = TRY(copy_typed_from_user(stack_ptr)); + // FIXME: The stack alignment is off by 8 bytes here, figure this out and remove this excessively aligned object. + alignas(alignof(FPUState) * 2) FPUState data {}; + TRY(copy_from_user(&data, bit_cast(stack_ptr))); + Thread::current()->fpu_state() = data; stack_ptr += sizeof(FPUState); #endif