All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails
@ 2022-08-11 23:23 Rafael Mendonca
  2022-08-12  5:42 ` Christoph Hellwig
  2022-08-12 12:42 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Rafael Mendonca @ 2022-08-11 23:23 UTC (permalink / raw)
  To: Jens Axboe, Hannes Reinecke
  Cc: Rafael Mendonca, syzbot+31c9594f6e43b9289b25, Hillf Danton,
	linux-block, linux-kernel

Commit 6f8191fdf41d ("block: simplify disk shutdown") removed the call
to blk_get_queue() during gendisk allocation but missed to remove the
corresponding cleanup code blk_put_queue() for it. Thus, if the gendisk
allocation fails, the request_queue refcount gets decremented and
reaches 0, causing blk_mq_release() to be called with a hctx still
alive. That triggers a WARNING report, as found by syzkaller:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 23016 at block/blk-mq.c:3881
blk_mq_release+0xf8/0x3e0 block/blk-mq.c:3881
[...] stripped
RIP: 0010:blk_mq_release+0xf8/0x3e0 block/blk-mq.c:3881
[...] stripped
Call Trace:
 <TASK>
 blk_release_queue+0x153/0x270 block/blk-sysfs.c:780
 kobject_cleanup lib/kobject.c:673 [inline]
 kobject_release lib/kobject.c:704 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1c8/0x540 lib/kobject.c:721
 __alloc_disk_node+0x4f7/0x610 block/genhd.c:1388
 __blk_mq_alloc_disk+0x13b/0x1f0 block/blk-mq.c:3961
 loop_add+0x3e2/0xaf0 drivers/block/loop.c:1978
 loop_control_ioctl+0x133/0x620 drivers/block/loop.c:2150
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
[...] stripped

Fixes: 6f8191fdf41d ("block: simplify disk shutdown")
Reported-by: syzbot+31c9594f6e43b9289b25@syzkaller.appspotmail.com
Suggested-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
 block/genhd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index b901fea1d55a..d36fabf0abc1 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1341,7 +1341,7 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
 
 	disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
 	if (!disk)
-		goto out_put_queue;
+		return NULL;
 
 	if (bioset_init(&disk->bio_split, BIO_POOL_SIZE, 0, 0))
 		goto out_free_disk;
@@ -1390,8 +1390,6 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
 	bioset_exit(&disk->bio_split);
 out_free_disk:
 	kfree(disk);
-out_put_queue:
-	blk_put_queue(q);
 	return NULL;
 }
 
-- 
2.34.1


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

* Re: [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails
  2022-08-11 23:23 [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails Rafael Mendonca
@ 2022-08-12  5:42 ` Christoph Hellwig
  2022-08-12 12:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2022-08-12  5:42 UTC (permalink / raw)
  To: Rafael Mendonca
  Cc: Jens Axboe, Hannes Reinecke, syzbot+31c9594f6e43b9289b25,
	Hillf Danton, linux-block, linux-kernel

Looks good:

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

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

* Re: [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails
  2022-08-11 23:23 [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails Rafael Mendonca
  2022-08-12  5:42 ` Christoph Hellwig
@ 2022-08-12 12:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-08-12 12:42 UTC (permalink / raw)
  To: rafaelmendsr, hare
  Cc: linux-block, hdanton, linux-kernel, syzbot+31c9594f6e43b9289b25

On Thu, 11 Aug 2022 20:23:37 -0300, Rafael Mendonca wrote:
> Commit 6f8191fdf41d ("block: simplify disk shutdown") removed the call
> to blk_get_queue() during gendisk allocation but missed to remove the
> corresponding cleanup code blk_put_queue() for it. Thus, if the gendisk
> allocation fails, the request_queue refcount gets decremented and
> reaches 0, causing blk_mq_release() to be called with a hctx still
> alive. That triggers a WARNING report, as found by syzkaller:
> 
> [...]

Applied, thanks!

[1/1] block: Do not call blk_put_queue() if gendisk allocation fails
      commit: aa0c680c3aa96a5f9f160d90dd95402ad578e2b0

Best regards,
-- 
Jens Axboe



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

end of thread, other threads:[~2022-08-12 12:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 23:23 [PATCH] block: Do not call blk_put_queue() if gendisk allocation fails Rafael Mendonca
2022-08-12  5:42 ` Christoph Hellwig
2022-08-12 12:42 ` 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.