blk-map: add kernel address validation in blk_rq_map_kern func
authorrenxudong <renxudong1@huawei.com>
Mon, 30 Dec 2019 12:17:41 +0000 (20:17 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 7 Jan 2020 04:01:39 +0000 (21:01 -0700)
commit78acda3832d1324cd7fd726d8dc5b8d95727a60e
tree7ab2e2680f9908c7a619462b26c2ac18df9fdff8
parent105663f73e71b5e79ecf472c0499c9acde654b28
blk-map: add kernel address validation in blk_rq_map_kern func

Blk_rq_map_kern func is used to map kernel data to a request,
in which kbuf par should be a valid kernel buffer. However,
kbuf par is only checked whether it is null in blk_rq_map_kern func.

If users pass a non kernel address to blk_rq_map_kern func in the
non-aligned scenario, the invalid kbuf will be set to bio->bi_private.
When the request is completed, bio_copy_kern_endio_read will be called
to copy data to the kernel address in bio->bi_private. If the bi_private
is not a valid kernel address, the system will oops. In this case, we
cannot judge whether the bio structure is damaged or the kernel address is
invalid.

Here, we add kernel address validation by calling virt_addr_valid.

Signed-off-by: renxudong <renxudong1@huawei.com>
Reviewed-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-map.c