linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 3/4] x86/syscall: treat out of range and gap system calls the same
Date: Fri, 14 May 2021 18:10:14 -0700	[thread overview]
Message-ID: <20210515011015.2707542-4-hpa@zytor.com> (raw)
In-Reply-To: <20210515011015.2707542-1-hpa@zytor.com>

From: "H. Peter Anvin (Intel)" <hpa@zytor.com>

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.

For example, before this patch, 335 for x86-64 would force the exit
code to be set to -ENOSYS even if poked by ptrace, but 548 would not,
creating an observable difference between an out of range system call
and a system call number that falls outside the range of the tables.

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) <hpa@zytor.com>
---
 arch/x86/entry/common.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index 00da0f5420de..f51bc17262db 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -52,6 +52,8 @@ __visible noinstr void do_syscall_64(struct pt_regs *regs, unsigned long nr)
 					X32_NR_syscalls);
 		regs->ax = x32_sys_call_table[nr](regs);
 #endif
+	} else if (unlikely((int)nr != -1)) {
+		regs->ax = __x64_sys_ni_syscall(regs);
 	}
 	instrumentation_end();
 	syscall_exit_to_user_mode(regs);
@@ -76,6 +78,8 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs,
 	if (likely(nr < IA32_NR_syscalls)) {
 		nr = array_index_nospec(nr, IA32_NR_syscalls);
 		regs->ax = ia32_sys_call_table[nr](regs);
+	} else if (unlikely((int)nr != -1)) {
+		regs->ax = __ia32_sys_ni_syscall(regs);
 	}
 }
 
-- 
2.31.1


  parent reply	other threads:[~2021-05-15  1:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-15  1:10 [RFC v3 PATCH 0/4] x86/syscall: use int for x86-64 system calls H. Peter Anvin
2021-05-15  1:10 ` [PATCH v3 1/4] x86/syscall: sign-extend system calls on entry to int H. Peter Anvin
2021-05-16  7:48   ` Ingo Molnar
2021-05-17 20:23     ` H. Peter Anvin
2021-05-15  1:10 ` [PATCH v3 2/4] x86/syscall: update and extend selftest syscall_numbering_64 H. Peter Anvin
2021-05-16  7:52   ` Ingo Molnar
2021-05-18  0:26     ` H. Peter Anvin
2021-05-18 15:04     ` H. Peter Anvin
2021-05-15  1:10 ` H. Peter Anvin [this message]
2021-05-15  1:10 ` [PATCH v3 4/4] x86/syscall: use int everywhere for system call numbers H. Peter Anvin
2021-05-15 15:37   ` Andy Lutomirski
2021-05-15 17:41     ` H. Peter Anvin
2021-05-15 17:42     ` H. Peter Anvin
     [not found]       ` <2ebf1bac-93c1-4b7f-add4-4ede3c149b52@www.fastmail.com>
2021-05-15 21:07         ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210515011015.2707542-4-hpa@zytor.com \
    --to=hpa@zytor.com \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).