Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp657227pxk; Thu, 3 Sep 2020 09:17:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNa5ajJFX0Qt81nTxkWOZHe/05wghLNNvEom1ypshpB9E96KtqRrp3j+k8pW5NMCGU9G0g X-Received: by 2002:a17:906:768c:: with SMTP id o12mr2851701ejm.269.1599149862956; Thu, 03 Sep 2020 09:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599149862; cv=none; d=google.com; s=arc-20160816; b=XIxqMY/xE3lzv/3Ur+kroFRmP6J+zLuCMeCxguX5bQY31rlzkAGtcCqfc95MD8GWJt Sbh12maqt+FzTayI2E0ddrsIIsJZbrlrJkqolCAcPCc/0PvdL4XsPqlU5kjGrvzP35up ohJuDMZlPUBizf/rinuAPFradblmMzlZgpO/27vgPt4Ba3z9ruyyAhl9j0CuB2Axrl8x mGt4Ebm9a/xRgnWBqiAcNkZNuUOcZm8wr4e6SEwQGqUiuKsYIakUTAJm9M+HAH8GVDaR E1r71IVebI5n6/qHp8SCyBdwaMT0bflI+wktv6ofi8vAh2Pxdf7K4XvpP1QuGB4F8A4U 8gQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=O1dKuvWU0N3BInfcFRcKO+px/FksxOZl77YkI2EAKyE=; b=i2PLVYbOtNldZV/4Euw3VYBNiRlweTB/+l4OX4A9H7URbdpLwFuwq1Y+NSyWHmg7EJ /QzlR1UCMUIsguqjMmf3X+Naavekmvjj1FLwFYrDqcGFezXv4+2FPjn8ku6vjT5PGmeh ljgVcW9YUSWpiNp2l87fRboAISbn8QSi6w6foLt9TnUyL6Odv74ZCzurGSX1wnki5xTa XG1x0DRQg/OfrSzuPDm5qY0ZjEZeU252iFVD2AgdQOaDoiPm7KN+23/+aI2SEpbzSM3r MrvxqL7m06Gm4TyrRZx6SU5QBUmE+6pUaSf+wPkdxVTtxLur/O+RB41vN6csuGJzn0sQ VYVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si2407242ejf.419.2020.09.03.09.17.19; Thu, 03 Sep 2020 09:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728491AbgICQQm (ORCPT + 99 others); Thu, 3 Sep 2020 12:16:42 -0400 Received: from brightrain.aerifal.cx ([216.12.86.13]:49254 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgICQQm (ORCPT ); Thu, 3 Sep 2020 12:16:42 -0400 Date: Thu, 3 Sep 2020 12:16:40 -0400 From: Rich Felker To: John Paul Adrian Glaubitz Cc: linux-sh@vger.kernel.org, Michael Karcher , linux-kernel@vger.kernel.org, Yoshinori Sato Subject: Re: [PATCH] sh: fix syscall tracing Message-ID: <20200903161639.GE3265@brightrain.aerifal.cx> References: <20200903054803.GX3265@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 03, 2020 at 12:14:43PM +0200, John Paul Adrian Glaubitz wrote: > Hi Rich! > > On 9/3/20 7:48 AM, Rich Felker wrote: > > Addition of SECCOMP_FILTER exposed a longstanding bug in > > do_syscall_trace_enter, whereby r0 (the 5th argument register) was > > mistakenly used where r3 (syscall_nr) was intended. By overwriting r0 > > rather than r3 with -1 when attempting to block a syscall, the > > existing code would instead have caused the syscall to execute with an > > argument clobbered. > > > > Commit 0bb605c2c7f2b4b3 then introduced skipping of the syscall when > > do_syscall_trace_enter returns -1, so that the return value set by > > seccomp filters would not be clobbered by -ENOSYS. This eliminated the > > clobbering of the 5th argument register, but instead caused syscalls > > made with a 5th argument of -1 to be misinterpreted as a request by > > do_syscall_trace_enter to suppress the syscall. > > > > Fixes: 0bb605c2c7f2b4b3 ("sh: Add SECCOMP_FILTER") > > Fixes: ab99c733ae73cce3 ("sh: Make syscall tracer use tracehook notifiers, add TIF_NOTIFY_RESUME.") > > Signed-off-by: Rich Felker > > --- > > arch/sh/kernel/entry-common.S | 1 - > > arch/sh/kernel/ptrace_32.c | 15 +++++---------- > > 2 files changed, 5 insertions(+), 11 deletions(-) > > > > diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S > > index ad963104d22d..91ab2607a1ff 100644 > > --- a/arch/sh/kernel/entry-common.S > > +++ b/arch/sh/kernel/entry-common.S > > @@ -370,7 +370,6 @@ syscall_trace_entry: > > nop > > cmp/eq #-1, r0 > > bt syscall_exit > > - mov.l r0, @(OFF_R0,r15) ! Save return value > > ! Reload R0-R4 from kernel stack, where the > > ! parent may have modified them using > > ! ptrace(POKEUSR). (Note that R0-R2 are > > diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c > > index b05bf92f9c32..5281685f6ad1 100644 > > --- a/arch/sh/kernel/ptrace_32.c > > +++ b/arch/sh/kernel/ptrace_32.c > > @@ -455,16 +455,11 @@ long arch_ptrace(struct task_struct *child, long request, > > > > asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) > > { > > - long ret = 0; > > - > > if (test_thread_flag(TIF_SYSCALL_TRACE) && > > - tracehook_report_syscall_entry(regs)) > > - /* > > - * Tracing decided this syscall should not happen. > > - * We'll return a bogus call number to get an ENOSYS > > - * error, but leave the original number in regs->regs[0]. > > - */ > > - ret = -1L; > > + tracehook_report_syscall_entry(regs)) { > > + regs->regs[0] = -ENOSYS; > > + return -1; > > + } > > > > if (secure_computing() == -1) > > return -1; > > @@ -475,7 +470,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) > > audit_syscall_entry(regs->regs[3], regs->regs[4], regs->regs[5], > > regs->regs[6], regs->regs[7]); > > > > - return ret ?: regs->regs[0]; > > + return 0; > > } > > > > asmlinkage void do_syscall_trace_leave(struct pt_regs *regs) > > > > I can confirm that this patch fixes both strace for me and does not break libseccomp, > I have run the libseccomp testsuite with my patch for SuperH support applied on top > of a rebased libseccomp with the 32-bit fixes. Attaching the testsuite log. > > Tested-by: John Paul Adrian Glaubitz Great! Thanks! Rich