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

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