doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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