From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbdAYKf2 (ORCPT ); Wed, 25 Jan 2017 05:35:28 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33498 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751864AbdAYKf0 (ORCPT ); Wed, 25 Jan 2017 05:35:26 -0500 Subject: Re: [PATCH] kvm: fix page struct leak in handle_vmon To: David Hildenbrand References: <1485255381-18069-1-git-send-email-pbonzini@redhat.com> <0cdfcfea-f1f6-fbcb-887a-dae659e2b844@redhat.com> <692606753.12365942.1485337926527.JavaMail.zimbra@redhat.com> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, dvyukov@google.com From: Paolo Bonzini Message-ID: <4c7a5eeb-cedd-3185-282a-192b10715b04@redhat.com> Date: Wed, 25 Jan 2017 11:35:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/01/2017 11:11, David Hildenbrand wrote: > Am 25.01.2017 um 10:57 schrieb David Hildenbrand: >> Am 25.01.2017 um 10:52 schrieb Paolo Bonzini: >>> >>> >>> ----- Original Message ----- >>>> From: "David Hildenbrand" >>>> To: "Paolo Bonzini" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org >>>> Cc: dvyukov@google.com >>>> Sent: Wednesday, January 25, 2017 10:31:13 AM >>>> Subject: Re: [PATCH] kvm: fix page struct leak in handle_vmon >>>> >>>> Am 24.01.2017 um 11:56 schrieb Paolo Bonzini: >>>>> handle_vmon gets a reference on VMXON region page, >>>>> but does not release it. Release the reference. >>>>> >>>>> Found by syzkaller; based on a patch by Dmitry. >>>>> >>>>> Reported-by: Dmitry Vyukov >>>>> Signed-off-by: Paolo Bonzini >>>>> --- >>>>> arch/x86/kvm/vmx.c | 9 +++++++-- >>>>> 1 file changed, 7 insertions(+), 2 deletions(-) >>>>> >>>>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >>>>> index 42cc3d6f4d20..0f7345035210 100644 >>>>> --- a/arch/x86/kvm/vmx.c >>>>> +++ b/arch/x86/kvm/vmx.c >>>>> @@ -7085,13 +7085,18 @@ static int nested_vmx_check_vmptr(struct kvm_vcpu >>>>> *vcpu, int exit_reason, >>>>> } >>>>> >>>>> page = nested_get_page(vcpu, vmptr); >>>>> - if (page == NULL || >>>>> - *(u32 *)kmap(page) != VMCS12_REVISION) { >>>>> + if (page == NULL) { >>>>> nested_vmx_failInvalid(vcpu); >>>>> + return kvm_skip_emulated_instruction(vcpu); >>>>> + } >>>>> + if (*(u32 *)kmap(page) != VMCS12_REVISION) { >>>> >>>> shouldn't we also check if kmap even returned a valid pointer before >>>> dereferencing it? >>> >>> I don't think kmap can fail (page_address can)? >> >> Then I wonder why there are some checks: >> >> e.g. nested_vmx_merge_msr_bitmap() >> >> msr_bitmap_l1 = (unsigned long *)kmap(page); >> if (!msr_bitmap_l1) { >> // no unmap >> ... >> return false; >> >> or vmx_complete_nested_posted_interrupt() >> >> vapic_page = kmap(vmx->nested.virtual_apic_page); >> if (!vapic_page) { >> // no unmap >> ... >> return -ENOMEM; >> >> >> But there is also no check in handle_vmptrld() for example. >> >> >>> >>> Paolo >> >> > > Think you're right it can't fail. > > So something like that could most likely be done > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index a236dec..a9be221 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -4973,10 +4973,6 @@ static int > vmx_complete_nested_posted_interrupt(struct kvm_vcpu *vcpu) > return 0; > > vapic_page = kmap(vmx->nested.virtual_apic_page); > - if (!vapic_page) { > - WARN_ON(1); > - return -ENOMEM; > - } > __kvm_apic_update_irr(vmx->nested.pi_desc->pir, vapic_page); > kunmap(vmx->nested.virtual_apic_page); > > @@ -9730,12 +9726,6 @@ static inline bool > nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu, > return false; > } > msr_bitmap_l1 = (unsigned long *)kmap(page); > - if (!msr_bitmap_l1) { > - nested_release_page_clean(page); > - WARN_ON(1); > - return false; > - } > - > memset(msr_bitmap_l0, 0xff, PAGE_SIZE); > > if (nested_cpu_has_virt_x2apic_mode(vmcs12)) { Yes, definitely. Want to send a patch? Paolo