mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-24 17:23:25 -05:00
bootconfig: Extend the magic check range to the preceding 3 bytes
Since Grub may align the size of initrd to 4 if user pass
initrd from cpio, we have to check the preceding 3 bytes as well.
Link: https://lkml.kernel.org/r/160520205132.303174.4876760192433315429.stgit@devnote2
Cc: stable@vger.kernel.org
Fixes: 85c46b78da
("bootconfig: Add bootconfig magic word for indicating bootconfig explicitly")
Reported-by: Chen Yu <yu.chen.surf@gmail.com>
Tested-by: Chen Yu <yu.chen.surf@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
This commit is contained in:
parent
645f224e7b
commit
50b8a74285
1 changed files with 12 additions and 2 deletions
14
init/main.c
14
init/main.c
|
@ -269,14 +269,24 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
|
||||||
u32 size, csum;
|
u32 size, csum;
|
||||||
char *data;
|
char *data;
|
||||||
u32 *hdr;
|
u32 *hdr;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!initrd_end)
|
if (!initrd_end)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
|
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
|
||||||
if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
|
/*
|
||||||
return NULL;
|
* Since Grub may align the size of initrd to 4, we must
|
||||||
|
* check the preceding 3 bytes as well.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
|
||||||
|
goto found;
|
||||||
|
data--;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
found:
|
||||||
hdr = (u32 *)(data - 8);
|
hdr = (u32 *)(data - 8);
|
||||||
size = hdr[0];
|
size = hdr[0];
|
||||||
csum = hdr[1];
|
csum = hdr[1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue