diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2023-06-29 13:31:19 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-06-29 23:20:41 +0200 |
commit | 06afda6b38d5d730fca3c65449096425933272bc (patch) | |
tree | 96f70dc16336d4671dae06de1bf0e669ee1eddd7 | |
parent | udev-builtin-net_id: align VF representor names with VF names (diff) | |
download | systemd-06afda6b38d5d730fca3c65449096425933272bc.tar.xz systemd-06afda6b38d5d730fca3c65449096425933272bc.zip |
core: reorder systemd arguments on reexec
When reexecuting system let's put our arguments carrying deserialization
info first followed by any existing arguments to make sure they get
parsed in case we get weird stuff from the kernel cmdline (like --).
See: https://github.com/systemd/systemd/issues/28184
-rw-r--r-- | src/core/main.c | 6 | ||||
-rwxr-xr-x | test/TEST-01-BASIC/test.sh | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/core/main.c b/src/core/main.c index 208d22f4f3..3f78f035d0 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1860,12 +1860,16 @@ static int do_reexecute( xsprintf(sfd, "--deserialize=%i", fileno(arg_serialization)); i = 1; /* Leave args[0] empty for now. */ - filter_args(args, &i, argv, argc); + /* Put our stuff first to make sure it always gets parsed in case + * we get weird stuff from the kernel cmdline (like --) */ if (IN_SET(objective, MANAGER_SWITCH_ROOT, MANAGER_SOFT_REBOOT)) args[i++] = "--switched-root"; args[i++] = runtime_scope_cmdline_option_to_string(arg_runtime_scope); args[i++] = sfd; + + filter_args(args, &i, argv, argc); + args[i++] = NULL; assert(i <= args_size); diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index cc6d0651c1..d0e714ac30 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -8,6 +8,11 @@ RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes} TEST_REQUIRE_INSTALL_TESTS=0 TEST_SUPPORTING_SERVICES_SHOULD_BE_MASKED=0 +# Check if we can correctly deserialize if the kernel cmdline contains "weird" stuff +# like an invalid argument, "end of arguments" separator, or a sysvinit argument (-z) +# See: https://github.com/systemd/systemd/issues/28184 +KERNEL_APPEND="foo -- -z bar --- baz $KERNEL_APPEND" + # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" |