From 086c5e6fc866e99208da3c1c9c8840cd0aeaec80 Mon Sep 17 00:00:00 2001 From: Jan Dabros Date: Fri, 21 Aug 2020 08:24:41 +0200 Subject: [PATCH] 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 Change-Id: I25d6291301797d10c6a267b5f6e56ac38b995b7b Reviewed-on: https://review.coreboot.org/c/coreboot/+/44667 Tested-by: build bot (Jenkins) Reviewed-by: Paul Fagerburg --- src/lib/imd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/imd.c b/src/lib/imd.c index 53d0616ab8..c86cf324c8 100644 --- a/src/lib/imd.c +++ b/src/lib/imd.c @@ -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)