Skip to content

Commit

Permalink
libfdt: Check for 8-byte address alignment in fdt_ro_probe_()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
trini authored and dgibson committed Nov 24, 2020
1 parent 67849a3 commit 5e73586
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libfdt/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 5 additions & 1 deletion libfdt/libfdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e73586

Please sign in to comment.