Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d8d046f authored by Li Zhong's avatar Li Zhong Committed by Greg Kroah-Hartman
Browse files

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: default avatarLi Zhong <floridsleeves@gmail.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 2b1b145c
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -2200,10 +2200,12 @@ 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) {
				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);
@@ -2214,6 +2216,7 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
					md_bitmap_set_pending(&bitmap->counts, block);
				}
				*bmc_new |= NEEDED_MASK;
			}
			if (new_blocks < old_blocks)
				old_blocks = new_blocks;
		}