Fix alignment of bootconfig
GRUB may align the init ramdisk size to 4 bytes, the magic number at the end of the init ramdisk that denotes bootconfig is attached may not be at the exact end of the ramdisk. The kernel needs to check back at least 4 bytes. -----BEGIN PGP SIGNATURE----- iIoEABYIADIWIQRRSw7ePDh/lE+zeZMp5XQQmuv6qgUCX66JaxQccm9zdGVkdEBn b29kbWlzLm9yZwAKCRAp5XQQmuv6qpWgAPwKHiHkSIBW2eFblngmknzLZsdmUep/ NAm+FxhQBHryJQEAido2x++mXD0/KVLotpTHQHsZv2xFkEbMZGY/3R2iog4= =Xhnj -----END PGP SIGNATURE----- Merge tag 'trace-v5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace Pull bootconfig fix from Steven Rostedt: "Fix alignment of bootconfig GRUB may align the init ramdisk size to 4 bytes, the magic number at the end of the init ramdisk that denotes bootconfig is attached may not be at the exact end of the ramdisk. The kernel needs to check back at least 4 bytes" * tag 'trace-v5.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: bootconfig: Extend the magic check range to the preceding 3 bytes
This commit is contained in:
commit
6186313d06
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;
|
||||
char *data;
|
||||
u32 *hdr;
|
||||
int i;
|
||||
|
||||
if (!initrd_end)
|
||||
return NULL;
|
||||
|
||||
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);
|
||||
size = hdr[0];
|
||||
csum = hdr[1];
|
||||
|
Loading…
Reference in New Issue
Block a user