Blame SOURCES/016-fencing-crash.patch

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