diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-09-22 23:41:41 +0000 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-09-22 23:41:41 +0000 |
commit | 6c5cad2aa56745302c1d42d2c8baf6424d29c0f3 (patch) | |
tree | ffd055a36f8e90fcbfde9e1e01d4a15d7aed3399 /src | |
parent | d47d9a50f2568927af51e21b2f2120409db1ab44 (diff) | |
download | musl-6c5cad2aa56745302c1d42d2c8baf6424d29c0f3.tar.gz musl-6c5cad2aa56745302c1d42d2c8baf6424d29c0f3.tar.bz2 musl-6c5cad2aa56745302c1d42d2c8baf6424d29c0f3.tar.xz musl-6c5cad2aa56745302c1d42d2c8baf6424d29c0f3.zip |
fix dlsym RTLD_NEXT behavior for fdpic
lookup the dso an address falls in based on the loadmap and not just a
base/length. fix the main app's fake loadmap used when loaded by a
non-fdpic-aware loader so that it does not cover the whole memory
space.
function descriptor addresses are also matched for future use by
dladdr, but reverse lookups of function descriptors via dladdr have
not been implemented yet. some revisions may be needed in the future
once reclaim_gaps supports fdpic, so that function descriptors
allocated in reclaimed heap space do not get detected as belonging to
the module whose gaps they were allocated in.
Diffstat (limited to 'src')
-rw-r--r-- | src/ldso/dynlink.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index 0c3b36ce..cab30089 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -1543,8 +1543,10 @@ _Noreturn void __dls3(size_t *sp) if (!app.loadmap) { app.loadmap = (void *)&app_dummy_loadmap; app.loadmap->nsegs = 1; - app.loadmap->segs[0].addr = (size_t)app.base; - app.loadmap->segs[0].p_memsz = -1; + app.loadmap->segs[0].addr = (size_t)app.map; + app.loadmap->segs[0].p_vaddr = (size_t)app.map + - (size_t)app.base; + app.loadmap->segs[0].p_memsz = app.map_len; } argv[-3] = (void *)app.loadmap; } @@ -1738,6 +1740,28 @@ static int invalid_dso_handle(void *h) return 1; } +static void *addr2dso(size_t a) +{ + struct dso *p; + for (p=head; p; p=p->next) { + if (DL_FDPIC && p->loadmap) { + size_t i; + for (i=0; i<p->loadmap->nsegs; i++) { + if (a-p->loadmap->segs[i].p_vaddr + < p->loadmap->segs[i].p_memsz) + return p; + } + i = count_syms(p); + if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs)) + return p; + } else { + if (a-(size_t)p->map < p->map_len) + return p; + } + } + return 0; +} + void *__tls_get_addr(size_t *); static void *do_dlsym(struct dso *p, const char *s, void *ra) @@ -1749,7 +1773,7 @@ static void *do_dlsym(struct dso *p, const char *s, void *ra) if (p == RTLD_DEFAULT) { p = head; } else if (p == RTLD_NEXT) { - for (p=head; p && (unsigned char *)ra-p->map>p->map_len; p=p->next); + p = addr2dso((size_t)ra); if (!p) p=head; p = p->next; } @@ -1806,7 +1830,7 @@ int __dladdr(const void *addr, Dl_info *info) char *bestname; pthread_rwlock_rdlock(&lock); - for (p=head; p && (unsigned char *)addr-p->map>p->map_len; p=p->next); + p = addr2dso((size_t)addr); pthread_rwlock_unlock(&lock); if (!p) return 0; |