From patchwork Thu Feb 27 21:16:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410905 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DB97924 for ; Thu, 27 Feb 2020 21:50:29 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 05DB124690 for ; Thu, 27 Feb 2020 21:50:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05DB124690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 2707E34B9B1; Thu, 27 Feb 2020 13:41:38 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id BD6A2348929 for ; Thu, 27 Feb 2020 13:21:08 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id B143D91BD; Thu, 27 Feb 2020 16:18:19 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id ADF1D47C; Thu, 27 Feb 2020 16:18:19 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:16:55 -0500 Message-Id: <1582838290-17243-548-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 547/622] lnet: check if current->nsproxy is NULL before using X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Serguei Smirnov , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Sonia Sharma 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. WC-bug-id: https://jira.whamcloud.com/browse/LU-11385 Lustre-commit: ef1783e282f6 ("LU-11385 lnet: check if current->nsproxy is NULL before using") Signed-off-by: Sonia Sharma Signed-off-by: Serguei Smirnov Reviewed-on: https://review.whamcloud.com/34577 Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Sebastien Buisson Signed-off-by: James Simmons --- net/lnet/klnds/o2iblnd/o2iblnd.h | 6 +++--- net/lnet/lnet/acceptor.c | 7 ++++--- net/lnet/lnet/config.c | 9 ++++++--- net/lnet/lnet/lib-move.c | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/net/lnet/klnds/o2iblnd/o2iblnd.h b/net/lnet/klnds/o2iblnd/o2iblnd.h index ac91757..2169fdd 100644 --- a/net/lnet/klnds/o2iblnd/o2iblnd.h +++ b/net/lnet/klnds/o2iblnd/o2iblnd.h @@ -108,9 +108,9 @@ struct kib_tunables { min((t)->lnd_peercredits_hiw, \ (u32)(conn)->ibc_queue_depth - 1)) -# 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) + /* 2 OOB shall suffice for 1 keepalive and 1 returning credits */ #define IBLND_OOB_CAPABLE(v) ((v) != IBLND_MSG_VERSION_1) #define IBLND_OOB_MSGS(v) (IBLND_OOB_CAPABLE(v) ? 2 : 0) diff --git a/net/lnet/lnet/acceptor.c b/net/lnet/lnet/acceptor.c index 23b5bf0..acd1d75 100644 --- a/net/lnet/lnet/acceptor.c +++ b/net/lnet/lnet/acceptor.c @@ -458,14 +458,15 @@ if (!lnet_count_acceptor_nets()) /* 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/net/lnet/lnet/config.c b/net/lnet/lnet/config.c index 2c8edcd..f521b0b 100644 --- a/net/lnet/lnet/config.c +++ b/net/lnet/lnet/config.c @@ -464,10 +464,10 @@ struct lnet_net * ni->ni_nid = LNET_MKNID(net->net_id, 0); /* Store net namespace in which current ni is being created */ - if (current->nsproxy->net_ns) + 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_state = LNET_NI_STATE_INIT; list_add_tail(&ni->ni_netlist, &net->net_ni_added); @@ -1642,7 +1642,10 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns) 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/net/lnet/lnet/lib-move.c b/net/lnet/lnet/lib-move.c index b8278ad..ca0009c 100644 --- a/net/lnet/lnet/lib-move.c +++ b/net/lnet/lnet/lib-move.c @@ -4826,9 +4826,9 @@ struct lnet_msg * * If not, assign order above 0xffff0000, * to make this ni not a priority. */ - if (!net_eq(ni->ni_net_ns, current->nsproxy->net_ns)) + if (current->nsproxy && + !net_eq(ni->ni_net_ns, current->nsproxy->net_ns)) order += 0xffff0000; - if (srcnidp) *srcnidp = ni->ni_nid; if (orderp)