Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2657315pxa; Mon, 17 Aug 2020 15:43:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzogXDlb0KOi7nsxgiZBOKg/tdGrOa39kdixbP23IVAqdIakboYv70D3XccLhDuOpvV6w9G X-Received: by 2002:aa7:d1cc:: with SMTP id g12mr17599058edp.385.1597704197781; Mon, 17 Aug 2020 15:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704197; cv=none; d=google.com; s=arc-20160816; b=ulmXFR2qEXdzcmQJClJjwv46+vm6HD/a/9H1uX1Oov3e1OnC5V6fwafBmqZutkvsw2 xUSnfDUIkc/0Omx2DmlH17AsniLdiociFKoN88VgO0jhe0OLUNCUnp4Ak9PPBsVb7pBp PByH19R50CSP0iuwAOH/1wV/cbug0vidreGkfKWYw8+0J6O0mg/7qZ/VdTi3CxaGJMdZ 7Lm5COw4+APO6mrjSvGJhKJQnh0VdixH2mdVgw3ZUPezEHVKtodjR/CEReU+eziAdgeS ImpgK6gaKJOLL1kp5UAzaetzc8HxRZNT6/IL9E7++6D/Vy24yIlmea9w8053oCxNJYBd nDQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D85Xdq3dWAkWnexCseI3EIY+PVOo7msLwVyAAU7AGQM=; b=gMM8nfJnNjjmCNTRaGQnyeYyMrecRC6MTkIskLeejhuUn2uTlZSyo5sV5DRiDEnb5W eb2PsIvaF9m1QbZyyVRt8pve6o5gctxqlJXUGEfqyzcbL1MOVoXIs6WczptBCMeBipVf VzdHXtOb09tZ8u0xnXL1762Cyrswf00x6IpoZJVTktBVC5PHgdGmZHdGOu7hbJdH0Tn5 YuPaZJsVgVHbe70aC7dnYUSyO9XafObyeJSe+WOr8OpS7VU+/s++5nvMB3OioRGTzqkX 3a/Gv9dWdCQohno7RwaY9atBGTqBtxj6CrhdUY7+8HqBn7rgRr+xoV5So4Q02j0zFU2Z K0ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Inzvtp6M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si12123001ejr.426.2020.08.17.15.42.53; Mon, 17 Aug 2020 15:43:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Inzvtp6M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391060AbgHQSaa (ORCPT + 99 others); Mon, 17 Aug 2020 14:30:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:48692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388151AbgHQQBq (ORCPT ); Mon, 17 Aug 2020 12:01:46 -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 E4B8820888; Mon, 17 Aug 2020 16:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680093; bh=drg9k6fAr4o4ZaB/KVXQaJmhieDdCk/mTFHnx7qh7P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Inzvtp6M2L92mzD0oKo3FPCDv7eT3wllShqtmQGwXooVhnfVNc93Y1rh+CiHLRGAk rtyoTBdOb2wZYA4l+9Iyd/pX2RqPPOnQhrnzoIQE52hnbtAPGjtd851xXnplXsMLLy DMMwp4zmPhT0O3G5Tnc5VzbP0nS9IqU+lym6sqMA= 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.4 049/270] loop: be paranoid on exit and prevent new additions / removals Date: Mon, 17 Aug 2020 17:14:10 +0200 Message-Id: <20200817143758.221285604@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 565e35e69f249..bddbbf5b3dda2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2325,6 +2325,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); @@ -2332,6 +2334,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); -- 2.25.1