Skip to content

Commit 0c40b1c

Browse files
committed
x86/setup: Warn when option parsing is done too early
Commit 4faa0e5 ("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) <[email protected]> Acked-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/20240409152541.GCZhVd9XIPXyTNd9vc@fat_crate.local
1 parent 52cccc6 commit 0c40b1c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

arch/x86/include/asm/setup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define NEW_CL_POINTER 0x228 /* Relative to real mode data */
2929

3030
#ifndef __ASSEMBLY__
31+
#include <linux/cache.h>
32+
3133
#include <asm/bootparam.h>
3234
#include <asm/x86_init.h>
3335

@@ -133,6 +135,12 @@ asmlinkage void __init __noreturn x86_64_start_reservations(char *real_mode_data
133135
#endif /* __i386__ */
134136
#endif /* _SETUP */
135137

138+
#ifdef CONFIG_CMDLINE_BOOL
139+
extern bool builtin_cmdline_added __ro_after_init;
140+
#else
141+
#define builtin_cmdline_added 0
142+
#endif
143+
136144
#else /* __ASSEMBLY */
137145

138146
.macro __RESERVE_BRK name, size

arch/x86/kernel/setup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ unsigned long saved_video_mode;
165165
static char __initdata command_line[COMMAND_LINE_SIZE];
166166
#ifdef CONFIG_CMDLINE_BOOL
167167
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
168+
bool builtin_cmdline_added __ro_after_init;
168169
#endif
169170

170171
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
@@ -765,6 +766,7 @@ void __init setup_arch(char **cmdline_p)
765766
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
766767
}
767768
#endif
769+
builtin_cmdline_added = true;
768770
#endif
769771

770772
strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);

arch/x86/lib/cmdline.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include <linux/kernel.h>
77
#include <linux/string.h>
88
#include <linux/ctype.h>
9+
910
#include <asm/setup.h>
1011
#include <asm/cmdline.h>
12+
#include <asm/bug.h>
1113

1214
static inline int myisspace(u8 c)
1315
{
@@ -205,12 +207,18 @@ __cmdline_find_option(const char *cmdline, int max_cmdline_size,
205207

206208
int cmdline_find_option_bool(const char *cmdline, const char *option)
207209
{
210+
if (IS_ENABLED(CONFIG_CMDLINE_BOOL))
211+
WARN_ON_ONCE(!builtin_cmdline_added);
212+
208213
return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option);
209214
}
210215

211216
int cmdline_find_option(const char *cmdline, const char *option, char *buffer,
212217
int bufsize)
213218
{
219+
if (IS_ENABLED(CONFIG_CMDLINE_BOOL))
220+
WARN_ON_ONCE(!builtin_cmdline_added);
221+
214222
return __cmdline_find_option(cmdline, COMMAND_LINE_SIZE, option,
215223
buffer, bufsize);
216224
}

0 commit comments

Comments
 (0)