Blame SOURCES/016-fencing-crash.patch

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