From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 902AECA9ED3 for ; Mon, 4 Nov 2019 22:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A74E204EC for ; Mon, 4 Nov 2019 22:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572906147; bh=dcVigU6fDMmZoextzHaCniTrTK6eBi3KgAmY8viInsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nlAUZSkEeqp9g528nMWi2alyCNuLv8mOlV7oLXV1xRZFxrEDcZ+uupJ1fznOoOgnR uTBjCPjCk2hadq+2Va7g+ejSU7kAFAl5Zwkrhr34dW48qe+GuPc0HqgsdGSm0YEiDb kKgi/siTYYkPWUWVsFyYQQ2LsyjI6Fns47UOoD1M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388393AbfKDV4e (ORCPT ); Mon, 4 Nov 2019 16:56:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:52120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388330AbfKDV4b (ORCPT ); Mon, 4 Nov 2019 16:56:31 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2107321D7D; Mon, 4 Nov 2019 21:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904590; bh=dcVigU6fDMmZoextzHaCniTrTK6eBi3KgAmY8viInsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/8iY5E/SV3AR03T5nRgDdOjOeP6+z0GarXJE6I2dXVg1oxWl9lUrDCjos3er6Oo2 USzT1kogqjUj+JolvlBRSoO2rvbMCbtw51u8wcXzH6aLKU3kePuBmhPGpReq/BOiVe Nph7c+AnwZOmdccYCTcZoLAVWTtDPGF3GNC2aGWs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Josef Bacik , Xiubo Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 53/95] nbd: fix possible sysfs duplicate warning Date: Mon, 4 Nov 2019 22:44:51 +0100 Message-Id: <20191104212104.916016633@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212038.056365853@linuxfoundation.org> References: <20191104212038.056365853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiubo Li [ Upstream commit 862488105b84ca744b3d8ff131e0fcfe10644be1 ] 1. nbd_put takes the mutex and drops nbd->ref to 0. It then does idr_remove and drops the mutex. 2. nbd_genl_connect takes the mutex. idr_find/idr_for_each fails to find an existing device, so it does nbd_dev_add. 3. just before the nbd_put could call nbd_dev_remove or not finished totally, but if nbd_dev_add try to add_disk, we can hit: debugfs: Directory 'nbd1' with parent 'block' already present! This patch will make sure all the disk add/remove stuff are done by holding the nbd_index_mutex lock. Reported-by: Mike Christie Reviewed-by: Josef Bacik Signed-off-by: Xiubo Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index a234600849558..3e45004407963 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -228,8 +228,8 @@ static void nbd_put(struct nbd_device *nbd) if (refcount_dec_and_mutex_lock(&nbd->refs, &nbd_index_mutex)) { idr_remove(&nbd_index_idr, nbd->index); - mutex_unlock(&nbd_index_mutex); nbd_dev_remove(nbd); + mutex_unlock(&nbd_index_mutex); } } -- 2.20.1