From: Zong Li <zong.li@sifive.com>
To: palmer@dabbelt.com, paul.walmsley@sifive.com, alex@ghiti.fr,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: Zong Li <zong.li@sifive.com>
Subject: [PATCH RFC 7/8] riscv/kaslr: add cmdline support to disable KASLR
Date: Tue, 24 Mar 2020 15:30:52 +0800 [thread overview]
Message-ID: <292e5511fff99d564c947c9ee71be367be947f55.1584352425.git.zong.li@sifive.com> (raw)
In-Reply-To: <cover.1584352425.git.zong.li@sifive.com>
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
next prev parent reply other threads:[~2020-03-24 7:31 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 7:30 [PATCH RFC 0/8] Support KASLR for RISC-V Zong Li
2020-03-24 7:30 ` [PATCH RFC 1/8] riscv/kaslr: add interface to get kaslr offset Zong Li
2020-04-07 5:08 ` Alex Ghiti
2020-03-24 7:30 ` [PATCH RFC 2/8] riscv/kaslr: introduce functions to clear page table Zong Li
2020-04-07 5:09 ` Alex Ghiti
2020-04-07 9:17 ` Zong Li
2020-03-24 7:30 ` [PATCH RFC 3/8] riscv/kaslr: support KASLR infrastructure Zong Li
2020-04-07 5:10 ` Alex Ghiti
2020-04-07 10:34 ` Zong Li
2020-04-09 5:53 ` Alex Ghiti
2020-04-09 11:08 ` Zong Li
2020-03-24 7:30 ` [PATCH RFC 4/8] riscv/kaslr: randomize the kernel image offset Zong Li
2020-04-07 5:11 ` Alex Ghiti
2020-04-07 10:53 ` Zong Li
2020-04-09 5:51 ` Alex Ghiti
2020-04-09 10:31 ` Zong Li
2020-04-10 15:58 ` Alex Ghiti
2020-04-11 8:20 ` Zong Li
2020-04-12 6:53 ` Alex Ghiti
2020-04-14 2:46 ` Zong Li
2020-04-14 5:43 ` Alex Ghiti
2020-04-14 7:00 ` Zong Li
2020-03-24 7:30 ` [PATCH RFC 5/8] riscv/kaslr: support sparse memory model Zong Li
2020-03-24 7:30 ` [PATCH RFC 6/8] riscv/kaslr: clear the original kernel image Zong Li
2020-04-07 5:11 ` Alex Ghiti
2020-04-07 11:18 ` Zong Li
2020-04-09 5:53 ` Alex Ghiti
2020-04-09 8:14 ` Alex Ghiti
2020-03-24 7:30 ` Zong Li [this message]
2020-03-24 7:30 ` [PATCH RFC 8/8] riscv/kaslr: dump out kernel offset information on panic Zong Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=292e5511fff99d564c947c9ee71be367be947f55.1584352425.git.zong.li@sifive.com \
--to=zong.li@sifive.com \
--cc=alex@ghiti.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).