summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Dabros <jsd@semihalf.com>2020-08-19 15:06:10 +0200
committerPatrick Georgi <pgeorgi@google.com>2020-08-26 07:32:45 +0000
commitfc83588e85c5ec080db368f30521e27f1535f34c (patch)
tree47f16c172a797b82726e69ebd8a11c04a2d0b840
parent28d4c2e9075ecc053cad32f6f8fdc706a30ccf26 (diff)
lib/imd: Add an extra check for root_size
Add a check that root_size provided by the caller accounts for one imd_entry necessary for covering imd_root region. Without this, we may end up with writing on unallocated memory. Signed-off-by: Jan Dabros <jsd@semihalf.com> Change-Id: I0a39d56f7a2a6fa026d259c5b5b78def4f115095 Reviewed-on: https://review.coreboot.org/c/coreboot/+/44665 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
-rw-r--r--src/lib/imd.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lib/imd.c b/src/lib/imd.c
index 3be38ea678..2b028a7b44 100644
--- a/src/lib/imd.c
+++ b/src/lib/imd.c
@@ -144,10 +144,11 @@ static int imdr_create_empty(struct imdr *imdr, size_t root_size,
/*
* root_size needs to be large enough to accommodate root pointer and
- * root book keeping structure. The caller needs to ensure there's
- * enough room for tracking individual allocations.
+ * root book keeping structure. Furthermore, there needs to be a space
+ * for at least one entry covering root region. The caller needs to
+ * ensure there's enough room for tracking individual allocations.
*/
- if (root_size < (sizeof(*rp) + sizeof(*r)))
+ if (root_size < (sizeof(*rp) + sizeof(*r) + sizeof(*e)))
return -1;
/* For simplicity don't allow sizes or alignments to exceed LIMIT_ALIGN.