From e510f55bed6c26c6b995e7d9f3c35e1e4e482769 Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Sat, 11 May 2019 22:40:22 +0530 Subject: glusterfsd/cleanup: Protect graph object under a lock While processing a cleanup_and_exit function, we are accessing a graph object. But this has not been protected under a lock. Because a parallel cleanup of a graph is quite possible which might lead to an invalid memory access Change-Id: Id05ca70d5b57e172b0401d07b6a1f5386c044e79 fixes: bz#1708926 Signed-off-by: Mohammed Rafi KC --- libglusterfs/src/statedump.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'libglusterfs/src/statedump.c') diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 04a7e18ef3b..7426b91a156 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -807,11 +807,17 @@ gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx) gf_msg_trace("dump", 0, "received statedump request (sig:USR1)"); - gf_proc_dump_lock(); - if (!ctx) goto out; + /* + * Multiplexed daemons can change the active graph when attach/detach + * is called. So this has to be protected with the cleanup lock. + */ + if (mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name)) + pthread_mutex_lock(&ctx->cleanup_lock); + gf_proc_dump_lock(); + if (!mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name) && (ctx && ctx->active)) { top = ctx->active->first; @@ -925,7 +931,11 @@ gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx) out: GF_FREE(dump_options.dump_path); dump_options.dump_path = NULL; - gf_proc_dump_unlock(); + if (ctx) { + gf_proc_dump_unlock(); + if (mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name)) + pthread_mutex_unlock(&ctx->cleanup_lock); + } return; } -- cgit