Blame SOURCES/0025-daemon-Fix-double-closed-fd-race-condition.patch

10661d
From b2ec373cfec2dd6a39acfd91ea1a67618ee209ac Mon Sep 17 00:00:00 2001
10661d
From: Martin Kutlak <mkutlak@redhat.com>
10661d
Date: Tue, 20 Nov 2018 19:03:55 +0100
10661d
Subject: [PATCH] daemon: Fix double closed fd race condition
10661d
10661d
When a communication channel is set up between abrtd and abrt-server it uses
10661d
abrt_gio_channel_unix_new(). In that function there is a call g_io_channel_set_close_on_unref() [1].
10661d
This function sets whether to close a file/socket/whatever associated with the channel when channel
10661d
recieves a final unref and is to be destroyed.
10661d
10661d
Calling a close() on fd associated with the channel before/after g_io_channel_unref()
10661d
created a double close() race condition when ABRT was processing a lot of crashes at the same time.
10661d
10661d
Thank you benzea for the patch.
10661d
10661d
Related BZ#1650622
10661d
10661d
1 - https://developer.gnome.org/glib/stable/glib-IO-Channels.html#g-io-channel-get-close-on-unref
10661d
10661d
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
10661d
---
10661d
 src/daemon/abrt-server.c | 1 -
10661d
 src/daemon/abrtd.c       | 4 +---
10661d
 2 files changed, 1 insertion(+), 4 deletions(-)
10661d
10661d
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
10661d
index 692ccee38..90068069d 100644
10661d
--- a/src/daemon/abrt-server.c
10661d
+++ b/src/daemon/abrt-server.c
10661d
@@ -364,7 +364,6 @@ static int run_post_create(const char *dirname, struct response *resp)
10661d
     g_main_loop_unref(context.main_loop);
10661d
     g_io_channel_unref(channel_signal);
10661d
     close(g_signal_pipe[1]);
10661d
-    close(g_signal_pipe[0]);
10661d
 
10661d
     log_notice("Waiting finished");
10661d
 
10661d
diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c
10661d
index 32753966b..fefb2e9c9 100644
10661d
--- a/src/daemon/abrtd.c
10661d
+++ b/src/daemon/abrtd.c
10661d
@@ -114,7 +114,6 @@ static void stop_abrt_server(struct abrt_server_proc *proc)
10661d
 
10661d
 static void dispose_abrt_server(struct abrt_server_proc *proc)
10661d
 {
10661d
-    close(proc->fdout);
10661d
     free(proc->dirname);
10661d
 
10661d
     if (proc->watch_id > 0)
10661d
@@ -231,8 +230,7 @@ static gboolean abrt_server_output_cb(GIOChannel *channel, GIOCondition conditio
10661d
     GList *item = g_list_find_custom(s_processes, &fdout, (GCompareFunc)abrt_server_compare_fdout);
10661d
     if (item == NULL)
10661d
     {
10661d
-        log_warning("Closing a pipe fd (%d) without a process assigned", fdout);
10661d
-        close(fdout);
10661d
+        log_warning("Removing an input channel fd (%d) without a process assigned", fdout);
10661d
         return FALSE;
10661d
     }
10661d
 
10661d
-- 
10661d
2.17.2
10661d