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 X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E90ECC433ED for ; Thu, 22 Apr 2021 12:50:49 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4098F613FB for ; Thu, 22 Apr 2021 12:50:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4098F613FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=PYu3vpi/aY6kM2effeqN2IUBV3qN974+MJg32Nbx+B4=; b=L5E0FMAsefSJ3Ll5POAa+3Riz h5kTjVoQsFC+a6NLukKbpR/q2rSEMSLtMLAKZcAl8Qeun5GNAmAMYPlBRPalC8rm/JO757DgLIFf8 Q8rWwZ4BubfWHE0Ldq0qDXUb48XS1NjqalM7zpUN0PJhEhkTeKV7o3UdWYbp2yT9PSu4w+m7Zr/3G BKm77Fe4iIfLU//7Awot2EnPi+NpMkO/YsFbojnfYH8SmcBkZnASzPYMiJfsYK6iTXsdWVAPHMZTk xbXeTy3SE4+rzpwTc2DHHKyExxeHSqujn20wTZi3dqONmuyeD6JiNGB/uN8j+TOtm+FW3WbAtoGi8 5MwtrAklA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZYlS-00GjfW-Kg; Thu, 22 Apr 2021 12:49:02 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZYlQ-00Gjf1-3M for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 12:49:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=D+OYN6sWJ5nnN/R/OMjh9xfaBeXHnoOtgYV995entTY=; b=q3nrTh+H6EQ/rYsSM0zC6n5VoY LHCUSgrTR1ELUB6ph9QaxVowK6p+ubJSC7cF1fXDiLvc6R1xiNhelB2kBYzmGqYfXPUwCWCqJYlZY LBn3NNCfVc6pO46rtzxYB5tkAHR2m9RsthjvEcZhbdwSc1fCzIMXKWYH4DFYJhtbi6IUp+Ia8RMzV +0Z3C9UOoIb872i0o8BgKwdKPI/OLqSVhI1QOtKldGhhBqJ+3DyKAzutzvizhqUoV7vdckKpk+iH4 bGZU9Fnqy6o0yHbXRataHi4p9UIHOtEMhE/vMcq/WV5Pf4X2NDLLEWzAN8F9z6qkgIBqz01LZGHuq dHMBl+ZQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZYlN-00DgnC-G2 for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 12:48:58 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id C42B761417; Thu, 22 Apr 2021 12:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619095736; bh=sio4yeEIpcAeAuHiVfe5CZRdx47ywV9hEITNO0odMhE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kE/zD7pFcFxF7sC9BIItIyqC7453Q2szTEBLlsKU70yuC9IaDYMdcGSJSZZc4+jaO a352SBjIYIFv9MIhAQF9NfLs+ByM5vQPLQfTtoegTH/G3Xt7HbL89GbyRT97Jr2kyN UuzCpspdrmOq0SDo5pKDdJjGBbdS7oTut34USllAKcJ1+EOM2bTWT1SwyWlkGU6IFl xWdvsq965CA50pKiJOW/gFt3+K30scIpxFFSyOlkJAjnv20i6L3ijG49qrfZrXGwU1 wHc3saIp5vHS9RQ0L/RjR2k+UdkdrSGHGzdBq8EgoZUxsWHYVBHN9R1spslWObPkAP dZnbFc6DTGnQg== Date: Thu, 22 Apr 2021 13:48:50 +0100 From: Will Deacon To: Liam Howlett , ebiederm@xmission.com Cc: Catalin Marinas , Julien Grall , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" Subject: Re: [PATCH 2/3] arm64: signal: sigreturn() and rt_sigreturn() sometime returns the wrong signals Message-ID: <20210422124849.GA1521@willie-the-truck> References: <20210420165001.3790670-1-Liam.Howlett@Oracle.com> <20210420165001.3790670-2-Liam.Howlett@Oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210420165001.3790670-2-Liam.Howlett@Oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210422_054857_634941_EDB23C55 X-CRM114-Status: GOOD ( 22.99 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org [+Eric as he actually understands how this is supposed to work] On Tue, Apr 20, 2021 at 04:50:13PM +0000, Liam Howlett wrote: > arm64_notify_segfault() was used to force a SIGSEGV in all error cases > in sigreturn() and rt_sigreturn() to avoid writing a new sig handler. > There is now a better sig handler to use which does not search the VMA > address space and return a slightly incorrect error code. Restore the > older and correct si_code of SI_KERNEL by using arm64_notify_die(). In > the case of !access_ok(), simply return SIGSEGV with si_code > SEGV_ACCERR. > > This change requires exporting arm64_notfiy_die() to the arm64 traps.h > > Fixes: f71016a8a8c5 (arm64: signal: Call arm64_notify_segfault when > failing to deliver signal) > Signed-off-by: Liam R. Howlett > --- > arch/arm64/include/asm/traps.h | 2 ++ > arch/arm64/kernel/signal.c | 8 ++++++-- > arch/arm64/kernel/signal32.c | 18 ++++++++++++++---- > 3 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h > index 54f32a0675df..9b76144fcba6 100644 > --- a/arch/arm64/include/asm/traps.h > +++ b/arch/arm64/include/asm/traps.h > @@ -29,6 +29,8 @@ void arm64_notify_segfault(unsigned long addr); > void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str); > void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str); > void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str); > +void arm64_notify_die(const char *str, struct pt_regs *regs, int signo, > + int sicode, unsigned long far, int err); > > /* > * Move regs->pc to next instruction and do necessary setup before it > diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c > index 6237486ff6bb..9fde6dc760c3 100644 > --- a/arch/arm64/kernel/signal.c > +++ b/arch/arm64/kernel/signal.c > @@ -544,7 +544,7 @@ SYSCALL_DEFINE0(rt_sigreturn) > frame = (struct rt_sigframe __user *)regs->sp; > > if (!access_ok(frame, sizeof (*frame))) > - goto badframe; > + goto e_access; > > if (restore_sigframe(regs, frame)) > goto badframe; > @@ -555,7 +555,11 @@ SYSCALL_DEFINE0(rt_sigreturn) > return regs->regs[0]; > > badframe: > - arm64_notify_segfault(regs->sp); > + arm64_notify_die("Bad frame", regs, SIGSEGV, SI_KERNEL, regs->sp, 0); > + return 0; > + > +e_access: > + force_signal_inject(SIGSEGV, SEGV_ACCERR, regs->sp, 0); > return 0; This seems really error-prone to me, but maybe I'm just missing some context. What's the rule for reporting an si_code of SI_KERNEL vs SEGV_ACCERR, and is the former actually valid for SIGSEGV? With this change, pointing the (signal) stack to a kernel address will result in SEGV_ACCERR but pointing it to something like a PROT_NONE user address will give SI_KERNEL (well, assuming that we manage to deliver the SEGV somehow). I'm having a hard time seeing why that's a useful distinction to make.. If it's important to get this a particular way around, please can you add some selftests? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel