Skip to content

Commit

Permalink
blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue
Browse files Browse the repository at this point in the history
[ 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>
  • Loading branch information
YangYang866 authored and gregkh committed Oct 29, 2020
1 parent eb66ae0 commit 1e2be69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 0 additions & 2 deletions block/blk-mq-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ static void blk_mq_hw_sysfs_release(struct kobject *kobj)
struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx,
kobj);

cancel_delayed_work_sync(&hctx->run_work);

if (hctx->flags & BLK_MQ_F_BLOCKING)
cleanup_srcu_struct(hctx->srcu);
blk_free_flush_queue(hctx->fq);
Expand Down
9 changes: 8 additions & 1 deletion block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,16 @@ static void __blk_release_queue(struct work_struct *work)

blk_free_queue_stats(q->stats);

if (queue_is_mq(q))
if (queue_is_mq(q)) {
struct blk_mq_hw_ctx *hctx;
int i;

cancel_delayed_work_sync(&q->requeue_work);

queue_for_each_hw_ctx(q, hctx, i)
cancel_delayed_work_sync(&hctx->run_work);
}

blk_exit_queue(q);

blk_queue_free_zone_bitmaps(q);
Expand Down

0 comments on commit 1e2be69

Please sign in to comment.