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