Skip to content

Commit 108f2cd

Browse files
committed
LoongArch: Add spectre boundry for syscall dispatch table
[ Upstream commit 0c965d2 ] 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: stable@vger.kernel.org Assisted-by: gkh_clanker_2000 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 29166a0 commit 108f2cd

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

arch/loongarch/kernel/syscall.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/entry-common.h>
1010
#include <linux/errno.h>
1111
#include <linux/linkage.h>
12+
#include <linux/nospec.h>
1213
#include <linux/syscalls.h>
1314
#include <linux/unistd.h>
1415

@@ -55,7 +56,7 @@ void noinstr do_syscall(struct pt_regs *regs)
5556
nr = syscall_enter_from_user_mode(regs, nr);
5657

5758
if (nr < NR_syscalls) {
58-
syscall_fn = sys_call_table[nr];
59+
syscall_fn = sys_call_table[array_index_nospec(nr, NR_syscalls)];
5960
regs->regs[4] = syscall_fn(regs->orig_a0, regs->regs[5], regs->regs[6],
6061
regs->regs[7], regs->regs[8], regs->regs[9]);
6162
}

0 commit comments

Comments
 (0)