All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: svm: Avoid NULL pointer dereference in svm_hv_update_vp_id()
@ 2021-06-14 11:38 Vitaly Kuznetsov
  2021-06-14 13:31 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Kuznetsov @ 2021-06-14 11:38 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Vineeth Pillai, Sean Christopherson, Wanpeng Li, Jim Mattson,
	Maxim Levitsky, linux-kernel

Hyper-V context is allocated dynamically when Hyper-V features are enabled
on a vCPU but svm_hv_update_vp_id() is called unconditionally from
svm_vcpu_run(), this leads to dereferencing to_hv_vcpu(vcpu) which can
be NULL. Use kvm_hv_get_vpindex() wrapper to avoid the problem.

Fixes: 4ba0d72aaa32 ("KVM: SVM: hyper-v: Direct Virtual Flush support")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
- The patch introducing the issue is currently in kvm/queue.
---
 arch/x86/kvm/svm/svm_onhyperv.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h
index ce23149670ea..9b9a55abc29f 100644
--- a/arch/x86/kvm/svm/svm_onhyperv.h
+++ b/arch/x86/kvm/svm/svm_onhyperv.h
@@ -99,9 +99,10 @@ static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
 {
 	struct hv_enlightenments *hve =
 		(struct hv_enlightenments *)vmcb->control.reserved_sw;
+	u32 vp_index = kvm_hv_get_vpindex(vcpu);
 
-	if (hve->hv_vp_id != to_hv_vcpu(vcpu)->vp_index) {
-		hve->hv_vp_id = to_hv_vcpu(vcpu)->vp_index;
+	if (hve->hv_vp_id != vp_index) {
+		hve->hv_vp_id = vp_index;
 		vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
 	}
 }
-- 
2.31.1


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

* Re: [PATCH] KVM: svm: Avoid NULL pointer dereference in svm_hv_update_vp_id()
  2021-06-14 11:38 [PATCH] KVM: svm: Avoid NULL pointer dereference in svm_hv_update_vp_id() Vitaly Kuznetsov
@ 2021-06-14 13:31 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-06-14 13:31 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Vineeth Pillai, Sean Christopherson, Wanpeng Li, Jim Mattson,
	Maxim Levitsky, linux-kernel

On 14/06/21 13:38, Vitaly Kuznetsov wrote:
> Hyper-V context is allocated dynamically when Hyper-V features are enabled
> on a vCPU but svm_hv_update_vp_id() is called unconditionally from
> svm_vcpu_run(), this leads to dereferencing to_hv_vcpu(vcpu) which can
> be NULL. Use kvm_hv_get_vpindex() wrapper to avoid the problem.
> 
> Fixes: 4ba0d72aaa32 ("KVM: SVM: hyper-v: Direct Virtual Flush support")
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
> - The patch introducing the issue is currently in kvm/queue.
> ---
>   arch/x86/kvm/svm/svm_onhyperv.h | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h
> index ce23149670ea..9b9a55abc29f 100644
> --- a/arch/x86/kvm/svm/svm_onhyperv.h
> +++ b/arch/x86/kvm/svm/svm_onhyperv.h
> @@ -99,9 +99,10 @@ static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
>   {
>   	struct hv_enlightenments *hve =
>   		(struct hv_enlightenments *)vmcb->control.reserved_sw;
> +	u32 vp_index = kvm_hv_get_vpindex(vcpu);
>   
> -	if (hve->hv_vp_id != to_hv_vcpu(vcpu)->vp_index) {
> -		hve->hv_vp_id = to_hv_vcpu(vcpu)->vp_index;
> +	if (hve->hv_vp_id != vp_index) {
> +		hve->hv_vp_id = vp_index;
>   		vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
>   	}
>   }
> 

Squashed, thanks.

Paolo


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

end of thread, other threads:[~2021-06-14 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 11:38 [PATCH] KVM: svm: Avoid NULL pointer dereference in svm_hv_update_vp_id() Vitaly Kuznetsov
2021-06-14 13:31 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.