]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/syscall: Mark exit[_group] syscall handlers __noreturn
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 26 Jun 2024 06:02:00 +0000 (23:02 -0700)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 28 Jun 2024 13:23:38 +0000 (15:23 +0200)
The direct-call syscall dispatch function doesn't know that the exit()
and exit_group() syscall handlers don't return, so the call sites aren't
optimized accordingly.

Fix that by marking the exit syscall declarations __noreturn.

Fixes the following warnings:

  vmlinux.o: warning: objtool: x64_sys_call+0x2804: __x64_sys_exit() is missing a __noreturn annotation
  vmlinux.o: warning: objtool: ia32_sys_call+0x29b6: __ia32_sys_exit_group() is missing a __noreturn annotation

Fixes: 1e3ad78334a6 ("x86/syscall: Don't force use of indirect calls for system calls")
Closes: https://lkml.kernel.org/lkml/6dba9b32-db2c-4e6d-9500-7a08852f17a3@paulmck-laptop
Reported-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://lore.kernel.org/r/5d8882bc077d8eadcc7fd1740b56dfb781f12288.1719381528.git.jpoimboe@kernel.org
arch/x86/entry/syscall_32.c
arch/x86/entry/syscall_64.c
arch/x86/entry/syscall_x32.c
arch/x86/entry/syscalls/syscall_32.tbl
arch/x86/entry/syscalls/syscall_64.tbl
arch/x86/um/sys_call_table_32.c
arch/x86/um/sys_call_table_64.c
scripts/syscalltbl.sh
tools/objtool/noreturns.h

index c2235bae17ef665098342c323a24e4b388c169cb..8cc9950d7104ab22e797677b30af07c88541871d 100644 (file)
 #endif
 
 #define __SYSCALL(nr, sym) extern long __ia32_##sym(const struct pt_regs *);
-
+#define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __ia32_##sym(const struct pt_regs *);
 #include <asm/syscalls_32.h>
