[PATCH v2025.09.y 53/58] of: fdt: fix heap-buffer-overflow in fdt_machine_is_compatible
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Mar 13 06:25:37 PDT 2026
From: Ahmad Fatoum <a.fatoum at barebox.org>
fdt_machine_is_compatible() reads the FDT property header fields
(len, nameoff) without first checking that the full struct fdt_property
fits within the FDT buffer. While the tag field (4 bytes) is validated
by dt_ptr_ok(fdt, tagp), the subsequent access to fdt_prop->len and
fdt_prop->nameoff (at offsets +4 and +8) can read past the buffer when
the FDT is truncated between the tag and the property header fields.
Add a dt_ptr_ok(fdt, fdt_prop) check before accessing the property
fields, matching the existing pattern in __of_unflatten_dtb().
Found by fuzz-fdt-compatible with AddressSanitizer.
(cherry picked from commit ef2e9ab5611cc5c8d4faec35f95915a4e204d3b2)
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
Link: https://lore.barebox.org/20260302135258.197132-3-a.fatoum@barebox.org
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/of/fdt.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index b529b4d1fe3d..2ef7658bc4ab 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -801,6 +801,9 @@ int fdt_machine_is_compatible(const struct fdt_header *fdt, size_t fdt_size, con
case FDT_PROP:
fdt_prop = (const void *)fdt + dt_struct;
+ if (!dt_ptr_ok(fdt, fdt_prop))
+ return 0;
+
len = fdt32_to_cpu(fdt_prop->len);
name = dt_string(&f, dt_strings, fdt32_to_cpu(fdt_prop->nameoff));
--
2.47.3
More information about the barebox
mailing list