From patchwork Fri Dec 7 18:39:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 153192 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp831733ljp; Fri, 7 Dec 2018 10:40:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/UHtxvs+WiFhT0YPw+SGC2EVvC46mCRt9XGUO+5Yq9QbrHBJvNRpk/YsVEAugdkmvlMiSdK X-Received: by 2002:a17:902:14b:: with SMTP id 69mr3241312plb.52.1544208040129; Fri, 07 Dec 2018 10:40:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544208040; cv=none; d=google.com; s=arc-20160816; b=N4+Ojk+Ij8s+mV7kVSY5oBeyqpO/VctqWW5qhrTzNxZSYX4Q+1altIUETU3xvNvtYa xcYsoaYxI6AtGY4n73uv8k1E70eLhiOmpd4GKaLmSA98XRSfHdfx/uDWJFdv0x4Gic5Y zTheaAOCppY6L18FuaQsYN99UWotGZ16FZARhsmA3CJslEP+ZX3iEcLeKtpXQNo6+ehs tSd53Q5JulnYXqyj1Ov//9i2p4iYqXXR2e9rhhVAMZ98mKVX6Hyt+xVEqunFljAwXtG6 ZcOvM7+4eadOD4r/bFEVFnwjCk8PQejgpUI3pu1pRRR3mrhw1XIc1I3i0edC6AkP0YgR TJBA== 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; bh=nbfuvLKSG7ktUMulhpijSbEvFR/rXox1O0mw1IqmIKs=; b=G+nEMHAai+KglA3C/PEaEiOlxGV8crOLIfWfMZd6x3/ghIXSfPdaW5AbhRe195CO5r ga0itgXe7iTJBh1F0Jh0krCiE5iMKTw21CX/fqDystBXd8Wn68NDRl7Yje7m44Zsg0a1 YU3sL9DOqnalagY5kIuzsH7F+C7AFeGCui0rYSFY+2eoJYyuyICsshMMG+iy7LjqRBGT yNOo8EUbRL/bbhnsjohRvn6NRuFuTfhnhmUYz2xJDk99HFx4OLPJ8SXT1LXAhrDGjd0D sg9Fzk6HqaoNcpi2YWmf2zFH9TK8zTyHdSjQ8fpqw+u3zHdOOmL60Eh1Ca+cCzvkRZax uKQA== 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 t186si3826626pfd.68.2018.12.07.10.40.39; Fri, 07 Dec 2018 10:40:40 -0800 (PST) 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 S1726393AbeLGSki (ORCPT + 31 others); Fri, 7 Dec 2018 13:40:38 -0500 Received: from foss.arm.com ([217.140.101.70]:52128 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbeLGSkg (ORCPT ); Fri, 7 Dec 2018 13:40:36 -0500 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 22BD8EBD; Fri, 7 Dec 2018 10:40:36 -0800 (PST) Received: from moonbear.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0989E3F5AF; Fri, 7 Dec 2018 10:40:32 -0800 (PST) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org Cc: Adam Wallis , Amit Kachhap , Andrew Jones , Ard Biesheuvel , Catalin Marinas , Christoffer Dall , Cyrill Gorcunov , Dave P Martin , Jacob Bramley , Kees Cook , Marc Zyngier , Mark Rutland , Ramana Radhakrishnan , Richard Henderson , Suzuki K Poulose , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: [PATCH v6 09/13] arm64: perf: strip PAC when unwinding userspace Date: Fri, 7 Dec 2018 18:39:27 +0000 Message-Id: <20181207183931.4285-10-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181207183931.4285-1-kristina.martsenko@arm.com> References: <20181207183931.4285-1-kristina.martsenko@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland 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 Signed-off-by: Kristina Martsenko Cc: Catalin Marinas Cc: Ramana Radhakrishnan Cc: Will Deacon --- arch/arm64/include/asm/pointer_auth.h | 7 +++++++ arch/arm64/kernel/perf_callchain.c | 6 +++++- 2 files changed, 12 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 5721228836c1..89190d93c850 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_switch(struct ptrauth_keys *keys) */ #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 ptrauth_thread_init_user(tsk) \ do { \ struct task_struct *__ptiu_tsk = (tsk); \ @@ -76,6 +82,7 @@ do { \ ptrauth_keys_switch(&(tsk)->thread_info.keys_user) #else /* CONFIG_ARM64_PTR_AUTH */ +#define ptrauth_strip_insn_pac(lr) (lr) #define ptrauth_thread_init_user(tsk) #define ptrauth_thread_switch(tsk) #endif /* CONFIG_ARM64_PTR_AUTH */ diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index bcafd7dcfe8b..94754f07f67a 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -18,6 +18,7 @@ #include #include +#include #include struct frame_tail { @@ -35,6 +36,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 +49,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