diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-12-30 19:19:37 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2021-05-11 17:16:37 +0100 |
commit | f4f8f4d4e0f92488431b268c8cd9555730b9afe9 (patch) | |
tree | 5bdda8e64325bdf0c3a69e3ddd483a0ce47fb614 /sysdeps | |
parent | 1387ad6225c2222f027790e3f460e31aa5dd2c54 (diff) | |
download | glibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.tar glibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.tar.gz glibc-f4f8f4d4e0f92488431b268c8cd9555730b9afe9.tar.bz2 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 'sysdeps')
-rw-r--r-- | sysdeps/x86_64/dl-tls.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/sysdeps/x86_64/dl-tls.c b/sysdeps/x86_64/dl-tls.c index 6595f6615b..24ef560b71 100644 --- a/sysdeps/x86_64/dl-tls.c +++ b/sysdeps/x86_64/dl-tls.c @@ -40,7 +40,8 @@ __tls_get_addr_slow (GET_ADDR_ARGS) { dtv_t *dtv = THREAD_DTV (); - if (__glibc_unlikely (dtv[0].counter != GL(dl_tls_generation))) + size_t gen = atomic_load_relaxed (&GL(dl_tls_generation)); + if (__glibc_unlikely (dtv[0].counter != gen)) return update_get_addr (GET_ADDR_PARAM); return tls_get_addr_tail (GET_ADDR_PARAM, dtv, NULL); |