summary refs log tree commit diff
path: root/elf/dl-open.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-12-30 19:19:37 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-05-11 17:16:37 +0100
commitf4f8f4d4e0f92488431b268c8cd9555730b9afe9 (patch)
tree5bdda8e64325bdf0c3a69e3ddd483a0ce47fb614 /elf/dl-open.c
parent1387ad6225c2222f027790e3f460e31aa5dd2c54 (diff)
downloadglibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.tar.gz
glibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.tar.xz
glibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.zip
elf: Use relaxed atomics for racy accesses [BZ #19329]
This is a follow up patch to the fix for bug 19329.  This adds relaxed
MO atomics to accesses that were previously data races but are now
race conditions, and where relaxed MO is sufficient.

The race conditions all follow the pattern that the write is behind the
dlopen lock, but a read can happen concurrently (e.g. during tls access)
without holding the lock.  For slotinfo entries the read value only
matters if it reads from a synchronized write in dlopen or dlclose,
otherwise the related dtv entry is not valid to access so it is fine
to leave it in an inconsistent state.  The same applies for
GL(dl_tls_max_dtv_idx) and GL(dl_tls_generation), but there the
algorithm relies on the fact that the read of the last synchronized
write is an increasing value.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/dl-open.c')
-rw-r--r--elf/dl-open.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 09f0df7d38..bb79ef00f1 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -395,9 +395,12 @@ update_tls_slotinfo (struct link_map *new)
 	}
     }
 
-  if (__builtin_expect (++GL(dl_tls_generation) == 0, 0))
+  size_t newgen = GL(dl_tls_generation) + 1;
+  if (__glibc_unlikely (newgen == 0))
     _dl_fatal_printf (N_("\
 TLS generation counter wrapped!  Please report this."));
+  /* Can be read concurrently.  */
+  atomic_store_relaxed (&GL(dl_tls_generation), newgen);
 
   /* We need a second pass for static tls data, because
      _dl_update_slotinfo must not be run while calls to