From: John Garry john.garry@huawei.com
mainline inclusion from mainline-v5.16-rc1 commit 8bdf7b3fe1f48a2c1c212d4685903bba01409c0e category: bugfix bugzilla: 186917, https://gitee.com/openeuler/kernel/issues/I5N1S5 CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
We should not reference the queue tagset in blk_mq_sched_tags_teardown() (see function comment) for the blk-mq flags, so use the passed flags instead.
This solves a use-after-free, similarly fixed earlier (and since broken again) in commit f0c1c4d2864e ("blk-mq: fix use-after-free in blk_mq_exit_sched").
Reported-by: Linux Kernel Functional Testing lkft@linaro.org Reported-by: Naresh Kamboju naresh.kamboju@linaro.org Tested-by: Anders Roxell anders.roxell@linaro.org Fixes: e155b0c238b2 ("blk-mq: Use shared tags for shared sbitmap support") Signed-off-by: John Garry john.garry@huawei.com Link: https://lore.kernel.org/r/1634890340-15432-1-git-send-email-john.garry@huawe... Signed-off-by: Jens Axboe axboe@kernel.dk
Conflict: block/blk-mq-sched.c Signed-off-by: Zhang Wensheng zhangwensheng5@huawei.com Reviewed-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Jason Yan yanaijie@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- block/blk-mq-sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 36cfae6e1dd3..b3c9eae72625 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -545,7 +545,7 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q, unsigned int fla
queue_for_each_hw_ctx(q, hctx, i) { if (hctx->sched_tags) { - if (!blk_mq_is_sbitmap_shared(q->tag_set->flags)) + if (!blk_mq_is_sbitmap_shared(flags)) blk_mq_free_rq_map(hctx->sched_tags); hctx->sched_tags = NULL; }