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 CC7E31DD539 for ; Tue, 28 Jan 2025 21:39:06 +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=1738100349; cv=none; b=qnEmMD6IPAW4jcOBDF/EeLXf4/LJ02TZZLgGb5NpVuL9+ynj0qgjEIh3XzTQqfWZQcmiTz3Av2VLwXgwYmGZU2+qubMjNAa8YbURcZeuDTdZdxEURDNb0CKm/i6W+LUfOuh0of0bPiKxwEDfCD3We/NYazi/Nub1SnlwqRsDj2M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738100349; c=relaxed/simple; bh=FB48kA8IK65kKqNsAqt2rjHliHkWh7N1WDQTOrmdCW4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bBXiSNfm3fy1X20SptrKjPAnZbLecUbWQHdWNG6RRUdJ40NlB45GcRe3kFKncp1hBrzFhVBeJ/jZgbAiJlym1UDU0NszC9Bv+Lodbg/O8xlxlS+PBSFFwGJzpALUwQQV+4nHMSMhTpFWZeQqRGmi3HocxkiGXHW/IC8QveTuTE8= 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 6AB4072C97D; Wed, 29 Jan 2025 00:39:05 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 576AA7CCB3A; Tue, 28 Jan 2025 23:39:05 +0200 (IST) Date: Tue, 28 Jan 2025 23:39:05 +0200 From: "Dmitry V. Levin" To: Christophe Leroy Cc: Michael Ellerman , Alexey Gladkov , Eugene Syromyatnikov , Oleg Nesterov , Madhavan Srinivasan , Nicholas Piggin , Naveen N Rao , linuxppc-dev@lists.ozlabs.org, strace-devel@lists.strace.io, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] powerpc: fix inconsistencies in syscall error return handling Message-ID: <20250128213905.GA14868@strace.io> References: <20250127181424.GB1373@strace.io> <695b2329-65d5-4e0b-b8ce-eb622c253986@csgroup.eu> 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: <695b2329-65d5-4e0b-b8ce-eb622c253986@csgroup.eu> On Tue, Jan 28, 2025 at 07:01:47PM +0100, Christophe Leroy wrote: > Le 27/01/2025 à 19:14, Dmitry V. Levin a écrit : > > Since the introduction of SECCOMP_RET_TRACE support, the kernel supports > > simultaneously both the generic kernel -ERRORCODE return value ABI and > > the powerpc sc syscall return ABI for PTRACE_EVENT_SECCOMP tracers. > > This change is an attempt to address the code inconsistencies in syscall > > error return handling that were introduced as a side effect of the dual > > ABI support. > > > > Signed-off-by: Dmitry V. Levin > > --- > > arch/powerpc/kernel/ptrace/ptrace.c | 23 ++++++++++++++++++++--- > > arch/powerpc/kernel/signal.c | 11 +++-------- > > arch/powerpc/kernel/syscall.c | 6 +++--- > > 3 files changed, 26 insertions(+), 14 deletions(-) > > > > diff --git a/arch/powerpc/kernel/ptrace/ptrace.c b/arch/powerpc/kernel/ptrace/ptrace.c > > index 727ed4a14545..3778775bf6ba 100644 > > --- a/arch/powerpc/kernel/ptrace/ptrace.c > > +++ b/arch/powerpc/kernel/ptrace/ptrace.c > > @@ -207,7 +207,7 @@ static int do_seccomp(struct pt_regs *regs) > > * syscall parameter. This is different to the ptrace ABI where > > * both r3 and orig_gpr3 contain the first syscall parameter. > > */ > > - regs->gpr[3] = -ENOSYS; > > + syscall_set_return_value(current, regs, -ENOSYS, 0); > > > > /* > > * We use the __ version here because we have already checked > > @@ -215,8 +215,18 @@ static int do_seccomp(struct pt_regs *regs) > > * have already loaded -ENOSYS into r3, or seccomp has put > > * something else in r3 (via SECCOMP_RET_ERRNO/TRACE). > > */ > > - if (__secure_computing(NULL)) > > + if (__secure_computing(NULL)) { > > + > > + /* > > + * Traditionally, both the generic kernel -ERRORCODE return > > + * value ABI and the powerpc sc syscall return ABI is > > + * supported. For consistency, if the former is detected, > > + * convert it to the latter. > > + */ > > + if (!trap_is_scv(regs) && IS_ERR_VALUE(regs->gpr[3])) > > Why !trap_is_scv(regs) ? Shouldn't this also work with scv allthough it > should be a noop ? In trap_is_scv(regs) case both the source and the target ABIs are -ERRORCODE so there is no subject for conversion. > > + syscall_set_return_value(current, regs, regs->gpr[3], 0); > > return -1; > > + } > > > > /* > > * The syscall was allowed by seccomp, restore the register > > @@ -226,6 +236,13 @@ static int do_seccomp(struct pt_regs *regs) > > * allow the syscall to proceed. > > */ > > regs->gpr[3] = regs->orig_gpr3; > > + if (!trap_is_scv(regs)) { > > + /* > > + * Clear SO bit that was set in this function earlier by > > + * syscall_set_return_value. > > + */ > > + regs->ccr &= ~0x10000000L; > > + } > > Can't we use syscall_set_return_value() to do that ? Of course we could do syscall_set_return_value(current, regs, 0, regs->orig_gpr3); but Michael has objected to this already, see https://lore.kernel.org/all/87jzajjde1.fsf@mpe.ellerman.id.au/ -- ldv