arch/x86_64: align the user signal frame and skip the ABI red zone

The signal frame was built inside the 128 byte red zone of the
interrupted user code and inherited its stack alignment, so a leaf
function could lose live data to the siginfo copy and the handler
could fault on an SSE access. Build the frame below the red zone,
16 byte aligned; the naked trampoline calls the handler itself and
its call provides the return address slot.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
This commit is contained in:
raiden00pl 2026-08-10 15:58:58 +02:00 committed by Xiang Xiao
parent 7c43502613
commit 7815a905af

View file

@ -39,6 +39,14 @@
#include "x86_64_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Red zone the System V AMD64 ABI reserves below the user stack pointer */
#define X86_64_ABI_RED_ZONE 128
/****************************************************************************
* Private Types
****************************************************************************/
@ -241,16 +249,18 @@ uint64_t *x86_64_syscall(uint64_t *regs)
rtcb->xcp.kstkptr = (uintptr_t *)regs[REG_RSP];
/* Copy "info" into user stack */
/* Create a 16 byte aligned frame for info below the red
* zone of the interrupted user code
*/
usp = rtcb->xcp.saved_ursp - 8;
/* Create a frame for info and copy the kernel info */
usp = usp - sizeof(siginfo_t);
usp = (rtcb->xcp.saved_ursp - X86_64_ABI_RED_ZONE -
sizeof(siginfo_t)) & ~0x0f;
memcpy((void *)usp, (void *)regs[REG_RSI], sizeof(siginfo_t));
/* Now set the updated SP and user copy of "info" to RSI */
/* Set the new SP and the user copy of "info" to RSI.
* The naked trampoline is entered with SP 16 byte
* aligned; its call provides the return address slot.
*/
regs[REG_RSP] = usp;
regs[REG_RSI] = usp;