From patchwork Thu May 3 13:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 134897 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1920443lji; Thu, 3 May 2018 06:21:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpzJSJP1k43DVk/NcupDu8C24LeOoGgWy3g13QP4nfz3TtRevfXX+41f+jY5CpR/cxV+muW X-Received: by 2002:a63:ad49:: with SMTP id y9-v6mr4153906pgo.179.1525353670983; Thu, 03 May 2018 06:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525353670; cv=none; d=google.com; s=arc-20160816; b=Kt3oPTQ44BbOJm/qo+HdmNA0l/Au3YEMcvjN11rfKX6ndWxyQNFScwy8c0dGZTX677 G7c3JV4oInFE8qXDi2ch1nD2JmfobfTkyOLJ5t6NB7A6yuSO7vVP1nj0UW9aa4arboGM u0pOFwQPEJBABlD8trvlOT++tPBY1cDcoYLJNEwqlYvYM5sQVUn11fQsEDuC2sbfyFzm cS1ZKWqkZl5oWD0eiD15DME6VxZLJMXeZksTfHvWXRimwd50NHbyZz135Nm127JUD63v rpbjMSfRkjTtQwZVydREWX+zRYwZV5T5caVWagDtHLlNghmysI0Ku7RkhjZg94w38hEj LAfQ== 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=2RQVwgLNfTO5515sE9tXUvFUS8r9YW6rbs+zjIVbzZA=; b=VbpkS46pBogLPh18rIjm4I6GiiT3FfQi8/JsM79FTNaxcXEhjrE3RPesWO/s47qyX1 1W0/qik+d3i6MEalzF03/8fT75QkR3j+KSqbUYiPKvmgJIQkBhHXnUihf/Fz7qO8zwFH +cWF9jxValKyyqy8rz7ZWeWY2nOLOAGLKVA5LPLchyOUrknxkgyw2AG+D5Cek/QJkMNx pr8U4mcqEY5bG5cAIHUAelu4XCb11CmsAhl6FiUs2HXNhgS88W8xLxK42XQwRQnuUXXP qKwZLMcP7Pzh7WHBUrg45Ulskw3Y/t1E+z/sBiYYgHn8ya7vlq7EX3lUY1+iytkC3KfV oubw== 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 b23-v6si11733231pgw.529.2018.05.03.06.21.10; Thu, 03 May 2018 06:21: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 S1751538AbeECNVH (ORCPT + 29 others); Thu, 3 May 2018 09:21:07 -0400 Received: from foss.arm.com ([217.140.101.70]:41664 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbeECNVB (ORCPT ); Thu, 3 May 2018 09:21:01 -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 36DF81596; Thu, 3 May 2018 06:21:01 -0700 (PDT) Received: from lakrids.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 266393F487; Thu, 3 May 2018 06:20:59 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, catalin.marinas@arm.com, christoffer.dall@arm.com, drjones@redhat.com, marc.zyngier@arm.com, mark.rutland@arm.com, ramana.radhakrishnan@arm.com, suzuki.poulose@arm.com, will.deacon@arm.com, awallis@codeaurora.org Subject: [PATCHv4 08/10] arm64: perf: strip PAC when unwinding userspace Date: Thu, 3 May 2018 14:20:29 +0100 Message-Id: <20180503132031.25705-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180503132031.25705-1-mark.rutland@arm.com> References: <20180503132031.25705-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the kernel is unwinding userspace callchains, we can't expect that the userspace consumer of these callchains has the data necessary to strip the PAC from the stored LR. This patch has the kernel strip the PAC from user stackframes when the in-kernel unwinder is used. This only affects the LR value, and not the FP. This only affects the in-kernel unwinder. When userspace performs unwinding, it is up to userspace to strip PACs as necessary (which can be determined from DWARF information). Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Ramana Radhakrishnan Cc: Will Deacon --- arch/arm64/include/asm/pointer_auth.h | 7 +++++++ arch/arm64/kernel/perf_callchain.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h index 0263b87f95f7..284db173ae5d 100644 --- a/arch/arm64/include/asm/pointer_auth.h +++ b/arch/arm64/include/asm/pointer_auth.h @@ -65,6 +65,12 @@ static inline void ptrauth_keys_dup(struct ptrauth_keys *old, */ #define ptrauth_pac_mask() GENMASK(54, VA_BITS) +/* Only valid for EL0 TTBR0 instruction pointers */ +static inline unsigned long ptrauth_strip_insn_pac(unsigned long ptr) +{ + return ptr & ~ptrauth_pac_mask(); +} + #define mm_ctx_ptrauth_init(ctx) \ ptrauth_keys_init(&(ctx)->ptrauth_keys) @@ -75,6 +81,7 @@ static inline void ptrauth_keys_dup(struct ptrauth_keys *old, ptrauth_keys_dup(&(oldctx)->ptrauth_keys, &(newctx)->ptrauth_keys) #else +#define ptrauth_strip_insn_pac(lr) (lr) #define mm_ctx_ptrauth_init(ctx) #define mm_ctx_ptrauth_switch(ctx) #define mm_ctx_ptrauth_dup(oldctx, newctx) diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index bcafd7dcfe8b..928204f6ab08 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -35,6 +35,7 @@ user_backtrace(struct frame_tail __user *tail, { struct frame_tail buftail; unsigned long err; + unsigned long lr; /* Also check accessibility of one struct frame_tail beyond */ if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) @@ -47,7 +48,9 @@ user_backtrace(struct frame_tail __user *tail, if (err) return NULL; - perf_callchain_store(entry, buftail.lr); + lr = ptrauth_strip_insn_pac(buftail.lr); + + perf_callchain_store(entry, lr); /* * Frame pointers should strictly progress back up the stack