diff mbox series

[SRU,bionic,2/2] s390/ptrace: return -ENOSYS when invalid syscall is supplied

Message ID 20210421135436.394371-2-ddstreet@canonical.com
State New
Headers show
Series [SRU,bionic,1/2] s390/ptrace: pass invalid syscall numbers to tracing | expand

Commit Message

Dan Streetman April 21, 2021, 1:54 p.m. UTC
From: Sven Schnelle <svens@linux.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1916485

The current code returns the syscall number which an invalid
syscall number is supplied and tracing is enabled. This makes
the strace testsuite fail.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
(cherry picked from commit cd29fa798001075a554b978df3a64e6656c25794)
Signed-off-by: Dan Streetman <ddstreet@canonical.com>
---
 arch/s390/kernel/ptrace.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Krzysztof Kozlowski April 21, 2021, 4:38 p.m. UTC | #1
On 21/04/2021 15:54, Dan Streetman wrote:
> From: Sven Schnelle <svens@linux.ibm.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1916485
> 
> The current code returns the syscall number which an invalid
> syscall number is supplied and tracing is enabled. This makes
> the strace testsuite fail.
> 
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
> (cherry picked from commit cd29fa798001075a554b978df3a64e6656c25794)

This does not match original commit, so the message should be
"(backported from" plus an explanation what changed in the backport.

I'll try to send the backport to upstream.



Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index 713e792ed24c..ab618e395942 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -868,6 +868,7 @@  long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 {
 	unsigned long mask = -1UL;
+	long ret = -1;
 
 	/*
 	 * The sysc_tracesys code in entry.S stored the system
@@ -879,27 +880,33 @@  asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 		 * Tracing decided this syscall should not happen. Skip
 		 * the system call and the system call restart handling.
 		 */
-		clear_pt_regs_flag(regs, PIF_SYSCALL);
-		return -1;
+		goto skip;
 	}
 
 	/* Do the secure computing check after ptrace. */
 	if (secure_computing(NULL)) {
 		/* seccomp failures shouldn't expose any additional code. */
-		return -1;
+		goto skip;
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_sys_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->int_code & 0xffff);
 
 	if (is_compat_task())
 		mask = 0xffffffff;
 
-	audit_syscall_entry(regs->gprs[2], regs->orig_gpr2 & mask,
+	audit_syscall_entry(regs->int_code & 0xffff, regs->orig_gpr2 & mask,
 			    regs->gprs[3] &mask, regs->gprs[4] &mask,
 			    regs->gprs[5] &mask);
 
+	if ((signed long)regs->gprs[2] >= NR_syscalls) {
+		regs->gprs[2] = -ENOSYS;
+		ret = -ENOSYS;
+	}
 	return regs->gprs[2];
+skip:
+	clear_pt_regs_flag(regs, PIF_SYSCALL);
+	return ret;
 }
 
 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)