From: Pan Zhang <zhangpan26@huawei.com>
To: <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<x86@kernel.org>, <hpa@zytor.com>, <nivedita@alum.mit.edu>,
<keescook@chromium.org>, <jroedel@suse.de>
Cc: <zhangpan26@huawei.com>, <hushiyuan@huawei.com>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] x86/kaslr: support separate multiple memmaps parameter parsing
Date: Tue, 22 Dec 2020 19:31:24 +0800 [thread overview]
Message-ID: <20201222113124.35367-1-zhangpan26@huawei.com> (raw)
When the kernel is loading,
the load address of the kernel needs to be calculated firstly.
If the kernel address space layout randomization(`kaslr`) is enabled,
the memory range reserved by the memmap parameter will be excluded
to avoid loading the kernel address into the memmap reserved area.
Currently, this is what the manual says:
`memmap = nn [KMG] @ss [KMG]
[KNL] Force usage of a specific region of memory.
Region of memory to be used is from ss to ss + nn.
If @ss [KMG] is omitted, it is equivalent to mem = nn [KMG],
which limits max address to nn [KMG].
Multiple different regions can be specified,
comma delimited.
Example:
memmap=100M@2G, 100M#3G, 1G!1024G
`
Can we relax the use of memmap?
In our production environment we see many people who use it like this:
Separate multiple memmaps parameters to reserve memory,
memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx
If this format is used, and the reserved memory segment is greater than 4,
there is no way to parse the 5th and subsequent memmaps and the kaslr cannot be disabled by `memmap_too_large`
so the kernel loading address may fall within the memmap range
(reserved memory area from memmap after fourth segment),
which will have bad consequences for use of reserved memory.
Signed-off-by: Pan Zhang <zhangpan26@huawei.com>
---
arch/x86/boot/compressed/kaslr.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index d7408af..24a2778 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -203,9 +203,6 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str)
{
static int i;
- if (i >= MAX_MEMMAP_REGIONS)
- return;
-
while (str && (i < MAX_MEMMAP_REGIONS)) {
int rc;
unsigned long long start, size;
@@ -233,7 +230,7 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str)
}
/* More than 4 memmaps, fail kaslr */
- if ((i >= MAX_MEMMAP_REGIONS) && str)
+ if ((i >= MAX_MEMMAP_REGIONS) && !memmap_too_large)
memmap_too_large = true;
}
--
2.7.4
next reply other threads:[~2020-12-22 11:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-22 11:31 Pan Zhang [this message]
2021-01-05 20:22 ` [PATCH] x86/kaslr: support separate multiple memmaps parameter parsing Arvind Sankar
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=20201222113124.35367-1-zhangpan26@huawei.com \
--to=zhangpan26@huawei.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=hushiyuan@huawei.com \
--cc=jroedel@suse.de \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=nivedita@alum.mit.edu \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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).