- Update to upstream patch for 806070 (#806070)

This commit is contained in:
Jeff Law 2012-05-15 22:21:22 -06:00
parent 86a57e60b3
commit 2bd73a18b3
2 changed files with 113 additions and 22 deletions

View File

@ -1,7 +1,68 @@
diff -rup c/nscd/nscd_gethst_r.c d/nscd/nscd_gethst_r.c
--- c/nscd/nscd_gethst_r.c 2012-01-01 05:16:32.000000000 -0700
+++ d/nscd/nscd_gethst_r.c 2012-03-28 10:45:51.546600822 -0600
@@ -101,9 +101,27 @@ libc_freeres_fn (hst_map_free)
commit 509072a0f7f8a37bedf61a78c0cdd7783368c65a
Author: Andreas Jaeger <aj@suse.de>
Date: Tue May 15 20:35:53 2012 +0200
Avoid race in nscd
2012-05-15 Jeff Law <law@redhat.com>
Andreas Jaeger <aj@suse.de>
[BZ #13594]
* nscd/nscd-client.h (__nscd_acquire_maplock): New function, split
out from...
* nscd/nscd_helper.c (__nscd_get_map_ref): ... here.
* nscd/nscd-client.h: Add __nscd_acquire_maplock.
* nscd/nscd_gethst_r.c (__nscd_get_nl_timestamp): Add locking to
code changing __hst_map_handle.map.
diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h
index e57a23c..325368e 100644
--- a/nscd/nscd-client.h
+++ b/nscd/nscd-client.h
@@ -1,5 +1,4 @@
-/* Copyright (c) 1998, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2011
- Free Software Foundation, Inc.
+/* Copyright (c) 1998-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -322,6 +321,24 @@ struct locked_map_ptr
};
#define libc_locked_map_ptr(class, name) class struct locked_map_ptr name
+/* Try acquiring lock for mapptr, returns true if it succeeds, false
+ if not. */
+static inline bool __nscd_acquire_maplock (volatile struct locked_map_ptr *mapptr)
+{
+ int cnt = 0;
+ while (__builtin_expect (atomic_compare_and_exchange_val_acq (&mapptr->lock,
+ 1, 0) != 0, 0))
+ {
+ // XXX Best number of rounds?
+ if (__builtin_expect (++cnt > 5, 0))
+ return false;
+
+ atomic_delay ();
+ }
+
+ return true;
+}
+
/* Open socket connection to nscd server. */
extern int __nscd_open_socket (const char *key, size_t keylen,
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index c1661f8..d64ad2e 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009, 2011
- Free Software Foundation, Inc.
+/* Copyright (C) 1998-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -100,9 +99,18 @@ libc_freeres_fn (hst_map_free)
uint32_t
__nscd_get_nl_timestamp (void)
{
@ -9,34 +70,25 @@ diff -rup c/nscd/nscd_gethst_r.c d/nscd/nscd_gethst_r.c
if (__nss_not_use_nscd_hosts != 0)
return 0;
+ int cnt = 0;
+ /* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING.
+ However, __nscd_get_mapping assumes the prior value was not NO_MAPPING.
+ Thus we have to acquire the lock to prevent this thread from changing
+ hst_map_handle.mapped to NO_MAPPING while another thread is inside
+ __nscd_get_mapping. */
+ while (__builtin_expect
+ (atomic_compare_and_exchange_val_acq (&__hst_map_handle.lock,
+ 1, 0) != 0, 0))
+ {
+ // XXX Best number of rounds?
+ if (__builtin_expect (++cnt > 5, 0))
+ return 0;
+
+ atomic_delay ();
+ }
+ if (!__nscd_acquire_maplock (&__hst_map_handle))
+ return 0;
+
struct mapped_database *map = __hst_map_handle.mapped;
if (map == NULL
@@ -113,9 +131,14 @@ __nscd_get_nl_timestamp (void)
@@ -112,9 +120,14 @@ __nscd_get_nl_timestamp (void)
map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
if (map == NO_MAPPING)
- return 0;
+ retval = 0;
+ retval = 0;
+ else
+ retval = map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
+ retval = map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
+
+ /* Release the lock. */
+ __hst_map_handle.lock = 0;
@ -46,3 +98,40 @@ diff -rup c/nscd/nscd_gethst_r.c d/nscd/nscd_gethst_r.c
}
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 92558b6..96fb93d 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2007, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -419,7 +419,6 @@ __nscd_get_mapping (request_type type, const char *key,
return result;
}
-
struct mapped_database *
__nscd_get_map_ref (request_type type, const char *name,
volatile struct locked_map_ptr *mapptr, int *gc_cyclep)
@@ -428,16 +427,8 @@ __nscd_get_map_ref (request_type type, const char *name,
if (cur == NO_MAPPING)
return cur;
- int cnt = 0;
- while (__builtin_expect (atomic_compare_and_exchange_val_acq (&mapptr->lock,
- 1, 0) != 0, 0))
- {
- // XXX Best number of rounds?
- if (__builtin_expect (++cnt > 5, 0))
- return NO_MAPPING;
-
- atomic_delay ();
- }
+ if (!__nscd_acquire_maplock (mapptr))
+ return NO_MAPPING;
cur = mapptr->mapped;

View File

@ -28,7 +28,7 @@
Summary: The GNU libc libraries
Name: glibc
Version: %{glibcversion}
Release: 39%{?dist}
Release: 40%{?dist}
# GPLv2+ is used in a bunch of programs, LGPLv2+ is used for libraries.
# Things that are linked directly into dynamically linked programs
# and shared libraries (e.g. crt files, lib*_nonshared.a) have an additional
@ -109,6 +109,7 @@ Patch1038: %{name}-rh798471.patch
Patch1039: %{name}-rh758888.patch
Patch1041: %{name}-rh794797-2.patch
Patch1046: %{name}-rh806403.patch
Patch1047: %{name}-rh806070.patch
Patch1048: %{name}-rh804792.patch
Patch1052: %{name}-sw13979.patch
Patch1053: %{name}-rh817276.patch
@ -172,8 +173,6 @@ Patch2040: %{name}-rh800224.patch
Patch2045: %{name}-rh803286.patch
# Upstream BZ 13594
Patch2047: %{name}-rh806070.patch
# Upstream BZ 13939
Patch2049: %{name}-rh789238-2.patch
@ -449,7 +448,7 @@ rm -rf %{glibcportsdir}
%patch0044 -p1
%patch2045 -p1
%patch1046 -p1
%patch2047 -p1
%patch1047 -p1
%patch1048 -p1
%patch2049 -p1
%patch2050 -p1
@ -1315,6 +1314,9 @@ rm -f *.filelist*
%endif
%changelog
* Tue May 15 2012 Jeff Law <law@redhat.com> - 2.15-40
- Update to upstream patch for 806070 (#806070)
* Mon May 14 2012 Jeff Law <law@redhat.com> - 2.15-39
- Update upstream patch for AVX testing (#801650)