From f7471c848033a337f92dd5db446ac795fd790156 Mon Sep 17 00:00:00 2001 From: hongjinghao Date: Thu, 1 Sep 2022 15:18:30 +0800 Subject: [PATCH] 1. Don't set AlternativeNamesPolicy by default 2. fix systemd-journald coredump --- ...et-AlternativeNamesPolicy-by-default.patch | 26 ++ ...-Only-move-to-objects-when-necessary.patch | 244 ++++++++++++++++++ systemd.spec | 8 +- 3 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 Don-t-set-AlternativeNamesPolicy-by-default.patch create mode 100644 backport-journal-Only-move-to-objects-when-necessary.patch diff --git a/Don-t-set-AlternativeNamesPolicy-by-default.patch b/Don-t-set-AlternativeNamesPolicy-by-default.patch new file mode 100644 index 0000000..24fe54b --- /dev/null +++ b/Don-t-set-AlternativeNamesPolicy-by-default.patch @@ -0,0 +1,26 @@ +From 1e3f74b7ca5ead53c10e5b37cf8660651f32d181 Mon Sep 17 00:00:00 2001 +From: xujing +Date: Thu, 11 Aug 2022 19:53:35 +0800 +Subject: [PATCH] Don't set AlternativeNamesPolicy by default + +When a network adapter is renamed, the altname of the network adapter may be +set based on AlternativeNamesPolicy. As a result, the network adapter name +fails to be restored. For example, after enp4s0 is renamed tmp, udev sets the +altname of tmp to enp4s0. If you want to restore tmp to enp4s0, it will fail. +--- + network/99-default.link | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/network/99-default.link b/network/99-default.link +index 31aee37..db48c4d 100644 +--- a/network/99-default.link ++++ b/network/99-default.link +@@ -12,5 +12,4 @@ OriginalName=* + + [Link] + NamePolicy=keep kernel database onboard slot path +-AlternativeNamesPolicy=database onboard slot path + MACAddressPolicy=none +-- +2.23.0 + diff --git a/backport-journal-Only-move-to-objects-when-necessary.patch b/backport-journal-Only-move-to-objects-when-necessary.patch new file mode 100644 index 0000000..68b0eee --- /dev/null +++ b/backport-journal-Only-move-to-objects-when-necessary.patch @@ -0,0 +1,244 @@ +From 57ba83ddd33d8ed5e8cee6a35f6ee780532a7a0d Mon Sep 17 00:00:00 2001 +From: Daan De Meyer +Date: Tue, 25 Jan 2022 11:50:40 +0000 +Subject: [PATCH] journal: Only move to objects when necessary + +Conflict:don't modify journal_file_read_object because 117e2112 isn't merged; +don't modify generic_array_get because 8d801e35cb isn't merged; adapt context +Reference:https://github.com/systemd/systemd/commit/ded10e3a5f4c9a9fca9a57f5feb7e77db4155dbd + +Let's make sure we only move to objects when it's required. If "ret" +is NULL, the caller isn't interested in the actual object and the +function being called shouldn't move to it unless it has to +inspect/modify the object itself. +--- + src/libsystemd/sd-journal/journal-file.c | 99 +++++++++-------------- + 1 file changed, 39 insertions(+), 60 deletions(-) + +diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c +index e3e926b..efc5018 100644 +--- a/src/libsystemd/sd-journal/journal-file.c ++++ b/src/libsystemd/sd-journal/journal-file.c +@@ -931,7 +931,6 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset + uint64_t s; + + assert(f); +- assert(ret); + + /* Objects may only be located at multiple of 64 bit */ + if (!VALID64(offset)) +@@ -986,7 +985,9 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset + if (r < 0) + return r; + +- *ret = o; ++ if (ret) ++ *ret = o; ++ + return 0; + } + +@@ -1584,19 +1585,11 @@ static int journal_file_append_field( + + hash = journal_file_hash_data(f, field, size); + +- r = journal_file_find_field_object_with_hash(f, field, size, hash, &o, &p); ++ r = journal_file_find_field_object_with_hash(f, field, size, hash, ret, ret_offset); + if (r < 0) + return r; +- if (r > 0) { +- +- if (ret) +- *ret = o; +- +- if (ret_offset) +- *ret_offset = p; +- ++ if (r > 0) + return 0; +- } + + osize = offsetof(Object, field.payload) + size; + r = journal_file_append_object(f, OBJECT_FIELD, osize, &o, &p); +@@ -1610,20 +1603,20 @@ static int journal_file_append_field( + if (r < 0) + return r; + +- /* The linking might have altered the window, so let's +- * refresh our pointer */ +- r = journal_file_move_to_object(f, OBJECT_FIELD, p, &o); +- if (r < 0) +- return r; ++ /* The linking might have altered the window, so let's only pass the offset to hmac which will ++ * move to the object again if needed. */ + + #if HAVE_GCRYPT +- r = journal_file_hmac_put_object(f, OBJECT_FIELD, o, p); ++ r = journal_file_hmac_put_object(f, OBJECT_FIELD, NULL, p); + if (r < 0) + return r; + #endif + +- if (ret) +- *ret = o; ++ if (ret) { ++ r = journal_file_move_to_object(f, OBJECT_FIELD, p, ret); ++ if (r < 0) ++ return r; ++ } + + if (ret_offset) + *ret_offset = p; +@@ -1647,19 +1640,11 @@ static int journal_file_append_data( + + hash = journal_file_hash_data(f, data, size); + +- r = journal_file_find_data_object_with_hash(f, data, size, hash, &o, &p); ++ r = journal_file_find_data_object_with_hash(f, data, size, hash, ret, ret_offset); + if (r < 0) + return r; +- if (r > 0) { +- +- if (ret) +- *ret = o; +- +- if (ret_offset) +- *ret_offset = p; +- ++ if (r > 0) + return 0; +- } + + osize = offsetof(Object, data.payload) + size; + r = journal_file_append_object(f, OBJECT_DATA, osize, &o, &p); +@@ -1693,17 +1678,16 @@ static int journal_file_append_data( + if (r < 0) + return r; + +-#if HAVE_GCRYPT +- r = journal_file_hmac_put_object(f, OBJECT_DATA, o, p); ++ /* The linking might have altered the window, so let's refresh our pointer. */ ++ r = journal_file_move_to_object(f, OBJECT_DATA, p, &o); + if (r < 0) + return r; +-#endif + +- /* The linking might have altered the window, so let's +- * refresh our pointer */ +- r = journal_file_move_to_object(f, OBJECT_DATA, p, &o); ++#if HAVE_GCRYPT ++ r = journal_file_hmac_put_object(f, OBJECT_DATA, o, p); + if (r < 0) + return r; ++#endif + + if (!data) + eq = NULL; +@@ -2307,20 +2290,15 @@ static int generic_array_get_plus_one( + uint64_t i, + Object **ret, uint64_t *ret_offset) { + +- Object *o; +- + assert(f); + + if (i == 0) { + int r; + +- r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, &o); ++ r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret); + if (r < 0) + return r; + +- if (ret) +- *ret = o; +- + if (ret_offset) + *ret_offset = extra; + +@@ -2349,7 +2327,7 @@ static int generic_array_bisect( + + uint64_t a, p, t = 0, i = 0, last_p = 0, last_index = UINT64_MAX; + bool subtract_one = false; +- Object *o, *array = NULL; ++ Object *array = NULL; + int r; + ChainCacheItem *ci; + +@@ -2537,12 +2515,11 @@ found: + else + p = le64toh(array->entry_array.items[i]); + +- r = journal_file_move_to_object(f, OBJECT_ENTRY, p, &o); +- if (r < 0) +- return r; +- +- if (ret) +- *ret = o; ++ if (ret) { ++ r = journal_file_move_to_object(f, OBJECT_ENTRY, p, ret); ++ if (r < 0) ++ return r; ++ } + + if (ret_offset) + *ret_offset = p; +@@ -2567,7 +2544,6 @@ static int generic_array_bisect_plus_one( + + int r; + bool step_back = false; +- Object *o; + + assert(f); + assert(test_object); +@@ -2610,12 +2586,11 @@ static int generic_array_bisect_plus_one( + return r; + + found: +- r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, &o); +- if (r < 0) +- return r; +- +- if (ret) +- *ret = o; ++ if (ret) { ++ r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, ret); ++ if (r < 0) ++ return r; ++ } + + if (ret_offset) + *ret_offset = extra; +@@ -3088,7 +3063,6 @@ int journal_file_move_to_entry_by_monotonic_for_data( + * exists in both bisection arrays */ + + for (;;) { +- Object *qo; + uint64_t p, q; + + r = journal_file_move_to_object(f, OBJECT_DATA, data_offset, &d); +@@ -3117,14 +3091,18 @@ int journal_file_move_to_entry_by_monotonic_for_data( + p, + test_object_offset, + direction, +- &qo, &q, NULL); ++ NULL, &q, NULL); + + if (r <= 0) + return r; + + if (p == q) { +- if (ret) +- *ret = qo; ++ if (ret) { ++ r = journal_file_move_to_object(f, OBJECT_ENTRY, q, ret); ++ if (r < 0) ++ return r; ++ } ++ + if (ret_offset) + *ret_offset = q; + +-- +2.23.0 + diff --git a/systemd.spec b/systemd.spec index 3ee7078..3fdfe94 100644 --- a/systemd.spec +++ b/systemd.spec @@ -20,7 +20,7 @@ Name: systemd Url: https://www.freedesktop.org/wiki/Software/systemd Version: 249 -Release: 32 +Release: 33 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -74,6 +74,7 @@ Patch0025: check-whether-command_prev-is-null-before-assigning-.patch Patch0026: print-the-real-reason-for-link-update.patch Patch0027: core-skip-change-device-to-dead-in-manager_catchup-d.patch Patch0028: revert-rpm-restart-services-in-posttrans.patch +Patch0029: Don-t-set-AlternativeNamesPolicy-by-default.patch #backport Patch6000: backport-core-fix-free-undefined-pointer-when-strdup-failed-i.patch @@ -107,6 +108,7 @@ Patch6027: backport-unit-coldplug-both-job-and-nop_job-if-possible.patch Patch6028: backport-meson.build-change-operator-combining-bools-from-to-.patch Patch6029: backport-Avoid-tmp-being-mounted-as-tmpfs-without-the-user-s-.patch Patch6030: backport-core-replace-slice-dependencies-as-they-get-added.patch +Patch6031: backport-journal-Only-move-to-objects-when-necessary.patch BuildRequires: gcc, gcc-c++ BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel @@ -1510,6 +1512,10 @@ fi %{_libdir}/security/pam_systemd.so %changelog +* Thu Sep 1 2022 hongjinghao - 249-33 +- 1. Don't set AlternativeNamesPolicy by default + 2. fix systemd-journald coredump + * Tue Aug 02 2022 zhukeqian -249-32 - core: replace slice dependencies as they get added