KASLR: Properly injest nokaslr on x86 to avoid passing it to init process
PATCH 1/1 KASLR: Properly injest nokaslr on x86 to avoid passing it to init process
Problem: Currently booting the kernel with "nokaslr" on x86 incorrectly doesn't recognize this parameter and passes it on to the init process
Reason: On x86, this parameter is parsed by the early loader, and so the main kernel itself doesn't do anything with it.
Example: I have encountered this issue when booting the kernel with QEMU using -kernel and -initrd with a simple initrd I have built containing bash as the init executable. Upon running init, the kernel passed the "unrecognized parameter" to bash causing bash to exit with a failure and the kernel to panic.
Solution: Ingest this parameter as part of the kernel logic in x86 so the kernel will recognize this as a valid parameter and not pass it to user mode.
This is similar to the logic that already exists in the case of ARM64 which can be found in arch/arm64/kernel/kaslr.c:43
Crediting also Mahmoud since he came up with a similar patch a couple of months ago, the patch was left with unaddressed CR comments by Borislav which I have addressed in this patch,
link to thread: https://lore.kernel.org/all/[email protected]/
--- arch/x86/mm/kaslr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/x86/mm/kaslr.c +15 -0
@@ -71,6 +71,21 @@ static inline unsigned long get_padding(struct kaslr_memory_region *region)return (region->size_tb <<TB_SHIFT ); } +/* +* nokaslr param handling is done by the loader which treats the +* boot parameters as read only so this is a hack to ingest this +* to keep it from passing to user mode +*/ +static int __init parse_nokaslr (char *p) +{ +if (!!(boot_params.hdr.loadflags &KASLR_FLAG )) { +pr_warn ("the loader has not parsed the nokaslr flag" ); + } + +return 0 ; +} +early_param ("nokaslr" , parse_nokaslr); +/* Initialize base and padding for each memory region randomized with KASLR */ void __init kernel_randomize_memory (void ) {
Signature · 1 line
2.39.2
PATCH v2 1/1 x86/kaslr: Ingest nokaslr to avoid passing it to init process
Problem: Currently booting the kernel with "nokaslr" on x86 incorrectly doesn't recognize this parameter and passes it on to the init process
Reason: On x86, this parameter is parsed by the early loader, and so the main kernel itself doesn't do anything with it.
Example: I have encountered this issue when booting the kernel with QEMU using -kernel and -initrd with a simple initrd I have built containing bash as the init executable. Upon running init, the kernel passed the "unrecognized parameter" to bash causing bash to exit with a failure and the kernel to panic.
Solution: Ingest this parameter as part of the kernel logic in x86 so the kernel will recognize this as a valid parameter and not pass it to user mode.
This is similar to the logic that already exists in the case of ARM64 which can be found in arch/arm64/kernel/kaslr.c:43
Crediting also Mahmoud since he came up with a similar patch a couple of months ago, the patch was left with unaddressed CR comments by Borislav which I have addressed in this patch,
link to thread: https://lore.kernel.org/all/[email protected]/
v2: Remove single line if-condition braces, following check patch script warning
--- arch/x86/mm/kaslr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/x86/mm/kaslr.c +14 -0
@@ -71,6 +71,20 @@ static inline unsigned long get_padding(struct kaslr_memory_region *region)return (region->size_tb <<TB_SHIFT ); } +/* +* nokaslr param handling is done by the loader which treats the +* boot parameters as read only so this is a hack to ingest this +* to keep it from passing to user mode +*/ +static int __init parse_nokaslr (char *p) +{ +if (!!(boot_params.hdr.loadflags &KASLR_FLAG )) +pr_warn ("the loader has not parsed the nokaslr flag" ); + +return 0 ; +} +early_param ("nokaslr" , parse_nokaslr); +/* Initialize base and padding for each memory region randomized with KASLR */ void __init kernel_randomize_memory (void ) {
Signature · 1 line
2.39.2