Skip to content

Commit 47ce030

Browse files
YangYang866axboe
authored andcommitted
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: 1b97871 ("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>
1 parent c728152 commit 47ce030

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

block/blk-mq-sysfs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ static void blk_mq_hw_sysfs_release(struct kobject *kobj)
3636
struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx,
3737
kobj);
3838

39-
cancel_delayed_work_sync(&hctx->run_work);
40-
4139
if (hctx->flags & BLK_MQ_F_BLOCKING)
4240
cleanup_srcu_struct(hctx->srcu);
4341
blk_free_flush_queue(hctx->fq);

block/blk-sysfs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,16 @@ static void blk_release_queue(struct kobject *kobj)
790790

791791
blk_free_queue_stats(q->stats);
792792

793-
if (queue_is_mq(q))
793+
if (queue_is_mq(q)) {
794+
struct blk_mq_hw_ctx *hctx;
795+
int i;
796+
794797
cancel_delayed_work_sync(&q->requeue_work);
795798

799+
queue_for_each_hw_ctx(q, hctx, i)
800+
cancel_delayed_work_sync(&hctx->run_work);
801+
}
802+
796803
blk_exit_queue(q);
797804

798805
blk_queue_free_zone_bitmaps(q);

0 commit comments

Comments
 (0)