Skip to contentSkip to conversation

arm64: wire up VM_FLUSH_RESET_PERMS

PATCH Applied Ard Biesheuvel 6 participants 20 messages May 23, 2019 – Jun 24, 2019

Subsystems (5)
Memory management BPF arm64 vmalloc +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover arm64: wire up VM_FLUSH_RESET_PERMS

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/cacheflush.h |  3 ++
 arch/arm64/kernel/module.c          |  4 +-
 arch/arm64/kernel/probes/kprobes.c  |  4 +-
 arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
 arch/arm64/net/bpf_jit_comp.c       |  2 +-
 mm/vmalloc.c                        | 11 -----
 7 files changed, 50 insertions(+), 23 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 arm64: module: create module allocations without exec permissions

Now that the core code manages the executable permissions of code regions of modules explicitly, it is no longer necessary to create the module vmalloc regions with RWX permissions, and we can create them with RW- permissions instead, which is preferred from a security perspective.

---
 arch/arm64/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/module.c +2 -2
index 2e4e3915b4d0..88f0ed31d9aa 100644
@@ -41,7 +41,7 @@ void *module_alloc(unsigned long size)
 
 	p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
 				module_alloc_base + MODULES_VSIZE,
-				gfp_mask, PAGE_KERNEL_EXEC, 0,
+				gfp_mask, PAGE_KERNEL, 0,
 				NUMA_NO_NODE, __builtin_return_address(0));
 
 	if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
@@ -57,7 +57,7 @@ void *module_alloc(unsigned long size)
 		 */
 		p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
 				module_alloc_base + SZ_4G, GFP_KERNEL,
-				PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+				PAGE_KERNEL, 0, NUMA_NO_NODE,
 				__builtin_return_address(0));
 
 	if (p && (kasan_module_alloc(p, size) < 0)) {
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/4] arm64: module: create module allocations without exec permissions

Quoted 2 lines · Ard Biesheuvel

Now that the core code manages the executable permissions of code regions of modules explicitly, it is no longer necessary to create

I guess the permission transition for various module sections happen through module_enable_[ro|nx]() after allocating via module_alloc().

Quoted 3 lines

the module vmalloc regions with RWX permissions, and we can create them with RW- permissions instead, which is preferred from a security perspective.

Makes sense. Will this be followed in all architectures now ?

Quoted 21 lines
---
 arch/arm64/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/module.c +1 -1
index 2e4e3915b4d0..88f0ed31d9aa 100644
@@ -41,7 +41,7 @@ void *module_alloc(unsigned long size)
 
 	p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
 				module_alloc_base + MODULES_VSIZE,
-				gfp_mask, PAGE_KERNEL_EXEC, 0,
+				gfp_mask, PAGE_KERNEL, 0,
 				NUMA_NO_NODE, __builtin_return_address(0));
 
 	if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&

arch/arm64/kernel/module.c void *module_alloc(unsigned long size) · line 63

Quoted 8 lines
arch/arm64/kernel/module.c +1 -1
@@ -57,7 +57,7 @@ void *module_alloc(unsigned long size)
 		 */
 		p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
 				module_alloc_base + SZ_4G, GFP_KERNEL,
-				PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+				PAGE_KERNEL, 0, NUMA_NO_NODE,
 				__builtin_return_address(0));
 
 	if (p && (kasan_module_alloc(p, size) < 0)) {

Which just makes sure that PTE_PXN never gets dropped while creating these mappings.

#3 lore raw

Re: [PATCH 1/4] arm64: module: create module allocations without exec permissions

Quoted 9 lines · Anshuman Khandual
Quoted 2 lines · Ard Biesheuvel

Now that the core code manages the executable permissions of code regions of modules explicitly, it is no longer necessary to create

I guess the permission transition for various module sections happen through module_enable_[ro|nx]() after allocating via module_alloc().

Indeed.

Quoted 6 lines
Quoted 3 lines

the module vmalloc regions with RWX permissions, and we can create them with RW- permissions instead, which is preferred from a security perspective.

Makes sense. Will this be followed in all architectures now ?

I am not sure if every architecture implements module_enable_[ro|nx](), but if they do, they should probably apply this change as well.

Quoted 27 lines
Quoted 27 lines
---
  arch/arm64/kernel/module.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/module.c +2 -2
index 2e4e3915b4d0..88f0ed31d9aa 100644
@@ -41,7 +41,7 @@ void *module_alloc(unsigned long size)
 
  	p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
  				module_alloc_base + MODULES_VSIZE,
-				gfp_mask, PAGE_KERNEL_EXEC, 0,
+				gfp_mask, PAGE_KERNEL, 0,
  				NUMA_NO_NODE, __builtin_return_address(0));
 
  	if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
@@ -57,7 +57,7 @@ void *module_alloc(unsigned long size)
  		 */
  		p = __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base,
  				module_alloc_base + SZ_4G, GFP_KERNEL,
-				PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+				PAGE_KERNEL, 0, NUMA_NO_NODE,
  				__builtin_return_address(0));
 
Quoted 6 lines

arch/arm64/kernel/module.c void *module_alloc(unsigned long size) · line 63

Quoted 2 lines
arch/arm64/kernel/module.c +0 -0
  	if (p && (kasan_module_alloc(p, size) < 0)) {

Which just makes sure that PTE_PXN never gets dropped while creating these mappings.

Not sure what you mean. Is there a question here?

#4 lore raw

PATCH 2/4 arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP

In reply to Ard Biesheuvel

Wire up the special helper functions to manipulate aliases of vmalloc regions in the linear map.

---
 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/cacheflush.h |  3 ++
 arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
 mm/vmalloc.c                        | 11 -----
 4 files changed, 44 insertions(+), 19 deletions(-)
arch/arm64/Kconfig +1 -0
index ca9c175fb949..4ab32180eabd 100644
@@ -26,6 +26,7 @@ config ARM64
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SETUP_DMA_OPS
+	select ARCH_HAS_SET_DIRECT_MAP
 	select ARCH_HAS_SET_MEMORY
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
arch/arm64/include/asm/cacheflush.h +3 -0
index 19844211a4e6..b9ee5510067f 100644
@@ -187,4 +187,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
 
 int set_memory_valid(unsigned long addr, int numpages, int enable);
 
+int set_direct_map_invalid_noflush(struct page *page);
+int set_direct_map_default_noflush(struct page *page);
+
 #endif
arch/arm64/mm/pageattr.c +40 -8

68 lines not on this page · raw message

mm/vmalloc.c +0 -11
index 233af6936c93..1135dd8f2665 100644
@@ -2128,17 +2128,6 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages)
 	int flush_reset = area->flags & VM_FLUSH_RESET_PERMS;
 	int i;
 
