All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions()
@ 2023-06-18 14:04 Yu Kuai
  2023-06-19  4:59 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yu Kuai @ 2023-06-18 14:04 UTC (permalink / raw)
  To: hch, axboe, brauner, dsterba, hare, jinpu.wang
  Cc: linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

After commit 2736e8eeb0cc ("block: use the holder as indication for
exclusive opens"), blkdev_get_by_dev() will warn if holder is NULL and
mode contains 'FMODE_EXCL'.

holder from blkdev_get_by_dev() from disk_scan_partitions() is always NULL,
hence it should not use 'FMODE_EXCL', which is broben by the commit. For
consequence, WARN_ON_ONCE() will be triggered from blkdev_get_by_dev()
if user scan partitions with device opened exclusively.

Fix this problem by removing 'FMODE_EXCL' from disk_scan_partitions(),
as it used to be.

Reported-by: syzbot+00cd27751f78817f167b@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=00cd27751f78817f167b
Fixes: 2736e8eeb0cc ("block: use the holder as indication for exclusive opens")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---

Changes in v2:
 - fix a typo

 block/genhd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index 2c2f9a716822..d1e845ae1b32 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -365,7 +365,8 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 	}
 
 	set_bit(GD_NEED_PART_SCAN, &disk->state);
-	bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL, NULL);
+	bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXEC, NULL,
+				 NULL);
 	if (IS_ERR(bdev))
 		ret =  PTR_ERR(bdev);
 	else
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions()
  2023-06-18 14:04 [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions() Yu Kuai
@ 2023-06-19  4:59 ` Christoph Hellwig
  2023-06-20  9:54 ` Christian Brauner
  2023-06-20 13:18 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-06-19  4:59 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, axboe, brauner, dsterba, hare, jinpu.wang, linux-block,
	linux-kernel, yukuai3, yi.zhang, yangerkun

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions()
  2023-06-18 14:04 [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions() Yu Kuai
  2023-06-19  4:59 ` Christoph Hellwig
@ 2023-06-20  9:54 ` Christian Brauner
  2023-06-20 13:18 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2023-06-20  9:54 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, axboe, dsterba, hare, jinpu.wang, linux-block, linux-kernel,
	yukuai3, yi.zhang, yangerkun

On Sun, Jun 18, 2023 at 10:04:02PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> After commit 2736e8eeb0cc ("block: use the holder as indication for
> exclusive opens"), blkdev_get_by_dev() will warn if holder is NULL and
> mode contains 'FMODE_EXCL'.
> 
> holder from blkdev_get_by_dev() from disk_scan_partitions() is always NULL,
> hence it should not use 'FMODE_EXCL', which is broben by the commit. For
> consequence, WARN_ON_ONCE() will be triggered from blkdev_get_by_dev()
> if user scan partitions with device opened exclusively.
> 
> Fix this problem by removing 'FMODE_EXCL' from disk_scan_partitions(),
> as it used to be.
> 
> Reported-by: syzbot+00cd27751f78817f167b@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=00cd27751f78817f167b
> Fixes: 2736e8eeb0cc ("block: use the holder as indication for exclusive opens")
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---

Looks good to me,
Reviewed-by: Christian Brauner <brauner@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions()
  2023-06-18 14:04 [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions() Yu Kuai
  2023-06-19  4:59 ` Christoph Hellwig
  2023-06-20  9:54 ` Christian Brauner
@ 2023-06-20 13:18 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2023-06-20 13:18 UTC (permalink / raw)
  To: hch, brauner, dsterba, hare, jinpu.wang, Yu Kuai
  Cc: linux-block, linux-kernel, yukuai3, yi.zhang, yangerkun


On Sun, 18 Jun 2023 22:04:02 +0800, Yu Kuai wrote:
> After commit 2736e8eeb0cc ("block: use the holder as indication for
> exclusive opens"), blkdev_get_by_dev() will warn if holder is NULL and
> mode contains 'FMODE_EXCL'.
> 
> holder from blkdev_get_by_dev() from disk_scan_partitions() is always NULL,
> hence it should not use 'FMODE_EXCL', which is broben by the commit. For
> consequence, WARN_ON_ONCE() will be triggered from blkdev_get_by_dev()
> if user scan partitions with device opened exclusively.
> 
> [...]

Applied, thanks!

[1/1] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions()
      commit: 985958b8584cc143555f1bd735e7ab5066c944a7

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-20 13:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 14:04 [PATCH -next v2] block: fix wrong mode for blkdev_get_by_dev() from disk_scan_partitions() Yu Kuai
2023-06-19  4:59 ` Christoph Hellwig
2023-06-20  9:54 ` Christian Brauner
2023-06-20 13:18 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.