From: Michael Prokop <mika@grml.org>
To: linux-kernel@vger.kernel.org
Cc: Dan Moulding <dmoulding@me.com>, Michael Prokop <mika@grml.org>
Subject: [PATCH 1/1] init/version.c: fix NULL pointer dereference on bare "hostname" param
Date: Thu, 3 Sep 2026 20:20:29 +0200 [thread overview]
Message-ID: <20260903182029.3329686-1-mika@grml.org> (raw)
early_hostname() passes its "arg" parameter straight to strscpy()
without checking it for NULL. As a result, a bare "hostname" (no
"=value") on the kernel command line calls early_hostname(NULL),
which dereferences a NULL pointer.
This happens during parse_early_param(), before console_init(), so the
kernel oopses with no visible output on the usual boot console and the
system fails to boot.
STR:
make x86_64_defconfig
./scripts/kconfig/merge_config.sh -m .config kernel/configs/kvm_guest.config
make olddefconfig
make bzImage
qemu-system-x86_64 -kernel arch/x86/boot/bzImage \
-nographic -no-reboot -m 512M -append \
"earlyprintk=ttyS0 earlycon=uart8250,io,0x3f8,115200n8 ignore_loglevel console=ttyS0 hostname"
Resulting in:
[ 0.000000] CR2: 0000000000000000 CR3: 0000000010d82000 CR4: 00000000000000b0
[ 0.000000] Call Trace:
[ 0.000000] Call Trace:
[ 0.000000] <TASK>
[ 0.000000] <TASK>
[ 0.000000] ? early_hostname+0x18/0x40
[ 0.000000] ? early_hostname+0x18/0x40
[ 0.000000] ? do_early_param+0x3f/0x70
[ 0.000000] ? do_early_param+0x3f/0x70
[ 0.000000] ? parse_args+0x15d/0x3c0
[ 0.000000] ? parse_args+0x15d/0x3c0
[ 0.000000] ? __pfx_do_early_param+0x10/0x10
[ 0.000000] ? __pfx_do_early_param+0x10/0x10
[ 0.000000] ? parse_early_options+0x24/0x30
[ 0.000000] ? parse_early_options+0x24/0x30
[ 0.000000] ? __pfx_do_early_param+0x10/0x10
[ 0.000000] ? __pfx_do_early_param+0x10/0x10
[ 0.000000] ? parse_early_param+0x31/0x80
[ 0.000000] ? parse_early_param+0x31/0x80
[ 0.000000] ? setup_arch+0x46b/0xab0
[ 0.000000] ? setup_arch+0x46b/0xab0
[ 0.000000] ? _printk+0x66/0x80
[ 0.000000] ? _printk+0x66/0x80
[ 0.000000] ? start_kernel+0x58/0x780
[ 0.000000] ? start_kernel+0x58/0x780
[ 0.000000] ? x86_64_start_reservations+0x24/0x30
[ 0.000000] ? x86_64_start_reservations+0x24/0x30
[ 0.000000] ? x86_64_start_kernel+0xce/0xd0
[ 0.000000] ? x86_64_start_kernel+0xce/0xd0
[ 0.000000] ? common_startup_64+0x13e/0x158
[ 0.000000] ? common_startup_64+0x13e/0x158
[ 0.000000] </TASK>
[ 0.000000] </TASK>
Fixes: 5a704629f2c1 ("init: add "hostname" kernel parameter")
Signed-off-by: Michael Prokop <mika@grml.org>
---
init/version.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/init/version.c b/init/version.c
index 94c96f6fbfe6..0bd5c45aabc4 100644
--- a/init/version.c
+++ b/init/version.c
@@ -23,6 +23,9 @@ static int __init early_hostname(char *arg)
size_t maxlen = bufsize - 1;
ssize_t arglen;
+ if (!arg)
+ return -EINVAL;
+
arglen = strscpy(init_uts_ns.name.nodename, arg, bufsize);
if (arglen < 0) {
pr_warn("hostname parameter exceeds %zd characters and will be truncated",
--
2.50.1
reply other threads:[~2026-09-03 18:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260903182029.3329686-1-mika@grml.org \
--to=mika@grml.org \
--cc=dmoulding@me.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®