-	/*
-	 * The below block can be removed when all architectures that have
-	 * direct map permissions also have set_direct_map_() implementations.
-	 * This is concerned with resetting the direct map any an vm alias with
-	 * execute permissions, without leaving a RW+X window.
-	 */
-	if (flush_reset && !IS_ENABLED(CONFIG_ARCH_HAS_SET_DIRECT_MAP)) {
-		set_memory_nx(addr, area->nr_pages);
-		set_memory_rw(addr, area->nr_pages);
-	}
-
 	remove_vm_area(area->addr);
 
 	/* If this is not VM_FLUSH_RESET_PERMS memory, no need for the below. */
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 2/4] arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP

Quoted 2 lines · Ard Biesheuvel

Wire up the special helper functions to manipulate aliases of vmalloc regions in the linear map.

IMHO the commit message here could be bit more descriptive because of the amount of changes this patch brings in.

Quoted 41 lines
---
 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/cacheflush.h |  3 ++
 arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
 mm/vmalloc.c                        | 11 -----
 4 files changed, 44 insertions(+), 19 deletions(-)
arch/arm64/Kconfig +1 -0
index ca9c175fb949..4ab32180eabd 100644
@@ -26,6 +26,7 @@ config ARM64
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SETUP_DMA_OPS
+	select ARCH_HAS_SET_DIRECT_MAP
 	select ARCH_HAS_SET_MEMORY
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
arch/arm64/include/asm/cacheflush.h +3 -0
index 19844211a4e6..b9ee5510067f 100644
@@ -187,4 +187,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
 
 int set_memory_valid(unsigned long addr, int numpages, int enable);
 
+int set_direct_map_invalid_noflush(struct page *page);
+int set_direct_map_default_noflush(struct page *page);
+
 #endif
arch/arm64/mm/pageattr.c +0 -0
index 6cd645edcf35..9c6b9039ec8f 100644
@@ -159,17 +159,48 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
 					__pgprot(PTE_VALID));
 }
 

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 170

Quoted 10 lines
arch/arm64/mm/pageattr.c +9 -1
-#ifdef CONFIG_DEBUG_PAGEALLOC
+int set_direct_map_invalid_noflush(struct page *page)
+{
+	struct page_change_data data = {
+		.set_mask = __pgprot(0),
+		.clear_mask = __pgprot(PTE_VALID),
+	};
+
+	if (!rodata_full)
+		return 0;

Why rodata_full needs to be probed here ? Should not we still require the following transition even if rodata_full is not enabled. Just wondering whether we can use VM_FLUSH_RESET_PERMS feature without these required transitions.

        /*
         * Set direct map to something invalid so that it won't be cached if
         * there are any accesses after the TLB flush, then flush the TLB and
         * reset the direct map permissions to the default.
         */
        set_area_direct_map(area, set_direct_map_invalid_noflush);
        _vm_unmap_aliases(start, end, 1);
        set_area_direct_map(area, set_direct_map_default_noflush);

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 181

Quoted 11 lines
arch/arm64/mm/pageattr.c +11 -0
+
+	return apply_to_page_range(&init_mm,
+				   (unsigned long)page_address(page),
+				   PAGE_SIZE, change_page_range, &data);
+}
+
+int set_direct_map_default_noflush(struct page *page)
+{
+	struct page_change_data data = {
+		.set_mask = __pgprot(PTE_VALID | PTE_WRITE),
+		.clear_mask = __pgprot(PTE_RDONLY),

Replace __pgprot(PTE_VALID | PTE_WRITE) with PAGE_KERNEL instead !

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 176

Quoted 10 lines
arch/arm64/mm/pageattr.c +10 -0
+	};
+
+	if (!rodata_full)
+		return 0;
+
+	return apply_to_page_range(&init_mm,
+				   (unsigned long)page_address(page),
+				   PAGE_SIZE, change_page_range, &data);
+}
+

IIUC set_direct_map_invalid_noflush() and set_direct_map_default_noflush() should set *appropriate* permissions as seen fit from platform perspective to implement this transition.

In here set_direct_map_invalid_noflush() makes the entry invalid preventing further MMU walks (hence new TLB entries). set_direct_map_default_noflush() makes it a valid write entry. Though it looks similar to PAGE_KERNEL which is the default permission for linear mapping on arm64 via __map_memblock(). Should not PAGE_KERNEL be used explicitly as suggested above.

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 196

Quoted 5 lines
arch/arm64/mm/pageattr.c +3 -0
 void __kernel_map_pages(struct page *page, int numpages, int enable)
 {
+	if (!debug_pagealloc_enabled() && !rodata_full)
+		return;
+

I guess this is not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP here and should be a fix or an enhancement to CONFIG_DEBUG_PAGEALLOC implementation. Just curious, !rodata_full check here to ensure that linear mapping does not have block or contig mappings and should be backed by regular pages only ?

Quoted 16 lines
arch/arm64/mm/pageattr.c +4 -5
 	set_memory_valid((unsigned long)page_address(page), numpages, enable);
 }
-#ifdef CONFIG_HIBERNATION
+
 /*
- * When built with CONFIG_DEBUG_PAGEALLOC and CONFIG_HIBERNATION, this function
- * is used to determine if a linear map page has been marked as not-valid by
- * CONFIG_DEBUG_PAGEALLOC. Walk the page table and check the PTE_VALID bit.
- * This is based on kern_addr_valid(), which almost does what we need.
+ * This function is used to determine if a linear map page has been marked as
+ * not-valid. Walk the page table and check the PTE_VALID bit. This is based
+ * on kern_addr_valid(), which almost does what we need.
  *
  * Because this is only called on the kernel linear map,  p?d_sect() implies
  * p?d_present(). When debug_pagealloc is enabled, sections mappings are

arch/arm64/mm/pageattr.c bool kernel_page_present(struct page *page) · line 219

Quoted 6 lines
arch/arm64/mm/pageattr.c +3 -0
@@ -183,6 +214,9 @@ bool kernel_page_present(struct page *page)
 	pte_t *ptep;
 	unsigned long addr = (unsigned long)page_address(page);
 
+	if (!debug_pagealloc_enabled() && !rodata_full)
+		return true;
+

Ditto, not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP.

#6 lore raw

Re: [PATCH 2/4] arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP

Quoted 65 lines · Anshuman Khandual
Quoted 2 lines · Ard Biesheuvel

Wire up the special helper functions to manipulate aliases of vmalloc regions in the linear map.

IMHO the commit message here could be bit more descriptive because of the amount of changes this patch brings in.

Quoted 41 lines
---
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  mm/vmalloc.c                        | 11 -----
  4 files changed, 44 insertions(+), 19 deletions(-)
arch/arm64/Kconfig +1 -0
index ca9c175fb949..4ab32180eabd 100644
@@ -26,6 +26,7 @@ config ARM64
  	select ARCH_HAS_MEMBARRIER_SYNC_CORE
  	select ARCH_HAS_PTE_SPECIAL
  	select ARCH_HAS_SETUP_DMA_OPS
+	select ARCH_HAS_SET_DIRECT_MAP
  	select ARCH_HAS_SET_MEMORY
  	select ARCH_HAS_STRICT_KERNEL_RWX
  	select ARCH_HAS_STRICT_MODULE_RWX
arch/arm64/include/asm/cacheflush.h +3 -0
index 19844211a4e6..b9ee5510067f 100644
@@ -187,4 +187,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
 
  int set_memory_valid(unsigned long addr, int numpages, int enable);
 
+int set_direct_map_invalid_noflush(struct page *page);
+int set_direct_map_default_noflush(struct page *page);
+
  #endif
arch/arm64/mm/pageattr.c +0 -0
index 6cd645edcf35..9c6b9039ec8f 100644
@@ -159,17 +159,48 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
  					__pgprot(PTE_VALID));
  }
 

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 170

Quoted 10 lines
arch/arm64/mm/pageattr.c +9 -1
-#ifdef CONFIG_DEBUG_PAGEALLOC
+int set_direct_map_invalid_noflush(struct page *page)
+{
+	struct page_change_data data = {
+		.set_mask = __pgprot(0),
+		.clear_mask = __pgprot(PTE_VALID),
+	};
+
+	if (!rodata_full)
+		return 0;

Why rodata_full needs to be probed here ? Should not we still require the following transition even if rodata_full is not enabled. Just wondering whether we can use VM_FLUSH_RESET_PERMS feature without these required transitions.

Quoted 10 lines
         /*
          * Set direct map to something invalid so that it won't be cached if
          * there are any accesses after the TLB flush, then flush the TLB and
          * reset the direct map permissions to the default.
          */
         set_area_direct_map(area, set_direct_map_invalid_noflush);
         _vm_unmap_aliases(start, end, 1);
         set_area_direct_map(area, set_direct_map_default_noflush);
Quoted 1 line
arch/arm64/mm/pageattr.c +1 -0
+

How would that work? With rodata_full disabled, the linear region is not mapped down to pages, and so there is no way we can manipulate linear aliases at page granularity.

Quoted 4 lines
Quoted 4 lines
arch/arm64/mm/pageattr.c +4 -0
+	return apply_to_page_range(&init_mm,
+				   (unsigned long)page_address(page),
+				   PAGE_SIZE, change_page_range, &data);
+}
Quoted 9 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 181

Quoted 6 lines
arch/arm64/mm/pageattr.c +6 -0
+
+int set_direct_map_default_noflush(struct page *page)
+{
+	struct page_change_data data = {
+		.set_mask = __pgprot(PTE_VALID | PTE_WRITE),
+		.clear_mask = __pgprot(PTE_RDONLY),

Replace __pgprot(PTE_VALID | PTE_WRITE) with PAGE_KERNEL instead !

This is a delta mask, so no need to pull in the PTE_MAYBE_NG or other attributes that we know we haven't changed.

Quoted 15 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 176

Quoted 10 lines
arch/arm64/mm/pageattr.c +10 -0
+	};
+
+	if (!rodata_full)
+		return 0;
+
+	return apply_to_page_range(&init_mm,
+				   (unsigned long)page_address(page),
+				   PAGE_SIZE, change_page_range, &data);
+}
+

IIUC set_direct_map_invalid_noflush() and set_direct_map_default_noflush() should set *appropriate* permissions as seen fit from platform perspective to implement this transition.

Quoted 6 lines

In here set_direct_map_invalid_noflush() makes the entry invalid preventing further MMU walks (hence new TLB entries). set_direct_map_default_noflush() makes it a valid write entry. Though it looks similar to PAGE_KERNEL which is the default permission for linear mapping on arm64 via __map_memblock(). Should not PAGE_KERNEL be used explicitly as suggested above.

No. We should restore the attributes that we cleared when manipulating the linear aliases. There isn't a lot of code that does that, so I don't see the need to use PAGE_KERNEL here.

Quoted 11 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 196

