blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue
authorYang Yang <yang.yang@vivo.com>
Fri, 9 Oct 2020 08:00:14 +0000 (01:00 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 9 Oct 2020 18:46:28 +0000 (12:46 -0600)
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>
block/blk-mq-sysfs.c
block/blk-sysfs.c

index 0622293..7b52e76 100644 (file)
@@ -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);
index bdc8cf5..b513f16 100644 (file)
@@ -790,9 +790,16 @@ static void blk_release_queue(struct kobject *kobj)
 
        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);