Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86, boot: Move checking of cmd_line_ptr out of common path

cmdline.c::__cmdline_find_option... are shared between 16-bit setup code
and 32/64 bit decompressor code.

for 32/64 only path via kexec, we should not check if ptr is less 1M.
as those cmdline could be put above 1M, or even 4G.

Move out accessible checking out of __cmdline_find_option()
So decompressor in misc.c can parse cmdline correctly.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Link: http://lkml.kernel.org/r/1359058816-7615-18-git-send-email-yinghai@kernel.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

authored by

Yinghai Lu and committed by
H. Peter Anvin
16a4baa6 f1da834c

+16 -6
+12 -2
arch/x86/boot/boot.h
··· 289 289 int __cmdline_find_option_bool(u32 cmdline_ptr, const char *option); 290 290 static inline int cmdline_find_option(const char *option, char *buffer, int bufsize) 291 291 { 292 - return __cmdline_find_option(boot_params.hdr.cmd_line_ptr, option, buffer, bufsize); 292 + u32 cmd_line_ptr = boot_params.hdr.cmd_line_ptr; 293 + 294 + if (cmd_line_ptr >= 0x100000) 295 + return -1; /* inaccessible */ 296 + 297 + return __cmdline_find_option(cmd_line_ptr, option, buffer, bufsize); 293 298 } 294 299 295 300 static inline int cmdline_find_option_bool(const char *option) 296 301 { 297 - return __cmdline_find_option_bool(boot_params.hdr.cmd_line_ptr, option); 302 + u32 cmd_line_ptr = boot_params.hdr.cmd_line_ptr; 303 + 304 + if (cmd_line_ptr >= 0x100000) 305 + return -1; /* inaccessible */ 306 + 307 + return __cmdline_find_option_bool(cmd_line_ptr, option); 298 308 } 299 309 300 310
+4 -4
arch/x86/boot/cmdline.c
··· 41 41 st_bufcpy /* Copying this to buffer */ 42 42 } state = st_wordstart; 43 43 44 - if (!cmdline_ptr || cmdline_ptr >= 0x100000) 45 - return -1; /* No command line, or inaccessible */ 44 + if (!cmdline_ptr) 45 + return -1; /* No command line */ 46 46 47 47 cptr = cmdline_ptr & 0xf; 48 48 set_fs(cmdline_ptr >> 4); ··· 111 111 st_wordskip, /* Miscompare, skip */ 112 112 } state = st_wordstart; 113 113 114 - if (!cmdline_ptr || cmdline_ptr >= 0x100000) 115 - return -1; /* No command line, or inaccessible */ 114 + if (!cmdline_ptr) 115 + return -1; /* No command line */ 116 116 117 117 cptr = cmdline_ptr & 0xf; 118 118 set_fs(cmdline_ptr >> 4);