Skip to content

Commit a6ae06c

Browse files
mrc0mmandbluca
authored andcommitted
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: systemd/systemd#28184 (cherry picked from commit 06afda6) (cherry picked from commit 884ab38) (cherry picked from commit 163be31)
1 parent d22dffa commit a6ae06c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/core/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,13 +1793,17 @@ static int do_reexecute(
17931793
xsprintf(sfd, "--deserialize=%i", fileno(arg_serialization));
17941794

17951795
i = 1; /* Leave args[0] empty for now. */
1796-
filter_args(args, &i, argv, argc);
17971796

1797+
/* Put our stuff first to make sure it always gets parsed in case
1798+
* we get weird stuff from the kernel cmdline (like --) */
17981799
if (switch_root_dir)
17991800
args[i++] = "--switched-root";
18001801

18011802
args[i++] = arg_system ? "--system" : "--user";
18021803
args[i++] = sfd;
1804+
1805+
filter_args(args, &i, argv, argc);
1806+
18031807
args[i++] = NULL;
18041808

18051809
assert(i <= args_size);

test/TEST-01-BASIC/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ IMAGE_NAME="basic"
77
RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes}
88
TEST_REQUIRE_INSTALL_TESTS=0
99

10+
# Check if we can correctly deserialize if the kernel cmdline contains "weird" stuff
11+
# like an invalid argument, "end of arguments" separator, or a sysvinit argument (-z)
12+
# See: https://github.com/systemd/systemd/issues/28184
13+
KERNEL_APPEND="foo -- -z bar --- baz $KERNEL_APPEND"
14+
1015
# shellcheck source=test/test-functions
1116
. "${TEST_BASE_DIR:?}/test-functions"
1217

0 commit comments

Comments
 (0)