Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp535739ybb; Wed, 8 Apr 2020 05:05:16 -0700 (PDT) X-Google-Smtp-Source: APiQypKfqD/vQ5LXsd8Qm6dEXgH8AXgaPp2lLqocXcXAxo8/dPKeVq4XpNgUD4Cjhkj8zJ7BxJL0 X-Received: by 2002:a9d:6a49:: with SMTP id h9mr4765150otn.189.1586347516480; Wed, 08 Apr 2020 05:05:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586347516; cv=none; d=google.com; s=arc-20160816; b=Sjon2KHW7O3LjThn0SJzNZuaBlpxaPMlRP+6CHcQjGi9l7Y3ofIPtgr8Cak9sMmUeY pIKk5KTqfOnT19mGaph+LuN7BcH43oNuIR3oxbekWLql0Lv4wybgd0fs6GQXvE9hNADh VbpPjo9a5+wZ0bL0rOVIV7w0vRxdCtQPe21LtJ+znkzYdQ67OfMqHzff985AjiNHgUo0 H+P3M4PRifO6uSQwCznz4Q8Ri5kUJArJsVwRn4ow3/IZCtaNH6m329K0aBz7iUYgKQby DcjPAklTlD4YU1tmwe/JnpoOUXYa1W2iiYMpkyBa6DbgvpdkGSrr7aMtjkkZrKEVtdcb 5Xtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qIkaOi9YpNnkEAVP6F2gar58gdp83MyXCs59K6nspBs=; b=FjjWauEo1297ChS0GmHAYMdjDIxK7rJF0O8krc3vW73JehD2DIZLX2slmwE5AsjZgg p6Q5D+IAKtQRZyXzkYkC2xCe31g91fm5LDH06y55IfjE7RZRfbKAhN8TKf6KHZPPm05U j/mPS9gAsWNsCsywxJJxRv4K1NeVqfNaThJN3BdYgh4iXuXwvRHBhesG9xkJAA6nw0kC MTUvQ3qfdhNZZKNIAP5sK7XUgy9EwzS0Z6/mPoWzN2BJv+1Tm/1DV/JOWta6QWpVC9Y/ PtjG3sxZHfNCgviIrvd3dfRTs5EhJblHKIRju35cxvpS0Mo59Aa9DJJ17+PeHWVxHNp1 X2uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KdDp3pBk; 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 g188si1940777oia.203.2020.04.08.05.04.50; Wed, 08 Apr 2020 05:05:16 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KdDp3pBk; 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 S1728999AbgDHMA4 (ORCPT + 99 others); Wed, 8 Apr 2020 08:00:56 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50138 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728979AbgDHMAx (ORCPT ); Wed, 8 Apr 2020 08:00:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qIkaOi9YpNnkEAVP6F2gar58gdp83MyXCs59K6nspBs=; b=KdDp3pBk4+DSwEG0+rXYK/ZlQk LW9cZZ1XU34vImXDe/8Cz4wkoVpF8TYZ0HVS74ywZQ2h2dJVTYSL4rQkyQmbg1TRRLKr4mq4A4b5Y Ca7e2MuhU2roGLWZ5rjZUm9jpGU1AV+pXuEhAMY7UbeRgS1nu1kboGBYygdZa3YULVawoLo693bjw nizcX9QkNm7Vl7Zd5pHm8bc9trFYXna3UVEEwT+bm4X+16sFF6EHwyWfkv+OSCmhQ4CzXIR/P5jVH 4+iJydI2V1HgfnDtZNEvEAF3s0CZeVic/ZXV+e8nWILvQb9DP5be3J7rtLFbfl1Uut/MXVFDDf7uj KsvVoaUA==; Received: from [2001:4bb8:180:5765:65b6:f11e:f109:b151] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jM9Nj-0005ML-NB; Wed, 08 Apr 2020 12:00:37 +0000 From: Christoph Hellwig To: 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 Cc: 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 Subject: [PATCH 18/28] mm: enforce that vmap can't map pages executable Date: Wed, 8 Apr 2020 13:59:16 +0200 Message-Id: <20200408115926.1467567-19-hch@lst.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200408115926.1467567-1-hch@lst.de> References: <20200408115926.1467567-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 /* 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