aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-11-04 08:06:05 -0500
committerDavid Gibson <david@gibson.dropbear.id.au>2020-11-24 16:41:45 +1100
commit5e735860c4786418c12751de639b519891a61192 (patch)
tree425448341e707ac07e368ad71a596d30ac18c7aa
parent67849a327927e1028010e973b36f7b1280ce8184 (diff)
downloaddtc-5e735860c4786418c12751de639b519891a61192.tar.gz
libfdt: Check for 8-byte address alignment in fdt_ro_probe_()
The device tree must be loaded in to memory at an 8-byte aligned address. Add a check for this condition in fdt_ro_probe_() and a new error code to return if we are not. Signed-off-by: Tom Rini <trini@konsulko.com> Message-Id: <20201104130605.28874-1-trini@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--libfdt/fdt.c4
-rw-r--r--libfdt/libfdt.h6
2 files changed, 9 insertions, 1 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 6cf2fa0..3e89307 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -22,6 +22,10 @@ int32_t fdt_ro_probe_(const void *fdt)
if (can_assume(VALID_DTB))
return totalsize;
+ /* The device tree must be at an 8-byte aligned address */
+ if ((uintptr_t)fdt & 7)
+ return -FDT_ERR_ALIGNMENT;
+
if (fdt_magic(fdt) == FDT_MAGIC) {
/* Complete tree */
if (!can_assume(LATEST)) {
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 5979832..89adee3 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -101,7 +101,11 @@ extern "C" {
/* FDT_ERR_BADFLAGS: The function was passed a flags field that
* contains invalid flags or an invalid combination of flags. */
-#define FDT_ERR_MAX 18
+#define FDT_ERR_ALIGNMENT 19
+ /* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
+ * aligned. */
+
+#define FDT_ERR_MAX 19
/* constants */
#define FDT_MAX_PHANDLE 0xfffffffe