Skip to content

Commit e522b75

Browse files
committed
Merge tag 's390-7.0-6' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Pull s390 fixes from Vasily Gorbik: - Add array_index_nospec() to syscall dispatch table lookup to prevent limited speculative out-of-bounds access with user-controlled syscall number - Mark array_index_mask_nospec() __always_inline since GCC may emit an out-of-line call instead of the inline data dependency sequence the mitigation relies on - Clear r12 on kernel entry to prevent potential speculative use of user value in system_call, ext/io/mcck interrupt handlers * tag 's390-7.0-6' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: s390/entry: Scrub r12 register on kernel entry s390/syscalls: Add spectre boundary for syscall dispatch table s390/barrier: Make array_index_mask_nospec() __always_inline
2 parents be762d8 + 0738d39 commit e522b75

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

arch/s390/include/asm/barrier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ do { \
6262
* @size: number of elements in array
6363
*/
6464
#define array_index_mask_nospec array_index_mask_nospec
65-
static inline unsigned long array_index_mask_nospec(unsigned long index,
66-
unsigned long size)
65+
static __always_inline unsigned long array_index_mask_nospec(unsigned long index,
66+
unsigned long size)
6767
{
6868
unsigned long mask;
6969

arch/s390/kernel/entry.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ SYM_CODE_START(system_call)
271271
xgr %r9,%r9
272272
xgr %r10,%r10
273273
xgr %r11,%r11
274+
xgr %r12,%r12
274275
la %r2,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
275276
mvc __PT_R8(64,%r2),__LC_SAVE_AREA(%r13)
276277
MBEAR %r2,%r13
@@ -407,6 +408,7 @@ SYM_CODE_START(\name)
407408
xgr %r6,%r6
408409
xgr %r7,%r7
409410
xgr %r10,%r10
411+
xgr %r12,%r12
410412
xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
411413
mvc __PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
412414
MBEAR %r11,%r13
@@ -496,6 +498,7 @@ SYM_CODE_START(mcck_int_handler)
496498
xgr %r6,%r6
497499
xgr %r7,%r7
498500
xgr %r10,%r10
501+
xgr %r12,%r12
499502
stmg %r8,%r9,__PT_PSW(%r11)
500503
xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
501504
xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)

arch/s390/kernel/syscall.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <linux/cpufeature.h>
16+
#include <linux/nospec.h>
1617
#include <linux/errno.h>
1718
#include <linux/sched.h>
1819
#include <linux/mm.h>
@@ -131,8 +132,10 @@ void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
131132
if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET)))
132133
goto out;
133134
regs->gprs[2] = -ENOSYS;
134-
if (likely(nr < NR_syscalls))
135+
if (likely(nr < NR_syscalls)) {
136+
nr = array_index_nospec(nr, NR_syscalls);
135137
regs->gprs[2] = sys_call_table[nr](regs);
138+
}
136139
out:
137140
syscall_exit_to_user_mode(regs);
138141
}

0 commit comments

Comments
 (0)