Skip to content

Commit 10573ae

Browse files
author
Russell King
committed
ARM: spectre-v1: fix syscall entry
Prevent speculation at the syscall table decoding by clamping the index used to zero on invalid system call numbers, and using the csdb speculative barrier. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Acked-by: Mark Rutland <mark.rutland@arm.com> Boot-tested-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Tony Lindgren <tony@atomide.com>
1 parent 1d4238c commit 10573ae

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎arch/arm/kernel/entry-common.S‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ local_restart:
242242
tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
243243
bne __sys_trace
244244

245-
cmp scno, #NR_syscalls @ check upper syscall limit
246-
badr lr, ret_fast_syscall @ return address
247-
ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
245+
invoke_syscall tbl, scno, r10, ret_fast_syscall
248246

249247
add r1, sp, #S_OFF
250248
2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
@@ -278,14 +276,8 @@ __sys_trace:
278276
mov r1, scno
279277
add r0, sp, #S_OFF
280278
bl syscall_trace_enter
281-
282-
badr lr, __sys_trace_return @ return address
283-
mov scno, r0 @ syscall number (possibly new)
284-
add r1, sp, #S_R0 + S_OFF @ pointer to regs
285-
cmp scno, #NR_syscalls @ check upper syscall limit
286-
ldmccia r1, {r0 - r6} @ have to reload r0 - r6
287-
stmccia sp, {r4, r5} @ and update the stack args
288-
ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
279+
mov scno, r0
280+
invoke_syscall tbl, scno, r10, __sys_trace_return, reload=1
289281
cmp scno, #-1 @ skip the syscall?
290282
bne 2b
291283
add sp, sp, #S_OFF @ restore stack
@@ -363,6 +355,10 @@ sys_syscall:
363355
bic scno, r0, #__NR_OABI_SYSCALL_BASE
364356
cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
365357
cmpne scno, #NR_syscalls @ check range
358+
#ifdef CONFIG_CPU_SPECTRE
359+
movhs scno, #0
360+
csdb
361+
#endif
366362
stmloia sp, {r5, r6} @ shuffle args
367363
movlo r0, r1
368364
movlo r1, r2

‎arch/arm/kernel/entry-header.S‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,31 @@
378378
#endif
379379
.endm
380380

381+
.macro invoke_syscall, table, nr, tmp, ret, reload=0
382+
#ifdef CONFIG_CPU_SPECTRE
383+
mov \tmp, \nr
384+
cmp \tmp, #NR_syscalls @ check upper syscall limit
385+
movcs \tmp, #0
386+
csdb
387+
badr lr, \ret @ return address
388+
.if \reload
389+
add r1, sp, #S_R0 + S_OFF @ pointer to regs
390+
ldmccia r1, {r0 - r6} @ reload r0-r6
391+
stmccia sp, {r4, r5} @ update stack arguments
392+
.endif
393+
ldrcc pc, [\table, \tmp, lsl #2] @ call sys_* routine
394+
#else
395+
cmp \nr, #NR_syscalls @ check upper syscall limit
396+
badr lr, \ret @ return address
397+
.if \reload
398+
add r1, sp, #S_R0 + S_OFF @ pointer to regs
399+
ldmccia r1, {r0 - r6} @ reload r0-r6
400+
stmccia sp, {r4, r5} @ update stack arguments
401+
.endif
402+
ldrcc pc, [\table, \nr, lsl #2] @ call sys_* routine
403+
#endif
404+
.endm
405+
381406
/*
382407
* These are the registers used in the syscall handler, and allow us to
383408
* have in theory up to 7 arguments to a function - r0 to r6.

0 commit comments

Comments
 (0)