From patchwork Fri Oct 5 08:47:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 148165 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp180328lji; Fri, 5 Oct 2018 01:50:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV63FJ+0Nq0Qb/G8Fanm2VJM3rnBQ8tc0mo/Jb+XI674qHpYaI9QIKlEq8fnyCBraVWis9yFx X-Received: by 2002:a62:85cb:: with SMTP id m72-v6mr10761359pfk.173.1538729423157; Fri, 05 Oct 2018 01:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538729423; cv=none; d=google.com; s=arc-20160816; b=rdUPuXfEa1H4cp9bAWKqMUFfaFrIhu0YRExGfTilzTCtLb3icO6Zc0Gb7XZOLI2/oa LdL2vNGMiXDnpGCi6zarxXHKjWIYWOlpLoFhNDzdOAw07Me+z7gTitx7tBOLkOY61H0d t4yoTtYq18kh8qcxJnNuUO0rVD4SYC85LeARkxcQv+9b1HooObQ7LTYLhF5hM7+uXJCp 0y1CZYn4vTWomTWnbZ8SgO3pZSZ9pl78xESejzI2Qke++EnsvzUKn2e0yQd2nX5bsMcx 0cQNdFey9/iwr6lO6NCqjXJ7gnE3khSTCQF49KkuZ2g5jGduqe3kQ175ETfXp+asVHBI OLjg== 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=2bWVTRCfEWijMRQjUg5R6tLPVRRhfmCkYP+tuaBrysw=; b=haRsBkm5SIyf7kjlJIKPsl43EUpHyOsnYLMC5mJ1aS8TWVEMs4kRUdxLt87BgTRtFI 8VqkFpuvZdqN//kcADL3liShKiXWLxQh1kD0jJHYws2G7+rSi4J+p7LJ4jXUPe2mS7l8 nKzb4x0xpQ5de6i4MV24l9DKTDwSP3nnhSjr6gVFk0JMIvpeUfVY07Hr9qxaIORBi+SM ozPlda7+5HgJFTP2hlOg28UKwmUMLSaHFS/maXlQX5LNglrkXWhaiT85ncIHAdOZl8WU KWb+G938sqpv+miaLQbPhJCkCKEhjGANy/kmxSAZgwTDGaDAiVNzDeDsImtUGqEXk4r8 3yNg== 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 s12-v6si6336911pgr.98.2018.10.05.01.50.22; Fri, 05 Oct 2018 01:50:23 -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 S1728866AbeJEPsF (ORCPT + 32 others); Fri, 5 Oct 2018 11:48:05 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47920 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbeJEPsE (ORCPT ); Fri, 5 Oct 2018 11:48:04 -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 8F6F2ED1; Fri, 5 Oct 2018 01:50:20 -0700 (PDT) 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 5A9CB3F5B3; Fri, 5 Oct 2018 01:50:17 -0700 (PDT) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org Cc: Adam Wallis , Amit Kachhap , Andrew Jones , Ard Biesheuvel , Arnd Bergmann , Catalin Marinas , Christoffer Dall , Dave P Martin , Jacob Bramley , Kees Cook , Marc Zyngier , Mark Rutland , Ramana Radhakrishnan , "Suzuki K . Poulose" , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 09/17] arm64: perf: strip PAC when unwinding userspace Date: Fri, 5 Oct 2018 09:47:46 +0100 Message-Id: <20181005084754.20950-10-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181005084754.20950-1-kristina.martsenko@arm.com> References: <20181005084754.20950-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 [kristina: add pointer_auth.h #include] 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 15486079e9ec..f5a4b075be65 100644 --- a/arch/arm64/include/asm/pointer_auth.h +++ b/arch/arm64/include/asm/pointer_auth.h @@ -57,6 +57,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 mm_ctx_ptrauth_init(ctx) \ ptrauth_keys_init(&(ctx)->ptrauth_keys) @@ -64,6 +70,7 @@ static inline void ptrauth_keys_switch(struct ptrauth_keys *keys) ptrauth_keys_switch(&(ctx)->ptrauth_keys) #else /* CONFIG_ARM64_PTR_AUTH */ +#define ptrauth_strip_insn_pac(lr) (lr) #define mm_ctx_ptrauth_init(ctx) #define mm_ctx_ptrauth_switch(ctx) #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