md/raid10: check slab-out-of-bounds in md_bitmap_get_counter
authorLi Nan <linan122@huawei.com>
Mon, 15 May 2023 13:48:05 +0000 (21:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:20:57 +0000 (16:20 +0200)
commitbe1a3ec63a840cc9e59a033acf154f56255699a1
tree60117e007a39e38b42c9bde75ecb7a6f687d8b6d
parente1379e067b9485e5af03399fe3f0d39bccb023ad
md/raid10: check slab-out-of-bounds in md_bitmap_get_counter

[ Upstream commit 301867b1c16805aebbc306aafa6ecdc68b73c7e5 ]

If we write a large number to md/bitmap_set_bits, md_bitmap_checkpage()
will return -EINVAL because 'page >= bitmap->pages', but the return value
was not checked immediately in md_bitmap_get_counter() in order to set
*blocks value and slab-out-of-bounds occurs.

Move check of 'page >= bitmap->pages' to md_bitmap_get_counter() and
return directly if true.

Fixes: ef4256733506 ("md/bitmap: optimise scanning of empty bitmaps.")
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230515134808.3936750-2-linan666@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/md-bitmap.c