summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNgo Luong Thanh Tra <S4210155@student.rmit.edu.au>2026-08-10 15:08:15 +0700
committerFabio Estevam <festevam@gmail.com>2026-08-14 16:19:31 -0300
commitb5c61b03c02917819541e3902973a78d0ca43d42 (patch)
tree882938a6f37b40fc27525451333b907dbea8a95a
parentd4be0a14bac3376222f4ff7680c39474151be967 (diff)
downloadu-boot-b5c61b03c02917819541e3902973a78d0ca43d42.tar.gz
u-boot-b5c61b03c02917819541e3902973a78d0ca43d42.zip
arm: imx: hab: validate HAB M4 event length before memcpy()
get_hab_status_m4() copies each HAB_TAG_EVT record from the HAB M4 persistent memory region into a fixed 128-byte stack buffer using a length taken straight from the record header: record_len = get_record_len(rec); if (rec->tag == HAB_TAG_EVT) memcpy(&event_data, rec, record_len); get_record_len() builds a 16-bit big-endian value from rec->len[], so record_len can be up to 65535, while event_data is 128 bytes. A record advertising a length above 128 therefore overflows the stack buffer. The A7 path in get_hab_status() does not have this problem because it passes sizeof(event_data) to hab_rvt_report_event() as an in/out bound. A zero-length record is also mishandled: offset += record_len leaves offset unchanged and the parse loop never terminates. Reject records whose length is zero or which extend past the end of the persistent memory region, and reject events larger than the destination buffer, before the copy is made. An invalid record means the region is corrupt, so abort the listing rather than continue, matching the existing handling of an invalid HAB_TAG_EVT_DEF header. Fixes: 58f75efeaf30 ("mx7ulp: hab: Add hab_status command for HABv4 M4 boot") Signed-off-by: Ngo Luong Thanh Tra <S4210155@student.rmit.edu.au> Cc: Stefano Babic <sbabic@nabladev.com> Cc: Fabio Estevam <festevam@gmail.com> Cc: NXP i.MX U-Boot Team <uboot-imx@nxp.com> Cc: Tom Rini <trini@konsulko.com>
-rw-r--r--arch/arm/mach-imx/hab.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index ab5861578e5..f92f77670a8 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -541,7 +541,19 @@ static int get_hab_status_m4(void)
record_len = get_record_len(rec);
+ if (!record_len ||
+ offset + record_len > HAB_M4_PERSISTENT_BYTES) {
+ puts("\nERROR: Invalid HAB record length\n");
+ return 1;
+ }
+
if (rec->tag == HAB_TAG_EVT) {
+ if (record_len > sizeof(event_data)) {
+ printf("\nERROR: HAB event %d too large (%zu bytes)\n",
+ index + 1, record_len);
+ return 1;
+ }
+
memcpy(&event_data, rec, record_len);
puts("\n");
printf("--------- HAB Event %d -----------------\n",