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 B01B8E7719C for ; Sat, 11 Jan 2025 01:16:43 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4YVLG16q7pz3cjL; Sat, 11 Jan 2025 12:16:41 +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=1736558201; cv=none; b=L1fxHhL/NJmVejGBRx16quVYcQKW9GJSQTzhH4GXPhzcLO6giOblC6Ob5jT9X3zeHSW6yVq3PFs5tFpK3WJmgqE/lGYdaE7Xmp7+kMeOuFhZovxsfOX/s2DfaSXR9UmbIB8Bx122U+s/84q1D9v9Qse/3pAxBIb1gvFT2+1ljCZpivkKYtiMSXAt17XaHuH43VgJBMlX/nFOWnBUxVUXWmjYUCwDvTzOFihE/7PJRjbZoUbo02Sn2yIadzMzJ516XU1hl9IgmvRHe1SXwaSwoEK1rfxhr6olvfvVVAaYAAN2/+LDdWYLb/VjWERnkla/FeZRxjKYSryVBjiRZ4tKeQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1736558201; c=relaxed/relaxed; bh=OGaUIIECp53nz7ZUChA/HGseFYhZkADFgRs/+WkgOTc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oBTwZ9UUW4aOibgJ4WTFc+4NpD3KPtEbL8UaQenxEL1s9nQfS5BMzswo165N7IMKVzJDhLMRubVVLwQzeBQDzUE7bOD+rvIqWUL88wsQCPCXLFEPJJgmMZ+jWGWJb+f4MAzXtZC6LfJZu3Hg9ZSJhTKwvHpgmGAm/t2N2fm11pGPkwqgEA4s/2MeX4/fEwkNJ6HtKLOepH8UYB5EJsJFXUsV5hWZmMkEcb4lT109cFO2Inzdq8wyKUgnz4v9eU9MZjlvB26V3nMVHdaBVlMKqSBv5AWfpqKyJFqWt3NZaxqOa8V0t3DFEfsJt4rt8wXfa2vcR3d7cNJrQWv1Y0ui6g== 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 4YVLG03sggz3cdm for ; Sat, 11 Jan 2025 12:16:38 +1100 (AEDT) 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> 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=us-ascii Content-Disposition: inline In-Reply-To: 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