blk-mq: move cancel of requeue_work to the front of blk_exit_queue
authorzhengbin <zhengbin13@huawei.com>
Mon, 12 Aug 2019 12:36:55 +0000 (20:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Oct 2019 06:26:10 +0000 (08:26 +0200)
commit40cdc71e11113d5cf0ec11f447e293828e6f4217
tree7886c2b1196807f4a1dd09d01d11b8ece3e8b7e2
parent313efb253d03d7b5dc3dee1d25098133fc8b12a5
blk-mq: move cancel of requeue_work to the front of blk_exit_queue

[ Upstream commit e26cc08265dda37d2acc8394604f220ef412299d ]

blk_exit_queue will free elevator_data, while blk_mq_requeue_work
will access it. Move cancel of requeue_work to the front of
blk_exit_queue to avoid use-after-free.

blk_exit_queue                blk_mq_requeue_work
  __elevator_exit               blk_mq_run_hw_queues
    blk_mq_exit_sched             blk_mq_run_hw_queue
      dd_exit_queue                 blk_mq_hctx_has_pending
        kfree(elevator_data)          blk_mq_sched_has_work
                                        dd_has_work

Fixes: fbc2a15e3433 ("blk-mq: move cancel of requeue_work into blk_mq_release")
Cc: stable@vger.kernel.org
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: zhengbin <zhengbin13@huawei.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-mq.c
block/blk-sysfs.c