From: Borislav Petkov <bp@alien8.de>
To: Evgeniy Baskov <baskov@ispras.ru>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org, x86@kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>
Subject: [PATCH 2/2] x86/boot: Use cmdline_prepare() in the compressed stage
Date: Tue, 15 Nov 2022 20:00:06 +0100 [thread overview]
Message-ID: <Y3PhtjKjt/G2kqAF@zn.tnic> (raw)
In-Reply-To: <Y3PhYRx9aAYsdvMQ@zn.tnic>
From: Borislav Petkov <bp@suse.de>
Date: Tue, 15 Nov 2022 19:30:09 +0100
Use cmdline_prepare() in the compressed stage so that builtin
command line (CONFIG_CMDLINE_BOOL) and overridden command line
(CONFIG_CMDLINE_OVERRIDE) strings are visible in the compressed kernel
too.
Use case being, supplying earlyprintk via a compile-time option for
booting on systems with broken UEFI command line arguments via EFISTUB.
Reported-by: Evgeniy Baskov <baskov@ispras.ru>
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/boot/compressed/misc.c | 7 +++++++
arch/x86/include/asm/shared/cmdline.h | 20 ++++++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index cf690d8712f4..b1077b2fdba6 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -18,6 +18,9 @@
#include "../string.h"
#include "../voffset.h"
#include <asm/bootparam_utils.h>
+#include <asm/shared/cmdline.h>
+
+extern unsigned long get_cmd_line_ptr(void);
/*
* WARNING!!
@@ -355,6 +358,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
{
const unsigned long kernel_total_size = VO__end - VO__text;
unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
+ char *cmdline = (char *)get_cmd_line_ptr();
unsigned long needed_size;
/* Retain x86 boot parameters pointer passed from startup_32/64. */
@@ -365,6 +369,9 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
sanitize_boot_params(boot_params);
+ /* Destination and boot command line are the same */
+ cmdline_prepare(cmdline, BUILTIN_CMDLINE, cmdline);
+
if (boot_params->screen_info.orig_video_mode == 7) {
vidmem = (char *) 0xb0000;
vidport = 0x3b4;
diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h
index e09c06338567..8a7d8f579575 100644
--- a/arch/x86/include/asm/shared/cmdline.h
+++ b/arch/x86/include/asm/shared/cmdline.h
@@ -8,6 +8,15 @@
#define BUILTIN_CMDLINE ""
#endif
+#define _SETUP
+#include <asm/setup.h> /* For COMMAND_LINE_SIZE */
+#undef _SETUP
+
+/*
+ * Add @boot_command_line to @dst only if it is not in @dst already. The compressed kernel
+ * has the command line pointer in setup_header.cmd_line_ptr which is set by the boot
+ * loader so @boot_command_line == @dst there, see the call in compressed/misc.c
+ */
static inline void cmdline_prepare(char *dst,
const char *builtin_cmdline,
char *boot_command_line)
@@ -20,15 +29,18 @@ static inline void cmdline_prepare(char *dst,
/* Add builtin cmdline */
strlcat(dst, builtin_cmdline, COMMAND_LINE_SIZE);
strlcat(dst, " ", COMMAND_LINE_SIZE);
- /* Add boot cmdline */
- strlcat(dst, boot_command_line, COMMAND_LINE_SIZE);
+
+ if (dst != boot_command_line)
+ strlcat(dst, boot_command_line, COMMAND_LINE_SIZE);
}
} else {
- strscpy(dst, boot_command_line, COMMAND_LINE_SIZE);
+ if (dst != boot_command_line)
+ strscpy(dst, boot_command_line, COMMAND_LINE_SIZE);
}
/* Copy back into boot command line, see setup_command_line() */
- strscpy(boot_command_line, dst, COMMAND_LINE_SIZE);
+ if (dst != boot_command_line)
+ strscpy(boot_command_line, dst, COMMAND_LINE_SIZE);
}
#endif /* _ASM_X86_SHARED_CMDLINE_H */
--
2.35.1
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2022-11-15 19:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 13:09 [PATCH v8 0/5] Parse CONFIG_CMDLINE in compressed kernel Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 1/5] x86/boot: Add strlcat() and strscpy() to " Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 2/5] x86: Add cmdline_prepare() helper Evgeniy Baskov
2022-11-14 14:28 ` Borislav Petkov
2022-11-15 18:58 ` Borislav Petkov
2022-11-15 18:59 ` [PATCH 1/2] x86/boot: Add a function for kernel command line preparation Borislav Petkov
2022-11-15 19:00 ` Borislav Petkov [this message]
2022-11-16 10:48 ` [PATCH 2/2] x86/boot: Use cmdline_prepare() in the compressed stage Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 3/5] x86/setup: Use cmdline_prepare() in setup.c Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 4/5] x86/boot: Use cmdline_prapare() in compressed kernel Evgeniy Baskov
2022-11-10 13:09 ` [PATCH v8 5/5] x86/boot: Remove no longer needed includes Evgeniy Baskov
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=Y3PhtjKjt/G2kqAF@zn.tnic \
--to=bp@alien8.de \
--cc=baskov@ispras.ru \
--cc=dave.hansen@linux.intel.com \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.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
all inboxes | Powered by JetHome®