diff options
author | Torvald Riegel <triegel@redhat.com> | 2016-08-17 13:56:11 +0200 |
---|---|---|
committer | Torvald Riegel <triegel@redhat.com> | 2016-08-18 20:53:37 +0200 |
commit | 6f9d4f595e4073807ad0e844cbb3b3d7158b76d5 (patch) | |
tree | d0064a3e11f1326fcdfcad1b239076044da9a762 /resolv | |
parent | b65f0b7b2ecd144800830633a4c2719f11775572 (diff) | |
download | glibc-6f9d4f595e4073807ad0e844cbb3b3d7158b76d5.tar glibc-6f9d4f595e4073807ad0e844cbb3b3d7158b76d5.tar.gz glibc-6f9d4f595e4073807ad0e844cbb3b3d7158b76d5.tar.bz2 glibc-6f9d4f595e4073807ad0e844cbb3b3d7158b76d5.zip |
Fix incorrect double-checked locking related to _res_hconf.initialized.
_res_hconf.initialized was not suitable for use in a multi-threaded
environment due to the lack of atomics and memory barriers. Use of it was
also unnecessary because _res_hconf_init did the right thing by using
__libc_once. This patch fixes the glibc-internal uses by just calling
_res_hconf_init unconditionally, and switches to a release MO atomic store
for _res_hconf.initialized to fix the glibc side of the synchronization
problem (which will maintain backward compatibility, but cannot fix the
lack of acquire MO on any glibc-external loads).
[BZ #20477]
* resolv/res_hconf.c (do_init): Use atomic access.
* resolv/res_hconf.h: Add comments.
* nscd/aicache.c (addhstaiX): Call _res_hconf_init unconditionally.
* nss/getXXbyYY_r.c (REENTRANT_NAME): Likewise.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
Diffstat (limited to 'resolv')
-rw-r--r-- | resolv/res_hconf.c | 3 | ||||
-rw-r--r-- | resolv/res_hconf.h | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c index 5cd128916d..093c26837f 100644 --- a/resolv/res_hconf.c +++ b/resolv/res_hconf.c @@ -348,7 +348,8 @@ do_init (void) arg_trimdomain_list (ENV_TRIM_OVERR, 1, envval); } - _res_hconf.initialized = 1; + /* See comments on the declaration of _res_hconf. */ + atomic_store_release (&_res_hconf.initialized, 1); } diff --git a/resolv/res_hconf.h b/resolv/res_hconf.h index b97734df9e..a3d23f3e58 100644 --- a/resolv/res_hconf.h +++ b/resolv/res_hconf.h @@ -25,6 +25,15 @@ struct hconf { + /* We keep the INITIALIZED member only for backwards compatibility. New + code should just call _res_hconf_init unconditionally. For this field + to be used safely, users must ensure that either (1) a call to + _res_hconf_init happens-before any load from INITIALIZED, or (2) an + assignment of zero to INITIALIZED happens-before any load from it, and + these loads use acquire MO if the intent is to skip calling + _res_hconf_init if the load returns a nonzero value. Such acquire MO + loads will then synchronize with the release MO store to INITIALIZED + in do_init in res_hconf.c; see pthread_once for more detail. */ int initialized; int unused1; int unused2[4]; |