Skip to content

Commit 25fd7ee

Browse files
Lukas GerlachPaul Walmsley
authored andcommitted
riscv: Sanitize syscall table indexing under speculation
The syscall number is a user-controlled value used to index into the syscall table. Use array_index_nospec() to clamp this value after the bounds check to prevent speculative out-of-bounds access and subsequent data leakage via cache side channels. Signed-off-by: Lukas Gerlach <lukas.gerlach@cispa.de> Link: https://patch.msgid.link/20251218191332.35849-3-lukas.gerlach@cispa.de Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 66562b6 commit 25fd7ee

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/riscv/kernel/traps.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ void do_trap_ecall_u(struct pt_regs *regs)
339339

340340
add_random_kstack_offset();
341341

342-
if (syscall >= 0 && syscall < NR_syscalls)
342+
if (syscall >= 0 && syscall < NR_syscalls) {
343+
syscall = array_index_nospec(syscall, NR_syscalls);
343344
syscall_handler(regs, syscall);
345+
}
344346

345347
/*
346348
* Ultimately, this value will get limited by KSTACK_OFFSET_MAX(),

0 commit comments

Comments
 (0)