diff options
| author | Ingo Molnar <[email protected]> | 2025-05-13 08:47:10 +0000 |
|---|---|---|
| committer | Ingo Molnar <[email protected]> | 2025-05-13 08:47:10 +0000 |
| commit | c4070e1996e05dd2eb5e08ee68d0d00553ae08f7 (patch) | |
| tree | 180e4a4bae29635fd54bf7e7ca29f5e15ff0b8fc /mm/execmem.c | |
| parent | Merge branch 'x86/platform' into x86/core, to merge dependent commits (diff) | |
| parent | Merge tag 'its-for-linus-20250509' of git://git.kernel.org/pub/scm/linux/kern... (diff) | |
| download | kernel-c4070e1996e05dd2eb5e08ee68d0d00553ae08f7.tar.gz kernel-c4070e1996e05dd2eb5e08ee68d0d00553ae08f7.zip | |
Merge commit 'its-for-linus-20250509-merge' into x86/core, to resolve conflicts
Conflicts:
Documentation/admin-guide/hw-vuln/index.rst
arch/x86/include/asm/cpufeatures.h
arch/x86/kernel/alternative.c
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/cpu/common.c
drivers/base/cpu.c
include/linux/cpu.h
Signed-off-by: Ingo Molnar <[email protected]>
Diffstat (limited to 'mm/execmem.c')
| -rw-r--r-- | mm/execmem.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/mm/execmem.c b/mm/execmem.c index e6c4f5076ca8..6f7a2653b280 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -254,6 +254,34 @@ out_unlock: return ptr; } +static bool execmem_cache_rox = false; + +void execmem_cache_make_ro(void) +{ + struct maple_tree *free_areas = &execmem_cache.free_areas; + struct maple_tree *busy_areas = &execmem_cache.busy_areas; + MA_STATE(mas_free, free_areas, 0, ULONG_MAX); + MA_STATE(mas_busy, busy_areas, 0, ULONG_MAX); + struct mutex *mutex = &execmem_cache.mutex; + void *area; + + execmem_cache_rox = true; + + mutex_lock(mutex); + + mas_for_each(&mas_free, area, ULONG_MAX) { + unsigned long pages = mas_range_len(&mas_free) >> PAGE_SHIFT; + set_memory_ro(mas_free.index, pages); + } + + mas_for_each(&mas_busy, area, ULONG_MAX) { + unsigned long pages = mas_range_len(&mas_busy) >> PAGE_SHIFT; + set_memory_ro(mas_busy.index, pages); + } + + mutex_unlock(mutex); +} + static int execmem_cache_populate(struct execmem_range *range, size_t size) { unsigned long vm_flags = VM_ALLOW_HUGE_VMAP; @@ -274,9 +302,15 @@ static int execmem_cache_populate(struct execmem_range *range, size_t size) /* fill memory with instructions that will trap */ execmem_fill_trapping_insns(p, alloc_size, /* writable = */ true); - err = set_memory_rox((unsigned long)p, vm->nr_pages); - if (err) - goto err_free_mem; + if (execmem_cache_rox) { + err = set_memory_rox((unsigned long)p, vm->nr_pages); + if (err) + goto err_free_mem; + } else { + err = set_memory_x((unsigned long)p, vm->nr_pages); + if (err) + goto err_free_mem; + } err = execmem_cache_add(p, alloc_size); if (err) |
