Skip to contentSkip to conversation

KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()

PATCH In review Joerg Roedel 3 participants 4 messages Sep 14, 2020

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

PATCH 1/1 KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()

From: Joerg Roedel <[email protected]>

The save and ctl pointers need to be initialized to NULL because there is a way through the function in which there is no memory allocated for the pointers but where they are freed in the end.

This involves the 'goto out_set_gif' before the memory for the pointers is allocated.

Fixes 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")
---
 arch/x86/kvm/svm/nested.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/nested.c +2 -2
index 598a769f1961..72a3d6f87107 100644
@@ -1062,8 +1062,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	struct vmcb *hsave = svm->nested.hsave;
 	struct vmcb __user *user_vmcb = (struct vmcb __user *)
 		&user_kvm_nested_state->data.svm[0];
-	struct vmcb_control_area *ctl;
-	struct vmcb_save_area *save;
+	struct vmcb_control_area *ctl = NULL;
+	struct vmcb_save_area *save = NULL;
 	int ret;
 	u32 cr0;
 
Signature · 1 line
2.28.0
#3 lore raw
In reply to Joerg Roedel
Quoted 6 lines · Joerg Roedel

Hi Vitaly,

Quoted 3 lines · Vitaly Kuznetsov

this was previously reported by Colin:
https://lore.kernel.org/kvm/[email protected]/

Quoted 7 lines
Quoted 3 lines

the fix itself looks good, however, I had an alternative suggestion on how to fix this:
https://lore.kernel.org/kvm/[email protected]/

This looks good to me, mind sending your diff as a patch with correct Fixes tag?

Sure, I was under the impression your "KVM: SVM: nested: Don't allocate VMCB structures on stack" is not commited yet and it can be fixed but I now see that it made it to 'tip' tree. Will send the patch out shortly.

Signature · 1 line
Vitaly
#1 lore raw
In reply to Joerg Roedel
Quoted 21 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

The save and ctl pointers need to be initialized to NULL because there is a way through the function in which there is no memory allocated for the pointers but where they are freed in the end.

This involves the 'goto out_set_gif' before the memory for the pointers is allocated.

Fixes 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")
---
 arch/x86/kvm/svm/nested.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/nested.c +0 -0
index 598a769f1961..72a3d6f87107 100644

arch/x86/kvm/svm/nested.c static int svm_set_nested_state(struct kvm_vcpu *vcpu, · line 1068

Quoted 9 lines
arch/x86/kvm/svm/nested.c +2 -2
@@ -1062,8 +1062,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	struct vmcb *hsave = svm->nested.hsave;
 	struct vmcb __user *user_vmcb = (struct vmcb __user *)
 		&user_kvm_nested_state->data.svm[0];
-	struct vmcb_control_area *ctl;
-	struct vmcb_save_area *save;
+	struct vmcb_control_area *ctl = NULL;
+	struct vmcb_save_area *save = NULL;
 	int ret;
 	u32 cr0;

Hi Joerg,

this was previously reported by Colin:
https://lore.kernel.org/kvm/[email protected]/

the fix itself looks good, however, I had an alternative suggestion on how to fix this:
https://lore.kernel.org/kvm/[email protected]/

Signature · 1 line
Vitaly