arch: arm: ARMv8-M built-in stack protection fixes in userspace.S

This commit provides two fixes for the ARMv8-M built-in stack
protection in userspace.S. First, it clears the PSPLIM register
before setting the PSP to the privileged stack. In the wake of
this, the privilege stack area can now be positioned enywhere,
i.e. does not have to be above the user stack area. Second, it
removes unncessary push/pop when clearing the PSPLIM register,
upon returning from the system call, since the r3 register is
not used anymore in this routine.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2019-02-11 12:33:14 +01:00 committed by Kumar Gala
parent 533cfa18fa
commit 314949fa3d

View file

@ -186,6 +186,14 @@ valid_syscall:
str sp, [ip, #0]
str lr, [ip, #4]
#if defined(CONFIG_BUILTIN_STACK_GUARD)
/* clear stack pointer limit before setting the PSP */
push {r3}
mov r3, #0
msr PSPLIM, r3
pop {r3}
#endif
/* switch to privileged stack */
msr PSP, ip
@ -215,10 +223,8 @@ dispatch_syscall:
#if defined(CONFIG_BUILTIN_STACK_GUARD)
/* clear stack limit (stack protection not required in user mode) */
push {r3}
mov r3, #0
msr PSPLIM, r3
pop {r3}
#endif
/* set stack back to unprivileged stack */