[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250128162544.GE11869@strace.io>
Date: Tue, 28 Jan 2025 18:25:44 +0200
From: "Dmitry V. Levin" <ldv@...ace.io>
To: Christophe Leroy <christophe.leroy@...roup.eu>
Cc: Oleg Nesterov <oleg@...hat.com>, linux-snps-arc@...ts.infradead.org,
Rich Felker <dalias@...c.org>, Thomas Gleixner <tglx@...utronix.de>,
Andreas Larsson <andreas@...sler.com>,
Catalin Marinas <catalin.marinas@....com>,
John Paul Adrian Glaubitz <glaubitz@...sik.fu-berlin.de>,
x86@...nel.org, Arnd Bergmann <arnd@...db.de>,
linux-mips@...r.kernel.org,
"James E.J. Bottomley" <James.Bottomley@...senPartnership.com>,
"H. Peter Anvin" <hpa@...or.com>, sparclinux@...r.kernel.org,
linux-hexagon@...r.kernel.org, WANG Xuerui <kernel@...0n.name>,
Will Deacon <will@...nel.org>,
Eugene Syromyatnikov <evgsyr@...il.com>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
Jonas Bonn <jonas@...thpole.se>, linux-s390@...r.kernel.org,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Yoshinori Sato <ysato@...rs.sourceforge.jp>,
linux-sh@...r.kernel.org, Michael Ellerman <mpe@...erman.id.au>,
Helge Deller <deller@....de>, Huacai Chen <chenhuacai@...nel.org>,
Russell King <linux@...linux.org.uk>,
linux-riscv@...ts.infradead.org,
Dave Hansen <dave.hansen@...ux.intel.com>,
Ingo Molnar <mingo@...hat.com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Vineet Gupta <vgupta@...nel.org>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
strace-devel@...ts.strace.io, linux-arch@...r.kernel.org,
Albert Ou <aou@...s.berkeley.edu>,
Mike Frysinger <vapier@...too.org>,
Davide Berardi <berardi.dav@...il.com>,
Renzo Davoli <renzo@...unibo.it>, linux-um@...ts.infradead.org,
Heiko Carstens <hca@...ux.ibm.com>,
Charlie Jenkins <charlie@...osinc.com>,
Naveen N Rao <naveen@...nel.org>,
Nicholas Piggin <npiggin@...il.com>,
Stefan Kristiansson <stefan.kristiansson@...nalahti.fi>,
linux-m68k@...ts.linux-m68k.org, Borislav Petkov <bp@...en8.de>,
loongarch@...ts.linux.dev, Paul Walmsley <paul.walmsley@...ive.com>,
Stafford Horne <shorne@...il.com>,
linux-arm-kernel@...ts.infradead.org,
Brian Cain <bcain@...cinc.com>, Michal Simek <monstr@...str.eu>,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
linux-parisc@...r.kernel.org, linux-openrisc@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
Dinh Nguyen <dinguyen@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>,
Sven Schnelle <svens@...ux.ibm.com>,
Richard Weinberger <richard@....at>,
Johannes Berg <johannes@...solutions.net>,
Alexey Gladkov <legion@...nel.org>,
"David S. Miller" <davem@...emloft.net>
Subject: Re: [PATCH v3 3/6] syscall.h: introduce syscall_set_nr()
On Tue, Jan 28, 2025 at 04:13:52PM +0100, Christophe Leroy wrote:
> Le 28/01/2025 à 10:16, Dmitry V. Levin a écrit :
> > Similar to syscall_set_arguments() that complements
> > syscall_get_arguments(), introduce syscall_set_nr()
> > that complements syscall_get_nr().
> >
> > syscall_set_nr() is going to be needed along with
> > syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK
> > architectures to implement PTRACE_SET_SYSCALL_INFO API.
> >
> > Signed-off-by: Dmitry V. Levin <ldv@...ace.io>
> > Tested-by: Charlie Jenkins <charlie@...osinc.com>
> > Reviewed-by: Charlie Jenkins <charlie@...osinc.com>
> > ---
> > arch/arc/include/asm/syscall.h | 11 +++++++++++
> > arch/arm/include/asm/syscall.h | 24 ++++++++++++++++++++++++
> > arch/arm64/include/asm/syscall.h | 16 ++++++++++++++++
> > arch/hexagon/include/asm/syscall.h | 7 +++++++
> > arch/loongarch/include/asm/syscall.h | 7 +++++++
> > arch/m68k/include/asm/syscall.h | 7 +++++++
> > arch/microblaze/include/asm/syscall.h | 7 +++++++
> > arch/mips/include/asm/syscall.h | 14 ++++++++++++++
> > arch/nios2/include/asm/syscall.h | 5 +++++
> > arch/openrisc/include/asm/syscall.h | 6 ++++++
> > arch/parisc/include/asm/syscall.h | 7 +++++++
> > arch/powerpc/include/asm/syscall.h | 10 ++++++++++
> > arch/riscv/include/asm/syscall.h | 7 +++++++
> > arch/s390/include/asm/syscall.h | 12 ++++++++++++
> > arch/sh/include/asm/syscall_32.h | 12 ++++++++++++
> > arch/sparc/include/asm/syscall.h | 12 ++++++++++++
> > arch/um/include/asm/syscall-generic.h | 5 +++++
> > arch/x86/include/asm/syscall.h | 7 +++++++
> > arch/xtensa/include/asm/syscall.h | 7 +++++++
> > include/asm-generic/syscall.h | 14 ++++++++++++++
> > 20 files changed, 197 insertions(+)
> >
>
> > diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
> > index 76020b66286b..712daa90e643 100644
> > --- a/arch/arm64/include/asm/syscall.h
> > +++ b/arch/arm64/include/asm/syscall.h
> > @@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task,
> > regs->regs[0] = val;
> > }
> >
> > +static inline void syscall_set_nr(struct task_struct *task,
> > + struct pt_regs *regs,
> > + int nr)
> > +{
> > + regs->syscallno = nr;
> > + if (nr == -1) {
> > + /*
> > + * When the syscall number is set to -1, the syscall will be
> > + * skipped. In this case the syscall return value has to be
> > + * set explicitly, otherwise the first syscall argument is
> > + * returned as the syscall return value.
> > + */
> > + syscall_set_return_value(task, regs, -ENOSYS, 0);
> > + }
> > +}
> > +
> > #define SYSCALL_MAX_ARGS 6
> >
> > static inline void syscall_get_arguments(struct task_struct *task,
>
> > diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h
> > index 521f279e6b33..7505dcfed247 100644
> > --- a/arch/powerpc/include/asm/syscall.h
> > +++ b/arch/powerpc/include/asm/syscall.h
> > @@ -39,6 +39,16 @@ static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
> > return -1;
> > }
> >
> > +static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)
> > +{
> > + /*
> > + * Unlike syscall_get_nr(), syscall_set_nr() can be called only when
> > + * the target task is stopped for tracing on entering syscall, so
> > + * there is no need to have the same check syscall_get_nr() has.
> > + */
> > + regs->gpr[0] = nr;
>
> Doesn't the same as for ARM64 apply here as well ?
I carefully checked all affected architectures and added that
syscall_set_return_value() call only where I think it's needed.
On powerpc it's not needed with the current implementation: their
do_seccomp() sets -ENOSYS before __secure_computing() invocation, and
their do_syscall_trace_enter() sets -ENOSYS in case of an invalid syscall
number.
--
ldv
Powered by blists - more mailing lists