Commit d5cd6f34 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

KVM: nSVM: Avoid freeing uninitialized pointers in svm_set_nested_state()

The save and ctl pointers are passed uninitialized to kfree() when
svm_set_nested_state() follows the 'goto out_set_gif' path. While the
issue could've been fixed by initializing these on-stack varialbles to
NULL, it seems preferable to eliminate 'out_set_gif' label completely as
it is not actually a failure path and duplicating a single svm_set_gif()
call doesn't look too bad.

 [ bp: Drop obscure Addresses-Coverity: tag. ]

Fixes: 6ccbd29a ("KVM: SVM: nested: Don't allocate VMCB structures on stack")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reported-by: default avatarJoerg Roedel <jroedel@suse.de>
Reported-by: default avatarColin King <colin.king@canonical.com>
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Acked-by: default avatarJoerg Roedel <jroedel@suse.de>
Tested-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Link: https://lkml.kernel.org/r/20200914133725.650221-1-vkuznets@redhat.comSigned-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2e3df760
...@@ -1094,7 +1094,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, ...@@ -1094,7 +1094,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
if (!(kvm_state->flags & KVM_STATE_NESTED_GUEST_MODE)) { if (!(kvm_state->flags & KVM_STATE_NESTED_GUEST_MODE)) {
svm_leave_nested(svm); svm_leave_nested(svm);
goto out_set_gif; svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
return 0;
} }
if (!page_address_valid(vcpu, kvm_state->hdr.svm.vmcb_pa)) if (!page_address_valid(vcpu, kvm_state->hdr.svm.vmcb_pa))
...@@ -1148,10 +1149,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, ...@@ -1148,10 +1149,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
nested_prepare_vmcb_control(svm); nested_prepare_vmcb_control(svm);
if (!nested_svm_vmrun_msrpm(svm)) if (!nested_svm_vmrun_msrpm(svm))
return -EINVAL; goto out_free;
out_set_gif:
svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
ret = 0; ret = 0;
out_free: out_free:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment