From patchwork Mon Aug 7 18:36:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 109593 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1952975qge; Mon, 7 Aug 2017 11:38:49 -0700 (PDT) X-Received: by 10.84.218.136 with SMTP id r8mr1601396pli.111.1502131129845; Mon, 07 Aug 2017 11:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502131129; cv=none; d=google.com; s=arc-20160816; b=U6De8cpsgaDLAPwto2heuV0L0kwNFnzxHSaYTjBQ6r3VL4BvAa1c7sMjnTCajYgDQx 0vLcJJUI0mEhdtyi1U/K2FeRf7s0EsLUGN/jyna9barNvl/eXwWnJZ7R4oB73+LDaEbR ZW/Ye68n+KCO1kDHUjGqsLnOi3U8hi+Mkb1j6Ea+qtqfmTUmdvwuW4x9uDCIXUSFITSg 87Mmj4nbR8CcpAny+/py1zFS++OKBGwWI0lJWRPzFGmzraUS3M9eBRvCxoWerOU6nYNI WOnEj9/Jv6WI/AbaFqHxK3gUahNFvqR+GGnQes/S5uiBIrx057153wrW5efldqBwTAf1 +7+Q== 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=fwdU1Ev1PcwI6UO6/HQOFFQq7oSstlvEZbWRcJy4Na0=; b=x4FTF6NBqPD5hMkcWnG7vYFtFt+MMhu2uEtle8vKmLGq+KvaDsxfWKe2+sxGOUY8HX Yi89vUnI2U9KTuhBm9HUAZtEMQnbPeVQy11KAYOQZ/DyBGcIB1ivs074A8hbp1kVfpWB RrY45/ERfM1hLgjDyY57OU86t3ZxyrWurRR4lCPkvAGCVwXilOgq+qD+iNDStOlsR/Ce BJLx/rU4AQL6Kpd4j6Sch9g+B1GMNJUBxrza04X7RDxYk95iPFIVI+DGvdD7GRhCkxc1 icHdtUf4LijsxLqp2XGyZ3zURKJsI/1Y0iNzCHqSPjSsoZNJAtsCl8DL+itSXTxNndxQ Ubrw== 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 b34si5637596pld.726.2017.08.07.11.38.49; Mon, 07 Aug 2017 11:38:49 -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 S1752253AbdHGSir (ORCPT + 25 others); Mon, 7 Aug 2017 14:38:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52748 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752202AbdHGSin (ORCPT ); Mon, 7 Aug 2017 14:38:43 -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 47AA91A25; Mon, 7 Aug 2017 11:38:43 -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 2B68F3F577; Mon, 7 Aug 2017 11:38:41 -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: [PATCH 13/14] arm64: add on_accessible_stack() Date: Mon, 7 Aug 2017 19:36:04 +0100 Message-Id: <1502130965-18710-14-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502130965-18710-1-git-send-email-mark.rutland@arm.com> References: <1502130965-18710-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 54f3463..d9b80eb 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)); }