Skip to content

Commit b337b49

Browse files
H. Peter Anvin (Intel)KAGA-KOKO
authored andcommitted
x86/entry: Treat out of range and gap system calls the same
The current 64-bit system call entry code treats out-of-range system calls differently than system calls that map to a hole in the system call table. This is visible to the user if system calls are intercepted via ptrace or seccomp and the return value (regs->ax) is modified: in the former case, the return value is preserved, and in the latter case, sys_ni_syscall() is called and the return value is forced to -ENOSYS. The API spec in <asm-generic/syscalls.h> is very clear that only (int)-1 is the non-system-call sentinel value, so make the system call behavior consistent by calling sys_ni_syscall() for all invalid system call numbers except for -1. Although currently sys_ni_syscall() simply returns -ENOSYS, calling it explicitly is friendly for tracing and future possible extensions, and as this is an error path there is no reason to optimize it. Signed-off-by: H. Peter Anvin (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0595494 commit b337b49

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/x86/entry/common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ __visible noinstr void do_syscall_64(struct pt_regs *regs, unsigned long nr)
5252
X32_NR_syscalls);
5353
regs->ax = x32_sys_call_table[nr](regs);
5454
#endif
55+
} else if (unlikely((int)nr != -1)) {
56+
regs->ax = __x64_sys_ni_syscall(regs);
5557
}
5658
instrumentation_end();
5759
syscall_exit_to_user_mode(regs);
@@ -76,6 +78,8 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs,
7678
if (likely(nr < IA32_NR_syscalls)) {
7779
nr = array_index_nospec(nr, IA32_NR_syscalls);
7880
regs->ax = ia32_sys_call_table[nr](regs);
81+
} else if (unlikely((int)nr != -1)) {
82+
regs->ax = __ia32_sys_ni_syscall(regs);
7983
}
8084
}
8185

0 commit comments

Comments
 (0)