From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C6C0C0218A for ; Tue, 28 Jan 2025 16:25:49 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Yj9d75Ctxz2yxP; Wed, 29 Jan 2025 03:25:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=194.107.17.57 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738081547; cv=none; b=Zmrg0koD800ahDK0t691Du8CdUr4utafuEpx0pPWLoN8rkFatt5OhUQlt5a9InS5NdFZ1Ycm5fAUY57JoQBoQZfLE+H8H8YpV8TaENoXbY1rBUVtBlmvh20BHkbZ8Q4YdpJ1nMh216SJ+xGMdvmYL+iCkUe+9kXFI9E5eCUpPp16C33mX93VkYJFj3zysBbdPQFXJiFhBCsoldo7fEzAGw1UgmO4PJ8PhB4MfMh4lKgn/DgGygrJGlEzSsJjPmRO0MYiWY+aWhXLKgXhPbHRizICyp0SZg5SWyQ5bPEGkoB82rJ4IX31DUdwvWUm5jjFm3G5dNmXEteyXeCkI5K7pA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1738081547; c=relaxed/relaxed; bh=Q+GzEo6xQjcCivH2uqqJkJdbnOBUjgfD/PowAlU4fmM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iEhePKhKlPvZfNLuCBvUtRJJkPFxZOnEX33hsdksV3HdGR+BF1cg0HBAH4kUIMczXKVwZ9hY7ZcYHxr7Mmzp0DE11jM/gWgomp69FDRDX6PtvCOHfM7htnKz0bdTdibsdvJRtGLxEByW8e4eQQKYRrukm0jkWPi2PmF3LWNgdmR4PVevx/zyya0plze7trAEcN1qb0rKD2EFnB9oSsDfDz6blcyraQYUtl5oyqAFbpo84nA+bXTrzAVjXSqdxlffu0tNaPuph5xSRE1BYirwPZGhdMQXiLqDsKKgO7CeB9JReylfVgGuzagCU5ICLkDrLMxsyGA8sOVOp8xTL08CsA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=strace.io; spf=pass (client-ip=194.107.17.57; helo=vmicros1.altlinux.org; envelope-from=ldv@altlinux.org; receiver=lists.ozlabs.org) smtp.mailfrom=altlinux.org Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=strace.io Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=altlinux.org (client-ip=194.107.17.57; helo=vmicros1.altlinux.org; envelope-from=ldv@altlinux.org; receiver=lists.ozlabs.org) Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by lists.ozlabs.org (Postfix) with ESMTP id 4Yj9d64v57z2yn2 for ; Wed, 29 Jan 2025 03:25:46 +1100 (AEDT) Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 2308C72C8CC; Tue, 28 Jan 2025 19:25:45 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 0E2917CCB3A; Tue, 28 Jan 2025 18:25:45 +0200 (IST) Date: Tue, 28 Jan 2025 18:25:44 +0200 From: "Dmitry V. Levin" To: Christophe Leroy Cc: Oleg Nesterov , linux-snps-arc@lists.infradead.org, Rich Felker , Thomas Gleixner , Andreas Larsson , Catalin Marinas , John Paul Adrian Glaubitz , x86@kernel.org, Arnd Bergmann , linux-mips@vger.kernel.org, "James E.J. Bottomley" , "H. Peter Anvin" , sparclinux@vger.kernel.org, linux-hexagon@vger.kernel.org, WANG Xuerui , Will Deacon , Eugene Syromyatnikov , Anton Ivanov , Jonas Bonn , linux-s390@vger.kernel.org, Alexander Gordeev , Madhavan Srinivasan , Vasily Gorbik , Yoshinori Sato , linux-sh@vger.kernel.org, Michael Ellerman , Helge Deller , Huacai Chen , Russell King , linux-riscv@lists.infradead.org, Dave Hansen , Ingo Molnar , Geert Uytterhoeven , Vineet Gupta , Christian Borntraeger , strace-devel@lists.strace.io, linux-arch@vger.kernel.org, Albert Ou , Mike Frysinger , Davide Berardi , Renzo Davoli , linux-um@lists.infradead.org, Heiko Carstens , Charlie Jenkins , Naveen N Rao , Nicholas Piggin , Stefan Kristiansson , linux-m68k@lists.linux-m68k.org, Borislav Petkov , loongarch@lists.linux.dev, Paul Walmsley , Stafford Horne , linux-arm-kernel@lists.infradead.org, Brian Cain , Michal Simek , Thomas Bogendoerfer , linux-parisc@vger.kernel.org, linux-openrisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Dinh Nguyen , Palmer Dabbelt , Sven Schnelle , Richard Weinberger , Johannes Berg , Alexey Gladkov , "David S. Miller" Subject: Re: [PATCH v3 3/6] syscall.h: introduce syscall_set_nr() Message-ID: <20250128162544.GE11869@strace.io> References: <20250128091636.GC8601@strace.io> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 > > Tested-by: Charlie Jenkins > > Reviewed-by: Charlie Jenkins > > --- > > 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