From: sayo <rg32@ciallo.tech>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
m.younesbadr@gmail.com, nir@lichtman.org
Subject: [PATCH v3 2/2] x86: claim the parameters consumed by the boot stub and decompressor
Date: Mon, 5 Oct 2026 13:13:46 -0400 [thread overview]
Message-ID: <20261005171815.49494-3-rg32@ciallo.tech> (raw)
In-Reply-To: <20261005171815.49494-1-rg32@ciallo.tech>
List the parameters that arch/x86/boot/ and the decompressor consume before
the main kernel is running, so that unknown_bootoption() no longer forwards
them to init:
nokaslr arch/x86/boot/compressed/kaslr.c
no5lvl arch/x86/boot/compressed/pgtable_64.c
mem_encrypt= arch/x86/boot/compressed/misc.c
edd= arch/x86/boot/edd.c
forcepae 32-bit only: its __setup() is compiled out on x86-64
Booted with "nokaslr no5lvl edd=off forcepae mem_encrypt=off foo=bar --
extra1" (plus the usual console=), before:
Unknown kernel command line parameters "nokaslr no5lvl forcepae edd=off
mem_encrypt=off foo=bar", will be passed to user space.
argv: {"/init", "nokaslr", "no5lvl", "forcepae", "extra1"}
envp: {"HOME=/", "TERM=linux", "edd=off", "mem_encrypt=off", "foo=bar"}
and after:
Unknown kernel command line parameters "foo=bar", will be passed to
user space.
argv: {"/init", "extra1"}
envp: {"HOME=/", "TERM=linux", "foo=bar"}
which is also what makes the notice useful again: it now only names
parameters that really are unknown.
Signed-off-by: sayo <rg32@ciallo.tech>
---
arch/x86/kernel/setup.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index cda6adb9f69c..34f7add84243 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1325,3 +1325,43 @@ bool arch_cpu_is_hotpluggable(int cpu)
return cpu > 0;
}
#endif /* CONFIG_HOTPLUG_CPU */
+
+/*
+ * Parameters that the boot code consumes before the main kernel is running.
+ * They are deliberately not registered with early_param()/__setup() here:
+ * what they configure has already been decided by the time this code runs,
+ * and the decompressor (a separate program, arch/x86/boot/compressed/) does
+ * not contribute to any section in this image.
+ *
+ * Without being claimed, they are treated as unknown parameters and handed
+ * to init - valueless ones as arguments, "key=value" ones as environment
+ * variables. openrc-init, for instance, reads the runlevel from argv[1] and
+ * then complains that "nokaslr is an invalid runlevel"; a shell used as init
+ * treats the argument as a script name and exits, which panics the kernel.
+ *
+ * Keep this in sync with the cmdline_find_option*() calls in
+ * arch/x86/boot/ and drivers/firmware/efi/libstub/.
+ */
+static const char * const boot_consumed_params[] __initconst = {
+ "nokaslr", /* arch/x86/boot/compressed/kaslr.c */
+ "no5lvl", /* arch/x86/boot/compressed/pgtable_64.c */
+ "mem_encrypt", /* arch/x86/boot/compressed/misc.c */
+ "edd", /* arch/x86/boot/edd.c */
+ "forcepae", /* 32-bit only: __setup() is compiled out on x86-64 */
+};
+
+bool __init boot_param_consumed(const char *param)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(boot_consumed_params); i++) {
+ const char *name = boot_consumed_params[i];
+ size_t len = strlen(name);
+
+ if (!strncmp(param, name, len) &&
+ (param[len] == '\0' || param[len] == '='))
+ return true;
+ }
+
+ return false;
+}
prev parent reply other threads:[~2026-10-05 17:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 17:13 [PATCH v3 0/2] x86: stop handing boot-stage parameters to init sayo
2026-10-05 17:13 ` [PATCH v3 1/2] init: claim parameters consumed before the main kernel sayo
2026-10-05 17:13 ` sayo [this message]
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=20261005171815.49494-3-rg32@ciallo.tech \
--to=rg32@ciallo.tech \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.younesbadr@gmail.com \
--cc=mingo@redhat.com \
--cc=nir@lichtman.org \
--cc=tglx@kernel.org \
--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
all inboxes | Powered by JetHome®