From fea400b3005982322c4e5c2df9b8376398a561ce Mon Sep 17 00:00:00 2001 From: Sonia Sharma Date: Sat, 30 Mar 2019 01:32:34 -0700 Subject: [PATCH] LU-11385 lnet: check if current->nsproxy is NULL before using 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. Lustre-change: https://review.whamcloud.com/34577 Lustre-commit: ef1783e282f6eba9d69b0957f1b5fed00be0cbd6 Change-Id: I06349e081f2c4ba0480b3924fc304f94ca765891 Signed-off-by: Serguei Smirnov Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Sebastien Buisson Signed-off-by: Minh Diep Reviewed-on: https://review.whamcloud.com/37313 Tested-by: jenkins Tested-by: Maloo --- lnet/klnds/o2iblnd/o2iblnd.h | 13 ++++++------- lnet/lnet/acceptor.c | 7 ++++--- lnet/lnet/config.c | 9 ++++++--- lnet/lnet/lib-move.c | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lnet/klnds/o2iblnd/o2iblnd.h b/lnet/klnds/o2iblnd/o2iblnd.h index eb3a4d0..5a8b966 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.h +++ b/lnet/klnds/o2iblnd/o2iblnd.h @@ -120,16 +120,15 @@ extern struct kib_tunables kiblnd_tunables; 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 -# 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 -# 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 diff --git a/lnet/lnet/acceptor.c b/lnet/lnet/acceptor.c index 7dff9d5..5be1dd8 100644 --- a/lnet/lnet/acceptor.c +++ b/lnet/lnet/acceptor.c @@ -480,14 +480,15 @@ lnet_acceptor_start(void) 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); - return -ESRCH; } diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 445d46b..4e2e13d 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -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 */ - 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 = NULL; + ni->ni_net_ns = get_net(&init_net); ni->ni_last_alive = ktime_get_real_seconds(); ni->ni_state = LNET_NI_STATE_INIT; @@ -1686,7 +1686,10 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets) 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, diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index eae754b..8925b7a 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -4993,9 +4993,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. */ - 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) -- 1.8.3.1