]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
dm space map common: add bounds check to sm_ll_lookup_bitmap()
authorJoe Thornber <ejt@redhat.com>
Fri, 10 Dec 2021 13:49:53 +0000 (13:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 08:04:28 +0000 (09:04 +0100)
[ Upstream commit cba23ac158db7f3cd48a923d6861bee2eb7a2978 ]

Corrupted metadata could warrant returning error from sm_ll_lookup_bitmap().

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/persistent-data/dm-space-map-common.c

index a284762e548e1dc840cef28df8f2167220b26051..5115a27196038dbb618444b1c82565b34fc79a4c 100644 (file)
@@ -279,6 +279,11 @@ int sm_ll_lookup_bitmap(struct ll_disk *ll, dm_block_t b, uint32_t *result)
        struct disk_index_entry ie_disk;
        struct dm_block *blk;
 
+       if (b >= ll->nr_blocks) {
+               DMERR_LIMIT("metadata block out of bounds");
+               return -EINVAL;
+       }
+
        b = do_div(index, ll->entries_per_block);
        r = ll->load_ie(ll, index, &ie_disk);
        if (r < 0)