libfdt: Check for 8-byte address alignment in fdt_ro_probe_()
PATCH 1/1 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.
--- libfdt/fdt.c | 4 ++++ libfdt/libfdt.h | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-)
libfdt/fdt.c +4 -0
@@ -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 )) {
libfdt/libfdt.h +5 -1
@@ -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
Signature · 1 line
2.17.1
A message that is not in the archive (sent off-list or not yet received): 20201104130605.28874-1-trini-OWPKS81ov/FWk0Htik3J/[email protected]
Quoted 32 lines · Tom Rini
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-OWPKS81ov/FWk0Htik3J/[email protected]>--- libfdt/fdt.c | 4 ++++ libfdt/libfdt.h | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-)libfdt/fdt.c +4
-0@@ -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 )) {libfdt/libfdt.h +0
-0@@ -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. */
libfdt/libfdt.h extern "C" { · line 111
Quoted 10 lines
libfdt/libfdt.h +5
-1-#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
Any comments? Thanks.
Signature · 1 line
Tom
David Gibson
AppliedQuoted 5 lines · Tom Rini
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-OWPKS81ov/FWk0Htik3J/[email protected]>
Applied, thanks, sorry it took so long.
A testcase to make sure this fails on an unaligned blob would be a nice addition
Quoted 37 lines
--- libfdt/fdt.c | 4 ++++ libfdt/libfdt.h | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-)libfdt/fdt.c +4
-0@@ -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 )) {libfdt/libfdt.h +5
-1@@ -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
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · David Gibson
Quoted 5 lines · Tom Rini
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-OWPKS81ov/FWk0Htik3J/[email protected]>Applied, thanks, sorry it took so long.
Thanks.
Quoted 2 lines
A testcase to make sure this fails on an unaligned blob would be a nice addition
I think I see how that might be done, I'll put it on the TODO list.
Signature · 1 line
Tom