]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: reorder systemd arguments on reexec
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 29 Jun 2023 11:31:19 +0000 (13:31 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 29 Jun 2023 21:20:41 +0000 (22:20 +0100)
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

src/core/main.c
test/TEST-01-BASIC/test.sh

index 208d22f4f329848b7d4825d322eaf953512ed5a2..3f78f035d0e71126e7cb022d1343487b919f3cd6 100644 (file)
@@ -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);
index cc6d0651c145065f57c98ffc2921bec603bcd93b..d0e714ac30f0e42d7a5a3073b93136fd0619e88a 100755 (executable)
@@ -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"