Skip to content

Commit cca98e9

Browse files
Christoph Hellwigtorvalds
authored andcommitted
mm: enforce that vmap can't map pages executable
To help enforcing the W^X protection don't allow remapping existing pages as executable. x86 bits from Peter Zijlstra, arm64 bits from Mark Rutland. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: Mark Rutland <[email protected]>. Cc: Christian Borntraeger <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: David Airlie <[email protected]> Cc: Gao Xiang <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Haiyang Zhang <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: "K. Y. Srinivasan" <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Michael Kelley <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Sakari Ailus <[email protected]> Cc: Stephen Hemminger <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Wei Liu <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent d4efd79 commit cca98e9

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd)
407407
#define __pgprot_modify(prot,mask,bits) \
408408
__pgprot((pgprot_val(prot) & ~(mask)) | (bits))
409409

410+
#define pgprot_nx(prot) \
411+
__pgprot_modify(prot, 0, PTE_PXN)
412+
410413
/*
411414
* Mark the prot value as uncacheable and unbufferable.
412415
*/

arch/x86/include/asm/pgtable_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
282282

283283
typedef struct { pgdval_t pgd; } pgd_t;
284284

285+
static inline pgprot_t pgprot_nx(pgprot_t prot)
286+
{
287+
return __pgprot(pgprot_val(prot) | _PAGE_NX);
288+
}
289+
#define pgprot_nx pgprot_nx
290+
285291
#ifdef CONFIG_X86_PAE
286292

287293
/*

include/asm-generic/pgtable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ static inline int arch_unmap_one(struct mm_struct *mm,
491491
#define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address)
492492
#endif
493493

494+
#ifndef pgprot_nx
495+
#define pgprot_nx(prot) (prot)
496+
#endif
497+
494498
#ifndef pgprot_noncached
495499
#define pgprot_noncached(prot) (prot)
496500
#endif

mm/vmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,7 @@ void *vmap(struct page **pages, unsigned int count,
23912391
if (!area)
23922392
return NULL;
23932393

2394-
if (map_kernel_range((unsigned long)area->addr, size, prot,
2394+
if (map_kernel_range((unsigned long)area->addr, size, pgprot_nx(prot),
23952395
pages) < 0) {
23962396
vunmap(area->addr);
23972397
return NULL;

0 commit comments

Comments
 (0)