!830 [sync] PR-829: elf:sync some patches:
From: @openeuler-sync-bot Reviewed-by: @liqingqing_1229 Signed-off-by: @liqingqing_1229
This commit is contained in:
commit
93a1c370a1
209
backport-elf-Add-TLS-modid-reuse-test-for-bug-29039.patch
Normal file
209
backport-elf-Add-TLS-modid-reuse-test-for-bug-29039.patch
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
From 980450f12685326729d63ff72e93a996113bf073 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
|
||||||
|
Date: Wed, 29 Nov 2023 11:31:37 +0000
|
||||||
|
Subject: [PATCH] elf: Add TLS modid reuse test for bug 29039
|
||||||
|
|
||||||
|
This is a minimal regression test for bug 29039 which only affects
|
||||||
|
targets with TLSDESC and a reproducer requires that
|
||||||
|
|
||||||
|
1) Have modid gaps (closed modules) with old generation.
|
||||||
|
2) Update a DTV to a newer generation (needs a newer dlopen).
|
||||||
|
3) But do not update the closed gap entry in that DTV.
|
||||||
|
4) Reuse the modid gap for a new module (another dlopen).
|
||||||
|
5) Use dynamic TLSDESC in that new module with old generation (bug).
|
||||||
|
6) Access TLS via this TLSDESC and the now outdated DTV.
|
||||||
|
|
||||||
|
However step (3) in practice rarely happens: during DTV update the
|
||||||
|
entries for closed modids are initialized to "unallocated" and then
|
||||||
|
dynamic TLSDESC calls __tls_get_addr independently of its generation.
|
||||||
|
The only exception to this is DTV setup at thread creation (gaps are
|
||||||
|
initialized to NULL instead of unallocated) or DTV resize where the
|
||||||
|
gap entries are outside the previous DTV array (again NULL instead
|
||||||
|
of unallocated, and this requires loading > DTV_SURPLUS modules).
|
||||||
|
|
||||||
|
So the bug can only cause NULL (+ offset) dereference, not use after
|
||||||
|
free. And the easiest way to get (3) is via thread creation.
|
||||||
|
|
||||||
|
Note that step (5) requires that the newly loaded module has larger
|
||||||
|
TLS than the remaining optional static TLS. And for (6) there cannot
|
||||||
|
be other TLS access or dlopen in the thread that updates the DTV.
|
||||||
|
|
||||||
|
Tested on aarch64-linux-gnu.
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=980450f12685326729d63ff72e93a996113bf073
|
||||||
|
|
||||||
|
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||||
|
---
|
||||||
|
elf/Makefile | 15 +++++++
|
||||||
|
elf/tst-tlsgap-mod0.c | 2 +
|
||||||
|
elf/tst-tlsgap-mod1.c | 2 +
|
||||||
|
elf/tst-tlsgap-mod2.c | 2 +
|
||||||
|
elf/tst-tlsgap.c | 92 +++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
5 files changed, 113 insertions(+)
|
||||||
|
create mode 100644 elf/tst-tlsgap-mod0.c
|
||||||
|
create mode 100644 elf/tst-tlsgap-mod1.c
|
||||||
|
create mode 100644 elf/tst-tlsgap-mod2.c
|
||||||
|
create mode 100644 elf/tst-tlsgap.c
|
||||||
|
|
||||||
|
diff --git a/elf/Makefile b/elf/Makefile
|
||||||
|
index ed13f34d..b5de4dd4 100644
|
||||||
|
--- a/elf/Makefile
|
||||||
|
+++ b/elf/Makefile
|
||||||
|
@@ -425,6 +425,7 @@ tests += \
|
||||||
|
tst-tls5 \
|
||||||
|
tst-tlsalign \
|
||||||
|
tst-tlsalign-extern \
|
||||||
|
+ tst-tlsgap \
|
||||||
|
tst-tls-dlinfo \
|
||||||
|
tst-tls-ie \
|
||||||
|
tst-tls-ie-dlmopen \
|
||||||
|
@@ -704,6 +705,9 @@ modules-names = \
|
||||||
|
tst-tls20mod-bad \
|
||||||
|
tst-tls21mod \
|
||||||
|
tst-tlsalign-lib \
|
||||||
|
+ tst-tlsgap-mod0 \
|
||||||
|
+ tst-tlsgap-mod1 \
|
||||||
|
+ tst-tlsgap-mod2 \
|
||||||
|
tst-tls-ie-mod0 \
|
||||||
|
tst-tls-ie-mod1 \
|
||||||
|
tst-tls-ie-mod2 \
|
||||||
|
@@ -2498,3 +2502,14 @@ $(objpfx)tst-non-directory-path.out: tst-non-directory-path.sh \
|
||||||
|
'$(test-wrapper-env)' '$(run_program_env)' \
|
||||||
|
'$(rpath-link)' $(objpfx) > $@; \
|
||||||
|
$(evaluate-test)
|
||||||
|
+
|
||||||
|
+$(objpfx)tst-tlsgap: $(shared-thread-library)
|
||||||
|
+$(objpfx)tst-tlsgap.out: \
|
||||||
|
+ $(objpfx)tst-tlsgap-mod0.so \
|
||||||
|
+ $(objpfx)tst-tlsgap-mod1.so \
|
||||||
|
+ $(objpfx)tst-tlsgap-mod2.so
|
||||||
|
+ifeq (yes,$(have-mtls-dialect-gnu2))
|
||||||
|
+CFLAGS-tst-tlsgap-mod0.c += -mtls-dialect=gnu2
|
||||||
|
+CFLAGS-tst-tlsgap-mod1.c += -mtls-dialect=gnu2
|
||||||
|
+CFLAGS-tst-tlsgap-mod2.c += -mtls-dialect=gnu2
|
||||||
|
+endif
|
||||||
|
diff --git a/elf/tst-tlsgap-mod0.c b/elf/tst-tlsgap-mod0.c
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..1478b0be
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/elf/tst-tlsgap-mod0.c
|
||||||
|
@@ -0,0 +1,2 @@
|
||||||
|
+int __thread tls0;
|
||||||
|
+int *f0(void) { return &tls0; }
|
||||||
|
diff --git a/elf/tst-tlsgap-mod1.c b/elf/tst-tlsgap-mod1.c
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..b10fc370
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/elf/tst-tlsgap-mod1.c
|
||||||
|
@@ -0,0 +1,2 @@
|
||||||
|
+int __thread tls1[100]; /* Size > glibc.rtld.optional_static_tls / 2. */
|
||||||
|
+int *f1(void) { return tls1; }
|
||||||
|
diff --git a/elf/tst-tlsgap-mod2.c b/elf/tst-tlsgap-mod2.c
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..166c27d7
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/elf/tst-tlsgap-mod2.c
|
||||||
|
@@ -0,0 +1,2 @@
|
||||||
|
+int __thread tls2;
|
||||||
|
+int *f2(void) { return &tls2; }
|
||||||
|
diff --git a/elf/tst-tlsgap.c b/elf/tst-tlsgap.c
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..49328850
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/elf/tst-tlsgap.c
|
||||||
|
@@ -0,0 +1,92 @@
|
||||||
|
+/* TLS modid gap reuse regression test for bug 29039.
|
||||||
|
+ Copyright (C) 2023 Free Software Foundation, Inc.
|
||||||
|
+ This file is part of the GNU C Library.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
+ modify it under the terms of the GNU Lesser General Public
|
||||||
|
+ License as published by the Free Software Foundation; either
|
||||||
|
+ version 2.1 of the License, or (at your option) any later version.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
+ Lesser General Public License for more details.
|
||||||
|
+
|
||||||
|
+ You should have received a copy of the GNU Lesser General Public
|
||||||
|
+ License along with the GNU C Library; if not, see
|
||||||
|
+ <http://www.gnu.org/licenses/>. */
|
||||||
|
+
|
||||||
|
+#include <stdio.h>
|
||||||
|
+#include <dlfcn.h>
|
||||||
|
+#include <pthread.h>
|
||||||
|
+#include <support/xdlfcn.h>
|
||||||
|
+#include <support/xthread.h>
|
||||||
|
+#include <support/check.h>
|
||||||
|
+
|
||||||
|
+static void *mod[3];
|
||||||
|
+#define MOD(i) "tst-tlsgap-mod" #i ".so"
|
||||||
|
+static const char *modname[3] = { MOD(0), MOD(1), MOD(2) };
|
||||||
|
+#undef MOD
|
||||||
|
+
|
||||||
|
+static void
|
||||||
|
+open_mod (int i)
|
||||||
|
+{
|
||||||
|
+ mod[i] = xdlopen (modname[i], RTLD_LAZY);
|
||||||
|
+ printf ("open %s\n", modname[i]);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void
|
||||||
|
+close_mod (int i)
|
||||||
|
+{
|
||||||
|
+ xdlclose (mod[i]);
|
||||||
|
+ mod[i] = NULL;
|
||||||
|
+ printf ("close %s\n", modname[i]);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void
|
||||||
|
+access_mod (int i, const char *sym)
|
||||||
|
+{
|
||||||
|
+ int *(*f) (void) = xdlsym (mod[i], sym);
|
||||||
|
+ int *p = f ();
|
||||||
|
+ printf ("access %s: %s() = %p\n", modname[i], sym, p);
|
||||||
|
+ TEST_VERIFY_EXIT (p != NULL);
|
||||||
|
+ ++*p;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void *
|
||||||
|
+start (void *arg)
|
||||||
|
+{
|
||||||
|
+ /* The DTV generation is at the last dlopen of mod0 and the
|
||||||
|
+ entry for mod1 is NULL. */
|
||||||
|
+
|
||||||
|
+ open_mod (1); /* Reuse modid of mod1. Uses dynamic TLS. */
|
||||||
|
+
|
||||||
|
+ /* DTV is unchanged: dlopen only updates the DTV to the latest
|
||||||
|
+ generation if static TLS is allocated for a loaded module.
|
||||||
|
+
|
||||||
|
+ With bug 29039, the TLSDESC relocation in mod1 uses the old
|
||||||
|
+ dlclose generation of mod1 instead of the new dlopen one so
|
||||||
|
+ DTV is not updated on TLS access. */
|
||||||
|
+
|
||||||
|
+ access_mod (1, "f1");
|
||||||
|
+
|
||||||
|
+ return arg;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static int
|
||||||
|
+do_test (void)
|
||||||
|
+{
|
||||||
|
+ open_mod (0);
|
||||||
|
+ open_mod (1);
|
||||||
|
+ open_mod (2);
|
||||||
|
+ close_mod (0);
|
||||||
|
+ close_mod (1); /* Create modid gap at mod1. */
|
||||||
|
+ open_mod (0); /* Reuse modid of mod0, bump generation count. */
|
||||||
|
+
|
||||||
|
+ /* Create a thread where DTV of mod1 is NULL. */
|
||||||
|
+ pthread_t t = xpthread_create (NULL, start, NULL);
|
||||||
|
+ xpthread_join (t);
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#include <support/test-driver.c>
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
35
backport-elf-Check-objname-before-calling-fatal_error.patch
Normal file
35
backport-elf-Check-objname-before-calling-fatal_error.patch
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
From 1cce91d8aed5c3eca2b6f47767c82d9ed3e9e33f Mon Sep 17 00:00:00 2001
|
||||||
|
From: "H.J. Lu" <hjl.tools@gmail.com>
|
||||||
|
Date: Mon, 8 Apr 2024 09:06:09 -0700
|
||||||
|
Subject: [PATCH] elf: Check objname before calling fatal_error
|
||||||
|
|
||||||
|
_dl_signal_error may be called with objname == NULL. _dl_exception_create
|
||||||
|
checks objname == NULL. But fatal_error doesn't. Check objname before
|
||||||
|
calling fatal_error. This fixes BZ #31596.
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=1cce91d8aed5c3eca2b6f47767c82d9ed3e9e33f
|
||||||
|
|
||||||
|
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
|
||||||
|
---
|
||||||
|
elf/dl-error-skeleton.c | 4 ++++
|
||||||
|
1 file changed, 4 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/elf/dl-error-skeleton.c b/elf/dl-error-skeleton.c
|
||||||
|
index b699936c..26dfab55 100644
|
||||||
|
--- a/elf/dl-error-skeleton.c
|
||||||
|
+++ b/elf/dl-error-skeleton.c
|
||||||
|
@@ -121,7 +121,11 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
|
||||||
|
__longjmp (lcatch->env[0].__jmpbuf, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
+ {
|
||||||
|
+ if (objname == NULL)
|
||||||
|
+ objname = "";
|
||||||
|
fatal_error (errcode, objname, occation, errstring);
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
libc_hidden_def (_dl_signal_error)
|
||||||
|
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
From 3921c5b40f293c57cb326f58713c924b0662ef59 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Hector Martin <marcan@marcan.st>
|
||||||
|
Date: Tue, 28 Nov 2023 15:23:07 +0900
|
||||||
|
Subject: [PATCH] elf: Fix TLS modid reuse generation assignment (BZ 29039)
|
||||||
|
|
||||||
|
_dl_assign_tls_modid() assigns a slotinfo entry for a new module, but
|
||||||
|
does *not* do anything to the generation counter. The first time this
|
||||||
|
happens, the generation is zero and map_generation() returns the current
|
||||||
|
generation to be used during relocation processing. However, if
|
||||||
|
a slotinfo entry is later reused, it will already have a generation
|
||||||
|
assigned. If this generation has fallen behind the current global max
|
||||||
|
generation, then this causes an obsolete generation to be assigned
|
||||||
|
during relocation processing, as map_generation() returns this
|
||||||
|
generation if nonzero. _dl_add_to_slotinfo() eventually resets the
|
||||||
|
generation, but by then it is too late. This causes DTV updates to be
|
||||||
|
skipped, leading to NULL or broken TLS slot pointers and segfaults.
|
||||||
|
|
||||||
|
Fix this by resetting the generation to zero in _dl_assign_tls_modid(),
|
||||||
|
so it behaves the same as the first time a slot is assigned.
|
||||||
|
_dl_add_to_slotinfo() will still assign the correct static generation
|
||||||
|
later during module load, but relocation processing will no longer use
|
||||||
|
an obsolete generation.
|
||||||
|
|
||||||
|
Note that slotinfo entry (aka modid) reuse typically happens after a
|
||||||
|
dlclose and only TLS access via dynamic tlsdesc is affected. Because
|
||||||
|
tlsdesc is optimized to use the optional part of static TLS, dynamic
|
||||||
|
tlsdesc can be avoided by increasing the glibc.rtld.optional_static_tls
|
||||||
|
tunable to a large enough value, or by LD_PRELOAD-ing the affected
|
||||||
|
modules.
|
||||||
|
|
||||||
|
Fixes bug 29039.
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=3921c5b40f293c57cb326f58713c924b0662ef59
|
||||||
|
|
||||||
|
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
|
||||||
|
---
|
||||||
|
elf/dl-tls.c | 1 +
|
||||||
|
1 file changed, 1 insertion(+)
|
||||||
|
|
||||||
|
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
|
||||||
|
index 0070c8bb..42868eef 100644
|
||||||
|
--- a/elf/dl-tls.c
|
||||||
|
+++ b/elf/dl-tls.c
|
||||||
|
@@ -160,6 +160,7 @@ _dl_assign_tls_modid (struct link_map *l)
|
||||||
|
{
|
||||||
|
/* Mark the entry as used, so any dependency see it. */
|
||||||
|
atomic_store_relaxed (&runp->slotinfo[result - disp].map, l);
|
||||||
|
+ atomic_store_relaxed (&runp->slotinfo[result - disp].gen, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
From 434eca873f14f618d6c2279b54fb809fb56f2c50 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||||
|
Date: Mon, 6 Nov 2023 17:25:40 -0300
|
||||||
|
Subject: [PATCH] elf: Fix _dl_debug_vdprintf to work before self-relocation
|
||||||
|
|
||||||
|
The strlen might trigger and invalid GOT entry if it used before
|
||||||
|
the process is self-relocated (for instance on dl-tunables if any
|
||||||
|
error occurs).
|
||||||
|
|
||||||
|
For i386, _dl_writev with PIE requires to use the old 'int $0x80'
|
||||||
|
syscall mode because the calling the TLS register (gs) is not yet
|
||||||
|
initialized.
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=434eca873f14f618d6c2279b54fb809fb56f2c50
|
||||||
|
|
||||||
|
Checked on x86_64-linux-gnu.
|
||||||
|
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
||||||
|
---
|
||||||
|
elf/dl-misc.c | 15 +++++++++++++--
|
||||||
|
stdio-common/Makefile | 5 +++++
|
||||||
|
stdio-common/_itoa.c | 5 +++++
|
||||||
|
sysdeps/unix/sysv/linux/i386/dl-writev.h | 24 ++++++++++++++++++++++++
|
||||||
|
4 files changed, 47 insertions(+), 2 deletions(-)
|
||||||
|
create mode 100644 sysdeps/unix/sysv/linux/i386/dl-writev.h
|
||||||
|
|
||||||
|
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
|
||||||
|
index bba2e714..5b637c7e 100644
|
||||||
|
--- a/elf/dl-misc.c
|
||||||
|
+++ b/elf/dl-misc.c
|
||||||
|
@@ -16,6 +16,10 @@
|
||||||
|
License along with the GNU C Library; if not, see
|
||||||
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
+#include <string.h>
|
||||||
|
+#if BUILD_PIE_DEFAULT
|
||||||
|
+# pragma GCC visibility push(hidden)
|
||||||
|
+#endif
|
||||||
|
#include <assert.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ldsodefs.h>
|
||||||
|
@@ -23,7 +27,6 @@
|
||||||
|
#include <link.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
-#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
@@ -71,6 +74,14 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
+/* The function might be called before the process is self-relocated. */
|
||||||
|
+static size_t
|
||||||
|
+_dl_debug_strlen (const char *s)
|
||||||
|
+{
|
||||||
|
+ const char *p = s;
|
||||||
|
+ for (; *s != '\0'; s++);
|
||||||
|
+ return s - p;
|
||||||
|
+}
|
||||||
|
|
||||||
|
/* Bare-bones printf implementation. This function only knows about
|
||||||
|
the formats and flags needed and can handle only up to 64 stripes in
|
||||||
|
@@ -235,7 +246,7 @@ _dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
|
||||||
|
case 's':
|
||||||
|
/* Get the string argument. */
|
||||||
|
iov[niov].iov_base = va_arg (arg, char *);
|
||||||
|
- iov[niov].iov_len = strlen (iov[niov].iov_base);
|
||||||
|
+ iov[niov].iov_len = _dl_debug_strlen (iov[niov].iov_base);
|
||||||
|
if (prec != -1)
|
||||||
|
iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
|
||||||
|
++niov;
|
||||||
|
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
|
||||||
|
index 803f16da..f9763c27 100644
|
||||||
|
--- a/stdio-common/Makefile
|
||||||
|
+++ b/stdio-common/Makefile
|
||||||
|
@@ -181,6 +181,11 @@ CFLAGS-isoc99_scanf.c += -fexceptions
|
||||||
|
CFLAGS-errlist.c += $(fno-unit-at-a-time)
|
||||||
|
CFLAGS-siglist.c += $(fno-unit-at-a-time)
|
||||||
|
|
||||||
|
+# Called during static library initialization, so turn stack-protection
|
||||||
|
+# off for non-shared builds.
|
||||||
|
+CFLAGS-_itoa.o = $(no-stack-protector)
|
||||||
|
+CFLAGS-_itoa.op = $(no-stack-protector)
|
||||||
|
+
|
||||||
|
# scanf14a.c and scanf16a.c test a deprecated extension which is no
|
||||||
|
# longer visible under most conformance levels; see the source files
|
||||||
|
# for more detail.
|
||||||
|
diff --git a/stdio-common/_itoa.c b/stdio-common/_itoa.c
|
||||||
|
index c37d1c35..20c2e384 100644
|
||||||
|
--- a/stdio-common/_itoa.c
|
||||||
|
+++ b/stdio-common/_itoa.c
|
||||||
|
@@ -18,6 +18,11 @@
|
||||||
|
License along with the GNU C Library; if not, see
|
||||||
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
+/* Mark symbols hidden in static PIE for early self relocation to work.
|
||||||
|
+ Note: string.h may have ifuncs which cannot be hidden on i686. */
|
||||||
|
+#if BUILD_PIE_DEFAULT
|
||||||
|
+# pragma GCC visibility push(hidden)
|
||||||
|
+#endif
|
||||||
|
#include <gmp-mparam.h>
|
||||||
|
#include <gmp.h>
|
||||||
|
#include <limits.h>
|
||||||
|
diff --git a/sysdeps/unix/sysv/linux/i386/dl-writev.h b/sysdeps/unix/sysv/linux/i386/dl-writev.h
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..624d0e46
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/sysdeps/unix/sysv/linux/i386/dl-writev.h
|
||||||
|
@@ -0,0 +1,24 @@
|
||||||
|
+/* Message-writing for the dynamic linker. Linux/i386 version.
|
||||||
|
+ Copyright (C) 2013-2023 Free Software Foundation, Inc.
|
||||||
|
+ This file is part of the GNU C Library.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
+ modify it under the terms of the GNU Lesser General Public
|
||||||
|
+ License as published by the Free Software Foundation; either
|
||||||
|
+ version 2.1 of the License, or (at your option) any later version.
|
||||||
|
+
|
||||||
|
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
+ Lesser General Public License for more details.
|
||||||
|
+
|
||||||
|
+ You should have received a copy of the GNU Lesser General Public
|
||||||
|
+ License along with the GNU C Library; if not, see
|
||||||
|
+ <https://www.gnu.org/licenses/>. */
|
||||||
|
+
|
||||||
|
+#if BUILD_PIE_DEFAULT
|
||||||
|
+/* Can't use "call *%gs:SYSINFO_OFFSET" during startup in static PIE. */
|
||||||
|
+# define I386_USE_SYSENTER 0
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
+#include <sysdeps/unix/sysv/linux/dl-writev.h>
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
From 2aa0974d2573441bffd596b07bff8698b1f2f18c Mon Sep 17 00:00:00 2001
|
||||||
|
From: Florian Weimer <fweimer@redhat.com>
|
||||||
|
Date: Fri, 20 Oct 2023 14:29:50 +0200
|
||||||
|
Subject: [PATCH 1/1] elf: ldconfig should skip temporary files created by
|
||||||
|
package managers
|
||||||
|
|
||||||
|
This avoids crashes due to partially written files, after a package
|
||||||
|
update is interrupted.
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=2aa0974d2573441bffd596b07bff8698b1f2f18c
|
||||||
|
|
||||||
|
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||||
|
---
|
||||||
|
elf/ldconfig.c | 39 +++++++++++++++++++++++++++------------
|
||||||
|
1 file changed, 27 insertions(+), 12 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
|
||||||
|
index 6190e0ea..73b5ef27 100644
|
||||||
|
--- a/elf/ldconfig.c
|
||||||
|
+++ b/elf/ldconfig.c
|
||||||
|
@@ -746,6 +746,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)
|
||||||
|
@@ -822,18 +847,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)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
68
backport-ldconfig-Fixes-for-skipping-temporary-files.patch
Normal file
68
backport-ldconfig-Fixes-for-skipping-temporary-files.patch
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
From cfb5a97a93ea656e3b2263e42142a4032986d9ba Mon Sep 17 00:00:00 2001
|
||||||
|
From: Florian Weimer <fweimer@redhat.com>
|
||||||
|
Date: Mon, 23 Oct 2023 12:53:16 +0200
|
||||||
|
Subject: [PATCH] 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").
|
||||||
|
|
||||||
|
Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=cfb5a97a93ea656e3b2263e42142a4032986d9ba
|
||||||
|
---
|
||||||
|
elf/ldconfig.c | 19 +++++++++++++++----
|
||||||
|
1 file changed, 15 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
|
||||||
|
index 73b5ef27..5812a951 100644
|
||||||
|
--- a/elf/ldconfig.c
|
||||||
|
+++ b/elf/ldconfig.c
|
||||||
|
@@ -746,6 +746,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
|
||||||
|
@@ -755,8 +766,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")
|
||||||
|
@@ -764,10 +774,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;
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
19
glibc.spec
19
glibc.spec
@ -66,7 +66,7 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
Name: glibc
|
Name: glibc
|
||||||
Version: 2.34
|
Version: 2.34
|
||||||
Release: 149
|
Release: 150
|
||||||
Summary: The GNU libc libraries
|
Summary: The GNU libc libraries
|
||||||
License: %{all_license}
|
License: %{all_license}
|
||||||
URL: http://www.gnu.org/software/glibc/
|
URL: http://www.gnu.org/software/glibc/
|
||||||
@ -292,6 +292,12 @@ Patch205: backport-CVE-2024-33600-nscd-Avoid-null-pointer-crash-after-not-found-
|
|||||||
Patch206: backport-CVE-2024-33601-CVE-2024-33602-nscd-Use-two-buffer-in-addgetnetgrentX.patch
|
Patch206: backport-CVE-2024-33601-CVE-2024-33602-nscd-Use-two-buffer-in-addgetnetgrentX.patch
|
||||||
Patch207: backport-Use-errval-not-errno-to-guide-cache-update.patch
|
Patch207: backport-Use-errval-not-errno-to-guide-cache-update.patch
|
||||||
Patch208: backport-Skip-unusable-entries-in-first-pass-in-prune_cache.patch
|
Patch208: backport-Skip-unusable-entries-in-first-pass-in-prune_cache.patch
|
||||||
|
Patch209: backport-elf-Add-TLS-modid-reuse-test-for-bug-29039.patch
|
||||||
|
Patch210: backport-elf-Fix-TLS-modid-reuse-generation-assignment-BZ-290.patch
|
||||||
|
Patch211: backport-elf-Check-objname-before-calling-fatal_error.patch
|
||||||
|
Patch212: backport-elf-Fix-_dl_debug_vdprintf-to-work-before-self-reloc.patch
|
||||||
|
Patch213: backport-elf-ldconfig-should-skip-temporary-files-created-by-.patch
|
||||||
|
Patch214: backport-ldconfig-Fixes-for-skipping-temporary-files.patch
|
||||||
|
|
||||||
Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch
|
Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch
|
||||||
Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch
|
Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch
|
||||||
@ -1507,6 +1513,17 @@ fi
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri May 10 2024 shixuantong <shixuantong1@huawei.com> - 2.34-150
|
||||||
|
- Type:bugfix
|
||||||
|
- ID:
|
||||||
|
- SUG:NA
|
||||||
|
- DESC:elf: Add TLS modid reuse test for bug 29039
|
||||||
|
elf: Fix TLS modid reuse generation assignment
|
||||||
|
elf: Check objname before calling fatal_error
|
||||||
|
elf: Fix _dl_debug_vdprintf to work before self-relocation
|
||||||
|
elf: ldconfig should skip temporary files created by package managers
|
||||||
|
ldconfig: Fixes for skipping temporary files.
|
||||||
|
|
||||||
* Mon May 06 2024 chengyechun <chengyechun1@huaiwe.com> - 2.34-149
|
* Mon May 06 2024 chengyechun <chengyechun1@huaiwe.com> - 2.34-149
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- ID:
|
- ID:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user