From patchwork Tue Aug 15 12:50:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 110153 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp5440218obb; Tue, 15 Aug 2017 05:53:46 -0700 (PDT) X-Received: by 10.99.176.4 with SMTP id h4mr26753296pgf.300.1502801626218; Tue, 15 Aug 2017 05:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502801626; cv=none; d=google.com; s=arc-20160816; b=fkc2T3MbJKcbbG40UFVs/EhrpGuPz4Ha6PRzuFiZGKUi9SlBhGG1HF4XrzSgmDy2M5 EOr33y0wZWfqPK2Kc6kEJ5ZisxBzpy46obKrXz7dvqjKFD7wD3xQH84MAu50fD1gPjlS YA5Sq7waddSvp03ZtLNp788oo5AO5vY58XfpKRjKnht4MqD0MXFUXZtnI3hJH2j3CNF7 VTDNRTXvinrxiExUHqlemUwbORgnsPnU/VcPd1d1vBEJI7HIuJRf8IMoXWyjzQXVRaDV tu7YFYG1nRWlfZagsaLZbfSI8cPIDMBIcu+aWXx0SxroOwQ6MXxoSyN+4LFY8Sr447oG 10ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=NXnSjGXKxLst34agjQNzMCrXR12YpUbRfgTjX4wZwxs=; b=LDPS0HXzC0C/21M/vmtqYdkKHG94G7geSqWUUXHPVwqLUqwV6Ik43oo3RWzAY/v7s4 JAu43mzh09sgEwgK68vDlh+8am0XloJbP7u9lp0hAX6KTLQnzQ8jOsBKsGL1IbEpWFQp HY9jmH1DuqW3rgorU2LVIj5b2XWBGICZ4LHX/OCUZb46lNxVF+BZboMCyNDJ7hhk1oE0 lY9Nc8HKR6OzQScRFVe8WVxDg+2Zsz+LKqaEvB2jMQ/rcwdJcd2823kVsOjlU83viqqL 6f8Dl8m2EQC23fj7+AiJl4AThUmi7YxRy/WPjfJ946hDVi1zoYH4BxLnTT67dS7AhWTL h/7w== 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 t12si5534414pfj.329.2017.08.15.05.53.45; Tue, 15 Aug 2017 05:53:46 -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 S1752992AbdHOMxn (ORCPT + 25 others); Tue, 15 Aug 2017 08:53:43 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51638 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752852AbdHOMxI (ORCPT ); Tue, 15 Aug 2017 08:53:08 -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 3BFDC15BF; Tue, 15 Aug 2017 05:53:08 -0700 (PDT) Received: from leverpostej.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 1FAFC3F540; Tue, 15 Aug 2017 05:53:05 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: ard.biesheuvel@linaro.org, catalin.marinas@arm.com, james.morse@arm.com, labbott@redhat.com, linux-kernel@vger.kernel.org, luto@amacapital.net, mark.rutland@arm.com, matt@codeblueprint.co.uk, will.deacon@arm.com, kernel-hardening@lists.openwall.com, keescook@chromium.org Subject: [PATCHv2 13/14] arm64: add on_accessible_stack() Date: Tue, 15 Aug 2017 13:50:48 +0100 Message-Id: <1502801449-29246-14-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502801449-29246-1-git-send-email-mark.rutland@arm.com> References: <1502801449-29246-1-git-send-email-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both unwind_frame() and dump_backtrace() try to check whether a stack address is sane to access, with very similar logic. Both will need updating in order to handle overflow stacks. Factor out this logic into a helper, so that we can avoid further duplication when we add overflow stacks. Signed-off-by: Mark Rutland Cc: Ard Biesheuvel Cc: Catalin Marinas Cc: James Morse Cc: Laura Abbott Cc: Will Deacon --- arch/arm64/include/asm/stacktrace.h | 16 ++++++++++++++++ arch/arm64/kernel/stacktrace.c | 7 +------ arch/arm64/kernel/traps.c | 3 +-- 3 files changed, 18 insertions(+), 8 deletions(-) -- 1.9.1 diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index 4c68d8a..92ddb6d 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -57,4 +57,20 @@ static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp) return (low <= sp && sp < high); } +/* + * We can only safely access per-cpu stacks from current in a non-preemptible + * context. + */ +static inline bool on_accessible_stack(struct task_struct *tsk, unsigned long sp) +{ + if (on_task_stack(tsk, sp)) + return true; + if (tsk != current || preemptible()) + return false; + if (on_irq_stack(sp)) + return true; + + return false; +} + #endif /* __ASM_STACKTRACE_H */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 35588ca..3144584 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -50,12 +50,7 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) if (!tsk) tsk = current; - /* - * Switching between stacks is valid when tracing current and in - * non-preemptible context. - */ - if (!(tsk == current && !preemptible() && on_irq_stack(fp)) && - !on_task_stack(tsk, fp)) + if (!on_accessible_stack(tsk, fp)) return -EINVAL; frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 9633773..d01c598 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -193,8 +193,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) if (in_entry_text(frame.pc)) { stack = frame.fp - offsetof(struct pt_regs, stackframe); - if (on_task_stack(tsk, stack) || - (tsk == current && !preemptible() && on_irq_stack(stack))) + if (on_accessible_stack(tsk, stack)) dump_mem("", "Exception stack", stack, stack + sizeof(struct pt_regs)); }