]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
xen/arm: bootfdt: Harden handling of malformed mem reserve map
authorShawn Anastasio <sanastasio@raptorengineering.com>
Thu, 11 Jan 2024 23:24:22 +0000 (17:24 -0600)
committerJulien Grall <jgrall@amazon.com>
Fri, 12 Jan 2024 11:04:54 +0000 (11:04 +0000)
The early_print_info routine in bootfdt.c incorrectly stores the result
of a call to fdt_num_mem_rsv() in an unsigned int, which results in the
negative error code being interpreted incorrectly in a subsequent loop
in the case where the device tree is malformed. Fix this by properly
checking the return code for an error and calling panic().

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
xen/arch/arm/bootfdt.c

index 1cbac3cb2a64b5481a8935da2b3392e9b8c66254..35dbdf3384cb18b687e0e2b3671f7e7aa07b0de6 100644 (file)
@@ -463,7 +463,8 @@ static void __init early_print_info(void)
     struct meminfo *mem_resv = &bootinfo.reserved_mem;
     struct bootmodules *mods = &bootinfo.modules;
     struct bootcmdlines *cmds = &bootinfo.cmdlines;
-    unsigned int i, j, nr_rsvd;
+    unsigned int i, j;
+    int nr_rsvd;
 
     for ( i = 0; i < mi->nr_banks; i++ )
         printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n",
@@ -478,6 +479,9 @@ static void __init early_print_info(void)
                 boot_module_kind_as_string(mods->module[i].kind));
 
     nr_rsvd = fdt_num_mem_rsv(device_tree_flattened);
+    if ( nr_rsvd < 0 )
+        panic("Parsing FDT memory reserve map failed (%d)\n", nr_rsvd);
+
     for ( i = 0; i < nr_rsvd; i++ )
     {
         paddr_t s, e;