Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3149815imu; Sun, 27 Jan 2019 22:59:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Sk8o0NmIGagTe1nesbk7e437MoFFu45/NZTad5RMubXlMHWQfvzgeHQJWY1SL8gTQvyB2 X-Received: by 2002:a62:c101:: with SMTP id i1mr20783287pfg.80.1548658784234; Sun, 27 Jan 2019 22:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548658784; cv=none; d=google.com; s=arc-20160816; b=YPnsZgNLC6FfQxJz0Jw63M2CAL7aQfRT24xckSn709WKYquQ9p7EyLPlx2TLUvGJS8 xAz2seQtZn9jexQblWVeW6qeGn/XbVHx37v/Ar9Pg7RXhZEQoYa58DeeFb0F6ltTtolX YfXMHxiQsNuqo3znpHGvUgOiGtHkU+2fCGbSFL1W5OLshE21crwZ6oObUcXR96wbVbzZ IwjfXsyPDlDt0XxFWKNvZh21iyGqpbnqL/HN5Um+RdVhHD+g4Zup/rfl6YaFv56HnsA/ imvYmlcrtTAd6mxaBpWW3TVoXU1Vlt/IBbOAps7cyH20+cl/L+JcqHlaWo8VeqiQasYo iusw== 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=dJO0qV+qVwmL3qcvIXvWvVMtv3/z0FWMpBRlmnIY/aY=; b=aBq/aSU39trD0pE88DPZw/AW1xj+QNGsvdEa1ELY6CuMyvtWRpjwYDbl441hUXnEPF tT4WSQ2MbAvfbyofeDLxaNVPnqbm0nKtrpUv/IfSrJoXP7YrEPn2vk6cA9/U5MSp7EkQ RP9vZHUXrblglek97U2Sam1pPd6LquXP4awX72cSZKL7JzLWbVin+9nX9F1IZDtEjdQf RpFvJEg6GP4r3ERjrEzDVHZTen8SvrI8yNmS6QF7UR5dWb5IE5Bzca0yqpMj2ejYB2X9 0up+hw7f9eDceyYs8Sr9ul9beuPV2wKQLa7Wz94RQhmz9Qx+HCn3ey/ruqkB9yaqQ6Py +ZWQ== 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 p18si31189581plo.223.2019.01.27.22.59.28; Sun, 27 Jan 2019 22:59:44 -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 S1726805AbfA1G7S (ORCPT + 99 others); Mon, 28 Jan 2019 01:59:18 -0500 Received: from foss.arm.com ([217.140.101.70]:39828 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbfA1G7S (ORCPT ); Mon, 28 Jan 2019 01:59:18 -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 CDF731596; Sun, 27 Jan 2019 22:59:17 -0800 (PST) Received: from a075553-lin.blr.arm.com (a075553-lin.blr.arm.com [10.162.0.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 199BF3F5AF; Sun, 27 Jan 2019 22:59:13 -0800 (PST) From: Amit Daniel Kachhap To: linux-arm-kernel@lists.infradead.org Cc: Christoffer Dall , Marc Zyngier , Catalin Marinas , Will Deacon , Andrew Jones , Dave Martin , Ramana Radhakrishnan , kvmarm@lists.cs.columbia.edu, Kristina Martsenko , linux-kernel@vger.kernel.org, Amit Daniel Kachhap , Mark Rutland Subject: [PATCH v5 1/5] arm64: Add utilities to save restore pointer authentication keys Date: Mon, 28 Jan 2019 12:28:42 +0530 Message-Id: <1548658727-14271-2-git-send-email-amit.kachhap@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548658727-14271-1-git-send-email-amit.kachhap@arm.com> References: <1548658727-14271-1-git-send-email-amit.kachhap@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The keys can be switched either inside an assembly or such functions which do not have pointer authentication checks, so a GCC attribute is added to enable it. A function ptrauth_keys_store is added which is similar to existing function ptrauth_keys_switch but saves the key values in memory. This may be useful for save/restore scenarios when CPU changes privilege levels, suspend/resume etc. Signed-off-by: Amit Daniel Kachhap Cc: Mark Rutland Cc: Marc Zyngier Cc: Christoffer Dall Cc: Kristina Martsenko Cc: kvmarm@lists.cs.columbia.edu Cc: Ramana Radhakrishnan Cc: Will Deacon --- arch/arm64/include/asm/pointer_auth.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h index 15d4951..98441ce 100644 --- a/arch/arm64/include/asm/pointer_auth.h +++ b/arch/arm64/include/asm/pointer_auth.h @@ -11,6 +11,13 @@ #ifdef CONFIG_ARM64_PTR_AUTH /* + * Compile the function without pointer authentication instructions. This + * allows pointer authentication to be enabled/disabled within the function + * (but leaves the function unprotected by pointer authentication). + */ +#define __no_ptrauth __attribute__((target("sign-return-address=none"))) + +/* * Each key is a 128-bit quantity which is split across a pair of 64-bit * registers (Lo and Hi). */ @@ -50,6 +57,13 @@ do { \ write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \ } while (0) +#define __ptrauth_key_save(k, v) \ +do { \ + struct ptrauth_key __pki_v = (v); \ + __pki_v.lo = read_sysreg_s(SYS_ ## k ## KEYLO_EL1); \ + __pki_v.hi = read_sysreg_s(SYS_ ## k ## KEYHI_EL1); \ +} while (0) + static inline void ptrauth_keys_switch(struct ptrauth_keys *keys) { if (system_supports_address_auth()) { @@ -63,6 +77,19 @@ static inline void ptrauth_keys_switch(struct ptrauth_keys *keys) __ptrauth_key_install(APGA, keys->apga); } +static inline void ptrauth_keys_store(struct ptrauth_keys *keys) +{ + if (system_supports_address_auth()) { + __ptrauth_key_save(APIA, keys->apia); + __ptrauth_key_save(APIB, keys->apib); + __ptrauth_key_save(APDA, keys->apda); + __ptrauth_key_save(APDB, keys->apdb); + } + + if (system_supports_generic_auth()) + __ptrauth_key_save(APGA, keys->apga); +} + extern int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg); /* @@ -88,6 +115,7 @@ do { \ ptrauth_keys_switch(&(tsk)->thread.keys_user) #else /* CONFIG_ARM64_PTR_AUTH */ +#define __no_ptrauth #define ptrauth_prctl_reset_keys(tsk, arg) (-EINVAL) #define ptrauth_strip_insn_pac(lr) (lr) #define ptrauth_thread_init_user(tsk) -- 2.7.4