]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: Sanitize syscall table indexing under speculation
authorLukas Gerlach <lukas.gerlach@cispa.de>
Thu, 18 Dec 2025 19:13:32 +0000 (20:13 +0100)
committerPaul Walmsley <pjw@kernel.org>
Wed, 31 Dec 2025 02:57:55 +0000 (19:57 -0700)
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>
arch/riscv/kernel/traps.c

index 80230de167def3c33db5bc190347ec5f87dbb6e3..47afea4ff1a8d224adbaa99208c7f5e4ffecd526 100644 (file)
@@ -339,8 +339,10 @@ void do_trap_ecall_u(struct pt_regs *regs)
 
                add_random_kstack_offset();
 
-               if (syscall >= 0 && syscall < NR_syscalls)
+               if (syscall >= 0 && syscall < NR_syscalls) {
+                       syscall = array_index_nospec(syscall, NR_syscalls);
                        syscall_handler(regs, syscall);
+               }
 
                /*
                 * Ultimately, this value will get limited by KSTACK_OFFSET_MAX(),