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 D8DB11607A4 for ; Mon, 27 Jan 2025 18:14:25 +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=1738001668; cv=none; b=rk2YKZDweqrPDS/R2p4b3uVycqcy+LTK+RoqeElyq5vMcnOAtaO8yaxr/JaxSaBDznbeqbl+8xiMGJxfhSy1dxc4kyfZCQiAaKPI1590eahDut3U6i7RVvlVOrLM7L8DPZBe+IG+J6Z3/+lMkzslXxXOKkxGr56cUJmSG9ioWiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738001668; c=relaxed/simple; bh=1h5jnLO4Lz8hRTC1H5fET6r84M6XuTc+Vok3QJ1TJFQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=HH0vRRcr7sEKQWBRR4sIx2r6MJsutMkI9JzkJlE5PHhuuXq8/IPnBlaZ3L5R0XyTSbMiY4I38VF9F6x6Zo72j9tv+kjY509A5c+T1LCEV+kgLTLZMToMeKO3A7Gi0IUWpnM/HI7yec2bFcBqzvg1WPY+NE1hpvQTZC15GxYovIE= 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 5CC7072C8CC; Mon, 27 Jan 2025 21:14:24 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 47C637CCB3A; Mon, 27 Jan 2025 20:14:24 +0200 (IST) Date: Mon, 27 Jan 2025 20:14:24 +0200 From: "Dmitry V. Levin" To: Michael Ellerman , Christophe Leroy Cc: 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: [PATCH 2/2] powerpc: fix inconsistencies in syscall error return handling Message-ID: <20250127181424.GB1373@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=us-ascii Content-Disposition: inline In-Reply-To: <20250127181322.GA1373@strace.io> 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])) + 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; + } return 0; } @@ -315,7 +332,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) * If we are aborting explicitly, or if the syscall number is * now invalid, set the return value to -ENOSYS. */ - regs->gpr[3] = -ENOSYS; + syscall_set_return_value(current, regs, -ENOSYS, 0); return -1; } diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c index aa17e62f3754..1a38d6bcaed6 100644 --- a/arch/powerpc/kernel/signal.c +++ b/arch/powerpc/kernel/signal.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "signal.h" @@ -229,14 +230,8 @@ static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, regs_add_return_ip(regs, -4); regs->result = 0; } else { - if (trap_is_scv(regs)) { - regs->result = -EINTR; - regs->gpr[3] = -EINTR; - } else { - regs->result = -EINTR; - regs->gpr[3] = EINTR; - regs->ccr |= 0x10000000; - } + regs->result = -EINTR; + syscall_set_return_value(current, regs, -EINTR, 0); } } diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c index be159ad4b77b..2fe47191e509 100644 --- a/arch/powerpc/kernel/syscall.c +++ b/arch/powerpc/kernel/syscall.c @@ -122,7 +122,7 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0) if (unlikely(trap_is_unsupported_scv(regs))) { /* Unsupported scv vector */ _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); - return regs->gpr[3]; + return regs_return_value(regs); } /* * We use the return value of do_syscall_trace_enter() as the @@ -133,13 +133,13 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0) */ r0 = do_syscall_trace_enter(regs); if (unlikely(r0 >= NR_syscalls)) - return regs->gpr[3]; + return regs_return_value(regs); } else if (unlikely(r0 >= NR_syscalls)) { if (unlikely(trap_is_unsupported_scv(regs))) { /* Unsupported scv vector */ _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); - return regs->gpr[3]; + return regs_return_value(regs); } return -ENOSYS; } -- ldv