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>
This commit is contained in:
parent
28d4c2e907
commit
fc83588e85
|
@ -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_size needs to be large enough to accommodate root pointer and
|
||||||
* root book keeping structure. The caller needs to ensure there's
|
* root book keeping structure. Furthermore, there needs to be a space
|
||||||
* enough room for tracking individual allocations.
|
* 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;
|
return -1;
|
||||||
|
|
||||||
/* For simplicity don't allow sizes or alignments to exceed LIMIT_ALIGN.
|
/* For simplicity don't allow sizes or alignments to exceed LIMIT_ALIGN.
|
||||||
|
|
Loading…
Reference in New Issue