lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z04ACJSrBSPlyqY4@google.com>
Date: Mon, 2 Dec 2024 10:44:24 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: Xiaoyao Li <xiaoyao.li@...el.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Tom Lendacky <thomas.lendacky@....com>, Binbin Wu <binbin.wu@...ux.intel.com>, 
	Isaku Yamahata <isaku.yamahata@...el.com>, Kai Huang <kai.huang@...el.com>
Subject: Re: [PATCH v4 5/6] KVM: x86: Always complete hypercall via function callback

On Thu, Nov 28, 2024, Xiaoyao Li wrote:
> On 11/28/2024 8:43 AM, Sean Christopherson wrote:
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 11434752b467..39be2a891ab4 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -9982,10 +9982,11 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
> >   	return kvm_skip_emulated_instruction(vcpu);
> >   }
> > -unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
> > -				      unsigned long a0, unsigned long a1,
> > -				      unsigned long a2, unsigned long a3,
> > -				      int op_64_bit, int cpl)
> > +int __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
> > +			    unsigned long a0, unsigned long a1,
> > +			    unsigned long a2, unsigned long a3,
> > +			    int op_64_bit, int cpl,
> > +			    int (*complete_hypercall)(struct kvm_vcpu *))
> >   {
> >   	unsigned long ret;
> > @@ -10061,7 +10062,7 @@ unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
> >   			vcpu->run->hypercall.flags |= KVM_EXIT_HYPERCALL_LONG_MODE;
> >   		WARN_ON_ONCE(vcpu->run->hypercall.flags & KVM_EXIT_HYPERCALL_MBZ);
> > -		vcpu->arch.complete_userspace_io = complete_hypercall_exit;
> > +		vcpu->arch.complete_userspace_io = complete_hypercall;
> >   		/* stat is incremented on completion. */
> >   		return 0;
> >   	}
> > @@ -10071,13 +10072,15 @@ unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
> >   	}
> >   out:
> > -	return ret;
> > +	vcpu->run->hypercall.ret = ret;
> > +	complete_hypercall(vcpu);
> > +	return 1;
> 
> shouldn't it be
> 
> 	return complete_hypercall(vcpu);
> 
> ?

Ouch.  Yes, it most definitely should be.

> Originally, kvm_emulate_hypercall() returns kvm_skip_emulated_instruction().
> Now it becomes
> 
> 	kvm_skip_emulated_instruction();
> 	return 1;
> 
> I don't go deep to see if kvm_skip_emulated_instruction() always return 1
> for this case.

It doesn't.  KVM needs to exit to userspace if userspace is single-stepping, or
in the extremely unlikely scenario that KVM can't skip the emulated instruction
(which can very theoretically happen on older AMD CPUs).

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