From: Daniel Golle <daniel@makrotopia.org>
To: Aristo Chen <aristo.chen@canonical.com>
Cc: u-boot@lists.u-boot-project.org, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v2 1/2] boot: fit: bound the external data size on the imagemap storage path
Date: Sun, 29 Nov 2026 02:03:55 +0000 [thread overview]
Message-ID: <awuIC0PMtObc_N24@makrotopia.org> (raw)
In-Reply-To: <20261120131113.1044702-2-aristo.chen@canonical.com>
On Fri, Nov 20, 2026 at 01:11:07PM +0000, Aristo Chen wrote:
> fit_image_load_storage() loads an external-data sub-image by reading it
> from the storage device with a transfer sized from the FIT data-size
> property. That property is listed in exc_prop[] in boot/image-fit-sig.c,
> so it is excluded from the configuration signature and stays under the
> control of anyone able to modify the boot medium even when FIT_SIGNATURE
> is enabled. The read happens before fit_image_select() checks the image
> hash, and for an uncompressed image with a load address it goes straight
> to that address, so an inflated data-size overruns the destination
> before the corruption can be detected.
>
> The other branch is not changed. There imagemap_map() reads into a
> buffer that it allocates from LMB at the requested size. Its size
> arithmetic can wrap for a data-size close to 4 GiB when ulong or
> phys_size_t is 32 bits wide; that needs a fix in imagemap_map() itself
> and is not part of this patch.
>
> Before the direct read, reject an image whose data-size is larger than
> the memory that lmb_get_free_size() reports as free at the load address,
> and print a message that gives both. Within the limits of that helper,
> which are listed below, this keeps the read away from U-Boot itself,
> from reserved memory and from the buffers imagemap_map() has allocated.
> It does not limit how large an image may be.
>
> This is partial hardening, not a complete fix. Free memory behind the
> real payload can still be written before the hash check rejects the
> image, and the destination of a direct read is not reserved in LMB, so
> a sub-image that was read directly is not protected from a later one.
>
> lmb_get_free_size() has three limits that are left as they are:
>
> - It stops at every used region and returns 0 from inside one. That
> includes the LMB_NONE regions that the load commands, tftp, wget,
> "sf read" and bootm leave behind, so a valid image is refused when
> the load address of a sub-image is still recorded as used after an
> earlier load in the same session. tftp and wget stopped using the
> helper for that reason, in commit af45c84871e4 ("tftp: rework the
> logic to validate the load address") and commit 51ebd514ec78 ("wget:
> rework the logic to validate the load address").
> - With more than one RAM bank, the size it returns can run across the
> hole to the next bank.
> - With a 32-bit phys_addr_t, it does not see a reservation that ends at
> 4 GiB from an address inside that reservation.
>
> Fixes: 46d32e38ee4e ("boot: fit: support on-demand loading in fit_image_load()")
> Addresses-Coverity-ID: CID 661899: Insecure data handling (TAINTED_SCALAR)
> Suggested-by: Daniel Golle <daniel@makrotopia.org>
> Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
> ---
> v2: bound only the direct read, by the free memory that LMB reports at
> the load address, as suggested by Daniel. The CONFIG_SYS_BOOTM_LEN
> ceiling and the Kconfig change are gone. Commit message rewritten; it
> now lists the limits of lmb_get_free_size().
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
next prev parent reply other threads:[~2026-11-29 2:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 14:31 [PATCH v1 0/2] boot: fit: bound the external data size on the imagemap storage path Aristo Chen
2026-11-15 14:31 ` [PATCH v1 1/2] " Aristo Chen
2026-11-15 21:39 ` Daniel Golle
2026-11-17 9:53 ` Aristo Chen
2026-11-15 14:31 ` [PATCH v1 2/2] test: boot: imagemap: reject an oversized data-size Aristo Chen
2026-11-20 13:11 ` [PATCH v2 0/2] boot: fit: bound the external data size on the imagemap storage path Aristo Chen
2026-11-20 13:11 ` [PATCH v2 1/2] " Aristo Chen
2026-11-29 2:03 ` Daniel Golle [this message]
2026-11-20 13:11 ` [PATCH v2 2/2] test: boot: imagemap: check the data-size bound on a direct read Aristo Chen
2026-11-29 2:05 ` Daniel Golle
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=awuIC0PMtObc_N24@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=aristo.chen@canonical.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.