Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3012861imm; Sun, 1 Jul 2018 10:17:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJj5gYskcFeq/BzS39gbQtgDkadicBef7kkLJs7piUtq3IYVVP9DmqNyQHKHztXOKriPZEC X-Received: by 2002:a65:6147:: with SMTP id o7-v6mr19126723pgv.163.1530465430437; Sun, 01 Jul 2018 10:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530465430; cv=none; d=google.com; s=arc-20160816; b=0dmE7AM8bIyIAKSyCBUFQW2aZ1dly/2LONPsW7AX1s2JL0ZAyWV9utaGPHWGUGPCt2 o9ggpbBjlVIrrQqUcRVwJbwLPj4a2WdirZhAs+sHLsbC557CGgt6+wfU4B9fQH+BYtjd zX8NsiUQDDkQBMgDTVukQYOVIcMkVqGi0887N0IJUwK8khdZA5zNvnJFu0YUFrHsP/WO vfpOrJpR1LSb+fWQ52s6b0MM9m4yYrUC2ezt0ccs8iuBUJ0beJmBLWeIl08B+KZZ8Fjp YKha8Nqh9hkvSr7Pf9avU1TSX45wyo+f9bGvecyKHZMA1cms95ffazp4aQo18CT6SRV1 V6hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xx9mstoNb0ttpHKKGujTwrs+D2shfNdx808pmIuXM6M=; b=wSK5hXPj0IgsfVDoKNejP0/R0Atlkya8etpEd0xdTg/8U1INK8nQBoeVXRDAgIuCEg zdUIVx42oR3aaiOCFaSZ/TVvoDdFo9XwHqee5jvz7l6/agvBVsuvUWCGG9RBvQB2fIQK v1V//KbT2F/EfvYpWHrjGAOSInl259qVLznK/e49b7sAn8s3p1UclOhsA8m/6E1NYCtg iXZhMJsFLFpA6QNZr8HvZEjfqUlkE1OEsVjDVBjauO3OHN+y91ETsS5K6jJAR/ygZQGv FTKV8GMRY/lxKb9Dn/0ZOaSRDKMYRkDtsd3Y4qECCQ4+r3VV6Iitc/lBH87r9WsDUegg M7lw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5-v6si14390873plk.352.2018.07.01.10.16.55; Sun, 01 Jul 2018 10:17:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934129AbeGARQH (ORCPT + 99 others); Sun, 1 Jul 2018 13:16:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37012 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031308AbeGAQjs (ORCPT ); Sun, 1 Jul 2018 12:39:48 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9E7DAA73; Sun, 1 Jul 2018 16:39:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Martin , Sumit Semwal , Will Deacon , Catalin Marinas Subject: [PATCH 4.17 070/220] arm64: Fix syscall restarting around signal suppressed by tracer Date: Sun, 1 Jul 2018 18:21:34 +0200 Message-Id: <20180701160911.340143585@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Martin commit 0fe42512b2f03f9e5a20b9f55ef1013a68b4cd48 upstream. Commit 17c2895 ("arm64: Abstract syscallno manipulation") abstracts out the pt_regs.syscallno value for a syscall cancelled by a tracer as NO_SYSCALL, and provides helpers to set and check for this condition. However, the way this was implemented has the unintended side-effect of disabling part of the syscall restart logic. This comes about because the second in_syscall() check in do_signal() re-evaluates the "in a syscall" condition based on the updated pt_regs instead of the original pt_regs. forget_syscall() is explicitly called prior to the second check in order to prevent restart logic in the ret_to_user path being spuriously triggered, which means that the second in_syscall() check always yields false. This triggers a failure in tools/testing/selftests/seccomp/seccomp_bpf.c, when using ptrace to suppress a signal that interrups a nanosleep() syscall. Misbehaviour of this type is only expected in the case where a tracer suppresses a signal and the target process is either being single-stepped or the interrupted syscall attempts to restart via -ERESTARTBLOCK. This patch restores the old behaviour by performing the in_syscall() check only once at the start of the function. Fixes: 17c289586009 ("arm64: Abstract syscallno manipulation") Signed-off-by: Dave Martin Reported-by: Sumit Semwal Cc: Will Deacon Cc: # 4.14.x- Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/signal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -830,11 +830,12 @@ static void do_signal(struct pt_regs *re unsigned long continue_addr = 0, restart_addr = 0; int retval = 0; struct ksignal ksig; + bool syscall = in_syscall(regs); /* * If we were from a system call, check for system call restarting... */ - if (in_syscall(regs)) { + if (syscall) { continue_addr = regs->pc; restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4); retval = regs->regs[0]; @@ -886,7 +887,7 @@ static void do_signal(struct pt_regs *re * Handle restarting a different system call. As above, if a debugger * has chosen to restart at a different PC, ignore the restart. */ - if (in_syscall(regs) && regs->pc == restart_addr) { + if (syscall && regs->pc == restart_addr) { if (retval == -ERESTART_RESTARTBLOCK) setup_restart_syscall(regs); user_rewind_single_step(current);