aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-load.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2019-06-18 16:42:10 +0200
committerFlorian Weimer <fweimer@redhat.com>2019-06-18 16:42:10 +0200
commit2c75b545de6fe3c44138799c68217a94bc669a88 (patch)
treefa8cd3f23ec090151bfac600ee394757634cfa05 /elf/dl-load.c
parent02d8b5ab1c89bcef2627d2b621bfb35b573852c2 (diff)
downloadglibc-2c75b545de6fe3c44138799c68217a94bc669a88.tar
glibc-2c75b545de6fe3c44138799c68217a94bc669a88.tar.gz
glibc-2c75b545de6fe3c44138799c68217a94bc669a88.tar.bz2
glibc-2c75b545de6fe3c44138799c68217a94bc669a88.zip
elf: Refuse to dlopen PIE objects [BZ #24323]
Another executable has already been mapped, so the dynamic linker cannot perform relocations correctly for the second executable.
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r--elf/dl-load.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 2bbef81b6e..5abeb867f1 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1158,6 +1158,10 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
goto call_lose;
}
+ /* dlopen of an executable is not valid because it is not possible
+ to perform proper relocations, handle static TLS, or run the
+ ELF constructors. For PIE, the check needs the dynamic
+ section, so there is another check below. */
if (__glibc_unlikely (type != ET_DYN)
&& __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0))
{
@@ -1194,9 +1198,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
elf_get_dynamic_info (l, NULL);
/* Make sure we are not dlopen'ing an object that has the
- DF_1_NOOPEN flag set. */
- if (__glibc_unlikely (l->l_flags_1 & DF_1_NOOPEN)
- && (mode & __RTLD_DLOPEN))
+ DF_1_NOOPEN flag set, or a PIE object. */
+ if ((__glibc_unlikely (l->l_flags_1 & DF_1_NOOPEN)
+ && (mode & __RTLD_DLOPEN))
+ || (__glibc_unlikely (l->l_flags_1 & DF_1_PIE)
+ && __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0)))
{
/* We are not supposed to load this object. Free all resources. */
_dl_unmap_segments (l);
@@ -1207,7 +1213,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
if (l->l_phdr_allocated)
free ((void *) l->l_phdr);
- errstring = N_("shared object cannot be dlopen()ed");
+ if (l->l_flags_1 & DF_1_PIE)
+ errstring
+ = N_("cannot dynamically load position-independent executable");
+ else
+ errstring = N_("shared object cannot be dlopen()ed");
goto call_lose;
}