[RFC PATCH 0/2] powerpc: change syscall error return scheme

Nicholas Piggin posted 2 patches 1 year ago
arch/powerpc/include/asm/ptrace.h             | 13 +---
arch/powerpc/include/asm/syscall.h            | 31 +--------
arch/powerpc/kernel/interrupt.c               | 16 +++--
arch/powerpc/kernel/signal.c                  | 67 ++++++++++---------
arch/powerpc/kernel/signal_64.c               |  5 +-
tools/testing/selftests/seccomp/seccomp_bpf.c | 16 +++++
6 files changed, 69 insertions(+), 79 deletions(-)
[RFC PATCH 0/2] powerpc: change syscall error return scheme
Posted by Nicholas Piggin 1 year ago
Hi,

I've been toying with the seccomp vs syscall return value problems, and
wonder if something like this approach could give us a simpler alternative.
Basically all the core code uses -errno return value, then we convert it
to the powerpc convention at the last minute when returning.

This seems to pass the seccomp_bpf test cases when applied with the set
syscall info ptrace patches

https://lore.kernel.org/lkml/20250113171054.GA589@strace.io/

With patch 1 of that series reverted.

One concern is working out exact details of what tracers can see and
trying to ensure it doesn't break some corner case.

This could possibly be done for the other weird archs too, if it works
out for powerpc

Thanks,
Nick

Nicholas Piggin (2):
  powerpc/signal: Clean up pt_regs access
  powerpc/syscall: rework syscall return value handling

 arch/powerpc/include/asm/ptrace.h             | 13 +---
 arch/powerpc/include/asm/syscall.h            | 31 +--------
 arch/powerpc/kernel/interrupt.c               | 16 +++--
 arch/powerpc/kernel/signal.c                  | 67 ++++++++++---------
 arch/powerpc/kernel/signal_64.c               |  5 +-
 tools/testing/selftests/seccomp/seccomp_bpf.c | 16 +++++
 6 files changed, 69 insertions(+), 79 deletions(-)

-- 
2.47.1
Re: [RFC PATCH 0/2] powerpc: change syscall error return scheme
Posted by Dmitry V. Levin 1 year ago
Hi,

On Wed, Jan 29, 2025 at 11:21:41PM +1000, Nicholas Piggin wrote:
> Hi,
> 
> I've been toying with the seccomp vs syscall return value problems, and
> wonder if something like this approach could give us a simpler alternative.
> Basically all the core code uses -errno return value, then we convert it
> to the powerpc convention at the last minute when returning.
> 
> This seems to pass the seccomp_bpf test cases when applied with the set
> syscall info ptrace patches
> 
> https://lore.kernel.org/lkml/20250113171054.GA589@strace.io/
> 
> With patch 1 of that series reverted.
> 
> One concern is working out exact details of what tracers can see and
> trying to ensure it doesn't break some corner case.

Does the strace test suite also pass with your changes?
My bet is it doesn't pass because do_syscall_trace_leave() is called
with a different state of struct pt_regs.

As I wrote yesterday, the traditional powerpc sc syscall return ABI is
exposed to user space not just when returning to user space, but, besides
that, at syscall exit tracepoint (trace_sys_exit), ptrace syscall exit
stop (ptrace_report_syscall_exit), and PTRACE_EVENT_SECCOMP stop
(__secure_computing).

There could be other points where this is exposed.  For example, on many
architectures the tracer can specify syscall error return value also at
ptrace syscall entry stop (ptrace_report_syscall_entry), but powerpc does
not implement this.


-- 
ldv