public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()
@ 2020-09-14 11:51 Joerg Roedel
  2020-09-14 12:04 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2020-09-14 11:51 UTC (permalink / raw)
  To: Borislav Petkov, Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	x86, kvm, linux-kernel, Joerg Roedel, Dan Carpenter

From: Joerg Roedel <jroedel@suse.de>

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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 arch/x86/kvm/svm/nested.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 598a769f1961..72a3d6f87107 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -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;
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()
  2020-09-14 11:51 [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state() Joerg Roedel
@ 2020-09-14 12:04 ` Vitaly Kuznetsov
  2020-09-14 12:13   ` Joerg Roedel
  0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-09-14 12:04 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, x86, kvm,
	linux-kernel, Joerg Roedel, Dan Carpenter, Borislav Petkov,
	Paolo Bonzini, Colin King

Joerg Roedel <joro@8bytes.org> writes:

> From: Joerg Roedel <jroedel@suse.de>
>
> 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.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Fixes: 6ccbd29ade0d ("KVM: SVM: nested: Don't allocate VMCB structures on stack")
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>  arch/x86/kvm/svm/nested.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 598a769f1961..72a3d6f87107 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -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/20200911110730.24238-1-colin.king@canonical.com/

the fix itself looks good, however, I had an alternative suggestion on how
to fix this:
https://lore.kernel.org/kvm/87o8mclei1.fsf@vitty.brq.redhat.com/

-- 
Vitaly


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()
  2020-09-14 12:04 ` Vitaly Kuznetsov
@ 2020-09-14 12:13   ` Joerg Roedel
  2020-09-14 12:42     ` Vitaly Kuznetsov
  0 siblings, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2020-09-14 12:13 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: Joerg Roedel, Sean Christopherson, Wanpeng Li, Jim Mattson, x86,
	kvm, linux-kernel, Dan Carpenter, Borislav Petkov, Paolo Bonzini,
	Colin King

Hi Vitaly,

On Mon, Sep 14, 2020 at 02:04:27PM +0200, Vitaly Kuznetsov wrote:
> this was previously reported by Colin:
> https://lore.kernel.org/kvm/20200911110730.24238-1-colin.king@canonical.com/
> 
> the fix itself looks good, however, I had an alternative suggestion on how
> to fix this:
> https://lore.kernel.org/kvm/87o8mclei1.fsf@vitty.brq.redhat.com/

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

Thanks,

	Joerg

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state()
  2020-09-14 12:13   ` Joerg Roedel
@ 2020-09-14 12:42     ` Vitaly Kuznetsov
  0 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-09-14 12:42 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Joerg Roedel, Sean Christopherson, Wanpeng Li, Jim Mattson, x86,
	kvm, linux-kernel, Dan Carpenter, Borislav Petkov, Paolo Bonzini,
	Colin King

Joerg Roedel <jroedel@suse.de> writes:

> Hi Vitaly,
>
> On Mon, Sep 14, 2020 at 02:04:27PM +0200, Vitaly Kuznetsov wrote:
>> this was previously reported by Colin:
>> https://lore.kernel.org/kvm/20200911110730.24238-1-colin.king@canonical.com/
>> 
>> the fix itself looks good, however, I had an alternative suggestion on how
>> to fix this:
>> https://lore.kernel.org/kvm/87o8mclei1.fsf@vitty.brq.redhat.com/
>
> 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.

-- 
Vitaly


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-14 17:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-14 11:51 [PATCH -tip] KVM: SVM: nested: Initialize on-stack pointers in svm_set_nested_state() Joerg Roedel
2020-09-14 12:04 ` Vitaly Kuznetsov
2020-09-14 12:13   ` Joerg Roedel
2020-09-14 12:42     ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox