[PATCH v4 19/26] arm64: kaslr: defer initialization to late initcall where permitted

Will Deacon will at kernel.org
Fri Jun 24 06:08:09 PDT 2022


On Mon, Jun 13, 2022 at 04:45:43PM +0200, Ard Biesheuvel wrote:
> The early KASLR init code runs extremely early, and anything that could
> be deferred until later should be. So let's defer the randomization of
> the module region until much later - this also simplifies the
> arithmetic, given that we no longer have to reason about the link time
> vs load time placement of the core kernel explicitly. Also get rid of
> the global status variable, and infer the status reported by the
> diagnostic print from other KASLR related context.
> 
> While at it, get rid of the special case for KASAN without
> KASAN_VMALLOC, which never occurs in practice.
> 
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  arch/arm64/kernel/kaslr.c | 95 +++++++++-----------
>  1 file changed, 40 insertions(+), 55 deletions(-)

[...]

> @@ -163,33 +169,12 @@ u64 __init kaslr_early_init(void)
>  		 * when ARM64_MODULE_PLTS is enabled.
>  		 */
>  		module_range = MODULES_VSIZE - (u64)(_etext - _stext);
> -		module_alloc_base = (u64)_etext + offset - MODULES_VSIZE;
>  	}
>  
>  	/* use the lower 21 bits to randomize the base of the module region */
>  	module_alloc_base += (module_range * (seed & ((1 << 21) - 1))) >> 21;
>  	module_alloc_base &= PAGE_MASK;
>  
> -	return offset;
> -}
> -
> -static int __init kaslr_init(void)
> -{
> -	switch (kaslr_status) {
> -	case KASLR_ENABLED:
> -		pr_info("KASLR enabled\n");
> -		break;
> -	case KASLR_DISABLED_CMDLINE:
> -		pr_info("KASLR disabled on command line\n");
> -		break;
> -	case KASLR_DISABLED_NO_SEED:
> -		pr_warn("KASLR disabled due to lack of seed\n");
> -		break;
> -	case KASLR_DISABLED_FDT_REMAP:
> -		pr_warn("KASLR disabled due to FDT remapping failure\n");
> -		break;
> -	}
> -
>  	return 0;
>  }
> -core_initcall(kaslr_init)
> +late_initcall(kaslr_init)

Are you sure this isn't too late? I'm nervous that we might have called
request_module() off the back of all the other initcalls that we've run by
this point.

Will



More information about the linux-arm-kernel mailing list