Whamcloud - gitweb
LU-11385 lnet: check if current->nsproxy is NULL before using 77/34577/8
authorSonia Sharma <sharmaso@whamcloud.com>
Sat, 30 Mar 2019 08:32:34 +0000 (01:32 -0700)
committerOleg Drokin <green@whamcloud.com>
Sat, 14 Dec 2019 05:58:31 +0000 (05:58 +0000)
A crash is seen at few sites in the function
rdma_create_id(current->nsproxy->net_ns, cb, dev, ps, qpt).
The issue is identified with the first param in this
function - current->nsproxy->net_ns. There is a
possibility that this value is NULL and resulting in
"kernel NULL pointer dereference" crash.

Handle the case of NULL value gracefully by adding
a check and using init_net if current or
current->nsproxy is NULL.

Change-Id: I06349e081f2c4ba0480b3924fc304f94ca765891
Signed-off-by: Sonia Sharma <sharmaso@whamcloud.com>
Signed-off-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/34577
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
lnet/klnds/o2iblnd/o2iblnd.h
lnet/lnet/acceptor.c
lnet/lnet/config.c
lnet/lnet/lib-move.c

index 86e86a7..2af54cc 100644 (file)
@@ -117,16 +117,15 @@ extern struct kib_tunables  kiblnd_tunables;
                        min(t->lnd_peercredits_hiw, (__u32)conn->ibc_queue_depth - 1))
 
 #ifdef HAVE_RDMA_CREATE_ID_5ARG
                        min(t->lnd_peercredits_hiw, (__u32)conn->ibc_queue_depth - 1))
 
 #ifdef HAVE_RDMA_CREATE_ID_5ARG
-# define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) rdma_create_id(ns, cb, \
-                                                                   dev, ps, \
-                                                                   qpt)
+# define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) \
+        rdma_create_id((ns) ? (ns) : &init_net, cb, dev, ps, qpt)
 #else
 # ifdef HAVE_RDMA_CREATE_ID_4ARG
 #else
 # ifdef HAVE_RDMA_CREATE_ID_4ARG
-#  define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) rdma_create_id(cb, dev, \
-                                                                    ps, qpt)
+#  define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) \
+         rdma_create_id(cb, dev, ps, qpt)
 # else
 # else
-#  define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) rdma_create_id(cb, dev, \
-                                                                    ps)
+#  define kiblnd_rdma_create_id(ns, cb, dev, ps, qpt) \
+         rdma_create_id(cb, dev, ps)
 # endif
 #endif
 
 # endif
 #endif
 
index 7dff9d5..5be1dd8 100644 (file)
@@ -480,14 +480,15 @@ lnet_acceptor_start(void)
 
        if (lnet_count_acceptor_nets() == 0)  /* not required */
                return 0;
 
        if (lnet_count_acceptor_nets() == 0)  /* not required */
                return 0;
-
-       lnet_acceptor_state.pta_ns = current->nsproxy->net_ns;
+       if (current->nsproxy && current->nsproxy->net_ns)
+               lnet_acceptor_state.pta_ns = current->nsproxy->net_ns;
+       else
+               lnet_acceptor_state.pta_ns = &init_net;
        task = kthread_run(lnet_acceptor, (void *)(uintptr_t)secure,
                           "acceptor_%03ld", secure);
        if (IS_ERR(task)) {
                rc2 = PTR_ERR(task);
                CERROR("Can't start acceptor thread: %ld\n", rc2);
        task = kthread_run(lnet_acceptor, (void *)(uintptr_t)secure,
                           "acceptor_%03ld", secure);
        if (IS_ERR(task)) {
                rc2 = PTR_ERR(task);
                CERROR("Can't start acceptor thread: %ld\n", rc2);
-
                return -ESRCH;
        }
 
                return -ESRCH;
        }
 
index 5e367f0..24ec49c 100644 (file)
@@ -479,10 +479,10 @@ lnet_ni_alloc_common(struct lnet_net *net, char *iface)
        ni->ni_nid = LNET_MKNID(net->net_id, 0);
 
        /* Store net namespace in which current ni is being created */
        ni->ni_nid = LNET_MKNID(net->net_id, 0);
 
        /* Store net namespace in which current ni is being created */
-       if (current->nsproxy->net_ns != NULL)
+       if (current->nsproxy && current->nsproxy->net_ns)
                ni->ni_net_ns = get_net(current->nsproxy->net_ns);
        else
                ni->ni_net_ns = get_net(current->nsproxy->net_ns);
        else
-               ni->ni_net_ns = NULL;
+               ni->ni_net_ns = get_net(&init_net);
 
        ni->ni_state = LNET_NI_STATE_INIT;
        list_add_tail(&ni->ni_netlist, &net->net_ni_added);
 
        ni->ni_state = LNET_NI_STATE_INIT;
        list_add_tail(&ni->ni_netlist, &net->net_ni_added);
@@ -1699,7 +1699,10 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets)
        int        rc;
        int i;
 
        int        rc;
        int i;
 
-       nip = lnet_inet_enumerate(&ifaces, current->nsproxy->net_ns);
+       if (current->nsproxy && current->nsproxy->net_ns)
+               nip = lnet_inet_enumerate(&ifaces, current->nsproxy->net_ns);
+       else
+               nip = lnet_inet_enumerate(&ifaces, &init_net);
        if (nip < 0) {
                if (nip != -ENOENT) {
                        LCONSOLE_ERROR_MSG(0x117,
        if (nip < 0) {
                if (nip != -ENOENT) {
                        LCONSOLE_ERROR_MSG(0x117,
index 4354c82..4050395 100644 (file)
@@ -5095,9 +5095,9 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
                         * current net namespace.
                         * If not, assign order above 0xffff0000,
                         * to make this ni not a priority. */
                         * current net namespace.
                         * If not, assign order above 0xffff0000,
                         * to make this ni not a priority. */
-                       if (!net_eq(ni->ni_net_ns, current->nsproxy->net_ns))
-                               order += 0xffff0000;
-
+                       if (current->nsproxy &&
+                           !net_eq(ni->ni_net_ns, current->nsproxy->net_ns))
+                                       order += 0xffff0000;
                        if (srcnidp != NULL)
                                *srcnidp = ni->ni_nid;
                        if (orderp != NULL)
                        if (srcnidp != NULL)
                                *srcnidp = ni->ni_nid;
                        if (orderp != NULL)