From 79b6d270182b5fbb787b2be3fab044dc53e4b815 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Sun, 27 Apr 2025 12:08:42 +0800 Subject: [PATCH] arm64: fix SP_EL0 register handling in syscall return path Use regs[REG_SP_EL0] from register context instead of direct sp_el0 system register read/write operations in arm64_syscall(). Replace read_sysreg(sp_el0) with regs[REG_SP_EL0] and write_sysreg(usp, sp_el0) with direct assignment to regs[REG_SP_EL0]. Ensures userspace stack pointer is correctly maintained from register context during signal delivery, preventing userspace SP corruption on syscall return. Signed-off-by: hujun5 --- arch/arm64/src/common/arm64_syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/src/common/arm64_syscall.c b/arch/arm64/src/common/arm64_syscall.c index 6e837df1c23..ab1a67f4660 100644 --- a/arch/arm64/src/common/arm64_syscall.c +++ b/arch/arm64/src/common/arm64_syscall.c @@ -269,13 +269,13 @@ uint64_t *arm64_syscall(uint64_t *regs) /* Create a frame for info and copy the kernel info */ - rtcb->xcp.ustkptr = (uintptr_t *)read_sysreg(sp_el0); + rtcb->xcp.ustkptr = (uintptr_t *)regs[REG_SP_EL0]; usp = (uintptr_t)rtcb->xcp.ustkptr - sizeof(siginfo_t); memcpy((void *)usp, (void *)regs[REG_X2], sizeof(siginfo_t)); /* Now set the updated SP and user copy of "info" to R2 */ - write_sysreg(usp, sp_el0); + regs[REG_SP_EL0] = usp; regs[REG_X2] = usp; } #endif