summaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorAndreas Krebbel <Andreas.Krebbel@de.ibm.com>2010-10-26 00:23:14 -0400
committerPetr Baudis <pasky@suse.cz>2010-11-15 18:03:57 +0100
commit4e951b593897f603ecd754a43dfec721e8a64e6b (patch)
tree2791086f47fdfb7d8a264a5b872e45e7b3ea5d81 /elf
parentfa55fd7e5b1da8bd2dddffab82931e2495e82435 (diff)
downloadglibc-4e951b593897f603ecd754a43dfec721e8a64e6b.tar.gz
Fix concurrency problem between dl_open and dl_iterate_phdr
(cherry picked from commit f09677388a44cd1460f8986ef1b096c73bd5b958) Fix assertion in ld.so, introduced by delayed adding to global list. (cherry picked from commit fa41c84d73be804639ecb2250f0b793b1a6f765e)
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-load.c25
-rw-r--r--elf/dl-object.c46
-rw-r--r--elf/rtld.c11
3 files changed, 46 insertions, 36 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 8a8ffb4b60..aa324d1fba 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -801,19 +801,7 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
/* The file might already be closed. */
if (fd != -1)
(void) __close (fd);
- if (l != NULL)
- {
- /* Remove the stillborn object from the list and free it. */
- assert (l->l_next == NULL);
- if (l->l_prev == NULL)
- /* No other module loaded. This happens only in the static library,
- or in rtld under --verify. */
- GL(dl_ns)[l->l_ns]._ns_loaded = NULL;
- else
- l->l_prev->l_next = NULL;
- --GL(dl_ns)[l->l_ns]._ns_nloaded;
- free (l);
- }
+ free (l);
free (realname);
if (r != NULL)
@@ -898,6 +886,9 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
never be unloaded. */
__close (fd);
+ /* Add the map for the mirrored object to the object list. */
+ _dl_add_to_namespace_list (l, nsid);
+
return l;
}
#endif
@@ -1492,6 +1483,9 @@ cannot enable executable stack as shared object requires");
add_name_to_object (l, ((const char *) D_PTR (l, l_info[DT_STRTAB])
+ l->l_info[DT_SONAME]->d_un.d_val));
+ /* Now that the object is fully initialized add it to the object list. */
+ _dl_add_to_namespace_list (l, nsid);
+
#ifdef SHARED
/* Auditing checkpoint: we have a new object. */
if (__builtin_expect (GLRO(dl_naudit) > 0, 0)
@@ -2206,7 +2200,7 @@ _dl_map_object (struct link_map *loader, const char *name,
have. */
static const Elf_Symndx dummy_bucket = STN_UNDEF;
- /* Enter the new object in the list of loaded objects. */
+ /* Allocate a new object map. */
if ((name_copy = local_strdup (name)) == NULL
|| (l = _dl_new_object (name_copy, name, type, loader,
mode, nsid)) == NULL)
@@ -2224,6 +2218,9 @@ _dl_map_object (struct link_map *loader, const char *name,
l->l_nbuckets = 1;
l->l_relocated = 1;
+ /* Enter the object in the object list. */
+ _dl_add_to_namespace_list (l, nsid);
+
return l;
}
else if (found_other_class)
diff --git a/elf/dl-object.c b/elf/dl-object.c
index 788e2c07b9..542a28c2b4 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -1,5 +1,5 @@
/* Storage management for the chain of loaded shared objects.
- Copyright (C) 1995-2002,2004,2006-2008,2009 Free Software Foundation, Inc.
+ Copyright (C) 1995-2002,2004,2006-2009,2010 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
@@ -26,16 +26,36 @@
#include <assert.h>
+/* Add the new link_map NEW to the end of the namespace list. */
+void
+internal_function
+_dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
+{
+ if (GL(dl_ns)[nsid]._ns_loaded != NULL)
+ {
+ struct link_map *l = GL(dl_ns)[nsid]._ns_loaded;
+ while (l->l_next != NULL)
+ l = l->l_next;
+ new->l_prev = l;
+ /* new->l_next = NULL; Would be necessary but we use calloc. */
+ l->l_next = new;
+ }
+ else
+ GL(dl_ns)[nsid]._ns_loaded = new;
+ ++GL(dl_ns)[nsid]._ns_nloaded;
+ new->l_serial = GL(dl_load_adds);
+ ++GL(dl_load_adds);
+}
+
+
/* Allocate a `struct link_map' for a new object being loaded,
and enter it into the _dl_loaded list. */
-
struct link_map *
internal_function
_dl_new_object (char *realname, const char *libname, int type,
struct link_map *loader, int mode, Lmid_t nsid)
{
struct link_map *l;
- int idx;
size_t libname_len = strlen (libname) + 1;
struct link_map *new;
struct libname_list *newname;
@@ -94,25 +114,11 @@ _dl_new_object (char *realname, const char *libname, int type,
new->l_scope_max = sizeof (new->l_scope_mem) / sizeof (new->l_scope_mem[0]);
/* Counter for the scopes we have to handle. */
- idx = 0;
+ int idx = 0;
if (GL(dl_ns)[nsid]._ns_loaded != NULL)
- {
- l = GL(dl_ns)[nsid]._ns_loaded;
- while (l->l_next != NULL)
- l = l->l_next;
- new->l_prev = l;
- /* new->l_next = NULL; Would be necessary but we use calloc. */
- l->l_next = new;
-
- /* Add the global scope. */
- new->l_scope[idx++] = &GL(dl_ns)[nsid]._ns_loaded->l_searchlist;
- }
- else
- GL(dl_ns)[nsid]._ns_loaded = new;
- ++GL(dl_ns)[nsid]._ns_nloaded;
- new->l_serial = GL(dl_load_adds);
- ++GL(dl_load_adds);
+ /* Add the global scope. */
+ new->l_scope[idx++] = &GL(dl_ns)[nsid]._ns_loaded->l_searchlist;
/* If we have no loader the new object acts as it. */
if (loader == NULL)
diff --git a/elf/rtld.c b/elf/rtld.c
index 5b7eabcb85..26096936ce 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1088,11 +1088,15 @@ of this helper program; chances are you did not intend to run this program.\n\
main_map = _dl_new_object ((char *) "", "", lt_executable, NULL,
__RTLD_OPENEXEC, LM_ID_BASE);
assert (main_map != NULL);
- assert (main_map == GL(dl_ns)[LM_ID_BASE]._ns_loaded);
main_map->l_phdr = phdr;
main_map->l_phnum = phnum;
main_map->l_entry = *user_entry;
+ /* Even though the link map is not yet fully initialized we can add
+ it to the map list since there are no possible users running yet. */
+ _dl_add_to_namespace_list (main_map, LM_ID_BASE);
+ assert (main_map == GL(dl_ns)[LM_ID_BASE]._ns_loaded);
+
/* At this point we are in a bit of trouble. We would have to
fill in the values for l_dev and l_ino. But in general we
do not know where the file is. We also do not handle AT_EXECFD
@@ -1235,7 +1239,7 @@ of this helper program; chances are you did not intend to run this program.\n\
/* We were invoked directly, so the program might not have a
PT_INTERP. */
_dl_rtld_libname.name = GL(dl_rtld_map).l_name;
- /* _dl_rtld_libname.next = NULL; Already zero. */
+ /* _dl_rtld_libname.next = NULL; Already zero. */
GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
}
else
@@ -1360,6 +1364,9 @@ of this helper program; chances are you did not intend to run this program.\n\
l->l_libname->name = memcpy (copy, dsoname, len);
}
+ /* Add the vDSO to the object list. */
+ _dl_add_to_namespace_list (l, LM_ID_BASE);
+
/* Rearrange the list so this DSO appears after rtld_map. */
assert (l->l_next == NULL);
assert (l->l_prev == main_map);