summaryrefslogtreecommitdiffstats
path: root/src/sss_client/nss_mc.h
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2014-11-21 11:28:36 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-11-24 20:54:00 +0100
commit6a60e29468fc6b4043a4dc52d3aab73e8465db70 (patch)
tree8c79f852113b017fe6a875ff2259b67fb38b71ee /src/sss_client/nss_mc.h
parent19f6a6733b5c6cf7dd2f6f746cfa5c787706331c (diff)
downloadsssd-6a60e29468fc6b4043a4dc52d3aab73e8465db70.tar.gz
sssd-6a60e29468fc6b4043a4dc52d3aab73e8465db70.tar.xz
sssd-6a60e29468fc6b4043a4dc52d3aab73e8465db70.zip
sss_client: Fix race condition in memory cache
Thread safe initialisation was fixed in ticket #2380, but there is still race condition in reinitialisation. If caches is invalidated with command sss_cache -U (-G or -E) then client code will need to reinitialize fast memory cache. Let say we have two threads. The 1st thread find out that memory cache should be reinitialized; therefore the fast memory cached is unmapped and context destroyed. In the same time, 2nd thread tried to check header of memory cache whether it is initialized and valid. As a result of previously unmapped memory the 2nd thread access out of bound memory (SEGFAULT). The destroying of fast memory cache cannot be done any time. We need to be sure that there isn't any other thread which uses mmaped memory. The new counter of active threads was added for this purpose. The state of fast memory cache was converted from boolean to three value state (UNINITIALIZED, INITIALIZED, RECYCLED) UNINITIALIZED - the fast memory cache need to be initialized. - if there is a problem with initialisation the state will not change - after successful initialisation, the state will change to INITIALIZED INITIALIZED - if the cahe was invalidated or there is any other problem was detected in memory cache header the state will change to RECYCLED and memory cache IS NOT destroyed. RECYCLED - nothing will be done is there are any active threads which may use the data from mmaped memory - if there aren't active threads the fast memory cahe is destroyed and state is changed to UNINITIALIZED. https://fedorahosted.org/sssd/ticket/2445 Reviewed-by: Michal Židek <mzidek@redhat.com>
Diffstat (limited to 'src/sss_client/nss_mc.h')
-rw-r--r--src/sss_client/nss_mc.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/sss_client/nss_mc.h b/src/sss_client/nss_mc.h
index 685cc41c0..050bd4100 100644
--- a/src/sss_client/nss_mc.h
+++ b/src/sss_client/nss_mc.h
@@ -33,9 +33,15 @@
typedef int errno_t;
#endif
+enum sss_mc_state {
+ UNINITIALIZED = 0,
+ INITIALIZED,
+ RECYCLED,
+};
+
/* common stuff */
struct sss_cli_mc_ctx {
- bool initialized;
+ enum sss_mc_state initialized;
int fd;
uint32_t seed; /* seed from the tables header */
@@ -48,6 +54,8 @@ struct sss_cli_mc_ctx {
uint32_t *hash_table; /* hash table address (in mmap) */
uint32_t ht_size; /* size of hash table */
+
+ uint32_t active_threads; /* count of threads which use memory cache */
};
errno_t sss_nss_mc_get_ctx(const char *name, struct sss_cli_mc_ctx *ctx);