Skip to contentSkip to conversation

FAILED: patch "[PATCH] init: fix early boot crash with bare hostname parameter" failed to apply to 6.1-stable tree

PATCH New Sasha Levin 1 participant 3 messages Nov 7 – Nov 10 Stable branch

lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x b6bec5b63a5b812145e53aaad1e63661c7214f93
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From b6bec5b63a5b812145e53aaad1e63661c7214f93 Mon Sep 17 00:00:00 2001
From: Thorsten Blum <[email protected]>
Date: Wed, 26 Aug 2026 12:09:03 +0200
Subject: [PATCH] init: fix early boot crash with bare hostname parameter

When a bare hostname parameter is specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to early_hostname(), which dereferences it in strscpy() and can crash the system during early boot.

Reject NULL values in early_hostname() and return -EINVAL instead.

Fixes 5a704629f2c1 ("init: add "hostname" kernel parameter")
Cc Dan Moulding <[email protected]>
---
 init/version.c | 3 +++
 1 file changed, 3 insertions(+)
init/version.c +3 -0
index 94c96f6fbfe6a..0bd5c45aabc46 100644
@@ -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",
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/2 init/version.c: Replace strlcpy with strscpy

From: Azeem Shaikh <[email protected]>

[ Upstream commit 8ebab155ea18a6d6c47b17287a0ab4633334f6eb ]

strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy().

Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest).

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Stable-dep-of: b6bec5b63a5b ("init: fix early boot crash with bare hostname parameter")

---
 init/version.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
init/version.c +3 -3
index 01d4ab05f0bac..221ccede8902a 100644
@@ -22,10 +22,10 @@ static int __init early_hostname(char *arg)
 {
 	size_t bufsize = sizeof(init_uts_ns.name.nodename);
 	size_t maxlen  = bufsize - 1;
-	size_t arglen;
+	ssize_t arglen;
 
-	arglen = strlcpy(init_uts_ns.name.nodename, arg, bufsize);
-	if (arglen > maxlen) {
+	arglen = strscpy(init_uts_ns.name.nodename, arg, bufsize);
+	if (arglen < 0) {
 		pr_warn("hostname parameter exceeds %zd characters and will be truncated",
 			maxlen);
 	}
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH 2/2 init: fix early boot crash with bare hostname parameter

From: Thorsten Blum <[email protected]>

[ Upstream commit b6bec5b63a5b812145e53aaad1e63661c7214f93 ]

When a bare hostname parameter is specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to early_hostname(), which dereferences it in strscpy() and can crash the system during early boot.

Reject NULL values in early_hostname() and return -EINVAL instead.

Fixes 5a704629f2c1 ("init: add "hostname" kernel parameter")
Cc Dan Moulding <[email protected]>
---
 init/version.c | 3 +++
 1 file changed, 3 insertions(+)
init/version.c +3 -0
index 221ccede8902a..11cbd3fb60be5 100644
@@ -24,6 +24,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",
Signature · 1 line
2.53.0