Blame SOURCES/0006-CLIENT-MC-pointer-to-the-context-mutex-shouldn-t-be-.patch

de2e0a
From d386e94ef49d95d7305a3e6578e41a2cf61dfc5c Mon Sep 17 00:00:00 2001
de2e0a
From: Alexey Tikhonov <atikhono@redhat.com>
de2e0a
Date: Tue, 16 Aug 2022 21:51:03 +0200
de2e0a
Subject: [PATCH 6/6] CLIENT:MC: pointer to the context mutex shouldn't be
de2e0a
 touched
de2e0a
MIME-Version: 1.0
de2e0a
Content-Type: text/plain; charset=UTF-8
de2e0a
Content-Transfer-Encoding: 8bit
de2e0a
de2e0a
Even brief window inside `sss_nss_mc_destroy_ctx()` when `mutex == NULL`
de2e0a
was creating a possibility for a race.
de2e0a
de2e0a
Reviewed-by: Sumit Bose <sbose@redhat.com>
de2e0a
Reviewed-by: Tomáš Halman <thalman@redhat.com>
de2e0a
(cherry picked from commit 4ac93d9c5df59cdb7f397b4467f1c1c4822ff757)
de2e0a
---
de2e0a
 src/sss_client/nss_mc.h        |  4 +++-
de2e0a
 src/sss_client/nss_mc_common.c | 20 ++++++++++----------
de2e0a
 2 files changed, 13 insertions(+), 11 deletions(-)
de2e0a
de2e0a
diff --git a/src/sss_client/nss_mc.h b/src/sss_client/nss_mc.h
de2e0a
index 0f88521e9..9ab2736fa 100644
de2e0a
--- a/src/sss_client/nss_mc.h
de2e0a
+++ b/src/sss_client/nss_mc.h
de2e0a
@@ -44,7 +44,9 @@ enum sss_mc_state {
de2e0a
     RECYCLED,
de2e0a
 };
de2e0a
 
de2e0a
-/* common stuff */
de2e0a
+/* In the case this structure is extended, don't forget to update
de2e0a
+ * `SSS_CLI_MC_CTX_INITIALIZER` and `sss_nss_mc_destroy_ctx()`.
de2e0a
+ */
de2e0a
 struct sss_cli_mc_ctx {
de2e0a
     enum sss_mc_state initialized;
de2e0a
 #if HAVE_PTHREAD
de2e0a
diff --git a/src/sss_client/nss_mc_common.c b/src/sss_client/nss_mc_common.c
de2e0a
index f38a4a85a..3128861bf 100644
de2e0a
--- a/src/sss_client/nss_mc_common.c
de2e0a
+++ b/src/sss_client/nss_mc_common.c
de2e0a
@@ -130,25 +130,25 @@ errno_t sss_nss_check_header(struct sss_cli_mc_ctx *ctx)
de2e0a
 
de2e0a
 static void sss_nss_mc_destroy_ctx(struct sss_cli_mc_ctx *ctx)
de2e0a
 {
de2e0a
-    uint32_t active_threads = ctx->active_threads;
de2e0a
-#if HAVE_PTHREAD
de2e0a
-    pthread_mutex_t *mutex = ctx->mutex;
de2e0a
-#endif
de2e0a
 
de2e0a
     if ((ctx->mmap_base != NULL) && (ctx->mmap_size != 0)) {
de2e0a
         munmap(ctx->mmap_base, ctx->mmap_size);
de2e0a
     }
de2e0a
+    ctx->mmap_base = NULL;
de2e0a
+    ctx->mmap_size = 0;
de2e0a
+
de2e0a
     if (ctx->fd != -1) {
de2e0a
         close(ctx->fd);
de2e0a
     }
de2e0a
-    memset(ctx, 0, sizeof(struct sss_cli_mc_ctx));
de2e0a
     ctx->fd = -1;
de2e0a
 
de2e0a
-    /* restore count of active threads */
de2e0a
-    ctx->active_threads = active_threads;
de2e0a
-#if HAVE_PTHREAD
de2e0a
-    ctx->mutex = mutex;
de2e0a
-#endif
de2e0a
+    ctx->seed = 0;
de2e0a
+    ctx->data_table = NULL;
de2e0a
+    ctx->dt_size = 0;
de2e0a
+    ctx->hash_table = NULL;
de2e0a
+    ctx->ht_size = 0;
de2e0a
+    ctx->initialized = UNINITIALIZED;
de2e0a
+    /* `mutex` and `active_threads` should be left intact */
de2e0a
 }
de2e0a
 
de2e0a
 static errno_t sss_nss_mc_init_ctx(const char *name,
de2e0a
-- 
de2e0a
2.37.1
de2e0a