[PATCH] Fix incorrect double-checked locking in __nss_database_lookup. [BZ #20483]
Torvald Riegel
triegel@redhat.com
Thu Aug 18 20:49:00 GMT 2016
The pointer that serves as a cache for lookups (thus allowing users to
only perform lookup once) needs to be accessed using atomics (to avoid
data races) and with the appropriate memory orders (to ensure that
lookup actually happens-before any uses of the lookup's effects). It
might have been nicer to change the interface so that a pointer is
returned that does not need to be accessed atomically, but this would
change the ABI of nss; therefore, we keep the interface of
__nss_database_lookup unchanged but fix the synchronization in that
function and all callers.
While preparing the patch, I noticed two things that seemed odd in how
grp/initgroups.c uses __nss_database_lookup. They are marked by
comments added to the code. My guess is we should look at these in a
follow-up.
Tested on x86_64-linux.
[BZ #20483]
* nss/nsswitch.h (__nss_database_lookup): Add documentation.
* nss/nsswitch.c: Include <atomic.h>
(__nss_database_lookup): Fix synchronization.
(nss_load_all_libraries): Adapt.
* grp/initgroups.c (internal_getgrouplist): Adapt.
* nss/XXX-lookup.c (DB_LOOKUP_FCT): Adapt.
* nscd/aicache.c (addhstaiX): Adapt.
* nscd/initgrcache.c (addinitgroupsX): Adapt.
* nscd/netgroupcache.c (addgetnetgrentX): Adapt.
* nis/nss_compat/compat-grp.c (ni_once): New.
(init_nss_interface): Adapt.
* nis/nss_compat/compat-initgroups.c (init_nss_interface,
internal_setgrent): Adapt.
* nis/nss_compat/compat-pwd.c (ni_once): New.
(init_nss_interface): Adapt.
* nis/nss_compat/compat-spwd.c (ni_once): New.
(init_nss_interface): Adapt.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Adapt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nss_database_lookup.patch
Type: text/x-patch
Size: 19951 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160818/da75bb31/attachment.bin>
More information about the Libc-alpha
mailing list