Skip to content

Commit d5cd6f3

Browse files
vittyvkbonzini
authored andcommitted
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: 6ccbd29 ("KVM: SVM: nested: Don't allocate VMCB structures on stack") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reported-by: Joerg Roedel <jroedel@suse.de> Reported-by: Colin King <colin.king@canonical.com> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com> Acked-by: Joerg Roedel <jroedel@suse.de> Tested-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lkml.kernel.org/r/20200914133725.650221-1-vkuznets@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 2e3df76 commit d5cd6f3

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎arch/x86/kvm/svm/nested.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
10941094

10951095
if (!(kvm_state->flags & KVM_STATE_NESTED_GUEST_MODE)) {
10961096
svm_leave_nested(svm);
1097-
goto out_set_gif;
1097+
svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
1098+
return 0;
10981099
}
10991100

11001101
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,
11481149
nested_prepare_vmcb_control(svm);
11491150

11501151
if (!nested_svm_vmrun_msrpm(svm))
1151-
return -EINVAL;
1152-
1153-
out_set_gif:
1154-
svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
1152+
goto out_free;
11551153

11561154
ret = 0;
11571155
out_free:

0 commit comments

Comments
 (0)