diff options
author | Li Zhong <floridsleeves@gmail.com> | 2022-09-16 16:33:05 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-01-18 11:30:36 +0100 |
commit | 21e9aac9a74d30907d44bae0d24c036cb3819406 (patch) | |
tree | 5ea4233185162ec7e54a708b6601f5692d1f74a7 | |
parent | f5de6f9c695194e7bc9a7a280f65f58df86bbbd5 (diff) | |
download | linux-stable-21e9aac9a74d30907d44bae0d24c036cb3819406.tar.gz linux-stable-21e9aac9a74d30907d44bae0d24c036cb3819406.tar.bz2 linux-stable-21e9aac9a74d30907d44bae0d24c036cb3819406.zip |
drivers/md/md-bitmap: check the return value of md_bitmap_get_counter()
[ Upstream commit 3bd548e5b819b8c0f2c9085de775c5c7bff9052f ]
Check the return value of md_bitmap_get_counter() in case it returns
NULL pointer, which will result in a null pointer dereference.
v2: update the check to include other dereference
Signed-off-by: Li Zhong <floridsleeves@gmail.com>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/md/md-bitmap.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 7cf9d34ce20e..157a1735d7b7 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -2191,20 +2191,23 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks, if (set) { bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1); - if (*bmc_new == 0) { - /* need to set on-disk bits too. */ - sector_t end = block + new_blocks; - sector_t start = block >> chunkshift; - start <<= chunkshift; - while (start < end) { - md_bitmap_file_set_bit(bitmap, block); - start += 1 << chunkshift; + if (bmc_new) { + if (*bmc_new == 0) { + /* need to set on-disk bits too. */ + sector_t end = block + new_blocks; + sector_t start = block >> chunkshift; + + start <<= chunkshift; + while (start < end) { + md_bitmap_file_set_bit(bitmap, block); + start += 1 << chunkshift; + } + *bmc_new = 2; + md_bitmap_count_page(&bitmap->counts, block, 1); + md_bitmap_set_pending(&bitmap->counts, block); } - *bmc_new = 2; - md_bitmap_count_page(&bitmap->counts, block, 1); - md_bitmap_set_pending(&bitmap->counts, block); + *bmc_new |= NEEDED_MASK; } - *bmc_new |= NEEDED_MASK; if (new_blocks < old_blocks) old_blocks = new_blocks; } |