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.
This commit is contained in:
Ali Mohammad Pur 2022-03-02 21:41:37 +03:30 committed by Andreas Kling
parent a5d4824abe
commit 6608812e4b
Notes: sideshowbarker 2024-07-17 17:56:35 +09:00

View file

@ -89,7 +89,10 @@ ErrorOr<FlatPtr> 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<FPUState>(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<FPUState const*>(stack_ptr)));
Thread::current()->fpu_state() = data;
stack_ptr += sizeof(FPUState);
#endif