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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2025-04-27 12:08:42 +08:00 committed by Xiang Xiao
parent 3d45550da9
commit 79b6d27018

View file

@ -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