KVM: nSVM: avoid freeing uninitialized pointers in svm_set_nested_state()
PATCH 1/1 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.
Addresses-Coverity: ("Uninitialized pointer read")
--- arch/x86/kvm/svm/nested.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/nested.c +2 -2
@@ -1094,7 +1094,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,if (!(kvm_state->flags &KVM_STATE_NESTED_GUEST_MODE )) {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))
@@ -1150,7 +1151,6 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,if (!nested_svm_vmrun_msrpm (svm))return -EINVAL ; -out_set_gif:svm_set_gif (svm, !!(kvm_state->flags &KVM_STATE_NESTED_GIF_SET )); ret =0 ;
Signature · 1 line
2.25.4
Quoted 7 lines · Vitaly Kuznetsov
The save and ctl pointers are passed uninitialized to
kfree()whensvm_set_nested_state()follows the 'gotoout_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 singlesvm_set_gif()call doesn't look too bad.
Quoted 7 lines
Fixes 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")Addresses-Coverity: ("Uninitialized pointer read")
Reported-by Dan Carpenter <[email protected]>Reported-by Joerg Roedel <[email protected]>Reported-by Colin King <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>---
Quoted 7 lines · Vitaly Kuznetsov
The save and ctl pointers are passed uninitialized to
kfree()whensvm_set_nested_state()follows the 'gotoout_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 singlesvm_set_gif()call doesn't look too bad.
Quoted 6 lines
Fixes 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")Addresses-Coverity: ("Uninitialized pointer read")
Reported-by Dan Carpenter <[email protected]>Reported-by Joerg Roedel <[email protected]>Reported-by Colin King <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>
Quoted 7 lines · Vitaly Kuznetsov
The save and ctl pointers are passed uninitialized to
kfree()whensvm_set_nested_state()follows the 'gotoout_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 singlesvm_set_gif()call doesn't look too bad.
Quoted 6 lines
Fixes 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")Addresses-Coverity: ("Uninitialized pointer read")
Reported-by Dan Carpenter <[email protected]>Reported-by Joerg Roedel <[email protected]>Reported-by Colin King <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>
[tip: x86/seves] KVM: nSVM: Avoid freeing uninitialized pointers in svm_set_nested_state()
In reply to Vitaly KuznetsovThe following commit has been merged into the x86/seves branch of tip:
The following commit has been merged into the x86/seves branch of tip:
Commit-ID: e6eb15c9ba3165698488ae5c34920eea20eaa38e Gitweb: https://git.kernel.org/tip/e6eb15c9ba3165698488ae5c34920eea20eaa38e Author: Vitaly Kuznetsov <[email protected]> AuthorDate: Mon, 14 Sep 2020 15:37:25 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 14 Sep 2020 18:08:54 +02:00
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. ]
--- arch/x86/kvm/svm/nested.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/nested.c +2 -2
@@ -1092,7 +1092,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,if (!(kvm_state->flags &KVM_STATE_NESTED_GUEST_MODE )) {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))
@@ -1145,7 +1146,6 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,load_nested_vmcb_control (svm, ctl);nested_prepare_vmcb_control (svm); -out_set_gif:svm_set_gif (svm, !!(kvm_state->flags &KVM_STATE_NESTED_GIF_SET )); ret =0 ;