Blame SOURCES/012-notify-crash.patch

d4e586
From ed8b2c86ab77aaa3d7fd688c049ad5e1b922a9c6 Mon Sep 17 00:00:00 2001
d4e586
From: Reid Wahl <nrwahl@protonmail.com>
d4e586
Date: Thu, 13 Jan 2022 02:56:55 -0800
d4e586
Subject: [PATCH] Fix: liblrmd: Avoid double-free during notify operation
d4e586
d4e586
This commit fixes a regression introduced by 31c7fa8a, causing a
d4e586
double-free in notify operations. lrmd_dispatch_internal() assigns the
d4e586
exit_reason string directly from an XML node to a new lrmd_event_data_t
d4e586
object (without duplicating), and this string gets freed twice.
d4e586
d4e586
Free #1: pcmk__create_history_xml() (reached via callback) calls
d4e586
lrmd__set_result(), which frees event.exit_reason and sets it to NULL.
d4e586
Free #2: lrmd_ipc_dispatch() frees the XML node, which contains a
d4e586
pointer to the exit_reason string just freed, after
d4e586
lrmd_dispatch_internal() returns.
d4e586
d4e586
Prior to 31c7fa8a, pcmk__create_history_xml reset event.rc and
d4e586
event.op_status but **not** event.exit_reason.
d4e586
d4e586
In this commit we simply make a copy of event.exit_reason in
d4e586
lrmd_dispatch_internal() before the callback. This way we don't have to
d4e586
worry about whatever happens in the callback, and we can continue to
d4e586
unset the exit_reason alongside the rc and op_status. The added overhead
d4e586
should be minimal.
d4e586
d4e586
This commit also makes a copy of output. That's not strictly necessary
d4e586
but adds some futureproofing and allows us to call lrmd__reset_result()
d4e586
at the end of lrmd_dispatch_internal().
d4e586
d4e586
Resolves: RHBZ#2039675
d4e586
d4e586
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
d4e586
---
d4e586
 lib/lrmd/lrmd_client.c | 8 +++++---
d4e586
 1 file changed, 5 insertions(+), 3 deletions(-)
d4e586
d4e586
diff --git a/lib/lrmd/lrmd_client.c b/lib/lrmd/lrmd_client.c
d4e586
index ee31bb5ae9..5131a648b7 100644
d4e586
--- a/lib/lrmd/lrmd_client.c
d4e586
+++ b/lib/lrmd/lrmd_client.c
d4e586
@@ -305,9 +305,10 @@ lrmd_dispatch_internal(lrmd_t * lrmd, xmlNode * msg)
d4e586
         event.user_data = crm_element_value(msg, F_LRMD_RSC_USERDATA_STR);
d4e586
         event.type = lrmd_event_exec_complete;
d4e586
 
d4e586
-        // No need to duplicate the memory, so don't use setter functions
d4e586
-        event.output = crm_element_value(msg, F_LRMD_RSC_OUTPUT);
d4e586
-        event.exit_reason = crm_element_value(msg, F_LRMD_RSC_EXIT_REASON);
d4e586
+        /* output and exit_reason may be freed by a callback */
d4e586
+        event.output = crm_element_value_copy(msg, F_LRMD_RSC_OUTPUT);
d4e586
+        lrmd__set_result(&event, event.rc, event.op_status,
d4e586
+                         crm_element_value(msg, F_LRMD_RSC_EXIT_REASON));
d4e586
 
d4e586
         event.params = xml2list(msg);
d4e586
     } else if (pcmk__str_eq(type, LRMD_OP_NEW_CLIENT, pcmk__str_none)) {
d4e586
@@ -324,6 +325,7 @@ lrmd_dispatch_internal(lrmd_t * lrmd, xmlNode * msg)
d4e586
     if (event.params) {
d4e586
         g_hash_table_destroy(event.params);
d4e586
     }
d4e586
+    lrmd__reset_result(&event);
d4e586
 }
d4e586
 
d4e586
 // \return Always 0, to indicate that IPC mainloop source should be kept
d4e586
-- 
d4e586
2.27.0
d4e586