From patchwork Tue Oct 25 02:41:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 10472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp776892wru; Mon, 24 Oct 2022 20:10:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zSB47l2cVu6ekGlQCQ5y9LK2UvpJXOQzZjLFR/dEAWfe/CRqthXD43S1TrD4wmrHtlH8i X-Received: by 2002:a17:907:6e24:b0:791:905f:7881 with SMTP id sd36-20020a1709076e2400b00791905f7881mr30491438ejc.120.1666667457147; Mon, 24 Oct 2022 20:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666667457; cv=none; d=google.com; s=arc-20160816; b=nh0ecLSXkWVL0n98GMF0VaAYgYq5pfw6hiBk3VLbjf4jLX9IsOZV7YzAj89cn+rW0w oFErvmZ1rH3EHXjVgP9nzH73N2lnyZwdgt/q6pQ6KvdvG+D4rCUP6MIosdls3jTCDblb Au2pyPO3I7wAZgOVm0sHnzptuSviAj+sOyItdGDM5kcQWT4LTf+ImSEY5ptIIpnuSULr 3H+JhLjpaVMztcPiXI4ZFH8c/vh7WZ2pSXcp4Ct5B35uRwRDhoBO4KGry67ZYB7KmsQk Xpu8lzPntGRZSC30drFEpoN4wbcv/ZZZqPUouDdSkpAYW6+lboyAQR1UNrqqzABnYjmB Wn2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=7fcBZ166+Uvg22oZBc74C8R5Qb08xvF3Ii/pAb5e5h8=; b=XHv9HghB+gE7oGBwPlr636IXLa9jCE4tHEJHj4eEE62eLGJ6We1MWEczBTqB+J/V5U NwImcKah0Sm8NWLr421z5+eBQlQeHvzRPY56a2ZP4I4ieJjDtAJU3Ro+gIMSNnoiqUcC 7uIMpXNiDQy3LLuRIPTzdYYT3jek+dCazN5GtdO7T6uk7+Zfs8FbuYxg2hXvT4QVeLlD 6xj8tHkqlPqnSvV4Ub+urLfROtZ3RaJLdL0TMFgUwLKMtKgcQ74YMAwoEzhHfRHhRsJn VQsEfX2GU/N9t2ISJ6q/wXgvH65KTAfy1oUwMcf+YoyLeg7LJRETtefAEobGgilLY+dR vMlw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020aa7cfd2000000b00461237816efsi1279145edy.120.2022.10.24.20.10.33; Mon, 24 Oct 2022 20:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbiJYCpV (ORCPT + 99 others); Mon, 24 Oct 2022 22:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbiJYCpS (ORCPT ); Mon, 24 Oct 2022 22:45:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E9213F3C; Mon, 24 Oct 2022 19:45:16 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MxGQ468rkzVj6p; Tue, 25 Oct 2022 10:40:28 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 10:45:14 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 10:45:14 +0800 From: Chen Zhongjin To: , CC: , , , , , , , , Subject: [PATCH] RDMA/core: Fix null-ptr-deref in ib_core_cleanup() Date: Tue, 25 Oct 2022 10:41:46 +0800 Message-ID: <20221025024146.109137-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747627495880445490?= X-GMAIL-MSGID: =?utf-8?q?1747627495880445490?= KASAN reported a null-ptr-deref error: KASAN: null-ptr-deref in range [0x0000000000000118-0x000000000000011f] CPU: 1 PID: 379 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:destroy_workqueue+0x2f/0x740 RSP: 0018:ffff888016137df8 EFLAGS: 00000202 ... Call Trace: ib_core_cleanup+0xa/0xa1 [ib_core] __do_sys_delete_module.constprop.0+0x34f/0x5b0 do_syscall_64+0x3a/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7fa1a0d221b7 ... It is because the fail of roce_gid_mgmt_init() is ignored: ib_core_init() roce_gid_mgmt_init() gid_cache_wq = alloc_ordered_workqueue # fail ... ib_core_cleanup() roce_gid_mgmt_cleanup() destroy_workqueue(gid_cache_wq) # destroy an unallocated wq Fix this by catching the fail of roce_gid_mgmt_init() in ib_core_init(). Fixes: 03db3a2d81e6 ("IB/core: Add RoCE GID table management") Signed-off-by: Chen Zhongjin --- drivers/infiniband/core/device.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index ae60c73babcc..b45431e6817b 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -2815,10 +2815,18 @@ static int __init ib_core_init(void) nldev_init(); rdma_nl_register(RDMA_NL_LS, ibnl_ls_cb_table); - roce_gid_mgmt_init(); + ret = roce_gid_mgmt_init(); + if (ret) { + pr_warn("Couldn't init RoCE GID management\n"); + goto err_parent; + } return 0; +err_parent: + nldev_exit(); + rdma_nl_unregister(RDMA_NL_LS); + unregister_pernet_device(&rdma_dev_net_ops); err_compat: unregister_blocking_lsm_notifier(&ibdev_lsm_nb); err_sa: