Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp652498ybb; Wed, 8 Apr 2020 07:23:50 -0700 (PDT) X-Google-Smtp-Source: APiQypL6AiqFhnsaObSi+T2AOgN0yOMWJgwpvpgbLnleUUyu1yij3nkFkxd+iUTiBQZiF+qRVYdW X-Received: by 2002:a9d:62c2:: with SMTP id z2mr6171330otk.155.1586355830380; Wed, 08 Apr 2020 07:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586355830; cv=none; d=google.com; s=arc-20160816; b=FYzZjrS7B5mGsC0xyQEJ1i6J/0miko6AvBxn5eh2r21FvMPLGsUqJnfX/TO0iWi+Gj 9ViyoNumyqJpVeRrg7Hg9862Txz6PJ9n5uiYHgdM/Sr67p2XtHRyRnVQVhsPTFtoFCeA sqbQVPJOgX7di4BG+djhQ7K09rmc8wdhvTy5O2VMzGLR6FYZQz1tGGKZsL0LD5MeK+KN ICo7wuB2XrIrXvpdQLUNhs2XYAG5QaR28QW3NITi/d/T/qidq9uFCyXbBaC89L+aIvJk wdlNWASvHPoEsNAV4gCyDJBsxpNQYWN5OJSIBYFyaXW99kzKEks+3aH1/yN79AXdDtzb SdUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HbNJLFEovQgNg1W3RsOYzf6vHZjFTFwpQkL4wCusd+U=; b=ggTthSZ8DVe7jKSko7T2Bc9ejd3eYtx2laPvwRH67AP0NyzuZ/krnPV11XukhLYSDA gdYdygQc+1vxAz1wT7/Ht8UKPCHqltuzqr/KGj0Pa1UsSKtjI9ERHYhkzuqe3I73z02F RL+m4JAffoNNI/kxMixQFF6tJSW8gZcI/n/x0o1XoSqmEw9j0Z7DVHPqFrSm3pIAZ6P+ /Bn/H5mXUXkghw7wBi43ELUTcwxjdtoLwxembunDVzfIyY/bs5kgm9pDBE3VqB9S3/Kc BggCkU+twpsQamB29Rls8UgWXqedJJlOCjhDTqy2hwNJr4XIM0oC8XEpYhg+jVcDAo03 d2Sg== 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 j18si2583740otk.166.2020.04.08.07.23.36; Wed, 08 Apr 2020 07:23:50 -0700 (PDT) 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 S1728804AbgDHMim (ORCPT + 99 others); Wed, 8 Apr 2020 08:38:42 -0400 Received: from foss.arm.com ([217.140.110.172]:38334 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726977AbgDHMim (ORCPT ); Wed, 8 Apr 2020 08:38:42 -0400 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 87C1331B; Wed, 8 Apr 2020 05:38:41 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0ADA83F73D; Wed, 8 Apr 2020 05:38:37 -0700 (PDT) Date: Wed, 8 Apr 2020 13:38:36 +0100 From: Mark Rutland To: Christoph Hellwig Cc: Andrew Morton , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , x86@kernel.org, David Airlie , Daniel Vetter , Laura Abbott , Sumit Semwal , Sakari Ailus , Minchan Kim , Nitin Gupta , Robin Murphy , Christophe Leroy , Peter Zijlstra , linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Catalin marinas Subject: Re: [PATCH 18/28] mm: enforce that vmap can't map pages executable Message-ID: <20200408123835.GB36478@lakrids.cambridge.arm.com> References: <20200408115926.1467567-1-hch@lst.de> <20200408115926.1467567-19-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200408115926.1467567-19-hch@lst.de> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 08, 2020 at 01:59:16PM +0200, Christoph Hellwig wrote: > To help enforcing the W^X protection don't allow remapping existing > pages as executable. > > Based on patch from Peter Zijlstra . > > Signed-off-by: Christoph Hellwig > --- > arch/x86/include/asm/pgtable_types.h | 6 ++++++ > include/asm-generic/pgtable.h | 4 ++++ > mm/vmalloc.c | 2 +- > 3 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h > index 947867f112ea..2e7c442cc618 100644 > --- a/arch/x86/include/asm/pgtable_types.h > +++ b/arch/x86/include/asm/pgtable_types.h > @@ -282,6 +282,12 @@ typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; > > typedef struct { pgdval_t pgd; } pgd_t; > > +static inline pgprot_t pgprot_nx(pgprot_t prot) > +{ > + return __pgprot(pgprot_val(prot) | _PAGE_NX); > +} > +#define pgprot_nx pgprot_nx > + > #ifdef CONFIG_X86_PAE I reckon for arm64 we can do similar in our : #define pgprot_nx(pgprot_t prot) \ __pgprot_modify(prot, 0, PTE_PXN) ... matching the style of our existing pgprot_*() modifier helpers. Mark. > > /* > diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h > index 329b8c8ca703..8c5f9c29698b 100644 > --- a/include/asm-generic/pgtable.h > +++ b/include/asm-generic/pgtable.h > @@ -491,6 +491,10 @@ static inline int arch_unmap_one(struct mm_struct *mm, > #define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address) > #endif > > +#ifndef pgprot_nx > +#define pgprot_nx(prot) (prot) > +#endif > + > #ifndef pgprot_noncached > #define pgprot_noncached(prot) (prot) > #endif > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 7356b3f07bd8..334c75251ddb 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2390,7 +2390,7 @@ void *vmap(struct page **pages, unsigned int count, > if (!area) > return NULL; > > - if (map_kernel_range((unsigned long)area->addr, size, prot, > + if (map_kernel_range((unsigned long)area->addr, size, pgprot_nx(prot), > pages) < 0) { > vunmap(area->addr); > return NULL; > -- > 2.25.1 >