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