From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F81C10F27 for ; Tue, 10 Mar 2020 15:08:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A86E20727 for ; Tue, 10 Mar 2020 15:08:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Dd9H/BsE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A86E20727 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i0UBgzkxUHZfOOG8hIIB1jV8iDjlZb9Fvj3oXwPgj7s=; b=Dd9H/BsEjjarM2 9/aGkvZwOSYP3Mu1uvCuNTigJtsNnFU2PyB3cPws7CJEWWk0MOJ8N8Gq5k9cVOHV9pIUxWgCOjwwF uGoOY9IfLPa3ARz2nVmSUrWoN5u99MPlOE3ugecIQ7WblnsE7bHXNixdxxw4UeNV4bv1LKLza5GPy IEfydyM4Elx5WOYz2iCsupbiVSSyxFyX07vfXRha7yunOlwX942ahL9Rq7q/juOyXl8GHgBEx0RPL 5xoQ4KdQEJthoArHNZIvoeHhVPMxp5H7oqs2mfp5EtSVxLkQooeENNAMkvkFy8J8KwOjD2TSafhKC Zu1oyC+lAIwFL71YZVug==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBgUv-0004DW-Q8; Tue, 10 Mar 2020 15:08:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jBgUs-0004D5-Mm for linux-arm-kernel@lists.infradead.org; Tue, 10 Mar 2020 15:08:44 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2EED81FB; Tue, 10 Mar 2020 08:08:42 -0700 (PDT) Received: from [10.37.12.115] (unknown [10.37.12.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EBCA33F6CF; Tue, 10 Mar 2020 08:08:39 -0700 (PDT) Subject: Re: [PATCH v6 11/18] arm64: initialize ptrauth keys for kernel booting task To: Amit Daniel Kachhap , linux-arm-kernel@lists.infradead.org References: <1583476525-13505-1-git-send-email-amit.kachhap@arm.com> <1583476525-13505-12-git-send-email-amit.kachhap@arm.com> From: Vincenzo Frascino Message-ID: <0480bdeb-d4b4-c8f9-0a1b-3cf07caeb050@arm.com> Date: Tue, 10 Mar 2020 15:09:04 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <1583476525-13505-12-git-send-email-amit.kachhap@arm.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200310_080842_829127_8A42E557 X-CRM114-Status: GOOD ( 19.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kees Cook , Suzuki K Poulose , Catalin Marinas , Kristina Martsenko , Dave Martin , Mark Brown , James Morse , Ramana Radhakrishnan , Will Deacon , Ard Biesheuvel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 3/6/20 6:35 AM, Amit Daniel Kachhap wrote: > This patch uses the existing boot_init_stack_canary arch function > to initialize the ptrauth keys for the booting task in the primary > core. The requirement here is that it should be always inline and > the caller must never return. > > As pointer authentication too detects a subset of stack corruption > so it makes sense to place this code here. > > Both pointer authentication and stack canary codes are protected > by their respective config option. > Reviewed-by: Vincenzo Frascino > Suggested-by: Ard Biesheuvel > Reviewed-by: Catalin Marinas > Signed-off-by: Amit Daniel Kachhap > --- > arch/arm64/include/asm/pointer_auth.h | 11 ++++++++++- > arch/arm64/include/asm/stackprotector.h | 5 +++++ > include/linux/stackprotector.h | 2 +- > 3 files changed, 16 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h > index aa956ca..833d3f9 100644 > --- a/arch/arm64/include/asm/pointer_auth.h > +++ b/arch/arm64/include/asm/pointer_auth.h > @@ -54,12 +54,18 @@ do { \ > write_sysreg_s(__pki_v.hi, SYS_ ## k ## KEYHI_EL1); \ > } while (0) > > -static inline void ptrauth_keys_init_kernel(struct ptrauth_keys_kernel *keys) > +static __always_inline void ptrauth_keys_init_kernel(struct ptrauth_keys_kernel *keys) > { > if (system_supports_address_auth()) > get_random_bytes(&keys->apia, sizeof(keys->apia)); > } > > +static __always_inline void ptrauth_keys_switch_kernel(struct ptrauth_keys_kernel *keys) > +{ > + if (system_supports_address_auth()) > + __ptrauth_key_install(APIA, keys->apia); > +} > + > extern int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg); > > /* > @@ -78,12 +84,15 @@ static inline unsigned long ptrauth_strip_insn_pac(unsigned long ptr) > ptrauth_keys_init_user(&(tsk)->thread.keys_user) > #define ptrauth_thread_init_kernel(tsk) \ > ptrauth_keys_init_kernel(&(tsk)->thread.keys_kernel) > +#define ptrauth_thread_switch_kernel(tsk) \ > + ptrauth_keys_switch_kernel(&(tsk)->thread.keys_kernel) > > #else /* CONFIG_ARM64_PTR_AUTH */ > #define ptrauth_prctl_reset_keys(tsk, arg) (-EINVAL) > #define ptrauth_strip_insn_pac(lr) (lr) > #define ptrauth_thread_init_user(tsk) > #define ptrauth_thread_init_kernel(tsk) > +#define ptrauth_thread_switch_kernel(tsk) > #endif /* CONFIG_ARM64_PTR_AUTH */ > > #endif /* __ASM_POINTER_AUTH_H */ > diff --git a/arch/arm64/include/asm/stackprotector.h b/arch/arm64/include/asm/stackprotector.h > index 5884a2b..7263e0b 100644 > --- a/arch/arm64/include/asm/stackprotector.h > +++ b/arch/arm64/include/asm/stackprotector.h > @@ -15,6 +15,7 @@ > > #include > #include > +#include > > extern unsigned long __stack_chk_guard; > > @@ -26,6 +27,7 @@ extern unsigned long __stack_chk_guard; > */ > static __always_inline void boot_init_stack_canary(void) > { > +#if defined(CONFIG_STACKPROTECTOR) > unsigned long canary; > > /* Try to get a semi random initial value. */ > @@ -36,6 +38,9 @@ static __always_inline void boot_init_stack_canary(void) > current->stack_canary = canary; > if (!IS_ENABLED(CONFIG_STACKPROTECTOR_PER_TASK)) > __stack_chk_guard = current->stack_canary; > +#endif > + ptrauth_thread_init_kernel(current); > + ptrauth_thread_switch_kernel(current); > } > > #endif /* _ASM_STACKPROTECTOR_H */ > diff --git a/include/linux/stackprotector.h b/include/linux/stackprotector.h > index 6b792d0..4c678c4 100644 > --- a/include/linux/stackprotector.h > +++ b/include/linux/stackprotector.h > @@ -6,7 +6,7 @@ > #include > #include > > -#ifdef CONFIG_STACKPROTECTOR > +#if defined(CONFIG_STACKPROTECTOR) || defined(CONFIG_ARM64_PTR_AUTH) > # include > #else > static inline void boot_init_stack_canary(void) > -- Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel