kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] KVM: nVMX: move vmclear and vmptrld pre-checks to nested_vmx_check_vmptr
@ 2017-05-18  7:41 Dan Carpenter
  2017-05-18 16:16 ` Radim Krčmář
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-05-18  7:41 UTC (permalink / raw)
  To: bsd; +Cc: kvm

Hello Bandan Das,

The patch 4291b58885f5: "KVM: nVMX: move vmclear and vmptrld
pre-checks to nested_vmx_check_vmptr" from May 6, 2014, leads to the
following static checker warning:

	arch/x86/kvm/vmx.c:7219 handle_vmclear()
	error: uninitialized symbol 'vmptr'.

arch/x86/kvm/vmx.c
  7206  /* Emulate the VMCLEAR instruction */
  7207  static int handle_vmclear(struct kvm_vcpu *vcpu)
  7208  {
  7209          struct vcpu_vmx *vmx = to_vmx(vcpu);
  7210          u32 zero = 0;
  7211          gpa_t vmptr;
  7212  
  7213          if (!nested_vmx_check_permission(vcpu))
  7214                  return 1;
  7215  
  7216          if (nested_vmx_check_vmptr(vcpu, EXIT_REASON_VMCLEAR, &vmptr))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are several success paths which don't initialize vmptr.  This feels
like a quite serious bug, but maybe handle_vmclear() is not used often
so it doesn't show up in testing?  I don't know.  Or it could be that this
code is just too complicated for my static checker and for my cursory analysis.

  7217                  return 1;
  7218  
  7219          if (vmptr == vmx->nested.current_vmptr)
  7220                  nested_release_vmcs12(vmx);
  7221  
  7222          kvm_vcpu_write_guest(vcpu,
  7223                          vmptr + offsetof(struct vmcs12, launch_state),
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  7224                          &zero, sizeof(zero));
  7225  
  7226          nested_free_vmcs02(vmx, vmptr);
  7227  
  7228          nested_vmx_succeed(vcpu);
  7229          return kvm_skip_emulated_instruction(vcpu);
  7230  }

Similar issue in:
arch/x86/kvm/vmx.c:7551 handle_vmptrld() error: uninitialized symbol 'vmptr'.

regards,
dan carpenter

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

* Re: [bug report] KVM: nVMX: move vmclear and vmptrld pre-checks to nested_vmx_check_vmptr
  2017-05-18  7:41 [bug report] KVM: nVMX: move vmclear and vmptrld pre-checks to nested_vmx_check_vmptr Dan Carpenter
@ 2017-05-18 16:16 ` Radim Krčmář
  0 siblings, 0 replies; 2+ messages in thread
From: Radim Krčmář @ 2017-05-18 16:16 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: bsd, kvm

2017-05-18 10:41+0300, Dan Carpenter:
> Hello Bandan Das,
> 
> The patch 4291b58885f5: "KVM: nVMX: move vmclear and vmptrld
> pre-checks to nested_vmx_check_vmptr" from May 6, 2014, leads to the
> following static checker warning:
> 
> 	arch/x86/kvm/vmx.c:7219 handle_vmclear()
> 	error: uninitialized symbol 'vmptr'.
> 
> arch/x86/kvm/vmx.c
>   7206  /* Emulate the VMCLEAR instruction */
>   7207  static int handle_vmclear(struct kvm_vcpu *vcpu)
>   7208  {
>   7209          struct vcpu_vmx *vmx = to_vmx(vcpu);
>   7210          u32 zero = 0;
>   7211          gpa_t vmptr;
>   7212  
>   7213          if (!nested_vmx_check_permission(vcpu))
>   7214                  return 1;
>   7215  
>   7216          if (nested_vmx_check_vmptr(vcpu, EXIT_REASON_VMCLEAR, &vmptr))
>                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> There are several success paths which don't initialize vmptr.  This feels
> like a quite serious bug, but maybe handle_vmclear() is not used often
> so it doesn't show up in testing?  I don't know.  Or it could be that this
> code is just too complicated for my static checker and for my cursory analysis.

The success path can only happen when single-stepping the guest from
userspace (a rare scenario), which is why it didn't show up in testing.

I'll prepare a patch, thanks for all the reports.

>   7217                  return 1;
>   7218  
>   7219          if (vmptr == vmx->nested.current_vmptr)
>   7220                  nested_release_vmcs12(vmx);
>   7221  
>   7222          kvm_vcpu_write_guest(vcpu,
>   7223                          vmptr + offsetof(struct vmcs12, launch_state),
>                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
>   7224                          &zero, sizeof(zero));
>   7225  
>   7226          nested_free_vmcs02(vmx, vmptr);
>   7227  
>   7228          nested_vmx_succeed(vcpu);
>   7229          return kvm_skip_emulated_instruction(vcpu);
>   7230  }
> 
> Similar issue in:
> arch/x86/kvm/vmx.c:7551 handle_vmptrld() error: uninitialized symbol 'vmptr'.
> 
> regards,
> dan carpenter

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

end of thread, other threads:[~2017-05-18 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-18  7:41 [bug report] KVM: nVMX: move vmclear and vmptrld pre-checks to nested_vmx_check_vmptr Dan Carpenter
2017-05-18 16:16 ` Radim Krčmář

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).