diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2015-09-26 13:09:21 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-09-29 13:32:46 -0400 |
commit | a723bab3d7529133f71fc8a5e96f86e3639a0d13 (patch) | |
tree | 658d5b5c71b7851f34ed07ce8c0022915acd33e4 /block | |
parent | 4593fdbe7a2f44d5e64c627c715dd0bcec9bdf14 (diff) |
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.c | 8 |
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) | |||
1925 | kfree(hctx); | 1925 | kfree(hctx); |
1926 | } | 1926 | } |
1927 | 1927 | ||
1928 | kfree(q->mq_map); | ||
1929 | q->mq_map = NULL; | ||
1930 | |||
1928 | kfree(q->queue_hw_ctx); | 1931 | kfree(q->queue_hw_ctx); |
1929 | 1932 | ||
1930 | /* ctx kobj stays in queue_ctx */ | 1933 | /* ctx kobj stays in queue_ctx */ |
@@ -2070,11 +2073,6 @@ void blk_mq_free_queue(struct request_queue *q) | |||
2070 | blk_mq_free_hw_queues(q, set); | 2073 | blk_mq_free_hw_queues(q, set); |
2071 | 2074 | ||
2072 | percpu_ref_exit(&q->mq_usage_counter); | 2075 | percpu_ref_exit(&q->mq_usage_counter); |
2073 | |||
2074 | kfree(q->mq_map); | ||
2075 | |||
2076 | q->mq_map = NULL; | ||
2077 | |||
2078 | mutex_lock(&all_q_mutex); | 2076 | mutex_lock(&all_q_mutex); |
2079 | list_del_init(&q->all_q_node); | 2077 | list_del_init(&q->all_q_node); |
2080 | mutex_unlock(&all_q_mutex); | 2078 | mutex_unlock(&all_q_mutex); |