From 643b11a3c2acc91e14b45f90b7c91c5412cd1460 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 14 Mar 2022 09:58:05 +0800 Subject: [PATCH] dm space map common: add bounds check to sm_ll_lookup_bitmap() stable inclusion from linux-4.19.226 commit 7d585b602a5c054e810b8f47183069872ac2fdf6 -------------------------------- [ Upstream commit cba23ac158db7f3cd48a923d6861bee2eb7a2978 ] Corrupted metadata could warrant returning error from sm_ll_lookup_bitmap(). Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin Signed-off-by: Yongqiang Liu Signed-off-by: Laibin Qiu Signed-off-by: Yongqiang Liu --- drivers/md/persistent-data/dm-space-map-common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/md/persistent-data/dm-space-map-common.c b/drivers/md/persistent-data/dm-space-map-common.c index a284762e548e..5115a2719603 100644 --- a/drivers/md/persistent-data/dm-space-map-common.c +++ b/drivers/md/persistent-data/dm-space-map-common.c @@ -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) -- GitLab