From c0757a163fb1b320a9686d5e6d4817af8af1bfc3 Mon Sep 17 00:00:00 2001 From: h30032433 Date: Wed, 28 Feb 2024 14:50:26 +0800 Subject: [PATCH] sync patches from systemd community --- ...fix-overflow-detection-in-sigbus_pop.patch | 51 ++++++++++ ...bus_log_parse_error-to-print-message.patch | 70 +++++++++++++ ...sctl-avoid-asserting-on-NULL-message.patch | 99 +++++++++++++++++++ ...-sd-event-state-before-setting-up-po.patch | 58 +++++++++++ systemd.spec | 15 ++- 5 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 backport-basic-fix-overflow-detection-in-sigbus_pop.patch create mode 100644 backport-bus-use-bus_log_parse_error-to-print-message.patch create mode 100644 backport-busctl-avoid-asserting-on-NULL-message.patch create mode 100644 backport-sd-journal-check-sd-event-state-before-setting-up-po.patch diff --git a/backport-basic-fix-overflow-detection-in-sigbus_pop.patch b/backport-basic-fix-overflow-detection-in-sigbus_pop.patch new file mode 100644 index 0000000..b321a2b --- /dev/null +++ b/backport-basic-fix-overflow-detection-in-sigbus_pop.patch @@ -0,0 +1,51 @@ +From b4a9d19e4ec527a7b2d774a1349a6133f7739847 Mon Sep 17 00:00:00 2001 +From: Rose <83477269+AtariDreams@users.noreply.github.com> +Date: Tue, 2 Jan 2024 10:13:27 -0500 +Subject: [PATCH] basic: fix overflow detection in sigbus_pop + +The current check checks for n_sigbus_queue +being greater than or equal to SIGBUS_QUEUE_MAX, +when it should be just greater than as +n_sigbus_queue being SIGBUS_QUEUE_MAX indicates +that the queue is full, but not overflowed. + +Conflict:adapt context +Reference:https://github.com/systemd/systemd/commit/b4a9d19e4ec527a7b2d774a1349a6133f7739847 + +--- + src/basic/sigbus.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/basic/sigbus.c b/src/basic/sigbus.c +index 7e5a493f6b..47ab0b81d8 100644 +--- a/src/basic/sigbus.c ++++ b/src/basic/sigbus.c +@@ -40,14 +40,14 @@ static void sigbus_push(void *addr) { + } + + /* If we can't, make sure the queue size is out of bounds, to +- * mark it as overflow */ ++ * mark it as overflowed */ + for (;;) { + unsigned c; + + __sync_synchronize(); + c = n_sigbus_queue; + +- if (c > SIGBUS_QUEUE_MAX) /* already overflow */ ++ if (c > SIGBUS_QUEUE_MAX) /* already overflowed */ + return; + + if (__sync_bool_compare_and_swap(&n_sigbus_queue, c, c + SIGBUS_QUEUE_MAX)) +@@ -70,7 +70,7 @@ int sigbus_pop(void **ret) { + if (_likely_(c == 0)) + return 0; + +- if (_unlikely_(c >= SIGBUS_QUEUE_MAX)) ++ if (_unlikely_(c > SIGBUS_QUEUE_MAX)) + return -EOVERFLOW; + + for (u = 0; u < SIGBUS_QUEUE_MAX; u++) { +-- +2.39.1 + diff --git a/backport-bus-use-bus_log_parse_error-to-print-message.patch b/backport-bus-use-bus_log_parse_error-to-print-message.patch new file mode 100644 index 0000000..286fb1c --- /dev/null +++ b/backport-bus-use-bus_log_parse_error-to-print-message.patch @@ -0,0 +1,70 @@ +From d67b1d18fcda2c8c5aacfc50f9591c8dc7a4a8a1 Mon Sep 17 00:00:00 2001 +From: fangxiuning +Date: Sat, 11 Jul 2020 18:13:01 +0800 +Subject: [PATCH] bus: use bus_log_parse_error to print message + +Conflict:NA +Reference:https://github.com/systemd/systemd/commit/d67b1d18fcda2c8c5aacfc50f9591c8dc7a4a8a1 + +--- + src/busctl/busctl.c | 2 +- + src/network/networkd-manager.c | 2 +- + src/resolve/resolved-bus.c | 2 +- + src/timedate/timedatectl.c | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c +index 56fb8d9367..ccb22d5f8b 100644 +--- a/src/busctl/busctl.c ++++ b/src/busctl/busctl.c +@@ -1322,7 +1322,7 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f + + r = sd_bus_message_read(m, "s", &name); + if (r < 0) +- return log_error_errno(r, "Failed to read lost name: %m"); ++ return bus_log_parse_error(r); + + if (streq(name, unique_name)) + is_monitor = true; +diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c +index 63e2f61d29..8c51cc12b2 100644 +--- a/src/network/networkd-manager.c ++++ b/src/network/networkd-manager.c +@@ -104,7 +104,7 @@ static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_b + + r = sd_bus_message_read(message, "b", &b); + if (r < 0) { +- log_debug_errno(r, "Failed to parse PrepareForSleep signal: %m"); ++ bus_log_parse_error(r); + return 0; + } + +diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c +index 2ecfcf498b..45687c8fca 100644 +--- a/src/resolve/resolved-bus.c ++++ b/src/resolve/resolved-bus.c +@@ -1987,7 +1987,7 @@ static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_b + + r = sd_bus_message_read(message, "b", &b); + if (r < 0) { +- log_debug_errno(r, "Failed to parse PrepareForSleep signal: %m"); ++ bus_log_parse_error(r); + return 0; + } + +diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c +index eaac3b3e35..49d68d2533 100644 +--- a/src/timedate/timedatectl.c ++++ b/src/timedate/timedatectl.c +@@ -664,7 +664,7 @@ static int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error + + r = sd_bus_message_read(m, "s", &name); + if (r < 0) +- return log_error_errno(r, "Failed to read interface name: %m"); ++ return bus_log_parse_error(r); + + if (!streq_ptr(name, "org.freedesktop.timesync1.Manager")) + return 0; +-- +2.41.0 + diff --git a/backport-busctl-avoid-asserting-on-NULL-message.patch b/backport-busctl-avoid-asserting-on-NULL-message.patch new file mode 100644 index 0000000..a7276dd --- /dev/null +++ b/backport-busctl-avoid-asserting-on-NULL-message.patch @@ -0,0 +1,99 @@ +From b4a21d51487e21052af49b755d1707d4616e2977 Mon Sep 17 00:00:00 2001 +From: Frantisek Sumsal +Date: Sun, 24 Dec 2023 14:49:23 +0100 +Subject: [PATCH] busctl: avoid asserting on NULL message +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Avoid passing a NULL message to sd_bus_message_is_signal(), to not trip +over an assertion: + +[ 132.869436] H testsuite-82.sh[614]: + systemctl --no-block --check-inhibitors=yes soft-reboot +[ 132.967386] H systemd[1]: Created slice system-systemd\x2dcoredump.slice. +[ 133.018292] H systemd[1]: Starting inhibit.service... +[ 133.122610] H systemd[1]: Started systemd-coredump@0-665-0.service. +[ 133.163643] H systemd[1]: Started inhibit.service. +[ 133.206836] H testsuite-82.sh[614]: + exec sleep infinity +[ 133.236762] H systemd-logind[611]: The system will reboot now! +[ 135.891607] H systemd-coredump[667]: [🡕] Process 663 (busctl) of user 0 dumped core. + + Stack trace of thread 663: + #0 0x00007f2ec45e6acf raise (libc.so.6 + 0x4eacf) + #1 0x00007f2ec45b9ea5 abort (libc.so.6 + 0x21ea5) + #2 0x00007f2ec4b5c9a6 log_assert_failed (libsystemd-shared-255.so + 0x1ff9a6) + #3 0x00007f2ec4b5dca5 log_assert_failed_return (libsystemd-shared-255.so + 0x200ca5) + #4 0x00007f2ec4bb3df6 sd_bus_message_is_signal (libsystemd-shared-255.so + 0x256df6) + #5 0x000000000040e478 monitor (busctl + 0xe478) + #6 0x000000000040e82f verb_monitor (busctl + 0xe82f) + #7 0x00007f2ec4b202cb dispatch_verb (libsystemd-shared-255.so + 0x1c32cb) + #8 0x00000000004074fa busctl_main (busctl + 0x74fa) + #9 0x0000000000407525 run (busctl + 0x7525) + #10 0x000000000040ff67 main (busctl + 0xff67) + #11 0x00007f2ec45d2d85 __libc_start_main (libc.so.6 + 0x3ad85) + #12 0x00000000004044be _start (busctl + 0x44be) + ELF object binary architecture: AMD x86-64 +[ 136.141152] H dbus-daemon[634]: [system] Monitoring connection :1.2 closed. +[ 136.152233] H systemd[1]: busctl.service: Main process exited, code=dumped, status=6/ABRT +[ 136.153996] H systemd[1]: busctl.service: Failed with result 'core-dump'. + +The asertion in question: + +Assertion 'm' failed at src/libsystemd/sd-bus/bus-message.c:1015, function sd_bus_message_is_signal(). Aborting. + +We can get a NULL message here through sd_bus_process() -> +bus_process_internal() -> process_running(), so let's handle this case +appropriately. + +Conflict:NA +Reference:https://github.com/systemd/systemd/commit/b4a21d51487e21052af49b755d1707d4616e2977 + +--- + src/busctl/busctl.c | 26 +++++++++++++------------- + 1 file changed, 13 insertions(+), 13 deletions(-) + +diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c +index d233fc55ad..b2c2bc644d 100644 +--- a/src/busctl/busctl.c ++++ b/src/busctl/busctl.c +@@ -1320,24 +1320,24 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f + if (r < 0) + return log_error_errno(r, "Failed to process bus: %m"); + +- if (!is_monitor) { +- const char *name; ++ if (m) { ++ if (!is_monitor) { ++ const char *name; + +- /* wait until we lose our unique name */ +- if (sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameLost") <= 0) +- continue; ++ /* wait until we lose our unique name */ ++ if (sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameLost") <= 0) ++ continue; + +- r = sd_bus_message_read(m, "s", &name); +- if (r < 0) +- return bus_log_parse_error(r); ++ r = sd_bus_message_read(m, "s", &name); ++ if (r < 0) ++ return bus_log_parse_error(r); + +- if (streq(name, unique_name)) +- is_monitor = true; ++ if (streq(name, unique_name)) ++ is_monitor = true; + +- continue; +- } ++ continue; ++ } + +- if (m) { + dump(m, stdout); + fflush(stdout); + +-- +2.39.1 + diff --git a/backport-sd-journal-check-sd-event-state-before-setting-up-po.patch b/backport-sd-journal-check-sd-event-state-before-setting-up-po.patch new file mode 100644 index 0000000..81b90d8 --- /dev/null +++ b/backport-sd-journal-check-sd-event-state-before-setting-up-po.patch @@ -0,0 +1,58 @@ +From 5b201ffb1e72100dc7a112c95bbac0ccbc98ab0d Mon Sep 17 00:00:00 2001 +From: Yu Watanabe +Date: Fri, 29 Dec 2023 04:31:21 +0900 +Subject: [PATCH] sd-journal: check sd-event state before setting up post + change timer + +The similar check already exists in schedule_post_change(). + +The function is currently called at two places. +- journal_file_open() in sd-journal: + In this case, if the timer is not set up, then journal_file_post_change() + will be called at the end of journal_file_append_entry(). So, the necessary + task will be done sequentially when an journal entry is stored to the opened + journal file. That is desired when the function is called at outside of the + event loop. +- server_open_journal() in journald: + This is not called after we exit the event loop. + +So, we can safely do nothing in the function if the event loop is being +finished or already finished. + +Fixes #30644. + +Conflict:adapt context +Reference:https://github.com/systemd/systemd/commit/5b201ffb1e72100dc7a112c95bbac0ccbc98ab0d + +--- + src/journal/journal-file.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c +index 9ea568f..4e4493c 100644 +--- a/src/journal/journal-file.c ++++ b/src/journal/journal-file.c +@@ -1896,6 +1896,11 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t) + assert(e); + assert(t); + ++ /* If we are already going down, we cannot install the timer. ++ * In such case, the caller needs to call journal_file_post_change() explicitly. */ ++ if (IN_SET(sd_event_get_state(e), SD_EVENT_EXITING, SD_EVENT_FINISHED)) ++ return 0; ++ + r = sd_event_add_time(e, &timer, CLOCK_MONOTONIC, 0, 0, post_change_thunk, f); + if (r < 0) + return r; +@@ -1907,7 +1912,7 @@ int journal_file_enable_post_change_timer(JournalFile *f, sd_event *e, usec_t t) + f->post_change_timer = TAKE_PTR(timer); + f->post_change_timer_period = t; + +- return r; ++ return 1; + } + + static int entry_item_cmp(const EntryItem *a, const EntryItem *b) { +-- +2.41.0 + diff --git a/systemd.spec b/systemd.spec index e1b8474..ac4f34c 100644 --- a/systemd.spec +++ b/systemd.spec @@ -16,7 +16,7 @@ Name: systemd Url: https://www.freedesktop.org/wiki/Software/systemd Version: 243 -Release: 74 +Release: 75 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -297,6 +297,10 @@ Patch0249: backport-rules-import-previous-SYSTEMD_READY-state-for-suspen.pa Patch0250: backport-rules-go-to-the-end-of-rules-indeed-when-dm-is-suspe.patch Patch0251: backport-CVE-2023-7008.patch Patch0252: backport-core-add-possibility-to-not-track-certain-unit-types.patch +Patch0253: backport-basic-fix-overflow-detection-in-sigbus_pop.patch +Patch0254: backport-bus-use-bus_log_parse_error-to-print-message.patch +Patch0255: backport-busctl-avoid-asserting-on-NULL-message.patch +Patch0256: backport-sd-journal-check-sd-event-state-before-setting-up-po.patch #openEuler Patch9002: 1509-fix-journal-file-descriptors-leak-problems.patch @@ -1704,6 +1708,15 @@ fi %exclude /usr/share/man/man3/* %changelog +* Wed Feb 28 2024 huyubiao - 243-75 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:add backport-basic-fix-overflow-detection-in-sigbus_pop.patch + backport-bus-use-bus_log_parse_error-to-print-message.patch + backport-busctl-avoid-asserting-on-NULL-message.patch + backport-sd-journal-check-sd-event-state-before-setting-up-po.patch + * Thu Jan 18 2024 hongjinghao - 243-74 - add: backport-core-add-possibility-to-not-track-certain-unit-types.patch