Quoted 5 lines
arch/arm64/mm/pageattr.c +3 -0
  void __kernel_map_pages(struct page *page, int numpages, int enable)
  {
+	if (!debug_pagealloc_enabled() && !rodata_full)
+		return;
+

I guess this is not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP here and should be a fix or an enhancement to CONFIG_DEBUG_PAGEALLOC implementation. Just curious, !rodata_full check here to ensure that linear mapping does not have block or contig mappings and should be backed by regular pages only ?

It is related. CONFIG_ARCH_HAS_SET_DIRECT_MAP introduces references to __kernel_map_pages() in generic code, so enabling CONFIG_ARCH_HAS_SET_DIRECT_MAP should make __kernel_map_pages() available unconditionally as well.

Quoted 19 lines
Quoted 19 lines
arch/arm64/mm/pageattr.c +4 -5
  	set_memory_valid((unsigned long)page_address(page), numpages, enable);
  }
-#ifdef CONFIG_HIBERNATION
+
  /*
- * When built with CONFIG_DEBUG_PAGEALLOC and CONFIG_HIBERNATION, this function
- * is used to determine if a linear map page has been marked as not-valid by
- * CONFIG_DEBUG_PAGEALLOC. Walk the page table and check the PTE_VALID bit.
- * This is based on kern_addr_valid(), which almost does what we need.
+ * This function is used to determine if a linear map page has been marked as
+ * not-valid. Walk the page table and check the PTE_VALID bit. This is based
+ * on kern_addr_valid(), which almost does what we need.
   *
   * Because this is only called on the kernel linear map,  p?d_sect() implies
   * p?d_present(). When debug_pagealloc is enabled, sections mappings are
@@ -183,6 +214,9 @@ bool kernel_page_present(struct page *page)
  	pte_t *ptep;
  	unsigned long addr = (unsigned long)page_address(page);
 
Quoted 6 lines

arch/arm64/mm/pageattr.c bool kernel_page_present(struct page *page) · line 219

Quoted 3 lines
arch/arm64/mm/pageattr.c +3 -0
+	if (!debug_pagealloc_enabled() && !rodata_full)
+		return true;
+

Ditto, not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP.

It is related.

#7 lore raw

Re: [PATCH 2/4] arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP

Quoted 72 lines · Ard Biesheuvel
Quoted 71 lines · Anshuman Khandual
Quoted 2 lines · Ard Biesheuvel

Wire up the special helper functions to manipulate aliases of vmalloc regions in the linear map.

IMHO the commit message here could be bit more descriptive because of the amount of changes this patch brings in.

Quoted 39 lines

---
  arch/arm64/Kconfig                  |  1 + arch/arm64/include/asm/cacheflush.h |  3 ++ arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++---- mm/vmalloc.c                        | 11 -----

  4 files changed, 44 insertions(+), 19 deletions(-)
arch/arm64/Kconfig +0 -0
index ca9c175fb949..4ab32180eabd 100644
@@ -26,6 +26,7 @@ config ARM64

      select ARCH_HAS_MEMBARRIER_SYNC_CORE
      select ARCH_HAS_PTE_SPECIAL
      select ARCH_HAS_SETUP_DMA_OPS
+    select ARCH_HAS_SET_DIRECT_MAP
      select ARCH_HAS_SET_MEMORY
      select ARCH_HAS_STRICT_KERNEL_RWX
      select ARCH_HAS_STRICT_MODULE_RWX

arch/arm64/include/asm/cacheflush.h +2 -0
index 19844211a4e6..b9ee5510067f 100644
@@ -187,4 +187,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
     int set_memory_valid(unsigned long addr, int numpages, int enable);
   +int set_direct_map_invalid_noflush(struct page *page);
+int set_direct_map_default_noflush(struct page *page);
+
   #endif
arch/arm64/mm/pageattr.c +0 -0
index 6cd645edcf35..9c6b9039ec8f 100644
@@ -159,17 +159,48 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
                       __pgprot(PTE_VALID));
   }

  -#ifdef CONFIG_DEBUG_PAGEALLOC

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 170

Quoted 9 lines
arch/arm64/mm/pageattr.c +9 -0
+int set_direct_map_invalid_noflush(struct page *page)
+{
+    struct page_change_data data = {
+        .set_mask = __pgprot(0),
+        .clear_mask = __pgprot(PTE_VALID),
+    };
+
+    if (!rodata_full)
+        return 0;

Why rodata_full needs to be probed here ? Should not we still require the following transition even if rodata_full is not enabled. Just wondering whether we can use VM_FLUSH_RESET_PERMS feature without these required transitions.

         /*
          * Set direct map to something invalid so that it won't be cached if
          * there are any accesses after the TLB flush, then flush the TLB and
          * reset the direct map permissions to the default.
          */
         set_area_direct_map(area, set_direct_map_invalid_noflush); _vm_unmap_aliases(start, end, 1); set_area_direct_map(area, set_direct_map_default_noflush);

Quoted 3 lines
Quoted 1 line

  > +

How would that work? With rodata_full disabled, the linear region is not mapped down to pages, and so there is no way we can manipulate linear aliases at page granularity.

Then should not we check debug_pagealloc_enabled() as well as in case for __kernel_map_pages() later in the patch.

Quoted 32 lines
Quoted 14 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 181

Quoted 11 lines

+    return apply_to_page_range(&init_mm,
+                   (unsigned long)page_address(page), +                   PAGE_SIZE, change_page_range, &data);

arch/arm64/mm/pageattr.c +7 -0
+}
+
+int set_direct_map_default_noflush(struct page *page)
+{
+    struct page_change_data data = {
+        .set_mask = __pgprot(PTE_VALID | PTE_WRITE),
+        .clear_mask = __pgprot(PTE_RDONLY),

Replace __pgprot(PTE_VALID | PTE_WRITE) with PAGE_KERNEL instead !

This is a delta mask, so no need to pull in the PTE_MAYBE_NG or other attributes that we know we haven't changed.

Quoted 15 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 176

Quoted 10 lines

+    };

arch/arm64/mm/pageattr.c +9 -0
+
+    if (!rodata_full)
+        return 0;
+
+    return apply_to_page_range(&init_mm,
+                   (unsigned long)page_address(page),
+                   PAGE_SIZE, change_page_range, &data);
+}
+

