From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 253AA1AA1FE; Tue, 28 Jan 2025 16:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738081548; cv=none; b=frLtTlQmZVuePV2O519MClVxP2EHpKk8NG5uT9S91vNtZV5dJ9R+FvS4hRnjDUTSQ2HPQW+y+rgghbsmtJln7wL1ONZzQZFXaLsK8QppRSP+S5xyRNcS/7wT0ePBQTkcSBkCD0OFiz4e77hG1D4ftK3EGMV90KHmEQf5lCDLZ5k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738081548; c=relaxed/simple; bh=jvB3dDUGhF3Hu8AIvKOd8DjrgajpM6JZ/iGC0VGHckA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A+KOnwMVOwUsj50OdChnv4TPJ9mU2/rKzEYeMAXQNdcjg3GPAeFckWPZvs2gFMG6Hq/6zoBcjTs0tR6fKcq106S1YBnBE4EajuDEHK8TkBr+L7Nr0tsCKmm0d0CA7pA9JjrAX0A/YrVcdnG+F6sqOIjQrXhAdYWrLfIG2QmqExs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=strace.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 2396B72C97D; 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: 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