]> git.baikalelectronics.ru Git - kernel.git/commit
blk-mq: fix null pointer dereference in blk_mq_clear_rq_mapping()
authorYu Kuai <yukuai3@huawei.com>
Tue, 11 Oct 2022 14:22:53 +0000 (22:22 +0800)
committerJens Axboe <axboe@kernel.dk>
Sun, 16 Oct 2022 23:22:51 +0000 (17:22 -0600)
commit7ede0acb311e4c0fc4dfae45965e128a85ea9ff4
tree4848bed6d3a876d7dd57e2ea65223cba8462348e
parent14fe1d17ece9f1d35c3edc375485720b7fe4cd23
blk-mq: fix null pointer dereference in blk_mq_clear_rq_mapping()

Our syzkaller report a null pointer dereference, root cause is
following:

__blk_mq_alloc_map_and_rqs
 set->tags[hctx_idx] = blk_mq_alloc_map_and_rqs
  blk_mq_alloc_map_and_rqs
   blk_mq_alloc_rqs
    // failed due to oom
    alloc_pages_node
    // set->tags[hctx_idx] is still NULL
    blk_mq_free_rqs
     drv_tags = set->tags[hctx_idx];
     // null pointer dereference is triggered
     blk_mq_clear_rq_mapping(drv_tags, ...)

This is because commit 73adb3ad8980 ("blk-mq:
Add blk_mq_alloc_map_and_rqs()") merged the two steps:

1) set->tags[hctx_idx] = blk_mq_alloc_rq_map()
2) blk_mq_alloc_rqs(..., set->tags[hctx_idx])

into one step:

set->tags[hctx_idx] = blk_mq_alloc_map_and_rqs()

Since tags is not initialized yet in this case, fix the problem by
checking if tags is NULL pointer in blk_mq_clear_rq_mapping().

Fixes: 73adb3ad8980 ("blk-mq: Add blk_mq_alloc_map_and_rqs()")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Link: https://lore.kernel.org/r/20221011142253.4015966-1-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c