Blame SOURCES/Do-not-call-gpm_grab_sock-twice.patch

472fdf
From 32578afb817f20446d888326814b52a8f3d6c0fe Mon Sep 17 00:00:00 2001
472fdf
From: Simo Sorce <simo@redhat.com>
472fdf
Date: Thu, 26 Oct 2017 16:59:18 -0400
472fdf
Subject: [PATCH] Do not call gpm_grab_sock() twice
472fdf
472fdf
In the gpm_get_ctx() call, we unnecessarily call gpm_grab_sock() which
472fdf
would cause the lock to be held by one thread and never released.  We
472fdf
already call gpm_grab_sock() as the first thing after gpm_get_ctx() in
472fdf
gpm_make_call(), plus gpm_make_call() properly releases the socket
472fdf
once done.
472fdf
472fdf
This corrects the deadlock fix in
472fdf
461a5fa9f91a2753ebeef6323a64239c35e2f250, which incorrectly released
472fdf
the lock we wanted to grab.  This caused the socket to not be locked
472fdf
to our thread.  Another thread could come along and change the global
472fdf
ctx while we were still using the socket from another thread, causing
472fdf
concurrency issues as only one request can be in flight on any given
472fdf
socket at the same time.
472fdf
472fdf
In special cases where the "thread" uid/gid changes (like in
472fdf
rpc.gssd), we end up closing the socket while we are still waiting for
472fdf
an answer from the server, causing additional issues and confusion.
472fdf
472fdf
[rharwood@redhat.com: squashed 2 commits; minor edits accordingly]
472fdf
Signed-off-by: Simo Sorce <simo@redhat.com>
472fdf
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
472fdf
Merges: #218
472fdf
(cherry picked from commit 8590c5dbc6fa07d0c366df23b982a4b6b9ffc259)
472fdf
---
472fdf
 proxy/src/client/gpm_common.c | 9 +++------
472fdf
 1 file changed, 3 insertions(+), 6 deletions(-)
472fdf
472fdf
diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c
472fdf
index 69f4741..2133618 100644
472fdf
--- a/proxy/src/client/gpm_common.c
472fdf
+++ b/proxy/src/client/gpm_common.c
472fdf
@@ -152,7 +152,9 @@ static int gpm_grab_sock(struct gpm_ctx *gpmctx)
472fdf
         ret = gpm_open_socket(gpmctx);
472fdf
     }
472fdf
 
472fdf
-    pthread_mutex_unlock(&gpmctx->lock);
472fdf
+    if (ret) {
472fdf
+        pthread_mutex_unlock(&gpmctx->lock);
472fdf
+    }
472fdf
     return ret;
472fdf
 }
472fdf
 
472fdf
@@ -304,11 +306,6 @@ static struct gpm_ctx *gpm_get_ctx(void)
472fdf
 
472fdf
     pthread_once(&gpm_init_once_control, gpm_init_once);
472fdf
 
472fdf
-    ret = gpm_grab_sock(&gpm_global_ctx);
472fdf
-    if (ret) {
472fdf
-        return NULL;
472fdf
-    }
472fdf
-
472fdf
     return &gpm_global_ctx;
472fdf
 }
472fdf