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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANRm+Cz55bkFrd=pHt7ca+7-HP03Ap7hupSVQQSVckTYnX3+HQ@mail.gmail.com>
Date:   Thu, 5 Apr 2018 08:04:57 +0800
From:   Wanpeng Li <kernellwp@...il.com>
To:     Paolo Bonzini <pbonzini@...hat.com>
Cc:     David Hildenbrand <david@...hat.com>,
        LKML <linux-kernel@...r.kernel.org>, kvm <kvm@...r.kernel.org>,
        Radim Krčmář <rkrcmar@...hat.com>,
        Andrew Cooper <andrew.cooper3@...rix.com>,
        Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>,
        Liran Alon <liran.alon@...cle.com>
Subject: Re: [PATCH v5 2/2] KVM: X86: Add Force Emulation Prefix for "emulate
 the next instruction"

2018-04-05 1:09 GMT+08:00 Paolo Bonzini <pbonzini@...hat.com>:
> On 04/04/2018 15:35, Wanpeng Li wrote:
>> 2018-04-04 19:59 GMT+08:00 David Hildenbrand <david@...hat.com>:
>>>
>>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>>> index 1eb495e..a55ecef 100644
>>>> --- a/arch/x86/kvm/x86.c
>>>> +++ b/arch/x86/kvm/x86.c
>>>> @@ -146,6 +146,9 @@ bool __read_mostly enable_vmware_backdoor = false;
>>>>  module_param(enable_vmware_backdoor, bool, S_IRUGO);
>>>>  EXPORT_SYMBOL_GPL(enable_vmware_backdoor);
>>>>
>>>> +static bool __read_mostly force_emulation_prefix = false;
>>>> +module_param(force_emulation_prefix, bool, S_IRUGO);
>>>> +
>>>>  #define KVM_NR_SHARED_MSRS 16
>>>>
>>>>  struct kvm_shared_msrs_global {
>>>> @@ -4844,6 +4847,21 @@ int handle_ud(struct kvm_vcpu *vcpu)
>>>>  {
>>>>       enum emulation_result er;
>>>>
>>>> +     if (force_emulation_prefix) {
>>>> +             char sig[5]; /* ud2; .ascii "kvm" */
>>>> +             struct x86_exception e;
>>>> +
>>>> +             if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt,
>>>> +                             kvm_get_linear_rip(vcpu), sig, sizeof(sig), &e))
>>>> +                     goto emulate_ud;
>>>> +
>>>> +             if (memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) {
>>>> +                     kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig));
>>>> +                     return emulate_instruction(vcpu, 0) == EMULATE_DONE;
>>>
>>> What if we would have an invalid instruction here? Shouldn't you handle
>>> the emulate_instruction() like below?
>>> (e.g. keep a variable with the emulation type (0 vs EMULTYPE_TRAP_UD)
>>> and reuse emulate_ud below)
>>
>> emulate_instruction(vcpu, 0) can handle invalid instruction.
>
> But David's observation is still better because your code doesn't handle usermode exits.

My code handles it, return emulate_instruction(vcpu, 0) ==
EMULATE_DONE, it will return 0 since EMULATE_USER_EXIT == EMULATE_DONE
fails.

> I've fixed this up.

Thanks. The codes similar to my v3 but more beauty. :) I change to
this view since Radim's comments to v3
https://www.spinics.net/lists/kvm/msg166999.html

Regards,
Wanpeng Li

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