1
Description: Fix thread locking for __nscd_get_mapping
2
This patch should solve occasional chromium-browser crashes,
3
and other possibly-related (ktorrent?) crashes from thread
4
corruption in __nscd_get_mapping.
5
Author: Jeff Law <law@redhat.com>
6
Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=13594
7
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/chromium-browser/+bug/929219
9
diff -rup c/nscd/nscd_gethst_r.c d/nscd/nscd_gethst_r.c
10
--- c/nscd/nscd_gethst_r.c 2012-01-01 05:16:32.000000000 -0700
11
+++ d/nscd/nscd_gethst_r.c 2012-03-28 10:45:51.546600822 -0600
12
@@ -101,9 +101,27 @@ libc_freeres_fn (hst_map_free)
14
__nscd_get_nl_timestamp (void)
17
if (__nss_not_use_nscd_hosts != 0)
21
+ /* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING.
22
+ However, __nscd_get_mapping assumes the prior value was not NO_MAPPING.
23
+ Thus we have to acquire the lock to prevent this thread from changing
24
+ hst_map_handle.mapped to NO_MAPPING while another thread is inside
25
+ __nscd_get_mapping. */
26
+ while (__builtin_expect
27
+ (atomic_compare_and_exchange_val_acq (&__hst_map_handle.lock,
30
+ // XXX Best number of rounds?
31
+ if (__builtin_expect (++cnt > 5, 0))
37
struct mapped_database *map = __hst_map_handle.mapped;
40
@@ -113,9 +131,14 @@ __nscd_get_nl_timestamp (void)
41
map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
43
if (map == NO_MAPPING)
47
+ retval = map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
49
+ /* Release the lock. */
50
+ __hst_map_handle.lock = 0;
52
- return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];