From: Michal Clapinski <mclapinski@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Chris Li <chrisl@kernel.org>,
x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Ard Biesheuvel <ardb@kernel.org>,
Michal Clapinski <mclapinski@google.com>,
Dan Williams <dan.j.williams@intel.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/1] x86/boot/compressed: Fix avoiding memmap in physical KASLR
Date: Thu, 6 Nov 2025 17:23:11 +0100 [thread overview]
Message-ID: <20251106162311.2705162-1-mclapinski@google.com> (raw)
The intent of the code was to cancel KASLR if there are more than 4
memmap args. Unfortunately, it was only doing that if the memmap args
were comma delimited, not if they were entirely separate.
So it would disable physical KASLR for:
memmap=1G!4G,1G!5G,1G!6G,1G!7G,1G!8G
since the whole function is just called once and we hit the `if` at
the end of the function.
But it would not disable physical KASLR for:
memmap=1G!4G memmap=1G!5G memmap=1G!6G memmap=1G!7G memmap=1G!8G
The whole function would be called 5 times in total. On the 4th run the
last `if` would not trigger since `str` would be null. On the 5th run
we would exit early via the first `if`. That way the last `if` would
never trigger.
For the second input, the code would avoid the first 4 memmap regions
but not the last one (it could put the kernel there).
The new code disables physical KASLR for both of those inputs.
Signed-off-by: Michal Clapinski <mclapinski@google.com>
Suggested-by: Chris Li <chrisl@kernel.org>
Link: https://lore.kernel.org/all/CAF8kJuMvX31n8yNWn11bo1wCgXXOwOAp8HbYpSEBy94LR6phDA@mail.gmail.com/
Fixes: d52e7d5a952c ("x86/KASLR: Parse all 'memmap=' boot option entries")
---
v3: added a link in the description and a better explanation
v2: used Chris Li's snippet to change the flow of the function
---
arch/x86/boot/compressed/kaslr.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 3b0948ad449f..649264503ce6 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -162,14 +162,18 @@ static void mem_avoid_memmap(char *str)
{
static int i;
- if (i >= MAX_MEMMAP_REGIONS)
- return;
-
- while (str && (i < MAX_MEMMAP_REGIONS)) {
+ while (str) {
int rc;
u64 start, size;
- char *k = strchr(str, ',');
+ char *k;
+
+ if (i >= MAX_MEMMAP_REGIONS) {
+ /* Too many memmap regions, disable physical KASLR. */
+ memmap_too_large = true;
+ return;
+ }
+ k = strchr(str, ',');
if (k)
*k++ = 0;
@@ -190,10 +194,6 @@ static void mem_avoid_memmap(char *str)
mem_avoid[MEM_AVOID_MEMMAP_BEGIN + i].size = size;
i++;
}
-
- /* More than 4 memmaps, fail kaslr */
- if ((i >= MAX_MEMMAP_REGIONS) && str)
- memmap_too_large = true;
}
/* Store the number of 1GB huge pages which users specified: */
--
2.51.2.1026.g39e6a42477-goog
next reply other threads:[~2025-11-06 16:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 16:23 Michal Clapinski [this message]
2025-11-06 16:32 ` [PATCH v3 1/1] x86/boot/compressed: Fix avoiding memmap in physical KASLR Ard Biesheuvel
2025-11-06 16:36 ` Dave Hansen
2025-12-08 13:27 ` Michał Cłapiński
2025-12-09 0:43 ` Borislav Petkov
2025-12-29 14:25 ` Michał Cłapiński
2026-01-08 13:36 ` Ard Biesheuvel
2026-01-12 21:39 ` Borislav Petkov
2026-01-13 11:21 ` Michał Cłapiński
2026-01-13 11:27 ` Borislav Petkov
2026-01-13 11:39 ` Michał Cłapiński
2026-01-13 11:54 ` Borislav Petkov
2026-01-13 12:18 ` Ard Biesheuvel
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=20251106162311.2705162-1-mclapinski@google.com \
--to=mclapinski@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=chrisl@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@soleen.com \
--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