diff options
| author | Wilson Felipe Pereira <wfelipe@google.com> | 2026-08-18 04:53:46 +0000 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-09-13 21:33:30 -0700 |
| commit | eb983ac9e62cd618330340f56bba9d8b2053fd7a (patch) | |
| tree | cf84f1cc01ee49ea7126d488d182a13b66a04c87 /scripts/integer-wrap-ignore.scl | |
| parent | 436ec3b7ee18a197205e9d2510952b7918f1ad6c (diff) | |
| download | linux-next-eb983ac9e62cd618330340f56bba9d8b2053fd7a.tar.gz linux-next-eb983ac9e62cd618330340f56bba9d8b2053fd7a.zip | |
init/main: fix off-by-one in argv_init cleanup
Patch series "init: fix array boundary bugs in boot parameter parsing".
This series fixes two distinct boundary logic edge-case bugs in
`init/main.c` related to parsing boot command-line arguments and
environment variables. Both bugs have been present since the early git
history (Linux-2.6.12-rc2).
1. The first patch fixes an off-by-one error in `init_setup()` where
the final slot of the `argv_init` array was left uncleared. This
allowed a stale kernel parameter to leak into the `init` process's
user-space command line if exactly `MAX_INIT_ARGS` unknown
parameters were passed.
2. The second patch fixes a false-positive kernel panic in
`unknown_bootoption()`. If a user filled the environment variable
array up to its exact limit (32) and then attempted to overwrite
the final variable, the kernel would panic before evaluating
whether it was a harmless duplicate.
Exact QEMU reproduction steps for both edge cases are documented inside
their respective commit descriptions.
This patch (of 2):
When cleaning up argv_init in init_setup() and rdinit_setup(), the loop
terminates one element early due to using '<' instead of '<='. Since
argv_init is sized MAX_INIT_ARGS+2, index MAX_INIT_ARGS is a valid element
that should be cleared to NULL.
If exactly MAX_INIT_ARGS unknown arguments are passed before 'init=', the
uncleared argv_init[MAX_INIT_ARGS] can act as a ghost argument to
/sbin/init or cause a spurious kernel panic when later appended to.
To verify the argument leak, boot a VM into a shell with 32 unknown kernel
arguments, the init parameter, and 31 user arguments:
STALE_ARGS=$(for i in {1..32}; do echo -n "stale$i "; done)
USER_ARGS=$(for i in {1..31}; do echo -n "user$i "; done)
qemu-system-x86_64 -kernel bzImage \
-append "$STALE_ARGS init=/bin/sh $USER_ARGS"
Running `cat /proc/1/cmdline` inside the shell reveals that the 32nd
kernel argument ('stale32') incorrectly leaked into the init process's
command line. This patch zeroes the final slot, cleanly terminating the
array.
Link: https://lore.kernel.org/20260818045357.4123784-1-wfelipe@google.com
Link: https://lore.kernel.org/20260818045357.4123784-2-wfelipe@google.com
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes: ffdfc40976dd ("[PATCH] Add rdinit parameter to pick early userspace init")
Signed-off-by: Wilson Felipe Pereira <wfelipe@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'scripts/integer-wrap-ignore.scl')
0 files changed, 0 insertions, 0 deletions
