History log of /sssd/src/sss_client/nss_mc_common.c
Revision Date Author Comments Expand
c269ca2669706bddb25c5938b50277b0c0a94ea4 11-Nov-2015 Lukas Slebodnik <lslebodn@redhat.com>

sssd_client: Do not use removed memory cache Resolves: https://fedorahosted.org/sssd/ticket/2726 Reviewed-by: Michal Židek <mzidek@redhat.com>

d4ff84434265dc959098ccfd4e8cd5d61d9052c9 11-Nov-2015 Lukas Slebodnik <lslebodn@redhat.com>

sss_client: Fix underflow of active_threads If the memory cache was not initialized and there was a failure in initialisation of memory cache context (e.g. memory cache file does not exist) then mc_context had to be destroyed to release resources. However the count of active threads in sss_cli_mc_ctx is already higher than zero because current thread is working wih the mc_context. But this counter was zero-ed with memset in sss_nss_mc_destroy_ctx due to issue with initialisation of memory cache. Then we have to decrease counter of active thread in function sss_nss_mc_get_ctx because initialisation of mc failed. And the result of this decrement is underflow of counter. Related to: https://fedorahosted.org/sssd/ticket/2726 Reviewed-by: Michal Židek <mzidek@redhat.com>

0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a 03-Jul-2015 Lukas Slebodnik <lslebodn@redhat.com>

sss_client: Use unique lock for memory cache Previously the sma lock was used as for communication with responder. However it would cause a deadlock in case of re-checking memcache after acquiring the lock and before communication with responder.. Required by: https://fedorahosted.org/sssd/ticket/2581 Reviewed-by: Michal Židek <mzidek@redhat.com>

6a60e29468fc6b4043a4dc52d3aab73e8465db70 24-Nov-2014 Lukas Slebodnik <lslebodn@redhat.com>

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>

19f6a6733b5c6cf7dd2f6f746cfa5c787706331c 24-Nov-2014 Lukas Slebodnik <lslebodn@redhat.com>

sss_client: Extract destroying of mmap cache to function Reviewed-by: Michal Židek <mzidek@redhat.com>

5a4df83d769ace54f92513f0be78e753e0985a25 22-Aug-2014 Nalin Dahyabhai <nalin@redhat.com>

sss_client: Fix "struct sss_cli_mc_ctx" reinitialize-on-errors When we have difficulty setting up an sss_cli_mc_ctx structure, we try to clean things up so that we'll be ready to try again the next time we're called. Part of that is closing the descriptor of the file if we've opened it and using memset() to clear the structure. Now that sss_nss_mc_get_ctx() does its work in two phases, and each one may end up doing the cleanup, each needs to be careful to reset the descriptor field so that the new value provided by memset() (0) isn't mistakenly treated as a file which should be closed by the other. Resolves: https://fedorahosted.org/sssd/ticket/2409 Reviewed-by: Simo Sorce <simo@redhat.com>

0d22416f94dff7756091e983518ed3684cc9597a 23-Jul-2014 Lukas Slebodnik <lslebodn@redhat.com>

sss_client: thread safe initialisation of sss_cli_mc_ctx In multi threaded application, it may happen that more threads will call function getpwuid(or similar) and sss client will not have initialized structure for fast memory cache. This structure is initialized just once. There isn't any problem with multi threaded application after successful initialisation. The race condition will happen if more threads try to initialise structure sss_cli_mc_ctx in function sss_nss_mc_get_ctx (ctx->initialized is false) It takes some time to initialise mmap cache: open file, get file size, mmap file, initialize structure sss_cli_mc_ctx. One of problems is that file with memory cache can be opened more times (file descriptor leak), but the race condition is with initialising structure sss_cli_mc_ctx. One tread will start to initialise this structure; another thread will think that structure is already initialised and will check consistency of this structure. It will fail because 1st thread did not finish initialisation. Therefore 2nd thread will return EINVAL and will do clean up in done section: munmap, close file and reset structure data. The 1st thread will finish an try to use memory cache, but structure was zero initialised by 2nd thread and it will cause dereference of NULL pointer in 1st thread (SIGSEGV) or dividing by zero in murmurhash function(SIGFPE) Function sss_nss_mc_get_ctx was split into two parts for simplification of locking and unlocking. The locking is used only in new static function sss_nss_mc_init_ctx. This function will not be called very often therefore the same mutex is used as in other nss functions. Resolves: https://fedorahosted.org/sssd/ticket/2380 Reviewed-by: Michal Židek <mzidek@redhat.com> Reviewed-by: Sumit Bose <sbose@redhat.com>

581de96fc30b7fe44070f17a8a73f3374d38d6ff 23-Sep-2013 Lukas Slebodnik <lslebodn@redhat.com>

mmap_cache: Use two chains for hash collision. struct sss_mc_rec had two hash members (hash1 and hash2) but only one next member. This was a big problem in case of higher probability of hash collision. structure sss_mc_rec will have two next members (next1, next2) with this patch. next1 is related to hash1 and next2 is related to hash1. Iterating over chains is changed, because we need to choose right next pointer. Right next pointer will be chosen after comparing record hashes. This behaviour is wrapped in function sss_mc_next_slot_with_hash. Adding new record to chain is also changed. The situation is very similar to iterating. We need to choose right next pointer (next1 or next2). Right next pointer will be chosen after comparing record hashes. Adding reference to next slot is wrapped in function sss_mc_chain_slot_to_record_with_hash Size of structure sss_mc_rec was increased from 32 bytes to 40 bytes. Resolves: https://fedorahosted.org/sssd/ticket/2049

fb1613b7f7deaa32957428af0e20b9a73e0f63e9 13-Sep-2013 Michal Zidek <mzidek@redhat.com>

Rename _SSS_MC_SPECIAL If the environment variable _SSS_MC_SPECIAL is set to "NO", the mmap cache is skipped in the client code. The name is not very descriptive. This patch renames the variable to SSS_NSS_USE_MEMCACHE.

3a4186ae40d0c3b7be46a4c973166f6048fcfe38 18-Mar-2013 Lukas Slebodnik <lslebodn@redhat.com>

Fix sss_client breakage. Adding missing dependencies for linker. Missing dependency was introduced by commit 22d381367c27910fe82f476a76b9f4ede555e35a in changed file src/sss_client/nss_mc_common.c All function declaration for io.c was moved from util.h to separate file io.h, https://fedorahosted.org/sssd/ticket/1838

22d381367c27910fe82f476a76b9f4ede555e35a 13-Mar-2013 Lukas Slebodnik <lslebodn@redhat.com>

Reuse sss_open_cloexec at other places in code. Functions open_cloexec and openat_cloexec were renamed with prefix "sss_" and moved to separete file. Replacing duplicated code of function sss_open_cloexec everywhere in the source code. https://fedorahosted.org/sssd/ticket/1794

53bf0219474371e4c7bc0315a42d1e39acf083bb 08-Jan-2013 Jakub Hrozek <jhrozek@redhat.com>

Potential resource leak in sss_nss_mc_get_record https://fedorahosted.org/sssd/ticket/1748

5fbd461972cb4da117cc6b3d70a932ae4de6becf 07-Jan-2013 Pavel Březina <pbrezina@redhat.com>

explicit null dereferenced in sss_nss_mc_get_record() https://fedorahosted.org/sssd/ticket/1724

a5ccff776edfa776b8846f62a161aaf358e17b66 13-Dec-2012 Simo Sorce <simo@redhat.com>

Add a macro to copy with barriers We have 2 places where we memcpy memory and need barriers protection. Use a macro so we can consolidate code in one place. Second fix for: https://fedorahosted.org/sssd/ticket/1694

fb0de650e7454e1dfa76136e325e62a00748238b 05-Dec-2012 Simo Sorce <simo@redhat.com>

Add memory barrier to mmap cache client code loop Fixes https://fedorahosted.org/sssd/ticket/1694

287e76479d68db4134274d4a4fca5fe0fbc9a605 22-Nov-2012 Jan Cholasta <jcholast@redhat.com>

Fix errors reported by rpmlint

611b6fcd3ae863bf36ae1fa4c0db89cfcdc76974 21-Jun-2012 Simo Sorce <simo@redhat.com>

Add close on exec support for old platforms Older platfroms like RHEL5 do not have support for O_CLOEXC and need an explicit fcntl after the fd is created. Add it conditionally so it can be clearly removed once we declared those platfroms obsolete and unsupported.

7767a7d37685ee8863873d65fdbf21122d742a28 21-Jun-2012 Simo Sorce <simo@redhat.com>

Do not leak file descriptors in client libs. We need to make sure the mc socket is not leaked otherwise child processes will pile up leaked file descriptors. Add O_CLOEXEC when opening the cache.

5f216c753dbd2f2b25a011c5f705ee4f8ad924e6 19-Mar-2012 Simo Sorce <simo@redhat.com>

sss_client: Add common shared memory cache utils