Skip to contentSkip to conversation

SVM: nSVM: fix resource leak on error path

PATCH In review Alex Dewar 3 participants 4 messages Sep 14, 2020 – Sep 16, 2020

Subsystems (3)
lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 SVM: nSVM: fix resource leak on error path

In svm_set_nested_state(), if nested_svm_vmrun_msrpm() returns false, then variables save and ctl will leak. Fix this.

Fixes 772b81bb2f9b ("SVM: nSVM: setup nested msr permission bitmap on nested state load")
---
 arch/x86/kvm/svm/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/nested.c +1 -1
index 598a769f1961..85f572cbabe4 100644
@@ -1148,7 +1148,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	nested_prepare_vmcb_control(svm);
 
 	if (!nested_svm_vmrun_msrpm(svm))
-		return -EINVAL;
+		goto out_free;	/* ret == -EINVAL */
 
 out_set_gif:
 	svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
Signature · 1 line
2.28.0
#1 lore raw
Quoted 14 lines · Alex Dewar

In svm_set_nested_state(), if nested_svm_vmrun_msrpm() returns false, then variables save and ctl will leak. Fix this.

Fixes 772b81bb2f9b ("SVM: nSVM: setup nested msr permission bitmap on nested state load")
---
 arch/x86/kvm/svm/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/nested.c +0 -0
index 598a769f1961..85f572cbabe4 100644

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

Quoted 8 lines
arch/x86/kvm/svm/nested.c +1 -1
@@ -1148,7 +1148,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	nested_prepare_vmcb_control(svm);
 
 	if (!nested_svm_vmrun_msrpm(svm))
-		return -EINVAL;
+		goto out_free;	/* ret == -EINVAL */
 
 out_set_gif:
 	svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));

I think that this patch is based on unmerged patch, since I don't see any memory allocation in nested_svm_vmrun_msrpm, nor out_free label. in nether kvm/master, kvm/queue nor in upstream/master

If I recall correctly that would be something about allocating ctrl/save dynamically rather than on stack.

Best regards,
Maxim Levitsky

maintainer
#2 lore raw
Quoted 3 lines · Maxim Levitsky

I think that this patch is based on unmerged patch, since I don't see any memory allocation in nested_svm_vmrun_msrpm, nor out_free label. in nether kvm/master, kvm/queue nor in upstream/master

Paolo and I need to figure out first how to share the SEV-ES enablement work and the other patches touching that file and then pile more fixes ontop.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#3 lore raw
Quoted 8 lines · Borislav Petkov
Quoted 3 lines · Maxim Levitsky

I think that this patch is based on unmerged patch, since I don't see any memory allocation in nested_svm_vmrun_msrpm, nor out_free label. in nether kvm/master, kvm/queue nor in upstream/master

Paolo and I need to figure out first how to share the SEV-ES enablement work and the other patches touching that file and then pile more fixes ontop.

Sorry for the noise! I didn't realise this was a work in progress -- Coverity picked it up.

Quoted 6 lines
Signature · 5 lines
-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette