From patchwork Sat May 9 03:10:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 11537945 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84C6115E6 for ; Sat, 9 May 2020 03:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E30124956 for ; Sat, 9 May 2020 03:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588993884; bh=3bw+hbodhz3UOr0LwSV1dP9R3ejBD7NRrNw2o8u8B3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kPttkC0izJAJmpSFN5LQHNfwo46sFwo/cKKewSzeCALyW810jGBKllyMy1q1Xluce nEOHf5CdRFcKSVB7VVqPsBQOyqPy0y3k57nfHzuorECqSZAiW0mjd8Kt8SNTrR0d1Y WgPL7shmeDzuH2ZDwCwgDNml0hoMBddeQixaV7ms= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbgEIDLL (ORCPT ); Fri, 8 May 2020 23:11:11 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34061 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728757AbgEIDLI (ORCPT ); Fri, 8 May 2020 23:11:08 -0400 Received: by mail-pg1-f196.google.com with SMTP id f6so1805981pgm.1; Fri, 08 May 2020 20:11:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B9qeuwlCWo2bLV/HUmko4UIQJaKMhP6Ukx+rQSkan8Y=; b=Xh2TeYTU1KbK4Y4PWoictCESWP3xVyfBcMd4MIkYYu8sttjEmhm+kphT/DFaAcmrzI mETsaIk/IX0VI80t/6Dk+FH5SHeUWPQTIoV035z4uddn9lz+Uj46vqPArAJzCSh/yqnk wsniio8+J6uLLiNnyUnVyL1DBbi3VR9ix16mPR6eKwf82PgZcVbAlC2XxV6E7CAWbXfx 0tuZEW0ZL1XznDYuwQoMR4DXb0g1PiV/g7DJ+0MeZpaNwhu7jwQ+udqZqCS7py4c87Q5 05+coDJSf0dJVd2qjIsnsbvCDLXPhHRiVkqUz4uSfHJZPzPwGVceaHdARTOnGlAYe+7h gulA== X-Gm-Message-State: AGi0PuaxwHaNjpMwFa0Ts/B1DBbWovOc4fkBQ8aX7B+aZKztHnzHKxcY KIx1xQQXQIEwkveZL21AVlA= X-Google-Smtp-Source: APiQypJ4gDoO4Ls5NVzNOvJO5nVpKEkSKJtyC67OMRsCvPXltLPj+Zy6NxHNyPn2f7uJc5uyHsOujA== X-Received: by 2002:a62:144b:: with SMTP id 72mr6234440pfu.246.1588993867590; Fri, 08 May 2020 20:11:07 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id v9sm3508964pju.3.2020.05.08.20.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 20:11:06 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 1484E41D95; Sat, 9 May 2020 03:11:00 +0000 (UTC) From: Luis Chamberlain To: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org Cc: mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH v4 5/5] loop: be paranoid on exit and prevent new additions / removals Date: Sat, 9 May 2020 03:10:58 +0000 Message-Id: <20200509031058.8239-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20200509031058.8239-1-mcgrof@kernel.org> References: <20200509031058.8239-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Be pedantic on removal as well and hold the mutex. This should prevent uses of addition while we exit. I cannot trigger an issue with this though, this is just a fix done through code inspection. Reviewed-by: Ming Lei Signed-off-by: Luis Chamberlain --- drivers/block/loop.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 14372df0f354..54fbcbd930de 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);