IIUC set_direct_map_invalid_noflush() and set_direct_map_default_noflush() should set *appropriate* permissions as seen fit from platform perspective to implement this transition.

Quoted 8 lines
Quoted 6 lines

In here set_direct_map_invalid_noflush() makes the entry invalid preventing further MMU walks (hence new TLB entries). set_direct_map_default_noflush() makes it a valid write entry. Though it looks similar to PAGE_KERNEL which is the default permission for linear mapping on arm64 via __map_memblock(). Should not PAGE_KERNEL be used explicitly as suggested above.

No. We should restore the attributes that we cleared when manipulating the linear aliases. There isn't a lot of code that does that, so I don't see the need to use PAGE_KERNEL here.

Fair enough.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

  void __kernel_map_pages(struct page *page, int numpages, int enable) {
+    if (!debug_pagealloc_enabled() && !rodata_full)
+        return;
+

Quoted 7 lines
Quoted 5 lines

I guess this is not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP here and should be a fix or an enhancement to CONFIG_DEBUG_PAGEALLOC implementation. Just curious, !rodata_full check here to ensure that linear mapping does not have block or contig mappings and should be backed by regular pages only ?

It is related. CONFIG_ARCH_HAS_SET_DIRECT_MAP introduces references to __kernel_map_pages() in generic code, so enabling CONFIG_ARCH_HAS_SET_DIRECT_MAP should make __kernel_map_pages() available unconditionally as well.

Ahh, got it.

Quoted 26 lines
Quoted 16 lines
Quoted 16 lines

      set_memory_valid((unsigned long)page_address(page), numpages, enable); }

arch/arm64/mm/pageattr.c +1 -1
-#ifdef CONFIG_HIBERNATION
+

  /*
- * When built with CONFIG_DEBUG_PAGEALLOC and CONFIG_HIBERNATION, this function
- * is used to determine if a linear map page has been marked as not-valid by
- * CONFIG_DEBUG_PAGEALLOC. Walk the page table and check the PTE_VALID bit.
- * This is based on kern_addr_valid(), which almost does what we need.
+ * This function is used to determine if a linear map page has been marked as
+ * not-valid. Walk the page table and check the PTE_VALID bit. This is based
+ * on kern_addr_valid(), which almost does what we need.
   *
   * Because this is only called on the kernel linear map,  p?d_sect() implies
   * p?d_present(). When debug_pagealloc is enabled, sections mappings are

Quoted 9 lines

arch/arm64/mm/pageattr.c bool kernel_page_present(struct page *page) · line 218

Quoted 6 lines
arch/arm64/mm/pageattr.c +2 -0
@@ -183,6 +214,9 @@ bool kernel_page_present(struct page *page)
       pte_t *ptep;
       unsigned long addr = (unsigned long)page_address(page);
   +    if (!debug_pagealloc_enabled() && !rodata_full)
+        return true;
+

Ditto, not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP.

Quoted 1 line

It is related.

Never mind.

#8 lore raw

Re: [PATCH 2/4] arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP

Quoted 75 lines · Anshuman Khandual
Quoted 72 lines · Ard Biesheuvel
Quoted 71 lines · Anshuman Khandual
Quoted 2 lines · Ard Biesheuvel

Wire up the special helper functions to manipulate aliases of vmalloc regions in the linear map.

IMHO the commit message here could be bit more descriptive because of the amount of changes this patch brings in.

Quoted 38 lines
---
   arch/arm64/Kconfig                  |  1 +
   arch/arm64/include/asm/cacheflush.h |  3 ++
   arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
   mm/vmalloc.c                        | 11 -----
   4 files changed, 44 insertions(+), 19 deletions(-)
arch/arm64/Kconfig +1 -0
index ca9c175fb949..4ab32180eabd 100644
@@ -26,6 +26,7 @@ config ARM64
       select ARCH_HAS_MEMBARRIER_SYNC_CORE
       select ARCH_HAS_PTE_SPECIAL
       select ARCH_HAS_SETUP_DMA_OPS
+    select ARCH_HAS_SET_DIRECT_MAP
       select ARCH_HAS_SET_MEMORY
       select ARCH_HAS_STRICT_KERNEL_RWX
       select ARCH_HAS_STRICT_MODULE_RWX
arch/arm64/include/asm/cacheflush.h +2 -0
index 19844211a4e6..b9ee5510067f 100644
@@ -187,4 +187,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
     int set_memory_valid(unsigned long addr, int numpages, int enable);
   +int set_direct_map_invalid_noflush(struct page *page);
+int set_direct_map_default_noflush(struct page *page);
+
   #endif
arch/arm64/mm/pageattr.c +0 -0
index 6cd645edcf35..9c6b9039ec8f 100644
@@ -159,17 +159,48 @@ int set_memory_valid(unsigned long addr, int numpages, int enable)
                       __pgprot(PTE_VALID));
   }

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 170

Quoted 10 lines
arch/arm64/mm/pageattr.c +9 -0
   -#ifdef CONFIG_DEBUG_PAGEALLOC
+int set_direct_map_invalid_noflush(struct page *page)
+{
+    struct page_change_data data = {
+        .set_mask = __pgprot(0),
+        .clear_mask = __pgprot(PTE_VALID),
+    };
+
+    if (!rodata_full)
+        return 0;

Why rodata_full needs to be probed here ? Should not we still require the following transition even if rodata_full is not enabled. Just wondering whether we can use VM_FLUSH_RESET_PERMS feature without these required transitions.

         /*
          * Set direct map to something invalid so that it won't be cached if
          * there are any accesses after the TLB flush, then flush the TLB and
          * reset the direct map permissions to the default.
          */
         set_area_direct_map(area, set_direct_map_invalid_noflush); _vm_unmap_aliases(start, end, 1); set_area_direct_map(area, set_direct_map_default_noflush);

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

  > +

