Skip to contentSkip to conversation

init: Fix early boot crash with bare hostname parameter

PATCH Applied Thorsten Blum 1 participant 1 message Aug 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 init/version.c | 3 +++
 1 file changed, 3 insertions(+)
init/version.c +3 -0
index 94c96f6fbfe6..0bd5c45aabc4 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",