[PATCH 05/11] boot: imagemap: do not resize a region the caller owns

Daniel Golle daniel at makrotopia.org
Mon Sep 28 17:05:22 PDT 2026


The extend path reserves memory at the recorded address and re-reads the
region into it. For a region recorded by imagemap_map_to() that address
belongs to the caller, which asked for the payload to be placed there:
imagemap reserves memory it was never given and overwrites whatever the
caller had put at the destination.

Restrict the extend path to regions allocated from LMB by imagemap
itself. A larger request against a caller-owned region now falls through
to a fresh allocation, leaving the caller's memory untouched.

Fixes: 9b41c7dbee96 ("boot: add imagemap on-demand loading from storage")
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 boot/imagemap.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/boot/imagemap.c b/boot/imagemap.c
index 89396a03730..a28c7928e46 100644
--- a/boot/imagemap.c
+++ b/boot/imagemap.c
@@ -233,13 +233,18 @@ void *imagemap_map(struct udevice *dev, loff_t img_offset, ulong size)
 	 */
 	alist_for_each(r, &priv->regions) {
 		if (r->img_offset == base_off && r->size < read_size) {
+			/*
+			 * Only a region this device allocated may be resized;
+			 * one recorded by imagemap_map_to() lives at an address
+			 * the caller chose and owns.
+			 */
+			if (!r->lmb_reserved)
+				break;
+
 			addr = map_to_sysmem(r->ram);
 
-			/* Free old LMB reservation if we own it */
-			if (r->lmb_reserved)
-				lmb_free(addr,
-					 ALIGN(r->size, ARCH_DMA_MINALIGN),
-					 LMB_NONE);
+			lmb_free(addr, ALIGN(r->size, ARCH_DMA_MINALIGN),
+				 LMB_NONE);
 
 			/* Try to re-reserve at the same address with new size */
 			if (lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &addr,
-- 
2.55.0



More information about the openwrt-devel mailing list