Skip to content

Commit 6a97b37

Browse files
committed
arch/arm/arm_dispatch_syscall: fix callee-saved reg corruption in protected
arm_dispatch_syscall in armv7-m clobbered r11 with 'mov r11, sp' and the user-space callee-saved register value leaked back through the exception frame when SYS_syscall_return restored the context, resulting in corrupted parameters on subsequent syscalls and system hangs in protected builds. In armv6-m, r4 was used to load g_stublookup (Thumb-1 cannot use ip for indexed addressing) but was not restored before SYS_syscall_return, causing the same class of register corruption. Fix with minimal changes: - armv7-m: remove 'mov r11, sp' to stop clobbering user r11 - armv6-m: restore r4 from the stack frame before SYS_syscall_return Signed-off-by: buxiasen <buxiasen@xiaomi.com>
1 parent 55f44ea commit 6a97b37

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

arch/arm/src/armv6-m/arm_dispatch_syscall.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ arm_dispatch_syscall:
8989
lsl r0, r0, #2 /* R0=Offset of the stub for this syscall */
9090
ldr r4, [r4, r0] /* R4=Address of the stub for this syscall */
9191
blx r4 /* Call the stub (modifies lr) */
92+
ldr r4, [sp, #0] /* Restore r4 */
9293
add sp, sp, #32 /* Destroy the stack frame */
9394
mov r2, r0 /* R2=Save return value in R2 */
9495
mov r0, SYS_syscall_return /* R0=SYS_syscall_return */

arch/arm/src/armv7-m/arm_dispatch_syscall.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@
7878
arm_dispatch_syscall:
7979
.cfi_sections .debug_frame
8080
.cfi_startproc
81-
mov r11, sp
82-
.cfi_register sp, r11
8381
sub sp, sp, #32
82+
.cfi_def_cfa_offset 32
8483
str r4, [sp, #0]
8584
.cfi_offset r4, 0
8685
str r5, [sp, #4]

0 commit comments

Comments
 (0)