public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Morgan <macroalpha82@gmail.com>
To: u-boot@lists.denx.de
Cc: macromorgan@hotmail.com, mkorpershoek@kernel.org,
	sjg@chromium.org, trini@konsulko.com, jmasson@baylibre.com,
	nbelin@baylibre.com, bisson.gary@gmail.com
Subject: [PATCH] bootstd: android: Fix write outside of memory
Date: Tue, 23 Dec 2025 17:44:56 -0600	[thread overview]
Message-ID: <20251223234456.1983614-1-macroalpha82@gmail.com> (raw)

From: Chris Morgan <macromorgan@hotmail.com>

It looks like under certain circumstances when reading the vendor_boot
partition it causes my device to write outside the range of memory
available. Near as I can tell this occurs because
scan_vendor_boot_part() calls android_image_get_vendor_bootimg_size()
which calls android_vendor_boot_image_v3_v4_parse_hdr() which calls
add_trailer() which attempts to copy information to a buffer allocated
with malloc in the scan_vendor_boot_part() function. On my board the
memory set aside for malloc is at the top of the system RAM, and given
a large enough vendor boot image size this causes the write from
add_trailer() to occur outside of the system RAM (nevermind outside
of what was allocated with the malloc().

While I don't know the absolute best way to handle this, I would assume
that if we simply map the memory we want to use to where we will
eventually load the vendor_boot image that would be the most logical.

Fixes: abadcda24b10 ("bootstd: android: don't read whole partition sizes")
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
 boot/bootmeth_android.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
index 1374551dbeb..c2c25d53ef3 100644
--- a/boot/bootmeth_android.c
+++ b/boot/bootmeth_android.c
@@ -118,9 +118,10 @@ static int scan_vendor_boot_part(struct udevice *blk, struct android_priv *priv)
 	struct blk_desc *desc = dev_get_uclass_plat(blk);
 	struct disk_partition partition;
 	char partname[PART_NAME_LEN];
-	ulong num_blks, bufsz;
+	ulong num_blks;
 	char *buf;
 	int ret;
+	ulong vloadaddr = env_get_hex("vendor_boot_comp_addr_r", 0);
 
 	if (priv->slot)
 		sprintf(partname, VENDOR_BOOT_PART_NAME "_%s", priv->slot);
@@ -132,28 +133,19 @@ static int scan_vendor_boot_part(struct udevice *blk, struct android_priv *priv)
 		return log_msg_ret("part info", ret);
 
 	num_blks = DIV_ROUND_UP(sizeof(struct andr_vnd_boot_img_hdr), desc->blksz);
-	bufsz = num_blks * desc->blksz;
-	buf = malloc(bufsz);
+	buf = map_sysmem(vloadaddr, 0);
 	if (!buf)
 		return log_msg_ret("buf", -ENOMEM);
 
 	ret = blk_read(blk, partition.start, num_blks, buf);
-	if (ret != num_blks) {
-		free(buf);
+	if (ret != num_blks)
 		return log_msg_ret("part read", -EIO);
-	}
 
-	if (!is_android_vendor_boot_image_header(buf)) {
-		free(buf);
+	if (!is_android_vendor_boot_image_header(buf))
 		return log_msg_ret("header", -ENOENT);
-	}
 
-	if (!android_image_get_vendor_bootimg_size(buf, &priv->vendor_boot_img_size)) {
-		free(buf);
+	if (!android_image_get_vendor_bootimg_size(buf, &priv->vendor_boot_img_size))
 		return log_msg_ret("get vendor bootimg size", -EINVAL);
-	}
-
-	free(buf);
 
 	return 0;
 }
-- 
2.43.0


             reply	other threads:[~2025-12-23 23:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23 23:44 Chris Morgan [this message]
2026-01-06 17:16 ` [PATCH] bootstd: android: Fix write outside of memory Tom Rini
2026-01-07  9:52   ` Mattijs Korpershoek
2026-01-15 22:16   ` Chris Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251223234456.1983614-1-macroalpha82@gmail.com \
    --to=macroalpha82@gmail.com \
    --cc=bisson.gary@gmail.com \
    --cc=jmasson@baylibre.com \
    --cc=macromorgan@hotmail.com \
    --cc=mkorpershoek@kernel.org \
    --cc=nbelin@baylibre.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox