[kvm-unit-tests PATCH 02/33] arm: Detect FDT overlap with uninitialised data

Suzuki K Poulose
2024-04-12T10:34:45Z

If the FDT was placed in a region overlapping the bss/stack area, it
would have been overwritten at early boot. Assert this never happened
to detect the case.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
lib/arm/setup.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 2f649aff..462a1d51 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -35,6 +35,7 @@
#define NR_MEM_REGIONS (MAX_DT_MEM_REGIONS + NR_EXTRA_MEM_REGIONS)

extern unsigned long _text, _etext, _data, _edata;
+extern unsigned long stacktop;

char *initrd;
u32 initrd_size;
@@ -196,6 +197,12 @@ static void freemem_push_fdt(void **freemem, const void *fdt)
u32 fdt_size;
int ret;

+ /*
+ * Ensure that the FDT was not overlapping with the uninitialised
+ * data that was overwritten.
+ */
+ assert((unsigned long)fdt > (unsigned long)&stacktop);
+
fdt_size = fdt_totalsize(fdt);
ret = fdt_move(fdt, *freemem, fdt_size);
assert(ret == 0);