* [PATCH V2] init: Handle bootloader identifier in kernel parameters
@ 2025-07-20 10:55 Huacai Chen
2025-07-20 11:10 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Huacai Chen @ 2025-07-20 10:55 UTC (permalink / raw)
To: Huacai Chen, Andrew Morton
Cc: linux-mm, Alexander Viro, Christian Brauner, Jan Kara,
linux-kernel, Huacai Chen, stable
BootLoader (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 user space. However
user space init program also doesn't recognized it.
KEXEC 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.
Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
V2: Update comments and commit messages.
init/main.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/init/main.c b/init/main.c
index 225a58279acd..c53863e5ad82 100644
--- a/init/main.c
+++ b/init/main.c
@@ -545,6 +545,7 @@ static int __init unknown_bootoption(char *param, char *val,
const char *unused, void *arg)
{
size_t len = strlen(param);
+ const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
/* Handle params aliased to sysctls */
if (sysctl_is_alias(param))
@@ -552,6 +553,12 @@ static int __init unknown_bootoption(char *param, char *val,
repair_env_string(param, val);
+ /* Handle bootloader identifier */
+ for (int i = 0; bootloader[i]; i++) {
+ if (!strncmp(param, bootloader[i], strlen(bootloader[i])))
+ return 0;
+ }
+
/* Handle obsolete-style parameters */
if (obsolete_checksetup(param))
return 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V2] init: Handle bootloader identifier in kernel parameters
2025-07-20 10:55 [PATCH V2] init: Handle bootloader identifier in kernel parameters Huacai Chen
@ 2025-07-20 11:10 ` Greg KH
2025-07-21 10:10 ` Huacai Chen
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2025-07-20 11:10 UTC (permalink / raw)
To: Huacai Chen
Cc: Huacai Chen, Andrew Morton, linux-mm, Alexander Viro,
Christian Brauner, Jan Kara, linux-kernel, stable
On Sun, Jul 20, 2025 at 06:55:09PM +0800, Huacai Chen wrote:
> BootLoader (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 user space. However
> user space init program also doesn't recognized it.
>
> KEXEC 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.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> V2: Update comments and commit messages.
>
> init/main.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/init/main.c b/init/main.c
> index 225a58279acd..c53863e5ad82 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -545,6 +545,7 @@ static int __init unknown_bootoption(char *param, char *val,
> const char *unused, void *arg)
> {
> size_t len = strlen(param);
> + const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
Where is this magic set of values now documented? Each of these need to
be strongly documented as to why we are ignoring them and who is adding
them and why they can't be fixed for whatever reason.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] init: Handle bootloader identifier in kernel parameters
2025-07-20 11:10 ` Greg KH
@ 2025-07-21 10:10 ` Huacai Chen
0 siblings, 0 replies; 3+ messages in thread
From: Huacai Chen @ 2025-07-21 10:10 UTC (permalink / raw)
To: Greg KH
Cc: Huacai Chen, Andrew Morton, linux-mm, Alexander Viro,
Christian Brauner, Jan Kara, linux-kernel, stable
On Sun, Jul 20, 2025 at 7:10 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Sun, Jul 20, 2025 at 06:55:09PM +0800, Huacai Chen wrote:
> > BootLoader (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 user space. However
> > user space init program also doesn't recognized it.
> >
> > KEXEC 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.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> > V2: Update comments and commit messages.
> >
> > init/main.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/init/main.c b/init/main.c
> > index 225a58279acd..c53863e5ad82 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -545,6 +545,7 @@ static int __init unknown_bootoption(char *param, char *val,
> > const char *unused, void *arg)
> > {
> > size_t len = strlen(param);
> > + const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
>
> Where is this magic set of values now documented? Each of these need to
> be strongly documented as to why we are ignoring them and who is adding
> them and why they can't be fixed for whatever reason.
OK, will do.
Huacai
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-21 10:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20 10:55 [PATCH V2] init: Handle bootloader identifier in kernel parameters Huacai Chen
2025-07-20 11:10 ` Greg KH
2025-07-21 10:10 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).