summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2015-09-27 02:09:21 +0900
committerJens Axboe <axboe@fb.com>2015-09-29 11:32:46 -0600
commita723bab3d7529133f71fc8a5e96f86e3639a0d13 (patch)
tree658d5b5c71b7851f34ed07ce8c0022915acd33e4 /block
parent4593fdbe7a2f44d5e64c627c715dd0bcec9bdf14 (diff)
downloadlinux-next-a723bab3d7529133f71fc8a5e96f86e3639a0d13.tar.gz
blk-mq: Fix use after of free q->mq_map
CPU hotplug handling for blk-mq (blk_mq_queue_reinit) updates q->mq_map by blk_mq_update_queue_map() for all request queues in all_q_list. On the other hand, q->mq_map is released before deleting the queue from all_q_list. So if CPU hotplug event occurs in the window, invalid memory access can happen. Fix it by releasing q->mq_map in blk_mq_release() to make it happen latter than removal from all_q_list. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Suggested-by: Ming Lei <tom.leiming@gmail.com> Reviewed-by: Ming Lei <tom.leiming@gmail.com> Cc: Ming Lei <tom.leiming@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-mq.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 0262131ac5f2..92648d8d6a4a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1925,6 +1925,9 @@ void blk_mq_release(struct request_queue *q)
kfree(hctx);
}
+ kfree(q->mq_map);
+ q->mq_map = NULL;
+
kfree(q->queue_hw_ctx);
/* ctx kobj stays in queue_ctx */
@@ -2070,11 +2073,6 @@ void blk_mq_free_queue(struct request_queue *q)
blk_mq_free_hw_queues(q, set);
percpu_ref_exit(&q->mq_usage_counter);
-
- kfree(q->mq_map);
-
- q->mq_map = NULL;
-
mutex_lock(&all_q_mutex);
list_del_init(&q->all_q_node);
mutex_unlock(&all_q_mutex);