How would that work? With rodata_full disabled, the linear region is not mapped down to pages, and so there is no way we can manipulate linear aliases at page granularity.

Then should not we check debug_pagealloc_enabled() as well as in case for __kernel_map_pages() later in the patch.

Yes, what we could do technically is to permit the direct_map_xx() calls to proceed if debug_pagealloc_enabled() returns true, since we are guaranteed to have a page granular mapping of the entire linear region.

However, that means we will be manipulating the linear aliases of vmalloc mappings even if the user has requested us not to, i.e., by passing rodata=on rather than rodata=full, so I don't think we should be doing that.

Quoted 90 lines
Quoted 32 lines
Quoted 14 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 181

Quoted 11 lines
arch/arm64/mm/pageattr.c +10 -0
+    return apply_to_page_range(&init_mm,
+                   (unsigned long)page_address(page),
+                   PAGE_SIZE, change_page_range, &data);
+}
+
+int set_direct_map_default_noflush(struct page *page)
+{
+    struct page_change_data data = {
+        .set_mask = __pgprot(PTE_VALID | PTE_WRITE),
+        .clear_mask = __pgprot(PTE_RDONLY),

Replace __pgprot(PTE_VALID | PTE_WRITE) with PAGE_KERNEL instead !

This is a delta mask, so no need to pull in the PTE_MAYBE_NG or other attributes that we know we haven't changed.

Quoted 15 lines

arch/arm64/mm/pageattr.c int set_memory_valid(unsigned long addr, int numpages, int enable) · line 176

Quoted 10 lines
arch/arm64/mm/pageattr.c +10 -0
+    };
+
+    if (!rodata_full)
+        return 0;
+
+    return apply_to_page_range(&init_mm,
+                   (unsigned long)page_address(page),
+                   PAGE_SIZE, change_page_range, &data);
+}
+

IIUC set_direct_map_invalid_noflush() and set_direct_map_default_noflush() should set *appropriate* permissions as seen fit from platform perspective to implement this transition.

Quoted 8 lines
Quoted 6 lines

In here set_direct_map_invalid_noflush() makes the entry invalid preventing further MMU walks (hence new TLB entries). set_direct_map_default_noflush() makes it a valid write entry. Though it looks similar to PAGE_KERNEL which is the default permission for linear mapping on arm64 via __map_memblock(). Should not PAGE_KERNEL be used explicitly as suggested above.

No. We should restore the attributes that we cleared when manipulating the linear aliases. There isn't a lot of code that does that, so I don't see the need to use PAGE_KERNEL here.

Fair enough.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
arch/arm64/mm/pageattr.c +3 -0
   void __kernel_map_pages(struct page *page, int numpages, int enable)
   {
+    if (!debug_pagealloc_enabled() && !rodata_full)
+        return;
+
Quoted 7 lines
Quoted 5 lines

I guess this is not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP here and should be a fix or an enhancement to CONFIG_DEBUG_PAGEALLOC implementation. Just curious, !rodata_full check here to ensure that linear mapping does not have block or contig mappings and should be backed by regular pages only ?

It is related. CONFIG_ARCH_HAS_SET_DIRECT_MAP introduces references to __kernel_map_pages() in generic code, so enabling CONFIG_ARCH_HAS_SET_DIRECT_MAP should make __kernel_map_pages() available unconditionally as well.

Ahh, got it.

Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
arch/arm64/mm/pageattr.c +4 -5
       set_memory_valid((unsigned long)page_address(page), numpages, enable);
   }
