[PATCH 2/2] init/main: fix false-positive kernel panic on environment variable overwrite
From: Wilson Felipe Pereira
Date: Tue Aug 18 2026 - 00:55:15 EST
In unknown_bootoption(), the limit checking for environment variables
sets panic_later *before* checking if the variable already exists in
envp_init.
If a user passes exactly MAX_INIT_ENVS custom variables and then
overwrites the final variable by matching its key, it causes a
false-positive hard panic on boot despite not actually exceeding the
array bounds or increasing the total variable count.
Swapping the order of these checks allows the duplicate check to
break out of the loop before the panic flag is erroneously latched.
To verify, boot a VM with 31 custom variables (filling the array up to its
limit of 32) and then overwrite the very last variable:
ENV_VARS=$(for i in {1..31}; do echo -n "var$i=$i "; done)
qemu-system-x86_64 -kernel bzImage -append "$ENV_VARS var31=overwrite"
Without this patch, the kernel crashes instantly with:
Kernel panic - not syncing: Too many boot env vars at 'var31=overwrite'
With this patch, the kernel safely overwrites the variable and boots.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Wilson Felipe Pereira <wfelipe@xxxxxxxxxx>
---
init/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/init/main.c b/init/main.c
index f02041a42111..577ae30570e0 100644
--- a/init/main.c
+++ b/init/main.c
@@ -539,12 +539,12 @@ static int __init unknown_bootoption(char *param, char *val,
/* Environment option */
unsigned int i;
for (i = 0; envp_init[i]; i++) {
+ if (!strncmp(param, envp_init[i], len+1))
+ break;
if (i == MAX_INIT_ENVS) {
panic_later = "env";
panic_param = param;
}
- if (!strncmp(param, envp_init[i], len+1))
- break;
}
envp_init[i] = param;
} else {
--
2.55.0.699.gb54405d56f-goog