Blob Blame History Raw
From dab35e6c44c8c54c05350dc2ba4ef0e02830586b Mon Sep 17 00:00:00 2001
From: Kaushal M <kaushal@redhat.com>
Date: Thu, 16 Jul 2015 14:52:36 +0530
Subject: [PATCH 265/279] rpc,server,glusterd: Init transport list for accepted transport

GlusterD or a brick would crash when encrypted transport was enabled and
an unencrypted client tried to connect to them. The crash occured when
GlusterD/server tried to remove the transport from their xprt_list due
to a DISCONNECT event. But as the client transport's list head wasn't
inited, the process would crash when list_del was performed.

Initing the client transports list head during acceptence, prevents this
crash.

Also, an extra check has been added to the GlusterD and Server
notification handlers for client DISCONNECT events. The handlers will
now first check if the client transport is a member of any list.
GlusterD and Server DISCONNECT event handlers could be called without
the ACCEPT handler, which adds the transport to the list, being called.
This situation also occurs when an unencrypted client tries to establish
a connection with an encrypted server.

Change-Id: Icc24a08d60e978aaa1d3322e0cbed680dcbda2b4
BUG: 1243722
Reviewed-upstream-on: https://review.gluster.org/11692
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/53141
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
---
 rpc/rpc-transport/socket/src/socket.c |    1 +
 xlators/mgmt/glusterd/src/glusterd.c  |    8 ++++++++
 xlators/protocol/server/src/server.c  |    8 ++++++++
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index eef5bd2..635be2a 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -2689,6 +2689,7 @@ socket_server_event_handler (int fd, int idx, void *data,
                                 GF_FREE (new_trans);
                                 goto unlock;
                         }
+                        INIT_LIST_HEAD (&new_trans->list);
 
                         new_trans->name = gf_strdup (this->name);
 
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 05723b9..1286488 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -343,6 +343,14 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
         }
         case RPCSVC_EVENT_DISCONNECT:
         {
+                /* A DISCONNECT event could come without an ACCEPT event
+                 * happening for this transport. This happens when the server is
+                 * expecting encrypted connections by the client tries to
+                 * connect unecnrypted
+                 */
+                if (list_empty (&xprt->list))
+                        break;
+
                 pthread_mutex_lock (&priv->xprt_lock);
                 list_del (&xprt->list);
                 pthread_mutex_unlock (&priv->xprt_lock);
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
index 9c10a50..9ddd045 100644
--- a/xlators/protocol/server/src/server.c
+++ b/xlators/protocol/server/src/server.c
@@ -518,6 +518,14 @@ server_rpc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
                 break;
         }
         case RPCSVC_EVENT_DISCONNECT:
+                /* A DISCONNECT event could come without an ACCEPT event
+                 * happening for this transport. This happens when the server is
+                 * expecting encrypted connections by the client tries to
+                 * connect unecnrypted
+                 */
+                if (list_empty (&trans->list))
+                        break;
+
                 /* transport has to be removed from the list upon disconnect
                  * irrespective of whether lock self heal is off or on, since
                  * new transport will be created upon reconnect.
-- 
1.7.1