73667d0be6
* Thu Apr 28 2022 Carlos O'Donell <carlos@redhat.com> - 2.34-32 - Sync with upstream branch release/2.34/master, commit c66c92181ddbd82306537a608e8c0282587131de: - posix/glob.c: update from gnulib (BZ#25659) - linux: Fix fchmodat with AT_SYMLINK_NOFOLLOW for 64 bit time_t (BZ#29097) * Wed Apr 27 2022 Carlos O'Donell <carlos@redhat.com> - 2.34-31 - Sync with upstream branch release/2.34/master, commit 55640ed3fde48360a8e8083be4843bd2dc7cecfe: - i386: Regenerate ulps - linux: Fix missing internal 64 bit time_t stat usage - x86: Optimize L(less_vec) case in memcmp-evex-movbe.S - x86: Don't set Prefer_No_AVX512 for processors with AVX512 and AVX-VNNI - x86-64: Use notl in EVEX strcmp [BZ #28646] - x86: Shrink memcmp-sse4.S code size - x86: Double size of ERMS rep_movsb_threshold in dl-cacheinfo.h - x86: Optimize memmove-vec-unaligned-erms.S - x86-64: Replace movzx with movzbl - x86-64: Remove Prefer_AVX2_STRCMP - x86-64: Improve EVEX strcmp with masked load - x86: Replace sse2 instructions with avx in memcmp-evex-movbe.S - x86: Optimize memset-vec-unaligned-erms.S - x86: Optimize memcmp-evex-movbe.S for frontend behavior and size - x86: Modify ENTRY in sysdep.h so that p2align can be specified - x86-64: Optimize load of all bits set into ZMM register [BZ #28252] - scripts/glibcelf.py: Mark as UNSUPPORTED on Python 3.5 and earlier - dlfcn: Do not use rtld_active () to determine ld.so state (bug 29078) - INSTALL: Rephrase -with-default-link documentation - misc: Fix rare fortify crash on wchar funcs. [BZ 29030] - Default to --with-default-link=no (bug 25812) - scripts: Add glibcelf.py module * Thu Apr 21 2022 Carlos O'Donell <carlos@redhat.com> - 2.34-30 - Sync with upstream branch release/2.34/master, commit 71326f1f2fd09dafb9c34404765fb88129e94237: - nptl: Fix pthread_cancel cancelhandling atomic operations - mips: Fix mips64n32 64 bit time_t stat support (BZ#29069) - hurd: Fix arbitrary error code - nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029) - S390: Add new s390 platform z16. - NEWS: Update fixed bug list for LD_AUDIT backports. - hppa: Fix bind-now audit (BZ #28857) - elf: Replace tst-audit24bmod2.so with tst-audit24bmod2 - Fix elf/tst-audit25a with default bind now toolchains - elf: Fix runtime linker auditing on aarch64 (BZ #26643) - elf: Issue la_symbind for bind-now (BZ #23734) - elf: Fix initial-exec TLS access on audit modules (BZ #28096) - elf: Add la_activity during application exit - elf: Do not fail for failed dlmopen on audit modules (BZ #28061) - elf: Issue audit la_objopen for vDSO - elf: Add audit tests for modules with TLSDESC - elf: Avoid unnecessary slowdown from profiling with audit (BZ#15533) - elf: Add _dl_audit_pltexit - elf: Add _dl_audit_pltenter - elf: Add _dl_audit_preinit - elf: Add _dl_audit_symbind_alt and _dl_audit_symbind - elf: Add _dl_audit_objclose - elf: Add _dl_audit_objsearch - elf: Add _dl_audit_activity_map and _dl_audit_activity_nsid - elf: Add _dl_audit_objopen - elf: Move la_activity (LA_ACT_ADD) after _dl_add_to_namespace_list() (BZ #28062) - elf: Move LAV_CURRENT to link_lavcurrent.h - elf: Fix elf_get_dynamic_info() for bootstrap - elf: Fix dynamic-link.h usage on rtld.c - elf: Fix elf_get_dynamic_info definition - elf: Avoid nested functions in the loader [BZ #27220] - powerpc: Delete unneeded ELF_MACHINE_BEFORE_RTLD_RELOC - hppa: Use END instead of PSEUDO_END in swapcontext.S - hppa: Implement swapcontext in assembler (bug 28960) Resolves: #2003291 Resolves: #2064181 Resolves: #2072328 Resolves: #2075713 Resolves: #2077838
242 lines
8.2 KiB
Diff
242 lines
8.2 KiB
Diff
commit c6df39a0bd2aafd2a4280a0000ef201f30273bee
|
|
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
Date: Mon Oct 11 16:01:49 2021 -0300
|
|
|
|
elf: Fix elf_get_dynamic_info definition
|
|
|
|
Before to 490e6c62aa31a8a ('elf: Avoid nested functions in the loader
|
|
[BZ #27220]'), elf_get_dynamic_info() was defined twice on rtld.c: on
|
|
the first dynamic-link.h include and later within _dl_start(). The
|
|
former definition did not define DONT_USE_BOOTSTRAP_MAP and it is used
|
|
on setup_vdso() (since it is a global definition), while the former does
|
|
define DONT_USE_BOOTSTRAP_MAP and it is used on loader self-relocation.
|
|
|
|
With the commit change, the function is now included and defined once
|
|
instead of defined as a nested function. So rtld.c defines without
|
|
defining RTLD_BOOTSTRAP and it brokes at least powerpc32.
|
|
|
|
This patch fixes by moving the get-dynamic-info.h include out of
|
|
dynamic-link.h, which then the caller can corirectly set the expected
|
|
semantic by defining STATIC_PIE_BOOTSTRAP, RTLD_BOOTSTRAP, and/or
|
|
RESOLVE_MAP.
|
|
|
|
It also required to enable some asserts only for the loader bootstrap
|
|
to avoid issues when called from setup_vdso().
|
|
|
|
As a side note, this is another issues with nested functions: it is
|
|
not clear from pre-processed output (-E -dD) how the function will
|
|
be build and its semantic (since nested function will be local and
|
|
extra C defines may change it).
|
|
|
|
I checked on x86_64-linux-gnu (w/o --enable-static-pie),
|
|
i686-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu-power4,
|
|
aarch64-linux-gnu, arm-linux-gnu, sparc64-linux-gnu, and
|
|
s390x-linux-gnu.
|
|
|
|
Reviewed-by: Fangrui Song <maskray@google.com>
|
|
(cherry picked from commit 4af6982e4c9fc465ffb7a54b794aaaa134241f05)
|
|
|
|
Resolved conflicts:
|
|
elf/rtld.c
|
|
|
|
diff --git a/elf/dl-conflict.c b/elf/dl-conflict.c
|
|
index 5c8e51d19ae095d6..d54356dee3f86ae0 100644
|
|
--- a/elf/dl-conflict.c
|
|
+++ b/elf/dl-conflict.c
|
|
@@ -17,6 +17,7 @@
|
|
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
+#include <assert.h>
|
|
#include <errno.h>
|
|
#include <libintl.h>
|
|
#include <stdlib.h>
|
|
diff --git a/elf/dl-load.c b/elf/dl-load.c
|
|
index 0976977fbdf21902..eea06629a978aaf3 100644
|
|
--- a/elf/dl-load.c
|
|
+++ b/elf/dl-load.c
|
|
@@ -58,6 +58,7 @@ struct filebuf
|
|
};
|
|
|
|
#include "dynamic-link.h"
|
|
+#include "get-dynamic-info.h"
|
|
#include <abi-tag.h>
|
|
#include <stackinfo.h>
|
|
#include <sysdep.h>
|
|
@@ -1295,7 +1296,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
|
if (l->l_ld != 0)
|
|
l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
|
|
|
|
- elf_get_dynamic_info (l);
|
|
+ elf_get_dynamic_info (l, false);
|
|
|
|
/* Make sure we are not dlopen'ing an object that has the
|
|
DF_1_NOOPEN flag set, or a PIE object. */
|
|
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
|
|
index a52ba8aeb8b573cb..f323b4dd0d5ba279 100644
|
|
--- a/elf/dl-reloc-static-pie.c
|
|
+++ b/elf/dl-reloc-static-pie.c
|
|
@@ -28,6 +28,7 @@
|
|
#define STATIC_PIE_BOOTSTRAP
|
|
#define RESOLVE_MAP(map, scope, sym, version, flags) map
|
|
#include "dynamic-link.h"
|
|
+#include "get-dynamic-info.h"
|
|
|
|
/* Relocate static executable with PIE. */
|
|
|
|
@@ -51,7 +52,7 @@ _dl_relocate_static_pie (void)
|
|
break;
|
|
}
|
|
|
|
- elf_get_dynamic_info (main_map);
|
|
+ elf_get_dynamic_info (main_map, false);
|
|
|
|
# ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
|
|
ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info);
|
|
diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
|
|
index 9d0d941000f6114f..61c260ddb81b586c 100644
|
|
--- a/elf/dl-runtime.c
|
|
+++ b/elf/dl-runtime.c
|
|
@@ -19,6 +19,7 @@
|
|
#define IN_DL_RUNTIME 1 /* This can be tested in dl-machine.h. */
|
|
|
|
#include <alloca.h>
|
|
+#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/param.h>
|
|
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
|
|
index 7cc30211649d3820..21cdfc88bbfb89ea 100644
|
|
--- a/elf/dynamic-link.h
|
|
+++ b/elf/dynamic-link.h
|
|
@@ -93,7 +93,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
|
|
|
|
#include <dl-machine.h>
|
|
|
|
-#include "get-dynamic-info.h"
|
|
|
|
#ifdef RESOLVE_MAP
|
|
|
|
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
|
|
index 15c316b38c05a90c..d169099fbc9897cf 100644
|
|
--- a/elf/get-dynamic-info.h
|
|
+++ b/elf/get-dynamic-info.h
|
|
@@ -25,7 +25,7 @@
|
|
#include <libc-diag.h>
|
|
|
|
static inline void __attribute__ ((unused, always_inline))
|
|
-elf_get_dynamic_info (struct link_map *l)
|
|
+elf_get_dynamic_info (struct link_map *l, bool check)
|
|
{
|
|
#if __ELF_NATIVE_CLASS == 32
|
|
typedef Elf32_Word d_tag_utype;
|
|
@@ -112,16 +112,19 @@ elf_get_dynamic_info (struct link_map *l)
|
|
assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
|
|
#endif
|
|
#ifdef RTLD_BOOTSTRAP
|
|
- /* Only the bind now flags are allowed. */
|
|
- assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
|
|
- || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
|
|
- /* Flags must not be set for ld.so. */
|
|
- assert (info[DT_FLAGS] == NULL
|
|
- || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
|
|
-#endif
|
|
-#if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP
|
|
- assert (info[DT_RUNPATH] == NULL);
|
|
- assert (info[DT_RPATH] == NULL);
|
|
+ if (check)
|
|
+ {
|
|
+ /* Only the bind now flags are allowed. */
|
|
+ assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
|
|
+ || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
|
|
+ /* Flags must not be set for ld.so. */
|
|
+ assert (info[DT_FLAGS] == NULL
|
|
+ || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
|
|
+# ifdef STATIC_PIE_BOOTSTRAP
|
|
+ assert (info[DT_RUNPATH] == NULL);
|
|
+ assert (info[DT_RPATH] == NULL);
|
|
+# endif
|
|
+ }
|
|
#else
|
|
if (info[DT_FLAGS] != NULL)
|
|
{
|
|
diff --git a/elf/rtld.c b/elf/rtld.c
|
|
index ee45657aeac14f3c..352d596dedb42e79 100644
|
|
--- a/elf/rtld.c
|
|
+++ b/elf/rtld.c
|
|
@@ -514,6 +514,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
|
|
is trivial: always the map of ld.so itself. */
|
|
#define RTLD_BOOTSTRAP
|
|
#define RESOLVE_MAP(map, scope, sym, version, flags) map
|
|
+#include "get-dynamic-info.h"
|
|
#include "dynamic-link.h"
|
|
|
|
static ElfW(Addr) __attribute_used__
|
|
@@ -549,7 +550,7 @@ _dl_start (void *arg)
|
|
/* Read our own dynamic section and fill in the info array. */
|
|
bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
|
|
bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION;
|
|
- elf_get_dynamic_info (&bootstrap_map);
|
|
+ elf_get_dynamic_info (&bootstrap_map, true);
|
|
|
|
#if NO_TLS_OFFSET != 0
|
|
bootstrap_map.l_tls_offset = NO_TLS_OFFSET;
|
|
@@ -1653,7 +1654,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
|
if (! rtld_is_main)
|
|
{
|
|
/* Extract the contents of the dynamic section for easy access. */
|
|
- elf_get_dynamic_info (main_map);
|
|
+ elf_get_dynamic_info (main_map, false);
|
|
|
|
/* If the main map is libc.so, update the base namespace to
|
|
refer to this map. If libc.so is loaded later, this happens
|
|
diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
|
|
index f44748bc9858e5fd..6fdffafcca5e9916 100644
|
|
--- a/elf/setup-vdso.h
|
|
+++ b/elf/setup-vdso.h
|
|
@@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
|
|
l->l_map_end += l->l_addr;
|
|
l->l_text_end += l->l_addr;
|
|
l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
|
|
- elf_get_dynamic_info (l);
|
|
+ elf_get_dynamic_info (l, false);
|
|
_dl_setup_hash (l);
|
|
l->l_relocated = 1;
|
|
|
|
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
|
|
index 7e6761bbe87540d5..86f866ca7c17bd9b 100644
|
|
--- a/sysdeps/arm/dl-machine.h
|
|
+++ b/sysdeps/arm/dl-machine.h
|
|
@@ -21,6 +21,7 @@
|
|
|
|
#define ELF_MACHINE_NAME "ARM"
|
|
|
|
+#include <assert.h>
|
|
#include <sys/param.h>
|
|
#include <tls.h>
|
|
#include <dl-tlsdesc.h>
|
|
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
|
|
index 78ce890c0ff333ca..fa902612ca8557f9 100644
|
|
--- a/sysdeps/i386/dl-machine.h
|
|
+++ b/sysdeps/i386/dl-machine.h
|
|
@@ -21,6 +21,7 @@
|
|
|
|
#define ELF_MACHINE_NAME "i386"
|
|
|
|
+#include <assert.h>
|
|
#include <sys/param.h>
|
|
#include <sysdep.h>
|
|
#include <tls.h>
|
|
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
|
|
index d3fcbb37bf1f4f7c..90c77cfea1de8d63 100644
|
|
--- a/sysdeps/x86_64/dl-machine.h
|
|
+++ b/sysdeps/x86_64/dl-machine.h
|
|
@@ -22,6 +22,7 @@
|
|
|
|
#define ELF_MACHINE_NAME "x86_64"
|
|
|
|
+#include <assert.h>
|
|
#include <sys/param.h>
|
|
#include <sysdep.h>
|
|
#include <tls.h>
|