[PATCH] LoongArch: add spectre boundry for syscall dispatch table

From: Greg Kroah-Hartman

Date: Tue Mar 24 2026 - 12:42:19 EST


The LoongArch syscall number is directly controlled by userspace, but
does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Cc: Huacai Chen <chenhuacai@xxxxxxxxxx>
Cc: WANG Xuerui <kernel@xxxxxxxxxx>
Assisted-by: gkh_clanker_2000
Cc: stable <stable@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
My scripts caught this as I think LoongArch is vulnerable to the
old-style Spectre 1 issues, but I couldn't find where it was addressed
in the syscall path. Did I just miss it somewhere, or is this patch
still needed?

arch/loongarch/kernel/syscall.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/loongarch/kernel/syscall.c b/arch/loongarch/kernel/syscall.c
index 1249d82c1cd0..f2c98bbafce3 100644
--- a/arch/loongarch/kernel/syscall.c
+++ b/arch/loongarch/kernel/syscall.c
@@ -8,6 +8,7 @@
#include <linux/capability.h>
#include <linux/entry-common.h>
#include <linux/errno.h>
+#include <linux/nospec.h>
#include <linux/linkage.h>
#include <linux/objtool.h>
#include <linux/randomize_kstack.h>
@@ -74,6 +75,7 @@ void noinstr __no_stack_protector do_syscall(struct pt_regs *regs)
add_random_kstack_offset();

if (nr < NR_syscalls) {
+ nr = array_index_nospec(nr, NR_syscalls);
syscall_fn = sys_call_table[nr];
regs->regs[4] = syscall_fn(regs->orig_a0, regs->regs[5], regs->regs[6],
regs->regs[7], regs->regs[8], regs->regs[9]);
--
2.53.0