From patchwork Thu Sep 7 17:36:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 9942583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F2373600CB for ; Thu, 7 Sep 2017 17:38:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3FC4285B5 for ; Thu, 7 Sep 2017 17:38:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8BCD285C2; Thu, 7 Sep 2017 17:38:14 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id F417B285B5 for ; Thu, 7 Sep 2017 17:38:13 +0000 (UTC) Received: (qmail 20324 invoked by uid 550); 7 Sep 2017 17:37:22 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 20197 invoked from network); 7 Sep 2017 17:37:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=docker.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wTMqlrSD9opSYjmt1poVezmy/+2uVGJTpEnRMa8QSSc=; b=hlqQhJY+vKL7/T1oR17XE2n6o6Garotip5o46m7zSv80j8APYfRJcCW+l21VkjR2HH h+G4ttgF+H4HeKDEN1oPp1ZCn9H+y14Otm+zhgzOYCgkcrK2m0ud+uxT/cknKJgauREl eFXXRIVanwjuG+ADvtHTEI7JL1u8Ms2SUr17M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wTMqlrSD9opSYjmt1poVezmy/+2uVGJTpEnRMa8QSSc=; b=TDfR355lScoSeuDn5C99gLs3mXTkDm+3mEJZeME6aDN0xz9trKle7CxI97sPTwy2ef VqRn/NhIPCV0u8RCGZzibdJ7shNdykTHgp/zZwO56+XeQyV1Ub7Uwmf5Y+0J7rJACmW/ ddG8jNjROEfPPuzPiy9Zo3sECIvMU9tg+KkesNV9h6d0YE0aRdOwcc3STISnv1c9ogzb 2cVeosq0J/TGAZihOchDpLVlEw6zPqaJC8imAV/tAiFh/PHu+CujoR/qLNM6LMSjvJro QT/FVvp7eqCyelbDLXvobvNbjcN4P4HGIMee3sfVtGfJZhYARmAYocEmDaEto8KZa5UP pOkw== X-Gm-Message-State: AHPjjUh5D0XNV0SYIIT6kbK459UA8SLC/7QW0nJhofFF37RS50ejZxKO XHWTdl4/ctwFsqJmP5kl3Q== X-Google-Smtp-Source: ADKCNb6oOzsEIpjCIQUeqawDF9/qLa+VNCPtonqvfNuRiYkok9EDJUS9OawjtWNu3esb6ub7dMKPug== X-Received: by 10.107.13.138 with SMTP id 132mr64842ion.351.1504805828709; Thu, 07 Sep 2017 10:37:08 -0700 (PDT) From: Tycho Andersen To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kernel-hardening@lists.openwall.com, Marco Benatto , Juerg Haefliger , linux-arm-kernel@lists.infradead.org, Tycho Andersen Date: Thu, 7 Sep 2017 11:36:03 -0600 Message-Id: <20170907173609.22696-6-tycho@docker.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170907173609.22696-1-tycho@docker.com> References: <20170907173609.22696-1-tycho@docker.com> Subject: [kernel-hardening] [PATCH v6 05/11] arm64/mm: Add support for XPFO X-Virus-Scanned: ClamAV using ClamSMTP From: Juerg Haefliger Enable support for eXclusive Page Frame Ownership (XPFO) for arm64 and provide a hook for updating a single kernel page table entry (which is required by the generic XPFO code). v6: use flush_tlb_kernel_range() instead of __flush_tlb_one() CC: linux-arm-kernel@lists.infradead.org Signed-off-by: Juerg Haefliger Signed-off-by: Tycho Andersen --- arch/arm64/Kconfig | 1 + arch/arm64/mm/Makefile | 2 ++ arch/arm64/mm/xpfo.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index dfd908630631..44fa44ef02ec 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -121,6 +121,7 @@ config ARM64 select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK + select ARCH_SUPPORTS_XPFO help ARM 64-bit (AArch64) Linux support. diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 9b0ba191e48e..22e5cab543d8 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -11,3 +11,5 @@ KASAN_SANITIZE_physaddr.o += n obj-$(CONFIG_KASAN) += kasan_init.o KASAN_SANITIZE_kasan_init.o := n + +obj-$(CONFIG_XPFO) += xpfo.o diff --git a/arch/arm64/mm/xpfo.c b/arch/arm64/mm/xpfo.c new file mode 100644 index 000000000000..678e2be848eb --- /dev/null +++ b/arch/arm64/mm/xpfo.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 Hewlett Packard Enterprise Development, L.P. + * Copyright (C) 2016 Brown University. All rights reserved. + * + * Authors: + * Juerg Haefliger + * Vasileios P. Kemerlis + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include + +#include + +/* + * Lookup the page table entry for a virtual address and return a pointer to + * the entry. Based on x86 tree. + */ +static pte_t *lookup_address(unsigned long addr) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) + return NULL; + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) + return NULL; + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return NULL; + + return pte_offset_kernel(pmd, addr); +} + +/* Update a single kernel page table entry */ +inline void set_kpte(void *kaddr, struct page *page, pgprot_t prot) +{ + pte_t *pte = lookup_address((unsigned long)kaddr); + + set_pte(pte, pfn_pte(page_to_pfn(page), prot)); +} + +inline void xpfo_flush_kernel_tlb(struct page *page, int order) +{ + unsigned long kaddr = (unsigned long)page_address(page); + unsigned long size = PAGE_SIZE; + + flush_tlb_kernel_range(kaddr, kaddr + (1 << order) * size); +}