Blame SOURCES/016-fencing-crash.patch

33afe3
From e330568504ec379ea42460d21a2e20b1652d9445 Mon Sep 17 00:00:00 2001
33afe3
From: Reid Wahl <nrwahl@protonmail.com>
33afe3
Date: Fri, 14 Jan 2022 01:35:35 -0800
33afe3
Subject: [PATCH] Fix: fencing: Don't set stonith action to pending if fork
33afe3
 fails
33afe3
33afe3
Currently, we set a stonith action to pending if
33afe3
services_action_async_fork_notify() returns true. However, "true" means
33afe3
that the svc_action should not be freed. This might be because the
33afe3
svc_action forked successfully and is pending, or it might be because
33afe3
the svc_action has already been freed.
33afe3
33afe3
In the case of stonith actions, if we fail to fork, the stonith_action_t
33afe3
object stored in svc_action->cb_data gets freed by the done callback,
33afe3
and services_action_async_fork_notify() returns true. If we try to set
33afe3
the action to pending, it causes a segfault.
33afe3
33afe3
This commit moves the "set to pending" step to the
33afe3
stonith_action_async_forked() callback. We avoid the segfault and only
33afe3
set it to pending if it's actually pending.
33afe3
33afe3
A slight difference in ordering was required to achieve this. Now, the
33afe3
action gets set to pending immediately before being added to the
33afe3
mainloop, instead of immediately after.
33afe3
33afe3
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
33afe3
---
33afe3
 lib/fencing/st_actions.c | 5 +++--
33afe3
 1 file changed, 3 insertions(+), 2 deletions(-)
33afe3
33afe3
diff --git a/lib/fencing/st_actions.c b/lib/fencing/st_actions.c
33afe3
index e4e43225cd..306001af69 100644
33afe3
--- a/lib/fencing/st_actions.c
33afe3
+++ b/lib/fencing/st_actions.c
33afe3
@@ -550,6 +550,9 @@ stonith_action_async_forked(svc_action_t *svc_action)
33afe3
         (action->fork_cb) (svc_action->pid, action->userdata);
33afe3
     }
33afe3
 
33afe3
+    pcmk__set_result(&(action->result), PCMK_OCF_UNKNOWN, PCMK_EXEC_PENDING,
33afe3
+                     NULL);
33afe3
+
33afe3
     crm_trace("Child process %d performing action '%s' successfully forked",
33afe3
               action->pid, action->action);
33afe3
 }
33afe3
@@ -619,8 +622,6 @@ internal_stonith_action_execute(stonith_action_t * action)
33afe3
         if (services_action_async_fork_notify(svc_action,
33afe3
                                               &stonith_action_async_done,
33afe3
                                               &stonith_action_async_forked)) {
33afe3
-            pcmk__set_result(&(action->result), PCMK_OCF_UNKNOWN,
33afe3
-                             PCMK_EXEC_PENDING, NULL);
33afe3
             return pcmk_ok;
33afe3
         }
33afe3
 
33afe3
-- 
33afe3
2.27.0
33afe3