diff options
| author | Will Deacon <will.deacon@arm.com> | 2018-02-05 10:34:20 -0500 |
|---|---|---|
| committer | Catalin Marinas <catalin.marinas@arm.com> | 2018-02-06 17:53:35 -0500 |
| commit | 6314d90e64936c584f300a52ef173603fb2461b5 (patch) | |
| tree | fb62ec15844bee34626b37a80ec6d82d6ee3f26a /arch/arm64 | |
| parent | 4d8efc2d5ee4c9ccfeb29ee8afd47a8660d0c0ce (diff) | |
arm64: entry: Ensure branch through syscall table is bounded under speculation
In a similar manner to array_index_mask_nospec, this patch introduces an
assembly macro (mask_nospec64) which can be used to bound a value under
speculation. This macro is then used to ensure that the indirect branch
through the syscall table is bounded under speculation, with out-of-range
addresses speculating as calls to sys_io_setup (0).
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64')
| -rw-r--r-- | arch/arm64/include/asm/assembler.h | 11 | ||||
| -rw-r--r-- | arch/arm64/kernel/entry.S | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 1f44b4255a28..1241fb211293 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h | |||
| @@ -123,6 +123,17 @@ | |||
| 123 | .endm | 123 | .endm |
| 124 | 124 | ||
| 125 | /* | 125 | /* |
| 126 | * Sanitise a 64-bit bounded index wrt speculation, returning zero if out | ||
| 127 | * of bounds. | ||
| 128 | */ | ||
| 129 | .macro mask_nospec64, idx, limit, tmp | ||
| 130 | sub \tmp, \idx, \limit | ||
| 131 | bic \tmp, \tmp, \idx | ||
| 132 | and \idx, \idx, \tmp, asr #63 | ||
| 133 | csdb | ||
| 134 | .endm | ||
| 135 | |||
| 136 | /* | ||
| 126 | * NOP sequence | 137 | * NOP sequence |
| 127 | */ | 138 | */ |
| 128 | .macro nops, num | 139 | .macro nops, num |
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 17c15f741780..4dd1b5a46642 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S | |||
| @@ -378,6 +378,7 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 | |||
| 378 | * x7 is reserved for the system call number in 32-bit mode. | 378 | * x7 is reserved for the system call number in 32-bit mode. |
| 379 | */ | 379 | */ |
| 380 | wsc_nr .req w25 // number of system calls | 380 | wsc_nr .req w25 // number of system calls |
| 381 | xsc_nr .req x25 // number of system calls (zero-extended) | ||
| 381 | wscno .req w26 // syscall number | 382 | wscno .req w26 // syscall number |
| 382 | xscno .req x26 // syscall number (zero-extended) | 383 | xscno .req x26 // syscall number (zero-extended) |
| 383 | stbl .req x27 // syscall table pointer | 384 | stbl .req x27 // syscall table pointer |
| @@ -935,6 +936,7 @@ el0_svc_naked: // compat entry point | |||
| 935 | b.ne __sys_trace | 936 | b.ne __sys_trace |
| 936 | cmp wscno, wsc_nr // check upper syscall limit | 937 | cmp wscno, wsc_nr // check upper syscall limit |
| 937 | b.hs ni_sys | 938 | b.hs ni_sys |
| 939 | mask_nospec64 xscno, xsc_nr, x19 // enforce bounds for syscall number | ||
| 938 | ldr x16, [stbl, xscno, lsl #3] // address in the syscall table | 940 | ldr x16, [stbl, xscno, lsl #3] // address in the syscall table |
| 939 | blr x16 // call sys_* routine | 941 | blr x16 // call sys_* routine |
| 940 | b ret_fast_syscall | 942 | b ret_fast_syscall |
