From 26fb3f4504ddfecee963600341e8e5c34c5b5000 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 21 Nov 2023 09:45:13 +0100 Subject: [PATCH] ldconfig should skip temporary files created by RPM (RHEL-14383) Resolves: RHEL-14383 --- glibc-RHEL-14383-1.patch | 72 ++++++++++++++++++++++++++++++++++++++++ glibc-RHEL-14383-2.patch | 61 ++++++++++++++++++++++++++++++++++ glibc.spec | 7 +++- 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 glibc-RHEL-14383-1.patch create mode 100644 glibc-RHEL-14383-2.patch diff --git a/glibc-RHEL-14383-1.patch b/glibc-RHEL-14383-1.patch new file mode 100644 index 0000000..7a2e8d6 --- /dev/null +++ b/glibc-RHEL-14383-1.patch @@ -0,0 +1,72 @@ +commit 2aa0974d2573441bffd596b07bff8698b1f2f18c +Author: Florian Weimer +Date: Fri Oct 20 14:29:50 2023 +0200 + + elf: ldconfig should skip temporary files created by package managers + + This avoids crashes due to partially written files, after a package + update is interrupted. + + Reviewed-by: Adhemerval Zanella + +Conflicts: + elf/ldconfig.c + (missing alloca removal downstream) + +diff --git a/elf/ldconfig.c b/elf/ldconfig.c +index be47ad8c2d7f89f3..f0c811001965cc46 100644 +--- a/elf/ldconfig.c ++++ b/elf/ldconfig.c +@@ -778,6 +778,31 @@ struct dlib_entry + struct dlib_entry *next; + }; + ++/* Skip some temporary DSO files. These files may be partially written ++ and lead to ldconfig crashes when examined. */ ++static bool ++skip_dso_based_on_name (const char *name, size_t len) ++{ ++ /* Skip temporary files created by the prelink program. Files with ++ names like these are never really DSOs we want to look at. */ ++ if (len >= sizeof (".#prelink#") - 1) ++ { ++ if (strcmp (name + len - sizeof (".#prelink#") + 1, ++ ".#prelink#") == 0) ++ return true; ++ if (len >= sizeof (".#prelink#.XXXXXX") - 1 ++ && memcmp (name + len - sizeof (".#prelink#.XXXXXX") ++ + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0) ++ return true; ++ } ++ /* Skip temporary files created by RPM. */ ++ if (memchr (name, len, ';') != NULL) ++ return true; ++ /* Skip temporary files created by dpkg. */ ++ if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0) ++ return true; ++ return false; ++} + + static void + search_dir (const struct dir_entry *entry) +@@ -854,18 +879,8 @@ search_dir (const struct dir_entry *entry) + continue; + + size_t len = strlen (direntry->d_name); +- /* Skip temporary files created by the prelink program. Files with +- names like these are never really DSOs we want to look at. */ +- if (len >= sizeof (".#prelink#") - 1) +- { +- if (strcmp (direntry->d_name + len - sizeof (".#prelink#") + 1, +- ".#prelink#") == 0) +- continue; +- if (len >= sizeof (".#prelink#.XXXXXX") - 1 +- && memcmp (direntry->d_name + len - sizeof (".#prelink#.XXXXXX") +- + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0) +- continue; +- } ++ if (skip_dso_based_on_name (direntry->d_name, len)) ++ continue; + len += strlen (entry->path) + 2; + if (len > file_name_len) + { diff --git a/glibc-RHEL-14383-2.patch b/glibc-RHEL-14383-2.patch new file mode 100644 index 0000000..4f68766 --- /dev/null +++ b/glibc-RHEL-14383-2.patch @@ -0,0 +1,61 @@ +commit cfb5a97a93ea656e3b2263e42142a4032986d9ba +Author: Florian Weimer +Date: Mon Oct 23 12:53:16 2023 +0200 + + ldconfig: Fixes for skipping temporary files. + + Arguments to a memchr call were swapped, causing incorrect skipping + of files. + + Files related to dpkg have different names: they actually end in + .dpkg-new and .dpkg-tmp, not .tmp as I mistakenly assumed. + + Fixes commit 2aa0974d2573441bffd59 ("elf: ldconfig should skip + temporary files created by package managers"). + +diff --git a/elf/ldconfig.c b/elf/ldconfig.c +index f0c811001965cc46..4a96c409994d96c8 100644 +--- a/elf/ldconfig.c ++++ b/elf/ldconfig.c +@@ -778,6 +778,17 @@ struct dlib_entry + struct dlib_entry *next; + }; + ++/* Return true if the N bytes at NAME end with with the characters in ++ the string SUFFIX. (NAME[N + 1] does not have to be a null byte.) ++ Expected to be called with a string literal for SUFFIX. */ ++static inline bool ++endswithn (const char *name, size_t n, const char *suffix) ++{ ++ return (n >= strlen (suffix) ++ && memcmp (name + n - strlen (suffix), suffix, ++ strlen (suffix)) == 0); ++} ++ + /* Skip some temporary DSO files. These files may be partially written + and lead to ldconfig crashes when examined. */ + static bool +@@ -787,8 +798,7 @@ skip_dso_based_on_name (const char *name, size_t len) + names like these are never really DSOs we want to look at. */ + if (len >= sizeof (".#prelink#") - 1) + { +- if (strcmp (name + len - sizeof (".#prelink#") + 1, +- ".#prelink#") == 0) ++ if (endswithn (name, len, ".#prelink#")) + return true; + if (len >= sizeof (".#prelink#.XXXXXX") - 1 + && memcmp (name + len - sizeof (".#prelink#.XXXXXX") +@@ -796,10 +806,11 @@ skip_dso_based_on_name (const char *name, size_t len) + return true; + } + /* Skip temporary files created by RPM. */ +- if (memchr (name, len, ';') != NULL) ++ if (memchr (name, ';', len) != NULL) + return true; + /* Skip temporary files created by dpkg. */ +- if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0) ++ if (endswithn (name, len, ".dpkg-new") ++ || endswithn (name, len, ".dpkg-tmp")) + return true; + return false; + } diff --git a/glibc.spec b/glibc.spec index a06127c..37258ce 100644 --- a/glibc.spec +++ b/glibc.spec @@ -155,7 +155,7 @@ end \ Summary: The GNU libc libraries Name: glibc Version: %{glibcversion} -Release: 89%{?dist} +Release: 90%{?dist} # In general, GPLv2+ is used by programs, LGPLv2+ is used for # libraries. @@ -775,6 +775,8 @@ Patch538: glibc-RHEL-3397.patch Patch539: glibc-RHEL-2123.patch Patch540: glibc-RHEL-16275.patch Patch541: glibc-RHEL-2491.patch +Patch542: glibc-RHEL-14383-1.patch +Patch543: glibc-RHEL-14383-2.patch ############################################################################## # Continued list of core "glibc" package information: @@ -2933,6 +2935,9 @@ update_gconv_modules_cache () %endif %changelog +* Tue Nov 21 2023 Florian Weimer - 2.34-90 +- ldconfig should skip temporary files created by RPM (RHEL-14383) + * Mon Nov 20 2023 Florian Weimer - 2.34-89 - Fix force-first handling in dlclose (RHEL-2491)