Skip to content

Commit e416f0e

Browse files
chenhuacaiakpm00
authored andcommitted
init: handle bootloader identifier in kernel parameters
BootLoaders (Grub, LILO, etc) may pass an identifier such as "BOOT_IMAGE= /boot/vmlinuz-x.y.z" to kernel parameters. But these identifiers are not recognized by the kernel itself so will be passed to userspace. However user space init program also don't recognize it. KEXEC/KDUMP (kexec-tools) may also pass an identifier such as "kexec" on some architectures. We cannot change BootLoader's behavior, because this behavior exists for many years, and there are already user space programs search BOOT_IMAGE= in /proc/cmdline to obtain the kernel image locations: https://github.com/linuxdeepin/deepin-ab-recovery/blob/master/util.go (search getBootOptions) https://github.com/linuxdeepin/deepin-ab-recovery/blob/master/main.go (search getKernelReleaseWithBootOption) So the the best way is handle (ignore) it by the kernel itself, which can avoid such boot warnings (if we use something like init=/bin/bash, bootloader identifier can even cause a crash): Kernel command line: BOOT_IMAGE=(hd0,1)/vmlinuz-6.x root=/dev/sda3 ro console=tty Unknown kernel command line parameters "BOOT_IMAGE=(hd0,1)/vmlinuz-6.x", will be passed to user space. [[email protected]: use strstarts()] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Huacai Chen <[email protected]> Cc: Al Viro <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Jan Kara <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ca78a04 commit e416f0e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

init/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,25 @@ static int __init unknown_bootoption(char *param, char *val,
544544
const char *unused, void *arg)
545545
{
546546
size_t len = strlen(param);
547+
/*
548+
* Well-known bootloader identifiers:
549+
* 1. LILO/Grub pass "BOOT_IMAGE=...";
550+
* 2. kexec/kdump (kexec-tools) pass "kexec".
551+
*/
552+
const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
547553

548554
/* Handle params aliased to sysctls */
549555
if (sysctl_is_alias(param))
550556
return 0;
551557

552558
repair_env_string(param, val);
553559

560+
/* Handle bootloader identifier */
561+
for (int i = 0; bootloader[i]; i++) {
562+
if (strstarts(param, bootloader[i]))
563+
return 0;
564+
}
565+
554566
/* Handle obsolete-style parameters */
555567
if (obsolete_checksetup(param))
556568
return 0;

0 commit comments

Comments
 (0)