Skip to contentSkip to conversation

x86/hyperv: Fix error pointer dereference

PATCH Applied Ethan Tidmore 2 participants 3 messages Feb 18

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

PATCH 1/1 x86/hyperv: Fix error pointer dereference

The function idle_thread_get() can return an error pointer and is not checked for it. Add check for error pointer.

Detected by Smatch:
arch/x86/hyperv/hv_vtl.c:126 hv_vtl_bringup_vcpu() error:
'idle' dereferencing possible ERR_PTR()

Fixes 2b4b90e053a29 ("x86/hyperv: Use per cpu initial stack for vtl context")

---
v2:
- Fixed typo.

 arch/x86/hyperv/hv_vtl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/hyperv/hv_vtl.c +5 -3
index c0edaed0efb3..9b6a9bc4ab76 100644
@@ -110,7 +110,7 @@ static void hv_vtl_ap_entry(void)
 
 static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored)
 {
-	u64 status;
+	u64 status, rsp, rip;
 	int ret = 0;
 	struct hv_enable_vp_vtl *input;
 	unsigned long irq_flags;
@@ -123,9 +123,11 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored)
 	struct desc_struct *gdt;
 
 	struct task_struct *idle = idle_thread_get(cpu);
-	u64 rsp = (unsigned long)idle->thread.sp;
+	if (IS_ERR(idle))
+		return PTR_ERR(idle);
 
-	u64 rip = (u64)&hv_vtl_ap_entry;
+	rsp = (unsigned long)idle->thread.sp;
+	rip = (u64)&hv_vtl_ap_entry;
 
 	native_store_gdt(&gdt_ptr);
 	store_idt(&idt_ptr);
Signature · 1 line
2.53.0
#1 lore raw
Quoted 10 lines · Ethan Tidmore

The function idle_thread_get() can return an error pointer and is not checked for it. Add check for error pointer.

Detected by Smatch:
arch/x86/hyperv/hv_vtl.c:126 hv_vtl_bringup_vcpu() error:
'idle' dereferencing possible ERR_PTR()

Fixes 2b4b90e053a29 ("x86/hyperv: Use per cpu initial stack for vtl context")

---

Oops, forgot v2 header this is the v2.

Thanks,

ET

maintainer Applied
#2 lore raw
Quoted 8 lines · Ethan Tidmore
Quoted 7 lines · Ethan Tidmore

The function idle_thread_get() can return an error pointer and is not checked for it. Add check for error pointer.

Detected by Smatch:
arch/x86/hyperv/hv_vtl.c:126 hv_vtl_bringup_vcpu() error:
'idle' dereferencing possible ERR_PTR()

Quoted 5 lines
Quoted 3 lines
Fixes 2b4b90e053a29 ("x86/hyperv: Use per cpu initial stack for vtl context")

---

Oops, forgot v2 header this is the v2.

Applied. Thanks.