Skip to content

Commit 1e2be69

Browse files
YangYang866gregkh
authored andcommitted
blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue
[ Upstream commit 47ce030 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eb66ae0 commit 1e2be69

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
@@ -896,9 +896,16 @@ static void __blk_release_queue(struct work_struct *work)
896896

897897
blk_free_queue_stats(q->stats);
898898

899-
if (queue_is_mq(q))
899+
if (queue_is_mq(q)) {
900+
struct blk_mq_hw_ctx *hctx;
901+
int i;
902+
900903
cancel_delayed_work_sync(&q->requeue_work);
901904

905+
queue_for_each_hw_ctx(q, hctx, i)
906+
cancel_delayed_work_sync(&hctx->run_work);
907+
}
908+
902909
blk_exit_queue(q);
903910

904911
blk_queue_free_zone_bitmaps(q);

0 commit comments

Comments
 (0)