Whamcloud - gitweb
LU-17000 lnet: Fix dereference after NULL under ksocknal_recv_hello 05/53305/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 1 Dec 2023 04:58:32 +0000 (23:58 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 Dec 2023 01:58:39 +0000 (01:58 +0000)
This patch fixes 'conn->ksnc_proto' which was
dereferenced under function ksocknal_recv_hello()
even though it could be NULL.

This patch also removes 'returns' in between
the function and replaces it with 'goto'.
Allowing exit from a single place.

CoverityID: 410244 ("Dereference after null check")
Test-Parameters: trivial testlist=sanity-lnet
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Fixes: cb5f92c0e (LU-10391 ksocklnd: use ksocknal_protocol v4 for IPv6)
Change-Id: I95196d481b537281ab8643f1ee6162db450bef20
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53305
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/klnds/socklnd/socklnd_cb.c

index b2a86c2..51e1dba 100644 (file)
@@ -1794,7 +1794,7 @@ ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                CERROR("Error %d reading HELLO from %pISc\n",
                       rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0);
-               return rc;
+               goto out_fatal;
        }
 
        if (hello->kshm_magic != LNET_PROTO_MAGIC &&
@@ -1804,7 +1804,7 @@ ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                CERROR("Bad magic(1) %#08x (%#08x expected) from %pISc\n",
                       __cpu_to_le32 (hello->kshm_magic),
                       LNET_PROTO_TCP_MAGIC, &conn->ksnc_peeraddr);
-               return -EPROTO;
+               goto out_unknown;
        }
 
        rc = lnet_sock_read(sock, &hello->kshm_version,
@@ -1813,7 +1813,7 @@ ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                CERROR("Error %d reading HELLO from %pISc\n",
                       rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0);
-               return rc;
+               goto out_fatal;
        }
 
        proto = ksocknal_parse_proto_version(hello);
@@ -1834,18 +1834,22 @@ ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                        else if (*ksocknal_tunables.ksnd_protocol == 1)
                                conn->ksnc_proto = &ksocknal_protocol_v1x;
 #endif
-                       if (!conn->ksnc_proto)
-                               goto unknown;
+                       if (!conn->ksnc_proto) {
+                               CERROR("Unknown protocol.Error reading HELLO from %pISc\n",
+                                      &conn->ksnc_peeraddr);
+                               goto out_unknown;
+                       }
 
                        hello->kshm_nips = 0;
                        ksocknal_send_hello(ni, conn, &ni->ni_nid,
                                            hello);
                }
-unknown:
                CERROR("Unknown protocol version (%d.x expected) from %pISc\n",
                       conn->ksnc_proto->pro_version, &conn->ksnc_peeraddr);
-
-               return -EPROTO;
+out_unknown:
+               rc = -EPROTO;
+out_fatal:
+               return rc;
        }
 
        proto_match = (conn->ksnc_proto == proto);