U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] boot: fit: bound the external data size on the imagemap storage path
@ 2026-11-15 14:31 Aristo Chen
  2026-11-15 14:31 ` [PATCH v1 1/2] " Aristo Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aristo Chen @ 2026-11-15 14:31 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Daniel Golle, Aristo Chen

This series bounds a read that the FIT loader sizes from unsigned
metadata on the imagemap storage path. It addresses Coverity CID 661899
from the scan report in [1]. It is partial hardening rather than a
complete fix; what it leaves open is described under patch 1.

fit_image_load_storage() in boot/image-fit.c reads an external-data
sub-image from the storage device with a transfer sized from the FIT
data-size property, and fit_image_load() only checks the image hash
after that, in fit_image_select(). data-size is in the exc_prop[]
exclusion list in boot/image-fit-sig.c, so it is not covered by the
configuration signature and stays under the control of anyone able to
modify the boot medium even when FIT_SIGNATURE is enabled. For an
uncompressed image with a load address that the caller asks to have
loaded (a ramdisk or a loadable, for example, but not the kernel, which
bootm moves later) the read goes straight to that address, so an
inflated value writes past the end of the image before the hash can
reject it. This is the same problem that
commit 8f71d7170f5c ("spl: fit: bound the external data size before
reading it") dealt with in load_simple_fit() for SPL.

Patch 1 rejects a data-size larger than CONFIG_SYS_BOOTM_LEN with
-EFBIG before the read is issued, the ceiling the SPL commit uses for
loads to a memory region, and prints a message that names the option.
Two consequences of that choice are spelled out in the commit message.

The ceiling is not a tight bound on the destination. On such a direct
read, a size inflated to anything at or below it is still written to
the load address, and the hash only rejects the image after that. What
goes away is the much larger overrun, limited until now only by the
32-bit data-size and the end of the partition. Removing the write
before verification altogether would mean not reading to the load
address at all (read to scratch memory, verify, then copy); this series
keeps the direct read and matches the SPL path instead.

The ceiling is also a new limit. On this path CONFIG_SYS_BOOTM_LEN now
applies to every external-data sub-image that is read into RAM, ramdisks
and loadables included, where so far it has only been the default limit
bootm applies when it decompresses or moves the OS image. A filesystem
image that is left on storage for dm-verity is not read and is not
affected.

Patch 1 also makes CONFIG_SYS_BOOTM_LEN available when IMAGEMAP is
enabled, since an IMAGEMAP build with no boot command and no legacy
image format enabled would otherwise not define it, and mentions the
new use in the help text of the option.

Patch 2 adds a sandbox unit test to test/boot/imagemap.c. It builds a
FIT with one external-data ramdisk whose data-size is far beyond the
ceiling, loads it through a mock imagemap device with verification on,
and checks that fit_image_load() returns -EFBIG and that the mock
reader was never entered. Without patch 1 the read is attempted and the
test fails with -EIO. The test is skipped when FIT is disabled, since
IMAGEMAP does not depend on it.

No in-tree boot flow hands an imagemap device to bootm yet:
imagemap_create() is only called from the unit tests and
bootm_info_set_imagemap() has no caller, so the new limit does not
change any in-tree boot flow.

Verified on sandbox: each commit builds, and the imagemap and bootm unit
test suites pass with the series applied (15 and 7 tests). The series
also builds with FIT disabled, where the new test is reported as
skipped. With the boot commands and the legacy image formats disabled,
boot/image-fit.c compiles with the Kconfig change of patch 1 and fails
on the undefined CONFIG_SYS_BOOTM_LEN without it.

The series is based on current main and does not conflict with the
imagemap series in [2]; that series applies on top of this one, and the
two test suites pass with both applied.

Link: https://lore.kernel.org/u-boot/20261109221650.GA3741582@bill-the-cat/ [1]
Link: https://lore.kernel.org/u-boot/cover.1794614777.git.daniel@makrotopia.org/ [2]

Aristo Chen (2):
  boot: fit: bound the external data size on the imagemap storage path
  test: boot: imagemap: reject an oversized data-size

 boot/Kconfig         |   5 +-
 boot/image-fit.c     |  20 +++++++
 test/boot/imagemap.c | 133 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+), 1 deletion(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-29  2:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox