Messages in this thread Patch in this message | | | From | Zong Li <> | Subject | [PATCH RFC 7/8] riscv/kaslr: add cmdline support to disable KASLR | Date | Tue, 24 Mar 2020 15:30:52 +0800 |
| |
Provide a cmdline parameter 'nokaslr' to disable KASLR.
Signed-off-by: Zong Li <zong.li@sifive.com> --- arch/riscv/kernel/kaslr.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
diff --git a/arch/riscv/kernel/kaslr.c b/arch/riscv/kernel/kaslr.c index 0bd30831c455..6920727e4b4a 100644 --- a/arch/riscv/kernel/kaslr.c +++ b/arch/riscv/kernel/kaslr.c @@ -156,6 +156,36 @@ static __init u64 kaslr_get_seed(void) return ret; } +static __init const u8 *kaslr_get_cmdline(void) +{ + static const u8 default_cmdline[] __initconst = CONFIG_CMDLINE; + + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { + int node; + const u8 *prop; + + node = fdt_path_offset(dtb_early_va, "/chosen"); + if (node < 0) + goto out; + + prop = fdt_getprop(dtb_early_va, node, "bootargs", NULL); + if (!prop) + goto out; + + return prop; + } + +out: + return default_cmdline; +} + +static __init bool kaslr_is_disabled(void) +{ + const u8 *cmdline = kaslr_get_cmdline(); + + return strstr(cmdline, "nokaslr") != NULL; +} + static __init bool is_overlap(uintptr_t s1, uintptr_t e1, uintptr_t s2, uintptr_t e2) { @@ -379,6 +409,10 @@ uintptr_t __init kaslr_early_init(void) if (!seed) return 0; + /* Check whether disable kaslr by cmdline. */ + if (kaslr_is_disabled()) + return 0; + /* Get the random number for kaslr offset. */ kaslr_offset = get_random_offset(seed, kernel_size); -- 2.25.1
| |