Skip to contentSkip to conversation

xen/setup: add paranoid index check and warning

PATCH In review Martin Kelly 1 participant 2 messages Oct 14, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/setup: add paranoid index check and warning

In a call to set_phys_range_identity, i-1 is used without checking that i is non-zero. Although unlikely, a bug in the code before it could cause the value to be 0, leading to erroneous behavior. This patch adds a check against 0 value and a corresponding warning.

---
 arch/x86/xen/setup.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/xen/setup.c +4 -1
index af72161..26e39af 100644
@@ -671,7 +671,10 @@ char * __init xen_memory_setup(void)
 	 * PFNs above MAX_P2M_PFN are considered identity mapped as
 	 * well.
 	 */
-	set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul);
+	if (i > 0)
+		set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul);
+	else
+		WARN(1, "Something went wrong clamping memory to a factor of EXTRA_MEM_RATIO!");
 
 	/*
 	 * In domU, the ISA region is normal, usable memory, but we
Signature · 1 line
2.1.1
#1 lore raw
Quoted 17 lines · Martin Kelly

In a call to set_phys_range_identity, i-1 is used without checking that i is non-zero. Although unlikely, a bug in the code before it could cause the value to be 0, leading to erroneous behavior. This patch adds a check against 0 value and a corresponding warning.

---
 arch/x86/xen/setup.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/xen/setup.c +0 -0
index af72161..26e39af 100644
@@ -671,7 +671,10 @@ char * __init xen_memory_setup(void)
 	 * PFNs above MAX_P2M_PFN are considered identity mapped as

arch/x86/xen/setup.c char * __init xen_memory_setup(void) · line 680

Quoted 10 lines
arch/x86/xen/setup.c +4 -1
 	 * well.
 	 */
-	set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul);
+	if (i > 0)
+		set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul);
+	else
+		WARN(1, "Something went wrong clamping memory to a factor of EXTRA_MEM_RATIO!");
 
 	/*
 	 * In domU, the ISA region is normal, usable memory, but we

Forgot to add [email protected]; resending.