From patchwork Fri Sep 8 17:24:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 9944725 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 DCA5660224 for ; Fri, 8 Sep 2017 17:24:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C31F728876 for ; Fri, 8 Sep 2017 17:24:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7C5A28878; Fri, 8 Sep 2017 17:24:41 +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 A1BD128876 for ; Fri, 8 Sep 2017 17:24:39 +0000 (UTC) Received: (qmail 3189 invoked by uid 550); 8 Sep 2017 17:24:38 -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 3155 invoked from network); 8 Sep 2017 17:24:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=docker.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=FmA5o+Y3GyPUWNeTJAGYLu7VXAIxEqdt4cGgdGq4h5Q=; b=ITwcSH01RtZdkSGHZvcekJjA48D06CVATov5NU2dRyV9qY3lGIOAdk6oILBt8IlX9U JV74a4maBK7SA1oB1ZiD58TrKMpRepYFyg8rr7AH6yjM6e6t/52BUU4pXuzsR+nHF5J/ 0g4s1HSLLvebA3H1x/md8yxgrrHFKP0hqer4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=FmA5o+Y3GyPUWNeTJAGYLu7VXAIxEqdt4cGgdGq4h5Q=; b=jMKGCnMrS7j6N9S8+KFNHYc7WohudO20WmkK6IL2TakFLa8DgkOnrtmoK0L4fQUbUa uUG+M8IC+FP1hPvuEqr/AS9Bnx5pHN2dQzXP/c7t2FTQWvwVNwNUmBVoM+aVzzPyMwZh RsiLuHIkk2tLhgZVcpQ6ErxhOaL91HDAb4b86JQfCJ4AWETzMU2Bi5K53F3s1/D0aeL3 0J7EIyYpuNvdsfSYSY29IH4WjymOFEAefaXukBsLcFqY89HC1c2rWJWF7f0dwaL67nDt nqfyPbqFpBP5FxzT2vYFdtU6f8Gon1FeJ6tmwawFNF3RstvWpHONBIE4Cgn61o3Qwj4/ e5aQ== X-Gm-Message-State: AHPjjUjtLgYV81DT28i0rojmTmJMJnzwpUobQV3bGWUu7YIbnDLYjU6e 0QgM1AmiD8S3Knc9 X-Google-Smtp-Source: AOwi7QDMVbMCYbIhjksLz2fD4Cq9+pDxFjVMvjFFfk7GZrNbFmccpP2rjRgpanxXl9RgybfYxURYjg== X-Received: by 10.107.11.89 with SMTP id v86mr4716290ioi.293.1504891465104; Fri, 08 Sep 2017 10:24:25 -0700 (PDT) Date: Fri, 8 Sep 2017 11:24:22 -0600 From: Tycho Andersen To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com, Marco Benatto , Juerg Haefliger , linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org Message-ID: <20170908172422.rxmhwd2vl6eye2or@docker> References: <20170907173609.22696-1-tycho@docker.com> <20170907173609.22696-6-tycho@docker.com> <20170908075347.GC4957@infradead.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170908075347.GC4957@infradead.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: [kernel-hardening] Re: [PATCH v6 05/11] arm64/mm: Add support for XPFO X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Sep 08, 2017 at 12:53:47AM -0700, Christoph Hellwig wrote: > > +/* > > + * 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) > > Seems like this should be moved to common arm64 mm code and used by > kernel_page_present. Sounds good, I'll include something like the patch below in the next series. Unfortunately, adding an implementation of lookup_address seems to be slightly more complicated than necessary, because of the xen piece. We have to define lookup_address() with the level parameter, but it's not obvious to me to name the page levels. So for now I've just left it as a WARN() if someone supplies it. It seems like xen still does need this to be defined, because if I define it without level: drivers/xen/xenbus/xenbus_client.c: In function ‘xenbus_unmap_ring_vfree_pv’: drivers/xen/xenbus/xenbus_client.c:760:4: error: too many arguments to function ‘lookup_address’ lookup_address(addr, &level)).maddr; ^~~~~~~~~~~~~~ In file included from ./arch/arm64/include/asm/page.h:37:0, from ./include/linux/mmzone.h:20, from ./include/linux/gfp.h:5, from ./include/linux/mm.h:9, from drivers/xen/xenbus/xenbus_client.c:33: ./arch/arm64/include/asm/pgtable-types.h:67:15: note: declared here extern pte_t *lookup_address(unsigned long addr); ^~~~~~~~~~~~~~ I've cc-d the xen folks, maybe they can suggest a way to untangle it? Alternatively, if someone can suggest a good naming scheme for the page levels, I can just do that. Cheers, Tycho From 0b3be95873e3e8caa39fa50efc0d06d57fc6eb5e Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Fri, 8 Sep 2017 10:43:26 -0600 Subject: [PATCH] arm64: add lookup_address() Similarly to x86, let's add lookup_address() and use it in kernel_page_present(). We'll use it in the next patch for the implementation of XPFO as well. Signed-off-by: Tycho Andersen --- arch/arm64/include/asm/pgtable-types.h | 2 ++ arch/arm64/mm/pageattr.c | 47 ++++++++++++++++++++-------------- include/xen/arm/page.h | 10 -------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-types.h b/arch/arm64/include/asm/pgtable-types.h index 345a072b5856..fad3db5a673f 100644 --- a/arch/arm64/include/asm/pgtable-types.h +++ b/arch/arm64/include/asm/pgtable-types.h @@ -64,4 +64,6 @@ typedef struct { pteval_t pgprot; } pgprot_t; #include #endif +extern pte_t *lookup_address(unsigned long addr, unsigned int *level); + #endif /* __ASM_PGTABLE_TYPES_H */ diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index a682a0a2a0fa..437a12485873 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -138,6 +138,32 @@ int set_memory_valid(unsigned long addr, int numpages, int enable) __pgprot(PTE_VALID)); } +pte_t *lookup_address(unsigned long addr, unsigned int *level) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + if (unlikely(level)) { + WARN(1, "level unused on arm64\n"); + *level = 0; + } + + 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); +} + #ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) { @@ -156,29 +182,12 @@ void __kernel_map_pages(struct page *page, int numpages, int enable) */ bool kernel_page_present(struct page *page) { - pgd_t *pgd; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; unsigned long addr = (unsigned long)page_address(page); + pte_t *pte = lookup_address(addr); - pgd = pgd_offset_k(addr); - if (pgd_none(*pgd)) - return false; - - pud = pud_offset(pgd, addr); - if (pud_none(*pud)) - return false; - if (pud_sect(*pud)) - return true; - - pmd = pmd_offset(pud, addr); - if (pmd_none(*pmd)) + if (!pte) return false; - if (pmd_sect(*pmd)) - return true; - pte = pte_offset_kernel(pmd, addr); return pte_valid(*pte); } #endif /* CONFIG_HIBERNATION */ diff --git a/include/xen/arm/page.h b/include/xen/arm/page.h index 415dbc6e43fd..6adc2a955340 100644 --- a/include/xen/arm/page.h +++ b/include/xen/arm/page.h @@ -84,16 +84,6 @@ static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr) BUG(); } -/* TODO: this shouldn't be here but it is because the frontend drivers - * are using it (its rolled in headers) even though we won't hit the code path. - * So for right now just punt with this. - */ -static inline pte_t *lookup_address(unsigned long address, unsigned int *level) -{ - BUG(); - return NULL; -} - extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops, struct gnttab_map_grant_ref *kmap_ops, struct page **pages, unsigned int count);