From a509eb117fac1d764b15eba64993f4bdb63d7f3c Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 27 Nov 2019 16:37:17 +0100 Subject: Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] This change splits the scope and TLS slotinfo updates in dlopen into two parts: one to resize the data structures, and one to actually apply the update. The call to add_to_global_resize in dl_open_worker is moved before the demarcation point at which no further memory allocations are allowed. _dl_add_to_slotinfo is adjusted to make the list update optional. There is some optimization possibility here because we could grow the slotinfo list of arrays in a single call, one the largest TLS modid is known. This commit does not fix the fatal meory allocation failure in _dl_update_slotinfo. Ideally, this error during dlopen should be recoverable. The update order of scopes and TLS data structures is retained, although it appears to be more correct to fully initialize TLS first, and then expose symbols in the newly loaded objects via the scope update. Tested on x86_64-linux-gnu. Change-Id: I240c58387dabda3ca1bcab48b02115175fa83d6c --- elf/dl-tls.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'elf/dl-tls.c') diff --git a/elf/dl-tls.c b/elf/dl-tls.c index a4b0529..65d3520 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -883,7 +883,7 @@ _dl_tls_get_addr_soft (struct link_map *l) void -_dl_add_to_slotinfo (struct link_map *l) +_dl_add_to_slotinfo (struct link_map *l, bool do_add) { /* Now that we know the object is loaded successfully add modules containing TLS data to the dtv info table. We @@ -939,6 +939,9 @@ cannot create TLS data structures")); } /* Add the information into the slotinfo data structure. */ - listp->slotinfo[idx].map = l; - listp->slotinfo[idx].gen = GL(dl_tls_generation) + 1; + if (do_add) + { + listp->slotinfo[idx].map = l; + listp->slotinfo[idx].gen = GL(dl_tls_generation) + 1; + } } -- cgit v1.1