x86/setup: Warn when option parsing is done too early
Commit
4faa0e5d6d
("x86/boot: Move kernel cmdline setup earlier in the boot process (again)")
fixed and issue where cmdline parsing would happen before the final
boot_command_line string has been built from the builtin and boot
cmdlines and thus cmdline arguments would get lost.
Add a check to catch any future wrong use ordering so that such issues
can be caught in time.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240409152541.GCZhVd9XIPXyTNd9vc@fat_crate.local
This commit is contained in:
parent
52cccc64cf
commit
0c40b1c7a8
3 changed files with 18 additions and 0 deletions
|
@ -28,6 +28,8 @@
|
||||||
#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
|
#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
|
||||||
|
|
||||||
#ifndef __ASSEMBLY__
|
#ifndef __ASSEMBLY__
|
||||||
|
#include <linux/cache.h>
|
||||||
|
|
||||||
#include <asm/bootparam.h>
|
#include <asm/bootparam.h>
|
||||||
#include <asm/x86_init.h>
|
#include <asm/x86_init.h>
|
||||||
|
|
||||||
|
@ -133,6 +135,12 @@ asmlinkage void __init __noreturn x86_64_start_reservations(char *real_mode_data
|
||||||
#endif /* __i386__ */
|
#endif /* __i386__ */
|
||||||
#endif /* _SETUP */
|
#endif /* _SETUP */
|
||||||
|
|
||||||
|
#ifdef CONFIG_CMDLINE_BOOL
|
||||||
|
extern bool builtin_cmdline_added __ro_after_init;
|
||||||
|
#else
|
||||||
|
#define builtin_cmdline_added 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* __ASSEMBLY */
|
#else /* __ASSEMBLY */
|
||||||
|
|
||||||
.macro __RESERVE_BRK name, size
|
.macro __RESERVE_BRK name, size
|
||||||
|
|
|
@ -165,6 +165,7 @@ unsigned long saved_video_mode;
|
||||||
static char __initdata command_line[COMMAND_LINE_SIZE];
|
static char __initdata command_line[COMMAND_LINE_SIZE];
|
||||||
#ifdef CONFIG_CMDLINE_BOOL
|
#ifdef CONFIG_CMDLINE_BOOL
|
||||||
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
|
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
|
||||||
|
bool builtin_cmdline_added __ro_after_init;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
|
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
|
||||||
|
@ -765,6 +766,7 @@ void __init setup_arch(char **cmdline_p)
|
||||||
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
|
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
builtin_cmdline_added = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
|
strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
|
|
||||||
#include <asm/setup.h>
|
#include <asm/setup.h>
|
||||||
#include <asm/cmdline.h>
|
#include <asm/cmdline.h>
|
||||||
|
#include <asm/bug.h>
|
||||||
|
|
||||||
static inline int myisspace(u8 c)
|
static inline int myisspace(u8 c)
|
||||||
{
|
{
|
||||||
|
@ -205,12 +207,18 @@ __cmdline_find_option(const char *cmdline, int max_cmdline_size,
|
||||||
|
|
||||||
int cmdline_find_option_bool(const char *cmdline, const char *option)
|
int cmdline_find_option_bool(const char *cmdline, const char *option)
|
||||||
{
|
{
|
||||||
|
if (IS_ENABLED(CONFIG_CMDLINE_BOOL))
|
||||||
|
WARN_ON_ONCE(!builtin_cmdline_added);
|
||||||
|
|
||||||
return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option);
|
return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmdline_find_option(const char *cmdline, const char *option, char *buffer,
|
int cmdline_find_option(const char *cmdline, const char *option, char *buffer,
|
||||||
int bufsize)
|
int bufsize)
|
||||||
{
|
{
|
||||||
|
if (IS_ENABLED(CONFIG_CMDLINE_BOOL))
|
||||||
|
WARN_ON_ONCE(!builtin_cmdline_added);
|
||||||
|
|
||||||
return __cmdline_find_option(cmdline, COMMAND_LINE_SIZE, option,
|
return __cmdline_find_option(cmdline, COMMAND_LINE_SIZE, option,
|
||||||
buffer, bufsize);
|
buffer, bufsize);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue