Linux block layer
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@infradead.org>,
	<linux-block@vger.kernel.org>, Jan Kara <jack@suse.cz>,
	stable@vger.kernel.org
Subject: [PATCH] block: Fixup condition detecting exclusive opener during partition rescan
Date: Thu,  1 Dec 2022 12:44:42 +0100	[thread overview]
Message-ID: <20221201114442.6829-1-jack@suse.cz> (raw)

The condition detecting whether somebody else has the device exclusively
open in disk_scan_partitions() has a brownpaper bag bug. It triggers also
when nobody has the device exclusively open and we are coming from
BLKRRPART path. Interestingly this didn't have any adverse effects
during testing because tools update kernel's notion of the partition
table using ioctls and don't rely on BLKRRPART. Fix the bug before
somebody trips over it.

Fixes: 8d67fc20caf8 ("block: Do not reread partition table on exclusively open device")
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
 block/genhd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index 012529d36f5b..29fb2c98b401 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -367,7 +367,7 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode, void *owner)
 	if (disk->open_partitions)
 		return -EBUSY;
 	/* Someone else has bdev exclusively open? */
-	if (disk->part0->bd_holder != owner)
+	if (disk->part0->bd_holder && disk->part0->bd_holder != owner)
 		return -EBUSY;
 
 	set_bit(GD_NEED_PART_SCAN, &disk->state);
-- 
2.35.3


             reply	other threads:[~2022-12-01 11:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 11:44 Jan Kara [this message]
2022-12-01 14:45 ` [PATCH] block: Fixup condition detecting exclusive opener during partition rescan Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221201114442.6829-1-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox