Sourceware Bugzilla – Attachment 13661 Details for
Bug 18684
dlmopen a DSO that dlopen's into RTLD_GLOBAL segfaults.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
1-line patch plus comments originally written by Carlos O'Donell
18684-RTLD_GLOBAL.patch (text/plain), 2.68 KB, created by
Eric Wheeler
on 2021-09-10 23:28:37 UTC
(
hide
)
Description:
1-line patch plus comments originally written by Carlos O'Donell
Filename:
MIME Type:
Creator:
Eric Wheeler
Created:
2021-09-10 23:28:37 UTC
Size:
2.68 KB
patch
obsolete
>diff --git a/dlfcn/dlmopen.c b/dlfcn/dlmopen.c >index 38dca7a..ba468d2 100644 >--- a/dlfcn/dlmopen.c >+++ b/dlfcn/dlmopen.c >@@ -61,11 +61,6 @@ dlmopen_doit (void *a) > if (args->file == NULL) > # endif > GLRO(dl_signal_error) (EINVAL, NULL, NULL, N_("invalid namespace")); >- >- /* It makes no sense to use RTLD_GLOBAL when loading a DSO into >- a namespace other than the base namespace. */ >- if (__glibc_unlikely (args->mode & RTLD_GLOBAL)) >- GLRO(dl_signal_error) (EINVAL, NULL, NULL, N_("invalid mode")); > } > > args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN, >diff --git a/elf/dl-open.c b/elf/dl-open.c >index 027c1e0..175ef16 100644 >--- a/elf/dl-open.c >+++ b/elf/dl-open.c >@@ -72,6 +72,31 @@ add_to_global (struct link_map *new) > if (new->l_searchlist.r_list[cnt]->l_global == 0) > ++to_add; > >+ struct link_namespaces *ns = &GL(dl_ns)[new->l_ns]; >+ >+ if (__glibc_unlikely (new->l_ns != LM_ID_BASE >+ && ns->_ns_main_searchlist == NULL)) >+ { >+ /* An initial object was loaded with dlmopen into a distinct namespace >+ that has no global searchlist (RTLD_GLOBAL) and RTLD_GLOBAL was used. >+ Or that object then dlopened another object into the global >+ searchlist. We find ourselves with no global searchlist initialized. >+ We have two choices, either we forbid this scenario and return an >+ error or treat the first RTLD_GLOBAL DSOs searchlist as the global >+ searchlist of the namespace. We do the latter since it's the most >+ sensible course of action since you may dlmopen other libraries which >+ have no idea they have been isolated. Thus RTLD_GLOBAL dlopen calls >+ within the new namespace are restricted to the new namespace and may >+ reference the symbols of the initial RTLD_GLOBAL dlmopen'd >+ libraries. */ >+ ns->_ns_main_searchlist = &new->l_searchlist; >+ /* Treat this list like it is read-only. A value of zero forces a copy >+ later if we need to extend this list. The list itself is already >+ being used as the primary scope for the first loaded RTLD_GLOBAL >+ object into the new namespace, thus we don't want to free it. */ >+ ns->_ns_global_scope_alloc = 0; >+ } >+ > /* The symbols of the new objects and its dependencies are to be > introduced into the global scope that will be used to resolve > references from other dynamically-loaded objects. >@@ -86,7 +111,6 @@ add_to_global (struct link_map *new) > in an realloc() call. Therefore we allocate a completely new > array the first time we have to add something to the locale scope. */ > >- struct link_namespaces *ns = &GL(dl_ns)[new->l_ns]; > if (ns->_ns_global_scope_alloc == 0) > { > /* This is the first dynamic object given global scope. */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 18684
: 13661