cb8e9e
From dab35e6c44c8c54c05350dc2ba4ef0e02830586b Mon Sep 17 00:00:00 2001
cb8e9e
From: Kaushal M <kaushal@redhat.com>
cb8e9e
Date: Thu, 16 Jul 2015 14:52:36 +0530
cb8e9e
Subject: [PATCH 265/279] rpc,server,glusterd: Init transport list for accepted transport
cb8e9e
cb8e9e
GlusterD or a brick would crash when encrypted transport was enabled and
cb8e9e
an unencrypted client tried to connect to them. The crash occured when
cb8e9e
GlusterD/server tried to remove the transport from their xprt_list due
cb8e9e
to a DISCONNECT event. But as the client transport's list head wasn't
cb8e9e
inited, the process would crash when list_del was performed.
cb8e9e
cb8e9e
Initing the client transports list head during acceptence, prevents this
cb8e9e
crash.
cb8e9e
cb8e9e
Also, an extra check has been added to the GlusterD and Server
cb8e9e
notification handlers for client DISCONNECT events. The handlers will
cb8e9e
now first check if the client transport is a member of any list.
cb8e9e
GlusterD and Server DISCONNECT event handlers could be called without
cb8e9e
the ACCEPT handler, which adds the transport to the list, being called.
cb8e9e
This situation also occurs when an unencrypted client tries to establish
cb8e9e
a connection with an encrypted server.
cb8e9e
cb8e9e
Change-Id: Icc24a08d60e978aaa1d3322e0cbed680dcbda2b4
cb8e9e
BUG: 1243722
cb8e9e
Reviewed-upstream-on: https://review.gluster.org/11692
cb8e9e
Signed-off-by: Kaushal M <kaushal@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/53141
cb8e9e
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
cb8e9e
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
cb8e9e
---
cb8e9e
 rpc/rpc-transport/socket/src/socket.c |    1 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd.c  |    8 ++++++++
cb8e9e
 xlators/protocol/server/src/server.c  |    8 ++++++++
cb8e9e
 3 files changed, 17 insertions(+), 0 deletions(-)
cb8e9e
cb8e9e
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
cb8e9e
index eef5bd2..635be2a 100644
cb8e9e
--- a/rpc/rpc-transport/socket/src/socket.c
cb8e9e
+++ b/rpc/rpc-transport/socket/src/socket.c
cb8e9e
@@ -2689,6 +2689,7 @@ socket_server_event_handler (int fd, int idx, void *data,
cb8e9e
                                 GF_FREE (new_trans);
cb8e9e
                                 goto unlock;
cb8e9e
                         }
cb8e9e
+                        INIT_LIST_HEAD (&new_trans->list);
cb8e9e
 
cb8e9e
                         new_trans->name = gf_strdup (this->name);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
index 05723b9..1286488 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
@@ -343,6 +343,14 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
cb8e9e
         }
cb8e9e
         case RPCSVC_EVENT_DISCONNECT:
cb8e9e
         {
cb8e9e
+                /* A DISCONNECT event could come without an ACCEPT event
cb8e9e
+                 * happening for this transport. This happens when the server is
cb8e9e
+                 * expecting encrypted connections by the client tries to
cb8e9e
+                 * connect unecnrypted
cb8e9e
+                 */
cb8e9e
+                if (list_empty (&xprt->list))
cb8e9e
+                        break;
cb8e9e
+
cb8e9e
                 pthread_mutex_lock (&priv->xprt_lock);
cb8e9e
                 list_del (&xprt->list);
cb8e9e
                 pthread_mutex_unlock (&priv->xprt_lock);
cb8e9e
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
cb8e9e
index 9c10a50..9ddd045 100644
cb8e9e
--- a/xlators/protocol/server/src/server.c
cb8e9e
+++ b/xlators/protocol/server/src/server.c
cb8e9e
@@ -518,6 +518,14 @@ server_rpc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
cb8e9e
                 break;
cb8e9e
         }
cb8e9e
         case RPCSVC_EVENT_DISCONNECT:
cb8e9e
+                /* A DISCONNECT event could come without an ACCEPT event
cb8e9e
+                 * happening for this transport. This happens when the server is
cb8e9e
+                 * expecting encrypted connections by the client tries to
cb8e9e
+                 * connect unecnrypted
cb8e9e
+                 */
cb8e9e
+                if (list_empty (&trans->list))
cb8e9e
+                        break;
cb8e9e
+
cb8e9e
                 /* transport has to be removed from the list upon disconnect
cb8e9e
                  * irrespective of whether lock self heal is off or on, since
cb8e9e
                  * new transport will be created upon reconnect.
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e