Skip to content

Commit 4578d07

Browse files
committed
Merge tag 'x86_boot_for_v6.11_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Borislav Petkov: - Add a check to warn when cmdline parsing happens before the final cmdline string has been built and thus arguments can get lost - Code cleanups and simplifications * tag 'x86_boot_for_v6.11_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/setup: Warn when option parsing is done too early x86/boot: Clean up the arch/x86/boot/main.c code a bit x86/boot: Use current_stack_pointer to avoid asm() in init_heap()
2 parents 208c677 + 0c40b1c commit 4578d07

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

arch/x86/boot/main.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,32 @@ char *heap_end = _end; /* Default end of heap = no heap */
2727
* screws up the old-style command line protocol, adjust by
2828
* filling in the new-style command line pointer instead.
2929
*/
30-
3130
static void copy_boot_params(void)
3231
{
3332
struct old_cmdline {
3433
u16 cl_magic;
3534
u16 cl_offset;
3635
};
37-
const struct old_cmdline * const oldcmd =
38-
absolute_pointer(OLD_CL_ADDRESS);
36+
const struct old_cmdline * const oldcmd = absolute_pointer(OLD_CL_ADDRESS);
3937

4038
BUILD_BUG_ON(sizeof(boot_params) != 4096);
4139
memcpy(&boot_params.hdr, &hdr, sizeof(hdr));
4240

43-
if (!boot_params.hdr.cmd_line_ptr &&
44-
oldcmd->cl_magic == OLD_CL_MAGIC) {
45-
/* Old-style command line protocol. */
41+
if (!boot_params.hdr.cmd_line_ptr && oldcmd->cl_magic == OLD_CL_MAGIC) {
42+
/* Old-style command line protocol */
4643
u16 cmdline_seg;
4744

48-
/* Figure out if the command line falls in the region
49-
of memory that an old kernel would have copied up
50-
to 0x90000... */
45+
/*
46+
* Figure out if the command line falls in the region
47+
* of memory that an old kernel would have copied up
48+
* to 0x90000...
49+
*/
5150
if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
5251
cmdline_seg = ds();
5352
else
5453
cmdline_seg = 0x9000;
5554

56-
boot_params.hdr.cmd_line_ptr =
57-
(cmdline_seg << 4) + oldcmd->cl_offset;
55+
boot_params.hdr.cmd_line_ptr = (cmdline_seg << 4) + oldcmd->cl_offset;
5856
}
5957
}
6058

@@ -66,6 +64,7 @@ static void copy_boot_params(void)
6664
static void keyboard_init(void)
6765
{
6866
struct biosregs ireg, oreg;
67+
6968
initregs(&ireg);
7069

7170
ireg.ah = 0x02; /* Get keyboard status */
@@ -83,8 +82,10 @@ static void query_ist(void)
8382
{
8483
struct biosregs ireg, oreg;
8584

86-
/* Some older BIOSes apparently crash on this call, so filter
87-
it from machines too old to have SpeedStep at all. */
85+
/*
86+
* Some older BIOSes apparently crash on this call, so filter
87+
* it from machines too old to have SpeedStep at all.
88+
*/
8889
if (cpu.level < 6)
8990
return;
9091

@@ -119,17 +120,13 @@ static void init_heap(void)
119120
char *stack_end;
120121

121122
if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
122-
asm("leal %n1(%%esp),%0"
123-
: "=r" (stack_end) : "i" (STACK_SIZE));
124-
125-
heap_end = (char *)
126-
((size_t)boot_params.hdr.heap_end_ptr + 0x200);
123+
stack_end = (char *) (current_stack_pointer - STACK_SIZE);
124+
heap_end = (char *) ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
127125
if (heap_end > stack_end)
128126
heap_end = stack_end;
129127
} else {
130128
/* Boot protocol 2.00 only, no heap available */
131-
puts("WARNING: Ancient bootloader, some functionality "
132-
"may be limited!\n");
129+
puts("WARNING: Ancient bootloader, some functionality may be limited!\n");
133130
}
134131
}
135132

@@ -150,12 +147,11 @@ void main(void)
150147

151148
/* Make sure we have all the proper CPU support */
152149
if (validate_cpu()) {
153-
puts("Unable to boot - please use a kernel appropriate "
154-
"for your CPU.\n");
150+
puts("Unable to boot - please use a kernel appropriate for your CPU.\n");
155151
die();
156152
}
157153

158-
/* Tell the BIOS what CPU mode we intend to run in. */
154+
/* Tell the BIOS what CPU mode we intend to run in */
159155
set_bios_mode();
160156

161157
/* Detect memory layout */

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)