Skip to content

Commit ac89e9c

Browse files
KAGA-KOKOgregkh
authored andcommitted
block: Ensure that a request queue is dissociated from the cgroup controller
commit 24ecc35 upstream. Several block drivers call alloc_disk() followed by put_disk() if something fails before device_add_disk() is called without calling blk_cleanup_queue(). Make sure that also for this scenario a request queue is dissociated from the cgroup controller. This patch avoids that loading the parport_pc, paride and pf drivers triggers the following kernel crash: BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride] Read of size 4 at addr 0000000000000008 by task modprobe/744 Call Trace: dump_stack+0x9a/0xeb kasan_report+0x139/0x350 pi_init+0x42e/0x580 [paride] pf_init+0x2bb/0x1000 [pf] do_one_initcall+0x8e/0x405 do_init_module+0xd9/0x2f2 load_module+0x3ab4/0x4700 SYSC_finit_module+0x176/0x1a0 do_syscall_64+0xee/0x2b0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Reported-by: Alexandru Moise <[email protected]> Fixes: a063057 ("block: Fix a race between request queue removal and the block cgroup controller") # v4.17 Signed-off-by: Bart Van Assche <[email protected]> Tested-by: Alexandru Moise <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Ming Lei <[email protected]> Cc: Alexandru Moise <[email protected]> Cc: Joseph Qi <[email protected]> Cc: <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d367a69 commit ac89e9c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

block/blk-sysfs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,21 @@ static void __blk_release_queue(struct work_struct *work)
804804
blk_stat_remove_callback(q, q->poll_cb);
805805
blk_stat_free_callback(q->poll_cb);
806806

807+
if (!blk_queue_dead(q)) {
808+
/*
809+
* Last reference was dropped without having called
810+
* blk_cleanup_queue().
811+
*/
812+
WARN_ONCE(blk_queue_init_done(q),
813+
"request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n",
814+
q);
815+
blk_exit_queue(q);
816+
}
817+
818+
WARN(blkg_root_lookup(q),
819+
"request queue %p is being released but it has not yet been removed from the blkcg controller\n",
820+
q);
821+
807822
blk_free_queue_stats(q->stats);
808823

809824
blk_exit_rl(q, &q->root_rl);

0 commit comments

Comments
 (0)