Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebe390b4 authored by Dmitry V. Levin's avatar Dmitry V. Levin Committed by Greg Kroah-Hartman
Browse files

parisc: Fix ptrace syscall number modification



commit b7dc5a071ddf69c0350396b203cba32fe5bab510 upstream.

Commit 910cd32e ("parisc: Fix and enable seccomp filter support")
introduced a regression in ptrace-based syscall tampering: when tracer
changes syscall number to -1, the kernel fails to initialize %r28 with
-ENOSYS and subsequently fails to return the error code of the failed
syscall to userspace.

This erroneous behaviour could be observed with a simple strace syscall
fault injection command which is expected to print something like this:

$ strace -a0 -ewrite -einject=write:error=enospc echo hello
write(1, "hello\n", 6) = -1 ENOSPC (No space left on device) (INJECTED)
write(2, "echo: ", 6) = -1 ENOSPC (No space left on device) (INJECTED)
write(2, "write error", 11) = -1 ENOSPC (No space left on device) (INJECTED)
write(2, "\n", 1) = -1 ENOSPC (No space left on device) (INJECTED)
+++ exited with 1 +++

After commit 910cd32e it loops printing
something like this instead:

write(1, "hello\n", 6../strace: Failed to tamper with process 12345: unexpectedly got no error (return value 0, error 0)
) = 0 (INJECTED)

This bug was found by strace test suite.

Fixes: 910cd32e ("parisc: Fix and enable seccomp filter support")
Cc: stable@vger.kernel.org # v4.5+
Signed-off-by: default avatarDmitry V. Levin <ldv@altlinux.org>
Tested-by: default avatarHelge Deller <deller@gmx.de>
Signed-off-by: default avatarHelge Deller <deller@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8b4b1d7c
Loading
Loading
Loading
Loading
+21 −8
Original line number Original line Diff line number Diff line
@@ -308,15 +308,29 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,


long do_syscall_trace_enter(struct pt_regs *regs)
long do_syscall_trace_enter(struct pt_regs *regs)
{
{
	if (test_thread_flag(TIF_SYSCALL_TRACE) &&
	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
	    tracehook_report_syscall_entry(regs)) {
		int rc = tracehook_report_syscall_entry(regs);

		/*
		/*
		 * Tracing decided this syscall should not happen or the
		 * As tracesys_next does not set %r28 to -ENOSYS
		 * debugger stored an invalid system call number. Skip
		 * when %r20 is set to -1, initialize it here.
		 * the system call and the system call restart handling.
		 */
		regs->gr[28] = -ENOSYS;

		if (rc) {
			/*
			 * A nonzero return code from
			 * tracehook_report_syscall_entry() tells us
			 * to prevent the syscall execution.  Skip
			 * the syscall call and the syscall restart handling.
			 *
			 * Note that the tracer may also just change
			 * regs->gr[20] to an invalid syscall number,
			 * that is handled by tracesys_next.
			 */
			 */
			regs->gr[20] = -1UL;
			regs->gr[20] = -1UL;
		goto out;
			return -1;
		}
	}
	}


	/* Do the secure computing check after ptrace. */
	/* Do the secure computing check after ptrace. */
@@ -340,7 +354,6 @@ long do_syscall_trace_enter(struct pt_regs *regs)
			regs->gr[24] & 0xffffffff,
			regs->gr[24] & 0xffffffff,
			regs->gr[23] & 0xffffffff);
			regs->gr[23] & 0xffffffff);


out:
	/*
	/*
	 * Sign extend the syscall number to 64bit since it may have been
	 * Sign extend the syscall number to 64bit since it may have been
	 * modified by a compat ptrace call
	 * modified by a compat ptrace call