Commit 39caa731 authored by Junichi Nomura's avatar Junichi Nomura Committed by Greg Kroah-Hartman

blk-mq: fix use-after-free in blk_mq_free_tag_set()

commit f42d79ab upstream.

tags is freed in blk_mq_free_rq_map() and should not be used after that.
The problem doesn't manifest if CONFIG_CPUMASK_OFFSTACK is false because
free_cpumask_var() is nop.

tags->cpumask is allocated in blk_mq_init_tags() so it's natural to
free cpumask in its counter part, blk_mq_free_tags().

Fixes: f26cdc85 ("blk-mq: Shared tag enhancements")
Signed-off-by: default avatarJun'ichi Nomura <j-nomura@ce.jp.nec.com>
Cc: Keith Busch <keith.busch@intel.com>
Reviewed-by: default avatarJeff Moyer <jmoyer@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ce446155
...@@ -628,6 +628,7 @@ void blk_mq_free_tags(struct blk_mq_tags *tags) ...@@ -628,6 +628,7 @@ void blk_mq_free_tags(struct blk_mq_tags *tags)
{ {
bt_free(&tags->bitmap_tags); bt_free(&tags->bitmap_tags);
bt_free(&tags->breserved_tags); bt_free(&tags->breserved_tags);
free_cpumask_var(tags->cpumask);
kfree(tags); kfree(tags);
} }
......
...@@ -2263,10 +2263,8 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set) ...@@ -2263,10 +2263,8 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)
int i; int i;
for (i = 0; i < set->nr_hw_queues; i++) { for (i = 0; i < set->nr_hw_queues; i++) {
if (set->tags[i]) { if (set->tags[i])
blk_mq_free_rq_map(set, set->tags[i], i); blk_mq_free_rq_map(set, set->tags[i], i);
free_cpumask_var(set->tags[i]->cpumask);
}
} }
kfree(set->tags); kfree(set->tags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment