Skip to content

Commit d30a0c8

Browse files
Nicolas PitreRussell King
authored andcommitted
ARM kprobes: don't let a single-stepped stmdb corrupt the exception stack
If kprobes installs a breakpoint on a "stmdb sp!, {...}" instruction, and then single-step it by simulation from the exception context, it will corrupt the saved regs on the stack from the previous context. To avoid this, let's add an optional parameter to the svc_entry macro allowing for a hole to be created on the stack before saving the interrupted context, and use it in the undef_svc handler when kprobes is enabled. Signed-off-by: Nicolas Pitre <nico@marvell.com>
1 parent 25ce1dd commit d30a0c8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arch/arm/kernel/entry-armv.S

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ common_invalid:
112112
#define SPFIX(code...)
113113
#endif
114114

115-
.macro svc_entry
116-
sub sp, sp, #S_FRAME_SIZE
115+
.macro svc_entry, stack_hole=0
116+
sub sp, sp, #(S_FRAME_SIZE + \stack_hole)
117117
SPFIX( tst sp, #4 )
118118
SPFIX( bicne sp, sp, #4 )
119119
stmib sp, {r1 - r12}
120120

121121
ldmia r0, {r1 - r3}
122122
add r5, sp, #S_SP @ here for interlock avoidance
123123
mov r4, #-1 @ "" "" "" ""
124-
add r0, sp, #S_FRAME_SIZE @ "" "" "" ""
124+
add r0, sp, #(S_FRAME_SIZE + \stack_hole)
125125
SPFIX( addne r0, r0, #4 )
126126
str r1, [sp] @ save the "real" r0 copied
127127
@ from the exception stack
@@ -242,7 +242,14 @@ svc_preempt:
242242

243243
.align 5
244244
__und_svc:
245+
#ifdef CONFIG_KPROBES
246+
@ If a kprobe is about to simulate a "stmdb sp..." instruction,
247+
@ it obviously needs free stack space which then will belong to
248+
@ the saved context.
249+
svc_entry 64
250+
#else
245251
svc_entry
252+
#endif
246253

247254
@
248255
@ call emulation code, which returns using r9 if it has emulated

0 commit comments

Comments
 (0)