Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp441486iog; Mon, 13 Jun 2022 06:05:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPFUAZ3+kxJZWGKLAhrPg34vVFRKkcJdo3jSM6iST7kkNTYYl+0r81c/B1wun5ykNHjNKF X-Received: by 2002:a17:90b:1d90:b0:1e8:5a44:820e with SMTP id pf16-20020a17090b1d9000b001e85a44820emr15836832pjb.217.1655125398154; Mon, 13 Jun 2022 06:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125398; cv=none; d=google.com; s=arc-20160816; b=BZjcy6OSYoFNdkIT/mHWylU892BmQ7wE8CimnQRRJySiOW0h240GxqIZc6mESU+Xj6 2ZUvOoY3VF/fe0bnNJ1XZLiryHdWAMMbH3EUAOqbxRd5In2P+B7rFt/MYzmioPd+mzzl bun3KxqtppHUmlvj4U18dBVHdaDROFFAR7mZoylFcTGwh9mjek3w8yk3xguOKYlRKJZD K25LT/nq7oUt/qA4xnlbWIwpSFAfBHQOFUU6izXOKr0eCqVDr2dJlinmiUTOjJFZVE57 ePNieNATMaVdm1+AZW2hjZWLMsR/TKO3A/VmQzw92sWUKGcnLKR8v7BlxILmLVdAAmF9 16Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HZUL1h0DCw2hOKAGZT5NnfuKdiQzwBnOnNrlt3F/RFo=; b=1A4XXtYv+pvMe1d25ot2uh5b6d3iZrooRLG/ow0tZqQlnwXoOQIKpiIE0sESzbTd83 ZsM7WLXzgpkt/kFdxaauhhvhQQ0C27UCNj7/Jppygo/7VxxvkuCEEXUH4a5Q+q/InwXT e8HkpsXtoTR3gW8jqIlb+xU7nVGeR2Lm4LdXyKzy70NDDtNl2G3J97PAcif9YplYBsVw /GmFkGMeHjWXozNmvhJ7ZGi/CwoueeJImY9blLyx04xIl4Kp2CL5bNZShpTvic1txHl1 Qi5vfU49uVYXdhVgCy7jxfxAnafjHTpEmJHvdKeDM7lcipdVkyOPWsMVi8mrkA5TnoY/ Zvcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYiznKe1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a25-20020a631a59000000b003fd8db87697si8817382pgm.441.2022.06.13.06.03.05; Mon, 13 Jun 2022 06:03:18 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PYiznKe1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356579AbiFMLtR (ORCPT + 99 others); Mon, 13 Jun 2022 07:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357249AbiFMLpx (ORCPT ); Mon, 13 Jun 2022 07:45:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E98B44A3E8; Mon, 13 Jun 2022 03:51:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9791FB80E93; Mon, 13 Jun 2022 10:51:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0255C34114; Mon, 13 Jun 2022 10:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117516; bh=DzOvs/gCbWtsCNT7TaafoGtLfICWxM3o9lVASQbU2Rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PYiznKe1zu2o3qDo5mb5Iw8ASxWVY3957sCGnWwqFVfemW4o+yONQkkebxFX2yqyV p7fKvbLPHDM7yQ1S+wPvvUigDljXSOrZnYJNDBS69kU0HjbXMoS0uhLVPzC6nxnRha 5NCo8vWPSbMD01skD4UjF8J9hmuofQQqc7AtlpKU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Yu Kuai , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 392/411] nbd: call genl_unregister_family() first in nbd_cleanup() Date: Mon, 13 Jun 2022 12:11:05 +0200 Message-Id: <20220613094940.424189162@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Yu Kuai [ Upstream commit 06c4da89c24e7023ea448cadf8e9daf06a0aae6e ] Otherwise there may be race between module removal and the handling of netlink command, which can lead to the oops as shown below: BUG: kernel NULL pointer dereference, address: 0000000000000098 Oops: 0002 [#1] SMP PTI CPU: 1 PID: 31299 Comm: nbd-client Tainted: G E 5.14.0-rc4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:down_write+0x1a/0x50 Call Trace: start_creating+0x89/0x130 debugfs_create_dir+0x1b/0x130 nbd_start_device+0x13d/0x390 [nbd] nbd_genl_connect+0x42f/0x748 [nbd] genl_family_rcv_msg_doit.isra.0+0xec/0x150 genl_rcv_msg+0xe5/0x1e0 netlink_rcv_skb+0x55/0x100 genl_rcv+0x29/0x40 netlink_unicast+0x1a8/0x250 netlink_sendmsg+0x21b/0x430 ____sys_sendmsg+0x2a4/0x2d0 ___sys_sendmsg+0x81/0xc0 __sys_sendmsg+0x62/0xb0 __x64_sys_sendmsg+0x1f/0x30 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae Modules linked in: nbd(E-) Signed-off-by: Hou Tao Signed-off-by: Yu Kuai Reviewed-by: Josef Bacik Link: https://lore.kernel.org/r/20220521073749.3146892-2-yukuai3@huawei.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 510e75435c43..f3425e51a54b 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2446,6 +2446,12 @@ static void __exit nbd_cleanup(void) struct nbd_device *nbd; LIST_HEAD(del_list); + /* + * Unregister netlink interface prior to waiting + * for the completion of netlink commands. + */ + genl_unregister_family(&nbd_genl_family); + nbd_dbg_close(); mutex_lock(&nbd_index_mutex); @@ -2461,7 +2467,6 @@ static void __exit nbd_cleanup(void) } idr_destroy(&nbd_index_idr); - genl_unregister_family(&nbd_genl_family); unregister_blkdev(NBD_MAJOR, "nbd"); } -- 2.35.1