Re: [PATCH v4 07/15] mm/execmem, arch: convert remaining overrides of module_alloc to execmem

From: Peter Zijlstra
Date: Mon Apr 15 2024 - 05:38:22 EST


On Thu, Apr 11, 2024 at 07:00:43PM +0300, Mike Rapoport wrote:

> +static struct execmem_info execmem_info __ro_after_init = {
> + .ranges = {
> + [EXECMEM_DEFAULT] = {
> + .flags = EXECMEM_KASAN_SHADOW,
> + .alignment = MODULE_ALIGN,
> + },
> + },
> +};
>
> +struct execmem_info __init *execmem_arch_setup(void)
> {
> + unsigned long start, offset = 0;
>
> + if (kaslr_enabled())
> + offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;
>
> + start = MODULES_VADDR + offset;
> + execmem_info.ranges[EXECMEM_DEFAULT].start = start;
> + execmem_info.ranges[EXECMEM_DEFAULT].end = MODULES_END;
> + execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL;
>
> + return &execmem_info;
> }

struct execmem_info __init *execmem_arch_setup(void)
{
unsigned long offset = 0;

if (kaslr_enabled())
offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;

execmem_info = (struct execmem_info){
.ranges = {
[EXECMEM_DEFAULT] = {
.start = MODULES_VADDR + offset,
.end = MODULES_END,
.pgprot = PAGE_KERNEL,
.flags = EXECMEM_KASAN_SHADOW,
.alignment = 1,
},
},
};

return &execmem_info;
}