Skip to content

Commit 301867b

Browse files
Li Nanliu-song-6
authored andcommitted
md/raid10: check slab-out-of-bounds in md_bitmap_get_counter
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: ef42567 ("md/bitmap: optimise scanning of empty bitmaps.") Signed-off-by: Li Nan <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3de1355 commit 301867b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/md/md-bitmap.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ __acquires(bitmap->lock)
5454
{
5555
unsigned char *mappage;
5656

57-
if (page >= bitmap->pages) {
58-
/* This can happen if bitmap_start_sync goes beyond
59-
* End-of-device while looking for a whole page.
60-
* It is harmless.
61-
*/
62-
return -EINVAL;
63-
}
64-
57+
WARN_ON_ONCE(page >= bitmap->pages);
6558
if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */
6659
return 0;
6760

@@ -1387,6 +1380,14 @@ __acquires(bitmap->lock)
13871380
sector_t csize;
13881381
int err;
13891382

1383+
if (page >= bitmap->pages) {
1384+
/*
1385+
* This can happen if bitmap_start_sync goes beyond
1386+
* End-of-device while looking for a whole page or
1387+
* user set a huge number to sysfs bitmap_set_bits.
1388+
*/
1389+
return NULL;
1390+
}
13901391
err = md_bitmap_checkpage(bitmap, page, create, 0);
13911392

13921393
if (bitmap->bp[page].hijacked ||

0 commit comments

Comments
 (0)