Skip to content

Commit

Permalink
Kernel: Over-align the FPUState on the stack in sigreturn
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alimpfard authored and awesomekling committed Mar 4, 2022
1 parent a5d4824 commit 6608812
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Kernel/Syscalls/sigaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6608812

Please sign in to comment.