View | Details | Raw Unified | Return to bug 18684
Collapse All | Expand All

(-)a/dlfcn/dlmopen.c (-5 lines)
Lines 61-71 dlmopen_doit (void *a) Link Here
61
      if (args->file == NULL)
61
      if (args->file == NULL)
62
# endif
62
# endif
63
	GLRO(dl_signal_error) (EINVAL, NULL, NULL, N_("invalid namespace"));
63
	GLRO(dl_signal_error) (EINVAL, NULL, NULL, N_("invalid namespace"));
64
65
      /* It makes no sense to use RTLD_GLOBAL when loading a DSO into
66
	 a namespace other than the base namespace.  */
67
      if (__glibc_unlikely (args->mode & RTLD_GLOBAL))
68
	GLRO(dl_signal_error) (EINVAL, NULL, NULL, N_("invalid mode"));
69
    }
64
    }
70
65
71
  args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
66
  args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
(-)a/elf/dl-open.c (-1 / +25 lines)
Lines 72-77 add_to_global (struct link_map *new) Link Here
72
    if (new->l_searchlist.r_list[cnt]->l_global == 0)
72
    if (new->l_searchlist.r_list[cnt]->l_global == 0)
73
      ++to_add;
73
      ++to_add;
74
74
75
  struct link_namespaces *ns = &GL(dl_ns)[new->l_ns];
76
77
  if (__glibc_unlikely (new->l_ns != LM_ID_BASE
78
			&& ns->_ns_main_searchlist == NULL))
79
    {
80
      /* An initial object was loaded with dlmopen into a distinct namespace
81
	 that has no global searchlist (RTLD_GLOBAL) and RTLD_GLOBAL was used.
82
	 Or that object then dlopened another object into the global
83
	 searchlist.  We find ourselves with no global searchlist initialized.
84
	 We have two choices, either we forbid this scenario and return an
85
	 error or treat the first RTLD_GLOBAL DSOs searchlist as the global
86
	 searchlist of the namespace.  We do the latter since it's the most
87
	 sensible course of action since you may dlmopen other libraries which
88
	 have no idea they have been isolated.  Thus RTLD_GLOBAL dlopen calls
89
	 within the new namespace are restricted to the new namespace and may
90
	 reference the symbols of the initial RTLD_GLOBAL dlmopen'd
91
	 libraries.  */
92
      ns->_ns_main_searchlist = &new->l_searchlist;
93
      /* Treat this list like it is read-only.  A value of zero forces a copy
94
	 later if we need to extend this list.  The list itself is already
95
	 being used as the primary scope for the first loaded RTLD_GLOBAL
96
	 object into the new namespace, thus we don't want to free it.  */
97
      ns->_ns_global_scope_alloc = 0;
98
    }
99
75
  /* The symbols of the new objects and its dependencies are to be
100
  /* The symbols of the new objects and its dependencies are to be
76
     introduced into the global scope that will be used to resolve
101
     introduced into the global scope that will be used to resolve
77
     references from other dynamically-loaded objects.
102
     references from other dynamically-loaded objects.
Lines 86-92 add_to_global (struct link_map *new) Link Here
86
     in an realloc() call.  Therefore we allocate a completely new
111
     in an realloc() call.  Therefore we allocate a completely new
87
     array the first time we have to add something to the locale scope.  */
112
     array the first time we have to add something to the locale scope.  */
88
113
89
  struct link_namespaces *ns = &GL(dl_ns)[new->l_ns];
90
  if (ns->_ns_global_scope_alloc == 0)
114
  if (ns->_ns_global_scope_alloc == 0)
91
    {
115
    {
92
      /* This is the first dynamic object given global scope.  */
116
      /* This is the first dynamic object given global scope.  */

Return to bug 18684