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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 563C1E77188 for ; Sat, 11 Jan 2025 01:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=G5ZJAL2YRuwYi9dhDzjF6/Q2lHB4xm5oK7HhTVtktqA=; b=O8ssK9Q/Es9ppj FDRdSF2MEaolzi9MreSL0xbBHU25T2F72hzG9KesAl+6T94R7XRG0jtHF5Lr4r9kRW74XJNifYY9Z 7qIW2GepWJd83TcKhpH8CscoV9GOwh5lMq4HYiulhe0Oudf5zz02TOfu6ZHwqoi3jO6oCaZS9OjWA CWaP5aC0Qo8M6+mvcLoSGyHKwufAHq3quamLlk9NqpOOVAagD56EBFPRgOZdGg/JzKi5MIcjckx/N Sp4cBGfy7F5B/sTIFOUcxibYQy0E9pgkBmNx48N0TNYTc0jWl6oo1USa/MaqaQYJ/SeYu7RfHDgvt mMyAGWdZlP8N1aJSlvTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tWQ7D-0000000HTnW-3fvv; Sat, 11 Jan 2025 01:16:39 +0000 Received: from vmicros1.altlinux.org ([194.107.17.57]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tWQ7B-0000000HTmw-0Y2E; Sat, 11 Jan 2025 01:16:38 +0000 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 3D21472C8FB; Sat, 11 Jan 2025 04:16:32 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 2736C7CCB3A; Sat, 11 Jan 2025 03:16:32 +0200 (IST) Date: Sat, 11 Jan 2025 03:16:32 +0200 From: "Dmitry V. Levin" To: Sven Schnelle Cc: Oleg Nesterov , Eugene Syromyatnikov , Mike Frysinger , Renzo Davoli , Davide Berardi , strace-devel@lists.strace.io, Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Brian Cain , Huacai Chen , WANG Xuerui , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Chris Zankel , Max Filippov , Arnd Bergmann , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-arch@vger.kernel.org Subject: Re: [PATCH 3/6] syscall.h: introduce syscall_set_nr() Message-ID: <20250111011632.GA1724@strace.io> References: <20250107230438.GC30633@strace.io> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250110_171637_501766_72E36C16 X-CRM114-Status: GOOD ( 21.30 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, Jan 10, 2025 at 08:37:46AM +0100, Sven Schnelle wrote: > "Dmitry V. Levin" writes: > > > 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. [...] > > diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h > > index b3dd883699e7..1c0e349fd5c9 100644 > > --- a/arch/s390/include/asm/syscall.h > > +++ b/arch/s390/include/asm/syscall.h > > @@ -24,6 +24,13 @@ static inline long syscall_get_nr(struct task_struct *task, > > (regs->int_code & 0xffff) : -1; > > } > > > > +static inline void syscall_set_nr(struct task_struct *task, > > + struct pt_regs *regs, > > + int nr) > > +{ > > I think there should be a > > if (!test_pt_regs_flags(regs, PIF_SYSCALL)) > return; > > before the modification so a user can't accidentally change int_code > when ptrace stopped in a non-syscall path. The reason why syscall_get_nr() has this check on s390 (and similar checks on arc, powerpc, and sparc) is that syscall_get_nr() can be called while the target task is not in syscall. Unlike syscall_get_nr(), syscall_set_nr() can be called only when the target task is stopped for tracing on entering syscall: the description in include/asm-generic/syscall.h explicitly states that, and the follow-up patch that introduces PTRACE_SET_SYSCALL_INFO adds a syscall_set_nr() call when the tracee is stopped on entering syscall in either PTRACE_SYSCALL_INFO_ENTRY or PTRACE_SYSCALL_INFO_SECCOMP state. I don't mind adding a check, but syscall_set_nr() invocation while the target task is not in syscall wouldn't be a result of user actions but a kernel programing error, and in that case WARN_ON_ONCE() would be more appropriate. If calling syscall_set_nr() while the target task is not in syscall was legal, then syscall_set_nr() would have been designed to return a value indicating the status of operation. Anyway, I'll add an explanatory comment to syscall_set_nr() on all architectures where syscall_get_nr() has a check. -- ldv _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv