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

Configure Feed

Select the types of activity you want to include in your feed.

init/main: read bootconfig header with get_unaligned_le32()

get_boot_config_from_initrd() scans up to 3 bytes before initrd_end to
handle GRUB 4-byte alignment. As a result, the bootconfig header
immediately preceding the magic may be unaligned.

Read the size and checksum fields with get_unaligned_le32() instead of
casting to u32 * and using le32_to_cpu(), avoiding potential unaligned
access and silencing sparse "cast to restricted __le32" warnings.

Sparse warnings (gcc + C=1):
init/main.c:292:16: warning: cast to restricted __le32
init/main.c:293:16: warning: cast to restricted __le32

No functional change intended.

Link: https://lkml.kernel.org/r/20260113101532.1630770-1-sun.jian.kdev@gmail.com
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sun Jian and committed by
Andrew Morton
499f86de a906f3ae

+5 -4
+5 -4
init/main.c
··· 104 104 #include <linux/pidfs.h> 105 105 #include <linux/ptdump.h> 106 106 #include <linux/time_namespace.h> 107 + #include <linux/unaligned.h> 107 108 #include <net/net_namespace.h> 108 109 109 110 #include <asm/io.h> ··· 271 270 { 272 271 u32 size, csum; 273 272 char *data; 274 - u32 *hdr; 273 + u8 *hdr; 275 274 int i; 276 275 277 276 if (!initrd_end) ··· 290 289 return NULL; 291 290 292 291 found: 293 - hdr = (u32 *)(data - 8); 294 - size = le32_to_cpu(hdr[0]); 295 - csum = le32_to_cpu(hdr[1]); 292 + hdr = (u8 *)(data - 8); 293 + size = get_unaligned_le32(hdr); 294 + csum = get_unaligned_le32(hdr + 4); 296 295 297 296 data = ((void *)hdr) - size; 298 297 if ((unsigned long)data < initrd_start) {