blk-mq: fix use-after-free in blk_mq_free_tag_set()
PATCH 1/1 blk-mq: fix use-after-free in blk_mq_free_tag_set()
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().
--- block/blk-mq-tag.c | 1 + block/blk-mq.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)
block/blk-mq-tag.c +1 -0
@@ -641,6 +641,7 @@ void blk_mq_free_tags(struct blk_mq_tags *tags) {bt_free (&tags->bitmap_tags);bt_free (&tags->breserved_tags); +free_cpumask_var (tags->cpumask);kfree (tags); }
block/blk-mq.c +1 -3
@@ -2296,10 +2296,8 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)int 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); -free_cpumask_var (set->tags[i]->cpumask); - } }kfree (set->tags);
Signature · 1 line
2.1.0
Quoted 11 lines · Junichi Nomura
tags is freed in
blk_mq_free_rq_map()and should not be used after that. The problem doesn't manifest ifCONFIG_CPUMASK_OFFSTACKis false becausefree_cpumask_var()is nop.
tags->cpumaskis allocated inblk_mq_init_tags()so it's natural to free cpumask in its counter part,blk_mq_free_tags().Fixes f26cdc8536ad ("blk-mq: Shared tag enhancements")Signed-off-by Jun'ichi Nomura <[email protected]>Cc Keith Busch <[email protected]>Cc Jens Axboe <[email protected]>
Quoted 33 lines
--- block/blk-mq-tag.c | 1 + block/blk-mq.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-)block/blk-mq-tag.c +1
-0@@ -641,6 +641,7 @@ void blk_mq_free_tags(struct blk_mq_tags *tags) {bt_free (&tags->bitmap_tags);bt_free (&tags->breserved_tags); +free_cpumask_var (tags->cpumask);kfree (tags); }block/blk-mq.c +1
-3@@ -2296,10 +2296,8 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)int 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); -free_cpumask_var (set->tags[i]->cpumask); - } }kfree (set->tags);
Quoted 6 lines · Junichi Nomura
tags is freed in
blk_mq_free_rq_map()and should not be used after that. The problem doesn't manifest ifCONFIG_CPUMASK_OFFSTACKis false becausefree_cpumask_var()is nop.
tags->cpumaskis allocated inblk_mq_init_tags()so it's natural to free cpumask in its counter part,blk_mq_free_tags().
Thanks for the fix.
Quoted 4 lines
Fixes f26cdc8536ad ("blk-mq: Shared tag enhancements")Signed-off-by Jun'ichi Nomura <[email protected]>Cc Keith Busch <[email protected]>Cc Jens Axboe <[email protected]>
Jens Axboe
AppliedQuoted 6 lines · Junichi Nomura
tags is freed in
blk_mq_free_rq_map()and should not be used after that. The problem doesn't manifest ifCONFIG_CPUMASK_OFFSTACKis false becausefree_cpumask_var()is nop.
tags->cpumaskis allocated inblk_mq_init_tags()so it's natural to free cpumask in its counter part,blk_mq_free_tags().
Thanks, applied. tags->cpumask should some day die a horrible death.
Signature · 1 line
Jens Axboe