Skip to contentSkip to conversation

arm64: fix wrong check of on_sdei_stack in nmi context

PATCH In review Wei Li 4 participants 4 messages Apr 1, 2019 – Apr 2, 2019 arm64

lore
Share & tools
lore

Wei Li

author
#0 lore raw

PATCH 1/1 arm64: fix wrong check of on_sdei_stack in nmi context

When doing unwind_frame() in the context of pseudo nmi (need enable CONFIG_ARM64_PSEUDO_NMI), reaching the botton of the stack (fp == 0, pc != 0), function on_sdei_stack() will return true while the sdei acpi table is not inited in fact. This will cause a "NULL pointer dereference" oops when going on.

---
 arch/arm64/kernel/sdei.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/kernel/sdei.c +6 -0
index 5ba4465e44f0..ea94cf8f9dc6 100644
@@ -94,6 +94,9 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info)
 	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
 	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
 	if (sp < low || sp >= high)
 		return false;
 
@@ -111,6 +114,9 @@ static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
 	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
 	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
 	if (sp < low || sp >= high)
 		return false;
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/1
#1 lore raw

Hi Wei,

Quoted 7 lines · Wei Li

When doing unwind_frame() in the context of pseudo nmi (need enable CONFIG_ARM64_PSEUDO_NMI), reaching the botton of the stack (fp == 0, pc != 0), function on_sdei_stack() will return true while the sdei acpi table is not inited in fact. This will cause a "NULL pointer dereference" oops when going on.

Thanks for catching this. The change makes sense to me.

Quoted 29 lines
---
 arch/arm64/kernel/sdei.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/kernel/sdei.c +6 -0
index 5ba4465e44f0..ea94cf8f9dc6 100644
@@ -94,6 +94,9 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info)
 	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
 	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
 	if (sp < low || sp >= high)
 		return false;
 
@@ -111,6 +114,9 @@ static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
 	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
 	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
 	if (sp < low || sp >= high)
 		return false;
 
Signature · 6 lines
Julien Thierry

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw
In reply to Wei Li
Quoted 2 lines · Wei Li

When doing unwind_frame() in the context of pseudo nmi (need enable CONFIG_ARM64_PSEUDO_NMI), reaching the botton of the stack (fp == 0,

botton -> bottom?

Heyi

Quoted 24 lines

pc != 0), function on_sdei_stack() will return true while the sdei acpi table is not inited in fact. This will cause a "NULL pointer dereference" oops when going on.

---
  arch/arm64/kernel/sdei.c | 6 ++++++
  1 file changed, 6 insertions(+)
arch/arm64/kernel/sdei.c +3 -0
index 5ba4465e44f0..ea94cf8f9dc6 100644
@@ -94,6 +94,9 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info)
  	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
  	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
  	if (sp < low || sp >= high)
  		return false;
 

arch/arm64/kernel/sdei.c static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info) · line 122

Quoted 9 lines
arch/arm64/kernel/sdei.c +3 -0
@@ -111,6 +114,9 @@ static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
  	unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
  	unsigned long high = low + SDEI_STACK_SIZE;
 
+	if (!low)
+		return false;
+
  	if (sp < low || sp >= high)
  		return false;
 

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#3 lore raw
In reply to Wei Li
Quoted 7 lines · Wei Li

When doing unwind_frame() in the context of pseudo nmi (need enable CONFIG_ARM64_PSEUDO_NMI), reaching the botton of the stack (fp == 0, pc != 0), function on_sdei_stack() will return true while the sdei acpi table is not inited in fact. This will cause a "NULL pointer dereference" oops when going on.

Thanks. I'll queue it for -rc4.

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel