cead9d
From 10f1730073b9fb02d2ed7f7de855afd6df0e5202 Mon Sep 17 00:00:00 2001
cead9d
From: Xavi Hernandez <xhernandez@redhat.com>
cead9d
Date: Wed, 19 Feb 2020 12:24:15 +0100
cead9d
Subject: [PATCH 355/355] core: Prevent crash on process termination
cead9d
cead9d
A previous patch (ce61da816a) has fixed a use-after-free issue,
cead9d
but it doesn't work well when the final cleanup is done at process
cead9d
termination because gluster doesn't stop other threads before
cead9d
calling exit().
cead9d
cead9d
For this reason, the final cleanup is removed to avoid the crash,
cead9d
at least until the termination sequence properly stops all gluster
cead9d
threads before exiting the program.
cead9d
cead9d
Upstream patch:
cead9d
> Upstream patch link: https://review.gluster.org/c/glusterfs/+/24138
cead9d
> Change-Id: Id7cfb4407fcf208e28f03a7c3cdc3ef9c1f3bf9b
cead9d
> Fixes: bz#1801684
cead9d
> Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
cead9d
cead9d
Change-Id: Id7cfb4407fcf208e28f03a7c3cdc3ef9c1f3bf9b
cead9d
BUG: 1800703
cead9d
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
cead9d
Reviewed-on: https://code.engineering.redhat.com/gerrit/192344
cead9d
Tested-by: RHGS Build Bot <nigelb@redhat.com>
cead9d
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
cead9d
---
cead9d
 libglusterfs/src/mem-pool.c | 30 +++++++++++-------------------
cead9d
 1 file changed, 11 insertions(+), 19 deletions(-)
cead9d
cead9d
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
cead9d
index 2b41c01..73503e0 100644
cead9d
--- a/libglusterfs/src/mem-pool.c
cead9d
+++ b/libglusterfs/src/mem-pool.c
cead9d
@@ -541,25 +541,17 @@ mem_pools_preinit(void)
cead9d
 static __attribute__((destructor)) void
cead9d
 mem_pools_postfini(void)
cead9d
 {
cead9d
-    per_thread_pool_list_t *pool_list, *next;
cead9d
-
cead9d
-    /* This is part of a process shutdown (or dlclose()) which means that
cead9d
-     * most probably all threads should be stopped. However this is not the
cead9d
-     * case for gluster and there are even legitimate situations in which we
cead9d
-     * could have some threads alive. What is sure is that none of those
cead9d
-     * threads should be using anything from this library, so destroying
cead9d
-     * everything here should be fine and safe. */
cead9d
-
cead9d
-    list_for_each_entry_safe(pool_list, next, &pool_threads, thr_list)
cead9d
-    {
cead9d
-        mem_pool_thread_destructor(pool_list);
cead9d
-    }
cead9d
-
cead9d
-    list_for_each_entry_safe(pool_list, next, &pool_free_threads, thr_list)
cead9d
-    {
cead9d
-        list_del(&pool_list->thr_list);
cead9d
-        FREE(pool_list);
cead9d
-    }
cead9d
+    /* TODO: This function should destroy all per thread memory pools that
cead9d
+     *       are still alive, but this is not possible right now because glibc
cead9d
+     *       starts calling destructors as soon as exit() is called, and
cead9d
+     *       gluster doesn't ensure that all threads have been stopped before
cead9d
+     *       calling exit(). Existing threads would crash when they try to use
cead9d
+     *       memory or they terminate if we destroy things here.
cead9d
+     *
cead9d
+     *       When we propertly terminate all threads, we can add the needed
cead9d
+     *       code here. Till then we need to leave the memory allocated. Most
cead9d
+     *       probably this function will be executed on process termination,
cead9d
+     *       so the memory will be released anyway by the system. */
cead9d
 }
cead9d
 
cead9d
 /* Call mem_pools_init() once threading has been configured completely. This
cead9d
-- 
cead9d
1.8.3.1
cead9d