-#ifdef CONFIG_HIBERNATION
+
   /*
- * When built with CONFIG_DEBUG_PAGEALLOC and CONFIG_HIBERNATION, this function
- * is used to determine if a linear map page has been marked as not-valid by
- * CONFIG_DEBUG_PAGEALLOC. Walk the page table and check the PTE_VALID bit.
- * This is based on kern_addr_valid(), which almost does what we need.
+ * This function is used to determine if a linear map page has been marked as
+ * not-valid. Walk the page table and check the PTE_VALID bit. This is based
+ * on kern_addr_valid(), which almost does what we need.
    *
    * Because this is only called on the kernel linear map,  p?d_sect() implies
    * p?d_present(). When debug_pagealloc is enabled, sections mappings are
Quoted 9 lines

arch/arm64/mm/pageattr.c bool kernel_page_present(struct page *page) · line 218

Quoted 6 lines
arch/arm64/mm/pageattr.c +2 -0
@@ -183,6 +214,9 @@ bool kernel_page_present(struct page *page)
       pte_t *ptep;
       unsigned long addr = (unsigned long)page_address(page);
   +    if (!debug_pagealloc_enabled() && !rodata_full)
+        return true;
+

Ditto, not related to CONFIG_ARCH_HAS_SET_DIRECT_MAP.

Quoted 1 line

It is related.

Never mind.

#9 lore raw

PATCH 3/4 arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages

In reply to Ard Biesheuvel

In order to avoid transient inconsistencies where freed code pages are remapped writable while stale TLB entries still exist on other cores, mark the kprobes text pages with the VM_FLUSH_RESET_PERMS attribute. This instructs the core vmalloc code not to defer the TLB flush when this region is unmapped and returned to the page allocator.

---
 arch/arm64/kernel/probes/kprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kernel/probes/kprobes.c +3 -1
index 2509fcb6d404..036cfbf9682a 100644
@@ -131,8 +131,10 @@ void *alloc_insn_page(void)
 	void *page;
 
 	page = vmalloc_exec(PAGE_SIZE);
-	if (page)
+	if (page) {
 		set_memory_ro((unsigned long)page, 1);
+		set_vm_flush_reset_perms(page);
+	}
 
 	return page;
 }
Signature · 1 line
2.17.1
#10 lore raw

Re: [PATCH 3/4] arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages

Quoted 6 lines · Ard Biesheuvel

In order to avoid transient inconsistencies where freed code pages are remapped writable while stale TLB entries still exist on other cores, mark the kprobes text pages with the VM_FLUSH_RESET_PERMS attribute. This instructs the core vmalloc code not to defer the TLB flush when this region is unmapped and returned to the page allocator.

Makes sense.

Quoted 11 lines
---
 arch/arm64/kernel/probes/kprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kernel/probes/kprobes.c +0 -0
index 2509fcb6d404..036cfbf9682a 100644

arch/arm64/kernel/probes/kprobes.c void *alloc_insn_page(void) · line 137

Quoted 8 lines
arch/arm64/kernel/probes/kprobes.c +3 -1
@@ -131,8 +131,10 @@ void *alloc_insn_page(void)
 	void *page;
 
 	page = vmalloc_exec(PAGE_SIZE);
-	if (page)
+	if (page) {
 		set_memory_ro((unsigned long)page, 1);
+		set_vm_flush_reset_perms(page);
+	}

Looks good. It seems there might be more users who would like to set VM_FLUSH_RESET_PERMS right after their allocation for the same reason. Hence would not it help to have a variant like vmalloc_exec_reset() or such which will tag vm_struct->flags with VM_FLUSH_RESET_PERMS right after it's allocation without requiring the caller to do the same.

#11 lore raw

Re: [PATCH 3/4] arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages

Quoted 25 lines · Anshuman Khandual
Quoted 6 lines · Ard Biesheuvel

In order to avoid transient inconsistencies where freed code pages are remapped writable while stale TLB entries still exist on other cores, mark the kprobes text pages with the VM_FLUSH_RESET_PERMS attribute. This instructs the core vmalloc code not to defer the TLB flush when this region is unmapped and returned to the page allocator.

Makes sense.

Quoted 13 lines
---
  arch/arm64/kernel/probes/kprobes.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kernel/probes/kprobes.c +0 -0
index 2509fcb6d404..036cfbf9682a 100644
@@ -131,8 +131,10 @@ void *alloc_insn_page(void)
  	void *page;
 
Quoted 13 lines

arch/arm64/kernel/probes/kprobes.c void *alloc_insn_page(void) · line 137

Quoted 6 lines
arch/arm64/kernel/probes/kprobes.c +3 -1
  	page = vmalloc_exec(PAGE_SIZE);
-	if (page)
+	if (page) {
  		set_memory_ro((unsigned long)page, 1);
+		set_vm_flush_reset_perms(page);
+	}

Looks good. It seems there might be more users who would like to set VM_FLUSH_RESET_PERMS right after their allocation for the same reason. Hence would not it help to have a variant like vmalloc_exec_reset() or such which will tag vm_struct->flags with VM_FLUSH_RESET_PERMS right after it's allocation without requiring the caller to do the same.

If there is a sufficient number of similar users, then of course, it makes sense to factor this out. However, the kprobes code is slightly unusual in the sense that it allocates memory and immediately remaps it read-only, and relies on code patching to populate this allocation. I am not expecting to see this pattern in other places.

#12 lore raw

PATCH 4/4 arm64: bpf: do not allocate executable memory

In reply to Ard Biesheuvel

The BPF code now takes care of mapping the code pages executable after mapping them read-only, to ensure that no RWX mapped regions are needed, even transiently. This means we can drop the executable permissions from the mapping at allocation time.

---
 arch/arm64/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/net/bpf_jit_comp.c +1 -1
index df845cee438e..aef4ff467222 100644
@@ -981,7 +981,7 @@ void *bpf_jit_alloc_exec(unsigned long size)
 {
 	return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
 				    BPF_JIT_REGION_END, GFP_KERNEL,
-				    PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
+				    PAGE_KERNEL, 0, NUMA_NO_NODE,
 				    __builtin_return_address(0));
 }
 
Signature · 1 line
2.17.1
#13 lore raw
In reply to Ard Biesheuvel
Quoted 23 lines · Ard Biesheuvel

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/cacheflush.h |  3 ++
 arch/arm64/kernel/module.c          |  4 +-
 arch/arm64/kernel/probes/kprobes.c  |  4 +-
 arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
 arch/arm64/net/bpf_jit_comp.c       |  2 +-
 mm/vmalloc.c                        | 11 -----
 7 files changed, 50 insertions(+), 23 deletions(-)

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Cheers,

Will

[1] https://lore.kernel.org/lkml/[email protected]/T/#u

#14 lore raw
Quoted 33 lines · Will Deacon
Quoted 23 lines · Ard Biesheuvel

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/kernel/module.c          |  4 +-
  arch/arm64/kernel/probes/kprobes.c  |  4 +-
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  arch/arm64/net/bpf_jit_comp.c       |  2 +-
  mm/vmalloc.c                        | 11 -----
  7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 3 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Note that you'll get a trivial conflict in the hunk against mm/vmalloc.c.

maintainer Acked-by
#15 lore raw
In reply to Will Deacon
Quoted 33 lines · Will Deacon
Quoted 23 lines · Ard Biesheuvel

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/cacheflush.h |  3 ++
 arch/arm64/kernel/module.c          |  4 +-
 arch/arm64/kernel/probes/kprobes.c  |  4 +-
 arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
 arch/arm64/net/bpf_jit_comp.c       |  2 +-
 mm/vmalloc.c                        | 11 -----
 7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 2 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Bah, I missed these landing in -rc5 and I think it's a bit too late for us to take this for 5.2. now particularly with our limited ability to fix any late regressions that might arise.

In which case, Catalin, please can you take these for 5.3? You might run into some testing failures with for-next/core due to the late of Rick's fixes, but linux-next should be alright and I don't think you'll get any conflicts.

Ard: are you ok with that?

Thanks,

Will

#16 lore raw
Quoted 41 lines · Will Deacon
Quoted 33 lines · Will Deacon
Quoted 23 lines · Ard Biesheuvel

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/kernel/module.c          |  4 +-
  arch/arm64/kernel/probes/kprobes.c  |  4 +-
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  arch/arm64/net/bpf_jit_comp.c       |  2 +-
  mm/vmalloc.c                        | 11 -----
  7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 2 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Bah, I missed these landing in -rc5 and I think it's a bit too late for us to take this for 5.2. now particularly with our limited ability to fix any late regressions that might arise.

Quoted 9 lines

In which case, Catalin, please can you take these for 5.3? You might run into some testing failures with for-next/core due to the late of Rick's fixes, but linux-next should be alright and I don't think you'll get any conflicts.

Ard: are you ok with that?

That is fine, although I won't be around to pick up the pieces by the time the merge window opens. Also, I'd like to follow up on the lazy vunmap thing for non-x86, but perhaps we can talk about this at plumbers?

#17 lore raw

(+ Catalin)

Quoted 48 lines · Ard Biesheuvel
Quoted 46 lines · Will Deacon
Quoted 33 lines · Will Deacon
Quoted 23 lines · Ard Biesheuvel

Wire up the code introduced in v5.2 to manage the permissions of executable vmalloc regions (and their linear aliases) more strictly.

One of the things that came up in the internal discussion is whether non-x86 architectures have any benefit at all from the lazy vunmap feature, and whether it would perhaps be better to implement eager vunmap instead.

Cc Nadav Amit <[email protected]>
Cc Rick Edgecombe <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Will Deacon <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc James Morse <[email protected]>

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/kernel/module.c          |  4 +-
  arch/arm64/kernel/probes/kprobes.c  |  4 +-
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  arch/arm64/net/bpf_jit_comp.c       |  2 +-
  mm/vmalloc.c                        | 11 -----
  7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 2 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Bah, I missed these landing in -rc5 and I think it's a bit too late for us to take this for 5.2. now particularly with our limited ability to fix any late regressions that might arise.

In which case, Catalin, please can you take these for 5.3? You might run into some testing failures with for-next/core due to the late of Rick's fixes, but linux-next should be alright and I don't think you'll get any conflicts.

Quoted 9 lines
Quoted 4 lines

Ard: are you ok with that?

That is fine, although I won't be around to pick up the pieces by the time the merge window opens. Also, I'd like to follow up on the lazy vunmap thing for non-x86, but perhaps we can talk about this at plumbers?

Actually, you will run into a couple of conflicts. Let me know if you want me to respin (although they still won't apply cleanly to both for-next/core and -next)

maintainer Applied
#18 lore raw
Quoted 35 lines · Ard Biesheuvel
Quoted 34 lines · Ard Biesheuvel
Quoted 32 lines · Will Deacon
Quoted 16 lines · Will Deacon
Quoted 6 lines · Ard Biesheuvel

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/kernel/module.c          |  4 +-
  arch/arm64/kernel/probes/kprobes.c  |  4 +-
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  arch/arm64/net/bpf_jit_comp.c       |  2 +-
  mm/vmalloc.c                        | 11 -----
  7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 2 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Bah, I missed these landing in -rc5 and I think it's a bit too late for us to take this for 5.2. now particularly with our limited ability to fix any late regressions that might arise.

In which case, Catalin, please can you take these for 5.3? You might run into some testing failures with for-next/core due to the late of Rick's fixes, but linux-next should be alright and I don't think you'll get any conflicts.

Ard: are you ok with that?

Quoted 7 lines
Quoted 3 lines

That is fine, although I won't be around to pick up the pieces by the time the merge window opens. Also, I'd like to follow up on the lazy vunmap thing for non-x86, but perhaps we can talk about this at plumbers?

Actually, you will run into a couple of conflicts. Let me know if you want me to respin (although they still won't apply cleanly to both for-next/core and -next)

I queued them in for-next/core (and fixed a minor conflict). Thanks.

Signature · 1 line
Catalin
#19 lore raw
Quoted 41 lines · Catalin Marinas
Quoted 39 lines · Ard Biesheuvel
Quoted 37 lines · Ard Biesheuvel
Quoted 24 lines · Will Deacon
Quoted 16 lines · Will Deacon
Quoted 6 lines · Ard Biesheuvel

Ard Biesheuvel (4):
arm64: module: create module allocations without exec permissions arm64/mm: wire up CONFIG_ARCH_HAS_SET_DIRECT_MAP arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages
arm64: bpf: do not allocate executable memory

Quoted 8 lines
  arch/arm64/Kconfig                  |  1 +
  arch/arm64/include/asm/cacheflush.h |  3 ++
  arch/arm64/kernel/module.c          |  4 +-
  arch/arm64/kernel/probes/kprobes.c  |  4 +-
  arch/arm64/mm/pageattr.c            | 48 ++++++++++++++++----
  arch/arm64/net/bpf_jit_comp.c       |  2 +-
  mm/vmalloc.c                        | 11 -----
  7 files changed, 50 insertions(+), 23 deletions(-)
Quoted 2 lines

Thanks, this all looks good to me. I can get pick this up for 5.2 if Rick's fixes [1] land soon enough.

Bah, I missed these landing in -rc5 and I think it's a bit too late for us to take this for 5.2. now particularly with our limited ability to fix any late regressions that might arise.

Quoted 8 lines

In which case, Catalin, please can you take these for 5.3? You might run into some testing failures with for-next/core due to the late of Rick's fixes, but linux-next should be alright and I don't think you'll get any conflicts.

Ard: are you ok with that?

That is fine, although I won't be around to pick up the pieces by the time the merge window opens. Also, I'd like to follow up on the lazy vunmap thing for non-x86, but perhaps we can talk about this at plumbers?

Quoted 6 lines
Quoted 3 lines

Actually, you will run into a couple of conflicts. Let me know if you want me to respin (although they still won't apply cleanly to both for-next/core and -next)

I queued them in for-next/core (and fixed a minor conflict). Thanks.

OK, in that case, you will get a conflict in -next on the hunk against mm/vmalloc.c in the second patch. Just FYI ...