From 1f94b56cee818068f57debfd78f035edd29f0e61 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2024 17:07:04 +0000 Subject: Partially backport PR #33016 to fix crashes in KDE 6.3.0 --- diff --git a/0001-core-dbus-execute-use-correct-char-for-representing-.patch b/0001-core-dbus-execute-use-correct-char-for-representing-.patch new file mode 100644 index 0000000..005d49f --- /dev/null +++ b/0001-core-dbus-execute-use-correct-char-for-representing-.patch @@ -0,0 +1,26 @@ +From af87bdc6bc0d5b50af87ffd3b5cbd3e7c472dd42 Mon Sep 17 00:00:00 2001 +From: Mike Yuan +Date: Sun, 26 May 2024 00:49:09 +0800 +Subject: [PATCH 1/2] core/dbus-execute: use correct char for representing + WorkingDirectory=home + +--- + src/core/dbus-execute.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c +index e907aa67af..e55fb6ee16 100644 +--- a/src/core/dbus-execute.c ++++ b/src/core/dbus-execute.c +@@ -2755,7 +2755,7 @@ int bus_exec_context_set_transient_property( + c->working_directory_home = is_home; + c->working_directory_missing_ok = missing_ok; + +- unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", c->working_directory_home ? "+" : ASSERT_PTR(c->working_directory)); ++ unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", c->working_directory_home ? "~" : ASSERT_PTR(c->working_directory)); + } + + return 1; +-- +2.45.1 + diff --git a/0002-core-dbus-execute-don-t-trigger-assertion-if-Working.patch b/0002-core-dbus-execute-don-t-trigger-assertion-if-Working.patch new file mode 100644 index 0000000..fc4c89f --- /dev/null +++ b/0002-core-dbus-execute-don-t-trigger-assertion-if-Working.patch @@ -0,0 +1,100 @@ +From 6f8ef80bb3ba5d244a428aee200c168e809a0079 Mon Sep 17 00:00:00 2001 +From: Mike Yuan +Date: Sun, 26 May 2024 00:53:46 +0800 +Subject: [PATCH 2/2] core/dbus-execute: don't trigger assertion if + WorkingDirectory="" or "-" + +Follow-up for 14631951cea807de2d482a430841c604c2040718 + +Before this commit, if WorkingDirectory= is empty or literally "-", +'simplified' is not populated, resulting in the ASSERT_PTR +in unit_write_settingf() below getting triggered. + +Also, do not accept "-", so that the parser is consistent +with load-fragment.c + +Fixes #33015 +--- + src/core/dbus-execute.c | 49 ++++++++++++++++++++++------------------- + 1 file changed, 26 insertions(+), 23 deletions(-) + +diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c +index e55fb6ee16..21c260b26b 100644 +--- a/src/core/dbus-execute.c ++++ b/src/core/dbus-execute.c +@@ -2716,38 +2716,38 @@ int bus_exec_context_set_transient_property( + + } else if (streq(name, "WorkingDirectory")) { + _cleanup_free_ char *simplified = NULL; +- bool missing_ok, is_home; ++ bool missing_ok = false, is_home = false; + const char *s; + + r = sd_bus_message_read(message, "s", &s); + if (r < 0) + return r; + +- if (s[0] == '-') { +- missing_ok = true; +- s++; +- } else +- missing_ok = false; +- +- if (isempty(s)) +- is_home = false; +- else if (streq(s, "~")) +- is_home = true; +- else { +- if (!path_is_absolute(s)) +- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); ++ if (!isempty(s)) { ++ if (s[0] == '-') { ++ missing_ok = true; ++ s++; ++ } + +- r = path_simplify_alloc(s, &simplified); +- if (r < 0) +- return r; ++ if (streq(s, "~")) ++ is_home = true; ++ else { ++ if (!path_is_absolute(s)) ++ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, ++ "WorkingDirectory= expects an absolute path or '~'"); + +- if (!path_is_normalized(simplified)) +- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects a normalized path or '~'"); ++ r = path_simplify_alloc(s, &simplified); ++ if (r < 0) ++ return r; + +- if (path_below_api_vfs(simplified)) +- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= may not be below /proc/, /sys/ or /dev/."); ++ if (!path_is_normalized(simplified)) ++ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, ++ "WorkingDirectory= expects a normalized path or '~'"); + +- is_home = false; ++ if (path_below_api_vfs(simplified)) ++ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, ++ "WorkingDirectory= may not be below /proc/, /sys/ or /dev/"); ++ } + } + + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { +@@ -2755,7 +2755,10 @@ int bus_exec_context_set_transient_property( + c->working_directory_home = is_home; + c->working_directory_missing_ok = missing_ok; + +- unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", c->working_directory_home ? "~" : ASSERT_PTR(c->working_directory)); ++ unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, ++ "WorkingDirectory=%s%s", ++ c->working_directory_missing_ok ? "-" : "", ++ c->working_directory_home ? "~" : strempty(c->working_directory)); + } + + return 1; +-- +2.45.1 + diff --git a/systemd.spec b/systemd.spec index fc07235..6e056ae 100644 --- a/systemd.spec +++ b/systemd.spec @@ -112,6 +112,11 @@ Patch0002: 0001-generator-setup-use-RET_GATHER.patch Patch0003: 0002-exec-util-use-the-stdio-array-of-safe_fork_full-wher.patch Patch0004: 0003-exec-util-make-sure-to-close-all-fds-for-invoked-gen.patch +# Backport part of https://github.com/systemd/systemd/pull/33016 +# to fix a bug that causes crashes in KDE Frameworks 6.3.0 +Patch0005: 0001-core-dbus-execute-use-correct-char-for-representing-.patch +Patch0006: 0002-core-dbus-execute-don-t-trigger-assertion-if-Working.patch + %if 0%{?fedora} < 41 # Work-around for dracut issue: run generators directly when we are in initrd # https://bugzilla.redhat.com/show_bug.cgi?id=2164404