7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matt Turner This fix is for 7.1.y, 7.2.y and 7.3.y only. Mainline is not affected since commit 83bd31c2840b ("alpha: enable GENERIC_ENTRY") in v7.4-rc1, which replaced the saved-r0 check with a flag in thread_info. That conversion is far too large for stable, so this patch fixes the old entry code instead. Syscalls that return data rather than a status, such as PTRACE_PEEKUSR, PTRACE_PEEKTEXT/PEEKDATA, osf_sigprocmask and shmat, call force_successful_syscall_return() so that a result with the top bit set is not mistaken for an error. On alpha that clears the saved r0, and $syscall_error and $strace_error used to check for this and take the success path. Commit 55b22075f784 ("alpha: add support for SECCOMP and SECCOMP_FILTER") moved the restart syscall number to r2 and dropped both checks, so any negative result now comes back to userspace as an error with a3 set. PTRACE_PEEKUSR of a register holding -1 fails with EPERM, which makes sandbox abort when it traces static binaries during Gentoo package builds, and PTRACE_PEEKUSR of a register holding 0xffffffffffffe000 fails with errno 8192, which breaks unwinding of a ptrace-stopped thread in elfutils (run-backtrace-native.sh). Restore the checks on both exit paths. On the traced path the success path also has to stop falling through into SYSCALL_SKIP_RETURN_RESTART_GATE, which is meant for skipped syscalls and would turn a forced-success result of -1 into ENOSYS. Link: https://bugs.gentoo.org/985765 Fixes: 55b22075f784 ("alpha: add support for SECCOMP and SECCOMP_FILTER") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Matt Turner Signed-off-by: Sasha Levin --- arch/alpha/kernel/entry.S | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/alpha/kernel/entry.S b/arch/alpha/kernel/entry.S index 9f2608de25446..fe88cd598492a 100644 --- a/arch/alpha/kernel/entry.S +++ b/arch/alpha/kernel/entry.S @@ -603,6 +603,14 @@ ret_to_kernel: .align 3 $syscall_error: + /* + * force_successful_syscall_return() zeroes the saved r0 (the + * syscall number): the negative return value is data, not an + * error number. + */ + ldq $18, 0($sp) + beq $18, $ret_success + /* Restart syscall nr comes from saved r2 (preserved even if r0 overwritten). */ ldq $18, 16($sp) /* old syscall nr for restart */ @@ -700,9 +708,11 @@ ret_from_straced: $strace_success: stq $31, 72($sp) /* a3=0 => no error */ stq $0, 0($sp) /* save return value */ + br $strace_leave $strace_skip_call: SYSCALL_SKIP_RETURN_RESTART_GATE +$strace_leave: DO_SWITCH_STACK jsr $26, syscall_trace_leave UNDO_SWITCH_STACK @@ -710,6 +720,10 @@ $strace_skip_call: .align 3 $strace_error: + /* See $syscall_error. */ + ldq $18, 0($sp) + beq $18, $strace_success + ldq $18, 16($sp) /* restart syscall nr */ ldq $19, 72($sp) /* .. and this a3 */ -- 2.53.0