Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-distro / recipes-security / gssproxy / files / Do-not-call-gpm_grab_sock-twice.patch
1 From 32578afb817f20446d888326814b52a8f3d6c0fe Mon Sep 17 00:00:00 2001
2 From: Simo Sorce <simo@redhat.com>
3 Date: Thu, 26 Oct 2017 16:59:18 -0400
4 Subject: [PATCH] Do not call gpm_grab_sock() twice
5
6 In the gpm_get_ctx() call, we unnecessarily call gpm_grab_sock() which
7 would cause the lock to be held by one thread and never released.  We
8 already call gpm_grab_sock() as the first thing after gpm_get_ctx() in
9 gpm_make_call(), plus gpm_make_call() properly releases the socket
10 once done.
11
12 This corrects the deadlock fix in
13 461a5fa9f91a2753ebeef6323a64239c35e2f250, which incorrectly released
14 the lock we wanted to grab.  This caused the socket to not be locked
15 to our thread.  Another thread could come along and change the global
16 ctx while we were still using the socket from another thread, causing
17 concurrency issues as only one request can be in flight on any given
18 socket at the same time.
19
20 In special cases where the "thread" uid/gid changes (like in
21 rpc.gssd), we end up closing the socket while we are still waiting for
22 an answer from the server, causing additional issues and confusion.
23
24 [rharwood@redhat.com: squashed 2 commits; minor edits accordingly]
25 Signed-off-by: Simo Sorce <simo@redhat.com>
26 Reviewed-by: Robbie Harwood <rharwood@redhat.com>
27 Merges: #218
28 (cherry picked from commit 8590c5dbc6fa07d0c366df23b982a4b6b9ffc259)
29 ---
30  proxy/src/client/gpm_common.c | 9 +++------
31  1 file changed, 3 insertions(+), 6 deletions(-)
32
33 diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c
34 index 69f4741..2133618 100644
35 --- a/proxy/src/client/gpm_common.c
36 +++ b/proxy/src/client/gpm_common.c
37 @@ -152,7 +152,9 @@ static int gpm_grab_sock(struct gpm_ctx *gpmctx)
38          ret = gpm_open_socket(gpmctx);
39      }
40  
41 -    pthread_mutex_unlock(&gpmctx->lock);
42 +    if (ret) {
43 +        pthread_mutex_unlock(&gpmctx->lock);
44 +    }
45      return ret;
46  }
47  
48 @@ -304,11 +306,6 @@ static struct gpm_ctx *gpm_get_ctx(void)
49  
50      pthread_once(&gpm_init_once_control, gpm_init_once);
51  
52 -    ret = gpm_grab_sock(&gpm_global_ctx);
53 -    if (ret) {
54 -        return NULL;
55 -    }
56 -
57      return &gpm_global_ctx;
58  }
59