From patchwork Mon Aug 17 15:11:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266453 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 4E69BC433E1 for ; Mon, 17 Aug 2020 15:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E1F320760 for ; Mon, 17 Aug 2020 15:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679035; bh=UnMzxSx1bFTza18KxTSF0DkGaDImt48XwHIJpKEOgLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j4mUHv3gilYsiSOAHwnzA/bngjChOhmP6NY5KCsxG7+IHX2kPcuZCha8Wq/5jkubW LTWBg1q7FEcqxXK+9BAHoUy5HPOgMRDO6PMB1lGG3nmuof1RyXtYRLytZqRnlEcsm7 ELyjCvz8L/CfCpIy0Rnf+8UNzrUBSyLhNvmAc8Vs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387668AbgHQPnj (ORCPT ); Mon, 17 Aug 2020 11:43:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:54120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387660AbgHQPng (ORCPT ); Mon, 17 Aug 2020 11:43:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B8E9622CF8; Mon, 17 Aug 2020 15:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679016; bh=UnMzxSx1bFTza18KxTSF0DkGaDImt48XwHIJpKEOgLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtbOoV8L0DV9GBA0qY7qP9hAZ65Z9ZDUp1fcL6/UPjkdG9pBsytFA1bCsV9Ic8UB9 N0YDxe9jWv/apiz4ILgYrwWOcBV1EFvCWSy+BYG54v8MAj2xzbXmZXn6XQD4X2DU5p CO/BoyBzhXKjVT2MwRqR8hhjJlkN5mkEwasJQGbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luis Chamberlain , Ming Lei , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.7 068/393] loop: be paranoid on exit and prevent new additions / removals Date: Mon, 17 Aug 2020 17:11:58 +0200 Message-Id: <20200817143822.909879084@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Luis Chamberlain [ Upstream commit 200f93377220504c5e56754823e7adfea6037f1a ] Be pedantic on removal as well and hold the mutex. This should prevent uses of addition while we exit. Signed-off-by: Luis Chamberlain Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/loop.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 418bb4621255a..6b36fc2f4edc7 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2333,6 +2333,8 @@ static void __exit loop_exit(void) range = max_loop ? max_loop << part_shift : 1UL << MINORBITS; + mutex_lock(&loop_ctl_mutex); + idr_for_each(&loop_index_idr, &loop_exit_cb, NULL); idr_destroy(&loop_index_idr); @@ -2340,6 +2342,8 @@ static void __exit loop_exit(void) unregister_blkdev(LOOP_MAJOR, "loop"); misc_deregister(&loop_misc); + + mutex_unlock(&loop_ctl_mutex); } module_init(loop_init);