From patchwork Wed Jan 25 10:11:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 9536663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86472601D3 for ; Wed, 25 Jan 2017 10:11:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6396526B39 for ; Wed, 25 Jan 2017 10:11:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5866C27E5A; Wed, 25 Jan 2017 10:11:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D05626B39 for ; Wed, 25 Jan 2017 10:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751800AbdAYKLH (ORCPT ); Wed, 25 Jan 2017 05:11:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751773AbdAYKLF (ORCPT ); Wed, 25 Jan 2017 05:11:05 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4CEE7FB8A; Wed, 25 Jan 2017 10:11:05 +0000 (UTC) Received: from [10.36.117.88] (ovpn-117-88.ams2.redhat.com [10.36.117.88]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0PAB401024149; Wed, 25 Jan 2017 05:11:04 -0500 Subject: Re: [PATCH] kvm: fix page struct leak in handle_vmon To: Paolo Bonzini 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: David Hildenbrand Organization: Red Hat GmbH Message-ID: Date: Wed, 25 Jan 2017 11:11:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 25 Jan 2017 10:11:06 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 @@ -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)) { 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);