-#undef __SYSCALL
+#undef  __SYSCALL
+
+#undef  __SYSCALL_NORETURN
+#define __SYSCALL_NORETURN __SYSCALL
 
 /*
  * The sys_call_table[] is no longer used for system calls, but
 const sys_call_ptr_t sys_call_table[] = {
 #include <asm/syscalls_32.h>
 };
-#undef __SYSCALL
+#undef  __SYSCALL
 #endif
 
 #define __SYSCALL(nr, sym) case nr: return __ia32_##sym(regs);
-
 long ia32_sys_call(const struct pt_regs *regs, unsigned int nr)
 {
        switch (nr) {
index 33b3f09e6f151e11faca1c9d13f0eb4917f3392b..ba8354424860cb48162a16f46150f706727b5c02 100644 (file)
@@ -8,8 +8,12 @@
 #include <asm/syscall.h>
 
 #define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs *);
+#define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *);
 #include <asm/syscalls_64.h>
-#undef __SYSCALL
+#undef  __SYSCALL
+
+#undef  __SYSCALL_NORETURN
+#define __SYSCALL_NORETURN __SYSCALL
 
 /*
  * The sys_call_table[] is no longer used for system calls, but
 const sys_call_ptr_t sys_call_table[] = {
 #include <asm/syscalls_64.h>
 };
-#undef __SYSCALL
+#undef  __SYSCALL
 
 #define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs);
-
 long x64_sys_call(const struct pt_regs *regs, unsigned int nr)
 {
        switch (nr) {
index 03de4a93213182c6fa5809b077a54ea51be411ea..fb77908f44f37b1b5670f5c73c05546ac0ec340f 100644 (file)
@@ -8,11 +8,14 @@
 #include <asm/syscall.h>
 
 #define __SYSCALL(nr, sym) extern long __x64_##sym(const struct pt_regs *);
+#define __SYSCALL_NORETURN(nr, sym) extern long __noreturn __x64_##sym(const struct pt_regs *);
 #include <asm/syscalls_x32.h>
-#undef __SYSCALL
+#undef  __SYSCALL
 
-#define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs);
+#undef  __SYSCALL_NORETURN
+#define __SYSCALL_NORETURN __SYSCALL
 
+#define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs);
 long x32_sys_call(const struct pt_regs *regs, unsigned int nr)
 {
        switch (nr) {
index 7fd1f57ad3d30cfffb47b4123caf896e8de8281e..09ca75bb51a0e09cea07c4e0233bb4c9a40deeb5 100644 (file)
@@ -2,7 +2,7 @@
 # 32-bit system call numbers and entry vectors
 #
 # The format is:
-# <number> <abi> <name> <entry point> <compat entry point>
+# <number> <abi> <name> <entry point> [<compat entry point> [noreturn]]
 #
 # The __ia32_sys and __ia32_compat_sys stubs are created on-the-fly for
 # sys_*() system calls and compat_sys_*() compat system calls if
@@ -12,7 +12,7 @@
 # The abi is always "i386" for this file.
 #
 0      i386    restart_syscall         sys_restart_syscall
-1      i386    exit                    sys_exit
+1      i386    exit                    sys_exit                        -                       noreturn
 2      i386    fork                    sys_fork
 3      i386    read                    sys_read
 4      i386    write                   sys_write
 249    i386    io_cancel               sys_io_cancel
 250    i386    fadvise64               sys_ia32_fadvise64
 # 251 is available for reuse (was briefly sys_set_zone_reclaim)
-252    i386    exit_group              sys_exit_group
+252    i386    exit_group              sys_exit_group                  -                       noreturn
 253    i386    lookup_dcookie
 254    i386    epoll_create            sys_epoll_create
 255    i386    epoll_ctl               sys_epoll_ctl
index a396f6e6ab5bf97df25666a1048d0f285b8d465e..a8068f937290a201afb2a79e3c54b390a65cd5c8 100644 (file)
@@ -2,7 +2,7 @@
 # 64-bit system call numbers and entry vectors
 #
 # The format is:
-# <number> <abi> <name> <entry point>
+# <number> <abi> <name> <entry point> [<compat entry point> [noreturn]]
 #
 # The __x64_sys_*() stubs are created on-the-fly for sys_*() system calls
 #
@@ -68,7 +68,7 @@
 57     common  fork                    sys_fork
 58     common  vfork                   sys_vfork
 59     64      execve                  sys_execve
-60     common  exit                    sys_exit
+60     common  exit                    sys_exit                        -                       noreturn
 61     common  wait4                   sys_wait4
 62     common  kill                    sys_kill
 63     common  uname                   sys_newuname
 228    common  clock_gettime           sys_clock_gettime
 229    common  clock_getres            sys_clock_getres
 230    common  clock_nanosleep         sys_clock_nanosleep
-231    common  exit_group              sys_exit_group
+231    common  exit_group              sys_exit_group                  -                       noreturn
 232    common  epoll_wait              sys_epoll_wait
 233    common  epoll_ctl               sys_epoll_ctl
 234    common  tgkill                  sys_tgkill
index 89df5d89d66409b4905791f58c18f50b9fbbd477..51655133eee36148714a09d1c0f5598733ba2745 100644 (file)
@@ -9,6 +9,10 @@
 #include <linux/cache.h>
 #include <asm/syscall.h>
 
+extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long,
+                                     unsigned long, unsigned long,
+                                     unsigned long, unsigned long);
+
 /*
  * Below you can see, in terms of #define's, the differences between the x86-64
  * and the UML syscall table.
 #define sys_vm86 sys_ni_syscall
 
 #define __SYSCALL_WITH_COMPAT(nr, native, compat)      __SYSCALL(nr, native)
+#define __SYSCALL_NORETURN __SYSCALL
 
 #define __SYSCALL(nr, sym) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
 #include <asm/syscalls_32.h>
+#undef  __SYSCALL
 
-#undef __SYSCALL
 #define __SYSCALL(nr, sym) sym,
-
-extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
-
 const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = {
 #include <asm/syscalls_32.h>
 };
index b0b4cfd2308c87e4bf078657b9fe6e3b3659f8f3..943d414f2109334b02e0a71715fdfd7080d38c55 100644 (file)
@@ -9,6 +9,10 @@
 #include <linux/cache.h>
 #include <asm/syscall.h>
 
+extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long,
+                                     unsigned long, unsigned long,
+                                     unsigned long, unsigned long);
+
 /*
  * Below you can see, in terms of #define's, the differences between the x86-64
  * and the UML syscall table.
 #define sys_iopl sys_ni_syscall
 #define sys_ioperm sys_ni_syscall
 
+#define __SYSCALL_NORETURN __SYSCALL
+
 #define __SYSCALL(nr, sym) extern asmlinkage long sym(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
 #include <asm/syscalls_64.h>
+#undef  __SYSCALL
 
-#undef __SYSCALL
 #define __SYSCALL(nr, sym) sym,
-
-extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
-
 const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = {
 #include <asm/syscalls_64.h>
 };
index 6abe143889ef6d293ada078ae2e52f7cc8f1669d..6a903b87a7c210c966a021ccd2fb816b17f21727 100755 (executable)
@@ -54,7 +54,7 @@ nxt=0
 
 grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | {
 
-       while read nr abi name native compat ; do
+       while read nr abi name native compat noreturn; do
 
                if [ $nxt -gt $nr ]; then
                        echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2
@@ -66,7 +66,21 @@ grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | {
                        nxt=$((nxt + 1))
                done
 
-               if [ -n "$compat" ]; then
+               if [ "$compat" = "-" ]; then
+                       unset compat
+               fi
+
+               if [ -n "$noreturn" ]; then
+                       if [ "$noreturn" != "noreturn" ]; then
+                               echo "error: $infile: invalid string \"$noreturn\" in 'noreturn' column"
+                               exit 1
+                       fi
+                       if [ -n "$compat" ]; then
+                               echo "__SYSCALL_COMPAT_NORETURN($nr, $native, $compat)"
+                       else
+                               echo "__SYSCALL_NORETURN($nr, $native)"
+                       fi
+               elif [ -n "$compat" ]; then
                        echo "__SYSCALL_WITH_COMPAT($nr, $native, $compat)"
                elif [ -n "$native" ]; then
                        echo "__SYSCALL($nr, $native)"
index 7ebf29c9118491193a0fa51bc33b78860b8c6e12..1e8141ef1b15d4e218ec384704b3553d38b31e9a 100644 (file)
@@ -7,12 +7,16 @@
  * Yes, this is unfortunate.  A better solution is in the works.
  */
 NORETURN(__fortify_panic)
+NORETURN(__ia32_sys_exit)
+NORETURN(__ia32_sys_exit_group)
 NORETURN(__kunit_abort)
 NORETURN(__module_put_and_kthread_exit)
 NORETURN(__reiserfs_panic)
 NORETURN(__stack_chk_fail)
 NORETURN(__tdx_hypercall_failed)
 NORETURN(__ubsan_handle_builtin_unreachable)
+NORETURN(__x64_sys_exit)
+NORETURN(__x64_sys_exit_group)
 NORETURN(arch_cpu_idle_dead)
 NORETURN(bch2_trans_in_restart_error)
 NORETURN(bch2_trans_restart_error)