Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue

blk_exit_queue will free elevator_data, while blk_mq_run_work_fn
will access it. Move cancel of hctx->run_work to the front of
blk_exit_queue to avoid use-after-free.

Fixes: 1b97871b501f ("blk-mq: move cancel of hctx->run_work into blk_mq_hw_sysfs_release")
Signed-off-by: Yang Yang <yang.yang@vivo.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yang Yang and committed by
Jens Axboe
47ce030b c7281524

+8 -3
-2
block/blk-mq-sysfs.c
··· 36 36 struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx, 37 37 kobj); 38 38 39 - cancel_delayed_work_sync(&hctx->run_work); 40 - 41 39 if (hctx->flags & BLK_MQ_F_BLOCKING) 42 40 cleanup_srcu_struct(hctx->srcu); 43 41 blk_free_flush_queue(hctx->fq);
+8 -1
block/blk-sysfs.c
··· 790 790 791 791 blk_free_queue_stats(q->stats); 792 792 793 - if (queue_is_mq(q)) 793 + if (queue_is_mq(q)) { 794 + struct blk_mq_hw_ctx *hctx; 795 + int i; 796 + 794 797 cancel_delayed_work_sync(&q->requeue_work); 798 + 799 + queue_for_each_hw_ctx(q, hctx, i) 800 + cancel_delayed_work_sync(&hctx->run_work); 801 + } 795 802 796 803 blk_exit_queue(q); 797 804