lib/imd: Fix imdr_recover for small regions

One of the checks inside imdr_recover() was written with the
assumption that imdr limit is always aligned to LIMIT_ALIGN. This is
true only for large allocations, thus may fail for small regions.

It's not necessary to check if root_pointer is under the limit, since
this is implicitly verified by imdr_get_root_pointer().

Signed-off-by: Jan Dabros <jsd@semihalf.com>
Change-Id: I25d6291301797d10c6a267b5f6e56ac38b995b7b
Reviewed-on: https://review.coreboot.org/c/coreboot/+/44667
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
Jan Dabros 2020-08-21 08:24:41 +02:00 committed by Patrick Georgi
parent 93d56f5165
commit 086c5e6fc8
1 changed files with 2 additions and 3 deletions

View File

@ -201,9 +201,8 @@ static int imdr_recover(struct imdr *imdr)
r = relative_pointer(rp, rp->root_offset);
/* Confirm the root and root pointer are just under the limit. */
if (ALIGN_UP((uintptr_t)&r->entries[r->max_entries], LIMIT_ALIGN) !=
imdr->limit)
/* Ensure that root is just under the root pointer */
if ((intptr_t)rp - (intptr_t)&r->entries[r->max_entries] > sizeof(struct imd_entry))
return -1;
if (r->num_entries > r->max_entries)