1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

elf: Allow dlopen of filter object to work [BZ #16272]

There are two fixes that are needed to be able to dlopen filter
objects. First _dl_map_object_deps cannot assume that map will be at
the beginning of l_searchlist.r_list[], as filtees are inserted before
map. Secondly dl_open_worker needs to ensure that filtees get
relocated.

In _dl_map_object_deps:

* avoiding removing relocation dependencies of map by setting
  l_reserved to 0 and otherwise processing the rest of the search
  list.

* ensure that map remains at the beginning of l_initfini - the list
  of things that need initialisation (and destruction). Do this by
  splitting the copy up. This may not be required, but matches the
  initialization order without dlopen.

Modify dl_open_worker to relocate the objects in new->l_inifini.
new->l_initfini is constructed in _dl_map_object_deps, and lists the
objects that need initialization and destruction. Originally the list
of objects in new->l_next are relocated. All of these objects should
also be included in new->l_initfini (both lists are populated with
dependencies in _dl_map_object_deps). We can't use new->l_prev to pick
up filtees, as during a recursive dlopen from an interposed malloc
call, l->prev can contain objects that are not ready for relocation.

Add tests to verify that symbols resolve to the filtee implementation
when auxiliary and filter objects are used, both as a normal link and
when dlopen'd.

Tested by running the testsuite on x86_64.
This commit is contained in:
David Kilroy
2020-02-12 14:28:15 -03:00
committed by Adhemerval Zanella
parent 6721b9d52e
commit eb447b7b4b
11 changed files with 327 additions and 16 deletions

View File

@ -621,22 +621,25 @@ dl_open_worker (void *a)
allows IFUNC relocations to work and it also means copy
relocation of dependencies are if necessary overwritten. */
unsigned int nmaps = 0;
struct link_map *l = new;
unsigned int j = 0;
struct link_map *l = new->l_initfini[0];
do
{
if (! l->l_real->l_relocated)
++nmaps;
l = l->l_next;
l = new->l_initfini[++j];
}
while (l != NULL);
/* Stack allocation is limited by the number of loaded objects. */
struct link_map *maps[nmaps];
nmaps = 0;
l = new;
j = 0;
l = new->l_initfini[0];
do
{
if (! l->l_real->l_relocated)
maps[nmaps++] = l;
l = l->l_next;
l = new->l_initfini[++j];
}
while (l != NULL);
_dl_sort_maps (maps, nmaps, NULL, false);