x86, boot: access cmdline when loaded high
PATCH 1/1 x86, boot: access cmdline when loaded high
The __cmdline_find_option routine requires that the kernel cmdline be located under 0x10000. When running the compressed boot code, if the cmdline is loaded above this range, it will be ignored. This breaks recognition of things like "earlyprintk=...". Since the compressed boot code is already tricking the cmdline routines about locations, take it all the way and access the cmdline via offset instead of via actual location.
--- arch/x86/boot/compressed/cmdline.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
arch/x86/boot/compressed/cmdline.c +9 -12
@@ -2,32 +2,29 @@#ifdef CONFIG_EARLY_PRINTK +/* +* We know where the cmdline is, so just retain it, and use a non-zero +* offset to trick __cmdline_find_option into running. +*/ static unsigned long fs;static inline void set_fs (unsigned long seg) { - fs = seg <<4 ;/* shift it back */ + fs = real_mode->hdr.cmd_line_ptr; + fs |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; }typedef unsigned long addr_t ;static inline char rdfs8 (addr_t addr) { -return *((char *)(fs + addr)); +return *((char *)(fs + addr -0x1 )); }#include "../cmdline.c" -static unsigned long get_cmd_line_ptr (void ) -{ -unsigned long cmd_line_ptr = real_mode->hdr.cmd_line_ptr; - - cmd_line_ptr |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; - -return cmd_line_ptr; -}int cmdline_find_option (const char *option,char *buffer,int bufsize) { -return __cmdline_find_option (get_cmd_line_ptr (), option, buffer, bufsize); +return __cmdline_find_option (0x1 , option, buffer, bufsize); }int cmdline_find_option_bool (const char *option) { -return __cmdline_find_option_bool (get_cmd_line_ptr (), option); +return __cmdline_find_option_bool (0x1 , option); }#endif
Signature · 6 lines
1.7.9.5 -- Kees Cook Chrome OS Security
Quoted 6 lines · Kees Cook
The
__cmdline_find_optionroutine requires that the kernel cmdline be located under0x10000. When running the compressed boot code, if the cmdline is loaded above this range, it will be ignored. This breaks recognition of things like "earlyprintk=...". Since the compressed boot code is already tricking the cmdline routines about locations, take it all the way and access the cmdline via offset instead of via actual location.
Hi,
What is point of the patch?
It looks like it try to fix one bug, but it doesn't, as there is no bug out there.
Before the patch, command line that is loaded high
can be processed correctly in arch/x86/boot/compressed/cmdline.c.
Quoted 34 lines
Signed-off-by Kees Cook <[email protected]>--- arch/x86/boot/compressed/cmdline.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)arch/x86/boot/compressed/cmdline.c +7
-4@@ -2,32 +2,29 @@#ifdef CONFIG_EARLY_PRINTK +/* +* We know where the cmdline is, so just retain it, and use a non-zero +* offset to trick __cmdline_find_option into running. +*/ static unsigned long fs;static inline void set_fs (unsigned long seg) { - fs = seg <<4 ;/* shift it back */ + fs = real_mode->hdr.cmd_line_ptr; + fs |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; }typedef unsigned long addr_t ;static inline char rdfs8 (addr_t addr) { -return *((char *)(fs + addr)); +return *((char *)(fs + addr -0x1 )); }#include "../cmdline.c" -static unsigned long get_cmd_line_ptr (void ) -{
arch/x86/boot/compressed/cmdline.c line 23
Quoted 10 lines
arch/x86/boot/compressed/cmdline.c +1
-7-unsigned long cmd_line_ptr = real_mode->hdr.cmd_line_ptr; - - cmd_line_ptr |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; - -return cmd_line_ptr; -}int cmdline_find_option (const char *option,char *buffer,int bufsize) { -return __cmdline_find_option (get_cmd_line_ptr (), option, buffer, bufsize); +return __cmdline_find_option (0x1 , option, buffer, bufsize);
that's funny, why do you pick 0x1 here?
why not use 0x10 or 0?
Quoted 20 lines
arch/x86/boot/compressed/cmdline.c +1
-2}int cmdline_find_option_bool (const char *option) { -return __cmdline_find_option_bool (get_cmd_line_ptr (), option); +return __cmdline_find_option_bool (0x1 , option); }#endif --1.7.9.5
--
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 8 lines · Yinghai Lu
Quoted 6 lines · Kees Cook
The
__cmdline_find_optionroutine requires that the kernel cmdline be located under0x10000. When running the compressed boot code, if the cmdline is loaded above this range, it will be ignored. This breaks recognition of things like "earlyprintk=...". Since the compressed boot code is already tricking the cmdline routines about locations, take it all the way and access the cmdline via offset instead of via actual location.
Quoted 8 lines
Hi,
What is point of the patch?
It looks like it try to fix one bug, but it doesn't, as there is no bug out there.Before the patch, command line that is loaded high
can be processed correctly inarch/x86/boot/compressed/cmdline.c.
It can't. Here is the code from arch/x86/boot/cmdline.c:
int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize)
...
if (!cmdline_ptr)
return -1; /* No command line */
cptr = cmdline_ptr & 0xf;
set_fs(cmdline_ptr >> 4);
while (cptr < 0x10000 && (c = rdfs8(cptr++))) {This means that if get_cmd_line_ptr() returns an address >= 0x10000, __cmdline_find_option will simply ignore the cmdline.
Quoted 38 lines
Quoted 38 lines
Signed-off-by Kees Cook <[email protected]>--- arch/x86/boot/compressed/cmdline.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)arch/x86/boot/compressed/cmdline.c +7
-9@@ -2,32 +2,29 @@#ifdef CONFIG_EARLY_PRINTK +/* +* We know where the cmdline is, so just retain it, and use a non-zero +* offset to trick __cmdline_find_option into running. +*/ static unsigned long fs;static inline void set_fs (unsigned long seg) { - fs = seg <<4 ;/* shift it back */ + fs = real_mode->hdr.cmd_line_ptr; + fs |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; }typedef unsigned long addr_t ;static inline char rdfs8 (addr_t addr) { -return *((char *)(fs + addr)); +return *((char *)(fs + addr -0x1 )); }#include "../cmdline.c" -static unsigned long get_cmd_line_ptr (void ) -{ -unsigned long cmd_line_ptr = real_mode->hdr.cmd_line_ptr; - - cmd_line_ptr |= (u64 )real_mode->ext_cmd_line_ptr <<32 ; - -return cmd_line_ptr;
Quoted 8 lines
arch/x86/boot/compressed/cmdline.c line 23
Quoted 5 lines
arch/x86/boot/compressed/cmdline.c +1
-2-}int cmdline_find_option (const char *option,char *buffer,int bufsize) { -return __cmdline_find_option (get_cmd_line_ptr (), option, buffer, bufsize); +return __cmdline_find_option (0x1 , option, buffer, bufsize);that's funny, why do you pick
0x1here?
why not use0x10or 0?
0 cannot be used because of the !cmdline_ptr test in __cmdline_find_option. There is no reason it's 1, except that it's the further possible from 0x10000 without being 0.
-Kees
Quoted 13 lines
Quoted 13 lines
arch/x86/boot/compressed/cmdline.c +1
-2}int cmdline_find_option_bool (const char *option) { -return __cmdline_find_option_bool (get_cmd_line_ptr (), option); +return __cmdline_find_option_bool (0x1 , option); }#endif --1.7.9.5
Quoted 8 lines
Quoted 8 lines
--
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
Kees Cook
Chrome OS Security
Quoted 11 lines · Kees Cook
Quoted 10 lines · Yinghai Lu
Quoted 6 lines · Kees Cook
The
__cmdline_find_optionroutine requires that the kernel cmdline be located under0x10000. When running the compressed boot code, if the cmdline is loaded above this range, it will be ignored. This breaks recognition of things like "earlyprintk=...". Since the compressed boot code is already tricking the cmdline routines about locations, take it all the way and access the cmdline via offset instead of via actual location.Hi,
Quoted 8 lines
Quoted 6 lines
What is point of the patch?
It looks like it try to fix one bug, but it doesn't, as there is no bug out there.Before the patch, command line that is loaded high
can be processed correctly inarch/x86/boot/compressed/cmdline.c.It can't. Here is the code from
arch/x86/boot/cmdline.c:
Are you sure?
I tested that with kexec loaded second kernel high.
How do you test that?
Quoted 13 lines
int
__cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize)
...if (!cmdline_ptr) return -1; /* No command line */ cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000 && (c = rdfs8(cptr++))) {
Quoted 2 lines
This means that if
get_cmd_line_ptr()returns an address >=0x10000,__cmdline_find_optionwill simply ignore the cmdline.
No, you read the code wrong. you miss the
cptr = cmdline_ptr & 0xf;
Yinghai
Quoted 11 lines · Yinghai Lu
Quoted 5 lines
Quoted 3 lines
Before the patch, command line that is loaded high
can be processed correctly inarch/x86/boot/compressed/cmdline.c.It can't. Here is the code from
arch/x86/boot/cmdline.c:Are you sure?
I tested that with kexec loaded second kernel high.
How do you test that?
double checked, it works already:
10:~/k # sh kkadd_buffer: base:11fff6000 bufsz:80e0 memsz:a000add_buffer: base:11fff0000 bufsz:44ce memsz:44ceadd_buffer: base:11d000000 bufsz:9084f0 memsz:2c43000add_buffer: base:11acef000 bufsz:230f6ec memsz:230f6ec
[ 33.551046] cpu0 machine_kexec: fn: ffffffff81076960, data: ffff880116a20000 10:~/k # kexec -d -e [ 52.939049] psmouse serio1: shutdown ... [ 52.965553] Starting new kernel
early console in decompress_kernel ============> from misc.cdecompress_kernel:
input: [0x11ea902c2-0x11f390ba1], output: 0x11d000000, heap:
[0x11f398500-0x11f3a04ff] ============>
from misc.c
Decompressing Linux... xz... Parsing ELF... done. ========> from misc.c
Booting the kernel.
[ 0.000000] real_mode_data : phys 000000011fff0000 [ 0.000000] real_mode_data : virt ffff88011fff0000 [ 0.000000] boot_params : init virt ffffffff82f839a0 [ 0.000000] boot_params : phys 000000011ef839a0 [ 0.000000] boot_params : virt ffff88011ef839a0 [ 0.000000] boot_command_line : init virt ffffffff82e51020 [ 0.000000] boot_command_line : phys 000000011ee51020 ===> is high ? [ 0.000000] boot_command_line : virt ffff88011ee51020 [ 0.000000] Kernel Layout: [ 0.000000] .text: [0x11d000000-0x11e0ae480] [ 0.000000] .rodata: [0x11e200000-0x11e9cefff] [ 0.000000] .data: [0x11ea00000-0x11ebd3fbf] [ 0.000000] .init: [0x11ebd5000-0x11ef6efff] [ 0.000000] .bss: [0x11ef7d000-0x11fc1dfff] [ 0.000000] .brk: [0x11fc1e000-0x11fc42fff] [ 0.000000] memblock_reserve: [0x0009f000-0x000fffff] * BIOS reserved [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct [ 0.000000] Linux version 3.10.0-rc5-yh-00864-g9cca511-dirty ([email protected]) (gcc version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (SUSE Linux) ) #1732 SMP Tue Jun 11 13:47:35 PDT 2013 [ 0.000000] memblock_reserve: [0x11d000000-0x11fc1dfff] TEXT DATA BSS [ 0.000000] memblock_reserve: [0x11acef000-0x11cffefff] RAMDISK [ 0.000000] Command line: initcall_debug pci=routeirq debug
ignore_loglevel apic=debug ramdisk_size=262144 root=/dev/ram0 rw ip=dhcp console=uart8250,io,0x3f8,115200n8
Quoted 40 lines · Yinghai Lu
Quoted 11 lines · Kees Cook
Quoted 10 lines · Yinghai Lu
Quoted 6 lines · Kees Cook
The
__cmdline_find_optionroutine requires that the kernel cmdline be located under0x10000. When running the compressed boot code, if the cmdline is loaded above this range, it will be ignored. This breaks recognition of things like "earlyprintk=...". Since the compressed boot code is already tricking the cmdline routines about locations, take it all the way and access the cmdline via offset instead of via actual location.Hi,
Quoted 8 lines
Quoted 6 lines
What is point of the patch?
It looks like it try to fix one bug, but it doesn't, as there is no bug out there.Before the patch, command line that is loaded high
can be processed correctly inarch/x86/boot/compressed/cmdline.c.It can't. Here is the code from
arch/x86/boot/cmdline.c:Are you sure?
I tested that with kexec loaded second kernel high.
How do you test that?
Quoted 13 lines
int
__cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize)
...if (!cmdline_ptr) return -1; /* No command line */ cptr = cmdline_ptr & 0xf; set_fs(cmdline_ptr >> 4); while (cptr < 0x10000 && (c = rdfs8(cptr++))) {
Quoted 6 lines
Quoted 2 lines
This means that if
get_cmd_line_ptr()returns an address >=0x10000,__cmdline_find_optionwill simply ignore the cmdline.No, you read the code wrong. you miss the
cptr =
cmdline_ptr&0xf;
Ah-ha! I see what I missed. I didn't notice 16a4baa6 which did this:
- if (!cmdline_ptr || cmdline_ptr >= 0x100000)
- return -1; /* No command line, or inaccessible */
+ if (!cmdline_ptr)
+ return -1; /* No command line */
That fixes the problem I was seeing. :)
Thanks!
-Kees
--
Kees Cook
Chrome OS Security