From patchwork Thu Jun 7 11:32:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 137883 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1975005lji; Thu, 7 Jun 2018 04:32:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKAWVLZ7HzWKa5a6aYIoGe+2+MOP0A80LLlV5K+UfzuttqMog51DfNOzpM0fipq2IpIfGk2 X-Received: by 2002:a17:902:6e01:: with SMTP id u1-v6mr1650792plk.96.1528371133476; Thu, 07 Jun 2018 04:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528371133; cv=none; d=google.com; s=arc-20160816; b=X3xnFjyuAmJxpglvgpZSNCGUgAHESty+wcQEIgfAF/BzJ5fJg/NtoQYbnrwXTd7Lk/ n+2elg1TXSPII04Ax86Cm8YbAjyFFMGR0OTP3aqmZhW6Us7YwhRfDk5e2Ehqe+dgdDvv VknCJMW80KH6bBP3DPEhiVfC6bRjAq9ZbX2s4R7aaL0cQ1uMhHthgi6fdCocajNMYDXP IQyTzEayzsyilIcDQE8y920VJBgUgufYYMUeIa7n1/BtCGrHarMMi/5RYgyFSiaZpGZW ko47WmcwYSuevKMtkDtySztXvbOhR6X2VeKr5fk43Q9RIGs/3iaRQVFKts6c+QhH98lQ +fkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=X9TN5gA5WHqkODAKf4QcKWSuP5dMUvK/3ati7TcJmIo=; b=fzJhZ4hTkSdoMfHFKFefXhH9zvj+RoBgSb8kmLvNU1DCzqKAx8R7oj06Uq/Rgykq3L Ab2M797hnPe83kb3nYEibYaweGaX7cNF0AOnQnNcWj2Ma6K+WCvBmvbawQV0u9iFAcGQ 7ESPIoq/BJz2xHj0714EXvuJzMHgLL85iaPL3qQMWxGWNlVOKmaQlNqMQfhagTO1uDkD BP7JAEH4yswA9tr3zJ7ica42mtoW9blL6ZrRfWTmADTnyWVGbvhDeslMgvlsFYL9BjU2 qssv5hi5hCqM6gbMIrDIK54IorLvlspHbNhfamUMMB4Myx6oD3WoJtgdRGEjbp1Tqd33 2g2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 y2-v6si21618420pgr.677.2018.06.07.04.32.13; Thu, 07 Jun 2018 04:32:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753354AbeFGLcM (ORCPT + 13 others); Thu, 7 Jun 2018 07:32:12 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50432 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753348AbeFGLcM (ORCPT ); Thu, 7 Jun 2018 07:32:12 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B308C15AB; Thu, 7 Jun 2018 04:32:11 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C7DF63F59D; Thu, 7 Jun 2018 04:32:10 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Catalin Marinas , , Sumit Semwal Subject: [PATCH] arm64: Fix syscall restarting around signal suppressed by tracer Date: Thu, 7 Jun 2018 12:32:05 +0100 Message-Id: <1528371125-24505-1-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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: Catalin Marinas Cc: # 4.14.x- --- arch/arm64/kernel/signal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.1.4 diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 154b7d3..f212090 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -830,11 +830,12 @@ static void do_signal(struct pt_regs *regs) 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 *regs) * 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);