From e66630c1927cdb2061523b06694d10710c875e8d Mon Sep 17 00:00:00 2001 From: Andrew Lukoshko Date: Thu, 17 Oct 2024 10:21:44 +0000 Subject: [PATCH] core: reorder systemd arguments on reexec --- ...-reorder-systemd-arguments-on-reexec.patch | 57 +++++++++++++++++++ SPECS/systemd.spec | 6 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 SOURCES/9000-core-reorder-systemd-arguments-on-reexec.patch diff --git a/SOURCES/9000-core-reorder-systemd-arguments-on-reexec.patch b/SOURCES/9000-core-reorder-systemd-arguments-on-reexec.patch new file mode 100644 index 0000000..8db7c01 --- /dev/null +++ b/SOURCES/9000-core-reorder-systemd-arguments-on-reexec.patch @@ -0,0 +1,57 @@ +From dcc55e1b0930c6db277e87b8a521e82f3d0f74c3 Mon Sep 17 00:00:00 2001 +From: Andrew Lukoshko +Date: Thu, 17 Oct 2024 10:19:25 +0000 +Subject: [PATCH] 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 +--- + src/core/main.c | 6 +++++- + test/TEST-01-BASIC/test.sh | 5 +++++ + 2 files changed, 10 insertions(+), 1 deletion(-) + +diff --git a/src/core/main.c b/src/core/main.c +index e7b8e98..6df29f3 100644 +--- a/src/core/main.c ++++ b/src/core/main.c +@@ -1813,13 +1813,17 @@ static int do_reexecute( + xsprintf(sfd, "%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 (switch_root_dir) + args[i++] = "--switched-root"; + args[i++] = arg_system ? "--system" : "--user"; + args[i++] = "--deserialize"; + 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 cc6d065..d0e714a 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" + +-- +2.43.5 + diff --git a/SPECS/systemd.spec b/SPECS/systemd.spec index 03e3aab..c2d3946 100644 --- a/SPECS/systemd.spec +++ b/SPECS/systemd.spec @@ -823,6 +823,7 @@ Patch0731: 0731-bootspec-fix-null-dereference-read.patch Patch0732: 0732-generator-uninline-generator_open_unit_file-and-gene.patch # Downstream-only patches (9000–9999) +Patch9000: 9000-core-reorder-systemd-arguments-on-reexec.patch %ifarch %{ix86} x86_64 aarch64 %global have_gnu_efi 1 @@ -1700,6 +1701,9 @@ systemd-hwdb update &>/dev/null || : %{_prefix}/lib/dracut/modules.d/70rhel-net-naming-sysattrs/* %changelog +* Thu Oct 17 2024 Andrew Lukoshko - 252-32.7.alma.1 +- core: reorder systemd arguments on reexec + * Thu Jul 18 2024 systemd maintenance team - 252-32.7 - generator: "uninline" generator_open_unit_file and generator_add_symlink (RHEL-49495) @@ -1732,7 +1736,7 @@ systemd-hwdb update &>/dev/null || : * Thu Apr 11 2024 systemd maintenance team - 252-32.1 - execute: Pass AT_FDCWD instead of -1 (RHEL-32259) -* Tue Apr 30 2024 Andrew Lukoshko - 252-32.alma.1 +* Mon Mar 18 2024 Andrew Lukoshko - 252-32.alma.1 - Debrand for AlmaLinux * Mon Mar 18 2024 Jan Macku - 252-32