From patchwork Fri Oct 5 08:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 10627689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9254C15E2 for ; Fri, 5 Oct 2018 09:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77A6C28EA2 for ; Fri, 5 Oct 2018 09:08:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B07228EB0; Fri, 5 Oct 2018 09:08:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB29628EA2 for ; Fri, 5 Oct 2018 09:08:57 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FvJoDkMoN1lVX2imLNFgn1uXgEjgYKkQRb7GrLvU5hk=; b=qxj8dBxPKqjtXHW6EJVVXS0Xc3 CSb/lj+RBOA4Qm9h6O7Nka9VUdSkIcR3PfchlByyjRTRiP20oKyzeKKLeKZmUoFm9cGSYrwq6Qone rxGRoYhUvpuG4DUhV7WzL/nlg0lMpHkQGyNXaudN2u/9sE1UB/FeRSlmVQzmRGXS7q26es+lMMdxw J5C+hhbJSjTPSaR0D2Urn60Q91RRHUPuja0LINnquXpZmfvmgJdzVozFrjGi8QrxFymoIIY9xgQcD bob2mrELnzKMst5SQuYu2g4DUR5YbmTvctPSmWNKC4XxFB54QxJBWQ7ERzEzJjWALta2lE9HjLW+U 8LcHwlLA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g8M6P-0002mf-8H; Fri, 05 Oct 2018 09:08:53 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g8Lok-0000en-0I for linux-arm-kernel@lists.infradead.org; Fri, 05 Oct 2018 08:52:32 +0000 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 6F80D15BF; Fri, 5 Oct 2018 01:50:37 -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 396F53F5B3; Fri, 5 Oct 2018 01:50:34 -0700 (PDT) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org Subject: [RFC 12/17] arm64: move ptrauth keys to thread_info Date: Fri, 5 Oct 2018 09:47:49 +0100 Message-Id: <20181005084754.20950-13-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181005_015038_172962_589776F4 X-CRM114-Status: GOOD ( 15.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-arch@vger.kernel.org, Andrew Jones , Jacob Bramley , Arnd Bergmann , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Adam Wallis , "Suzuki K . Poulose" , Will Deacon , Christoffer Dall , kvmarm@lists.cs.columbia.edu, Ramana Radhakrishnan , Amit Kachhap , Dave P Martin , linux-kernel@vger.kernel.org, Kees Cook MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mark Rutland To use pointer authentication in the kernel, we'll need to switch keys in the entry assembly. This patch moves the pointer auth keys into thread_info to make this possible. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Signed-off-by: Kristina Martsenko --- arch/arm64/include/asm/mmu.h | 5 ----- arch/arm64/include/asm/mmu_context.h | 13 ------------- arch/arm64/include/asm/pointer_auth.h | 13 +++++++------ arch/arm64/include/asm/thread_info.h | 4 ++++ arch/arm64/kernel/process.c | 4 ++++ 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index f6480ea7b0d5..dd320df0d026 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -25,15 +25,10 @@ #ifndef __ASSEMBLY__ -#include - typedef struct { atomic64_t id; void *vdso; unsigned long flags; -#ifdef CONFIG_ARM64_PTR_AUTH - struct ptrauth_keys ptrauth_keys; -#endif } mm_context_t; /* diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 983f80925566..387e810063c7 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -215,8 +215,6 @@ static inline void __switch_mm(struct mm_struct *next) return; } - mm_ctx_ptrauth_switch(&next->context); - check_and_switch_context(next, cpu); } @@ -242,17 +240,6 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next, void verify_cpu_asid_bits(void); void post_ttbr_update_workaround(void); -static inline void arch_bprm_mm_init(struct mm_struct *mm, - struct vm_area_struct *vma) -{ - mm_ctx_ptrauth_init(&mm->context); -} -#define arch_bprm_mm_init arch_bprm_mm_init - -/* - * We need to override arch_bprm_mm_init before including the generic hooks, - * which are otherwise sufficient for us. - */ #include #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h index f5a4b075be65..cedb03bd175b 100644 --- a/arch/arm64/include/asm/pointer_auth.h +++ b/arch/arm64/include/asm/pointer_auth.h @@ -63,16 +63,17 @@ 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) +#define ptrauth_task_init_user(tsk) \ + ptrauth_keys_init(&(tsk)->thread_info.keys_user); \ + ptrauth_keys_switch(&(tsk)->thread_info.keys_user) -#define mm_ctx_ptrauth_switch(ctx) \ - ptrauth_keys_switch(&(ctx)->ptrauth_keys) +#define ptrauth_task_switch(tsk) \ + ptrauth_keys_switch(&(tsk)->thread_info.keys_user) #else /* CONFIG_ARM64_PTR_AUTH */ #define ptrauth_strip_insn_pac(lr) (lr) -#define mm_ctx_ptrauth_init(ctx) -#define mm_ctx_ptrauth_switch(ctx) +#define ptrauth_task_init_user(tsk) +#define ptrauth_task_switch(tsk) #endif /* CONFIG_ARM64_PTR_AUTH */ #endif /* __ASM_POINTER_AUTH_H */ diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index cb2c10a8f0a8..ea9272fb52d4 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -28,6 +28,7 @@ struct task_struct; #include +#include #include #include @@ -43,6 +44,9 @@ struct thread_info { u64 ttbr0; /* saved TTBR0_EL1 */ #endif int preempt_count; /* 0 => preemptable, <0 => bug */ +#ifdef CONFIG_ARM64_PTR_AUTH + struct ptrauth_keys keys_user; +#endif }; #define thread_saved_pc(tsk) \ diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 7f1628effe6d..fae52be66c92 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #ifdef CONFIG_STACKPROTECTOR @@ -425,6 +426,7 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev, contextidr_thread_switch(next); entry_task_switch(next); uao_thread_switch(next); + ptrauth_task_switch(next); /* * Complete any pending TLB or cache maintenance on this CPU in case @@ -492,6 +494,8 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) void arch_setup_new_exec(void) { current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0; + + ptrauth_task_init_user(current); } #ifdef CONFIG_GCC_PLUGIN_STACKLEAK