Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3ed64a6 authored by Mark Rutland's avatar Mark Rutland Committed by Greg Kroah-Hartman
Browse files

arm64: entry: Ensure branch through syscall table is bounded under speculation




From: Will Deacon <will.deacon@arm.com>

commit 6314d90e64936c584f300a52ef173603fb2461b5 upstream.

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: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
[v4.9: use existing scno & sc_nr definitions]
Signed-off-by: Mark Rutland <mark.rutland@arm.com> [v4.9 backport]
Tested-by: default avatarGreg Hackmann <ghackmann@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 891bea95
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -93,6 +93,17 @@
	hint	#20
	.endm

/*
 * Sanitise a 64-bit bounded index wrt speculation, returning zero if out
 * of bounds.
 */
	.macro	mask_nospec64, idx, limit, tmp
	sub	\tmp, \idx, \limit
	bic	\tmp, \tmp, \idx
	and	\idx, \idx, \tmp, asr #63
	csdb
	.endm

/*
 * NOP sequence
 */
+1 −0
Original line number Diff line number Diff line
@@ -795,6 +795,7 @@ el0_svc_naked: // compat entry point
	b.ne	__sys_trace
	cmp     scno, sc_nr                     // check upper syscall limit
	b.hs	ni_sys
	mask_nospec64 scno, sc_nr, x19	// enforce bounds for syscall number
	ldr	x16, [stbl, scno, lsl #3]	// address in the syscall table
	blr	x16				// call sys_* routine
	b	ret_fast_syscall