Skip to content

Commit

Permalink
execmem: don't remove ROX cache from the direct map
Browse files Browse the repository at this point in the history
The memory allocated for the ROX cache was removed from the direct map to
reduce amount of direct map updates, however this cannot be tolerated by
/proc/kcore that accesses module memory using vread_iter() and the latter
does vmalloc_to_page() and copy_page_to_iter_nofault().

Instead of removing ROX cache memory from the direct map and mapping it as
ROX in vmalloc space, simply call set_memory_rox() that will take care of
proper permissions on both vmalloc and in the direct map.

Signed-off-by: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250126074733.1384926-5-rppt@kernel.org
  • Loading branch information
Mike Rapoport (Microsoft) authored and Peter Zijlstra committed Feb 3, 2025
1 parent 41d8848 commit 925f426
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions mm/execmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ static void *__execmem_cache_alloc(struct execmem_range *range, size_t size)
static int execmem_cache_populate(struct execmem_range *range, size_t size)
{
unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
unsigned long start, end;
struct vm_struct *vm;
size_t alloc_size;
int err = -ENOMEM;
Expand All @@ -275,26 +274,18 @@ 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);

start = (unsigned long)p;
end = start + alloc_size;

vunmap_range(start, end);

err = execmem_set_direct_map_valid(vm, false);
if (err)
goto err_free_mem;

err = vmap_pages_range_noflush(start, end, range->pgprot, vm->pages,
PMD_SHIFT);
err = set_memory_rox((unsigned long)p, vm->nr_pages);
if (err)
goto err_free_mem;

err = execmem_cache_add(p, alloc_size);
if (err)
goto err_free_mem;
goto err_reset_direct_map;

return 0;

err_reset_direct_map:
execmem_set_direct_map_valid(vm, true);
err_free_mem:
vfree(p);
return err;
Expand Down

0 comments on commit 925f426

Please sign in to comment.