From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751016AbdHaE7z (ORCPT ); Thu, 31 Aug 2017 00:59:55 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:58509 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbdHaE7x (ORCPT ); Thu, 31 Aug 2017 00:59:53 -0400 X-ME-Sender: X-Sasl-enc: oMwCB+N7eeyzbiQY+RypnoLMchAtkZbs1SkqVaiR+a51 1504155592 Date: Thu, 31 Aug 2017 06:59:57 +0200 From: Greg KH To: Suzuki K Poulose Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, christoffer.dall@linaro.org, pbonzini@redhat.com, agraf@suse.de, mark.rutland@arm.com, rkrcmar@redhat.com Subject: Re: [PATCH] [stable] kvm: arm/arm64: Fix race in resetting stage2 PGD Message-ID: <20170831045957.GB8356@kroah.com> References: <1504092652-13443-1-git-send-email-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1504092652-13443-1-git-send-email-suzuki.poulose@arm.com> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 30, 2017 at 12:30:52PM +0100, Suzuki K Poulose wrote: > commit 6c0d706b563af732adb094c5bf807437e8963e84 upstream. > > In kvm_free_stage2_pgd() we check the stage2 PGD before holding > the lock and proceed to take the lock if it is valid. And we unmap > the page tables, followed by releasing the lock. We reset the PGD > only after dropping this lock, which could cause a race condition > where another thread waiting on or even holding the lock, could > potentially see that the PGD is still valid and proceed to perform > a stage2 operation and later encounter a NULL PGD. > > [223090.242280] Unable to handle kernel NULL pointer dereference at > virtual address 00000040 > [223090.262330] PC is at unmap_stage2_range+0x8c/0x428 > [223090.262332] LR is at kvm_unmap_hva_handler+0x2c/0x3c > [223090.262531] Call trace: > [223090.262533] [] unmap_stage2_range+0x8c/0x428 > [223090.262535] [] kvm_unmap_hva_handler+0x2c/0x3c > [223090.262537] [] handle_hva_to_gpa+0xb0/0x104 > [223090.262539] [] kvm_unmap_hva+0x5c/0xbc > [223090.262543] [] kvm_mmu_notifier_invalidate_page+0x50/0x8c > [223090.262547] [] __mmu_notifier_invalidate_page+0x5c/0x84 > [223090.262551] [] try_to_unmap_one+0x1d0/0x4a0 > [223090.262553] [] rmap_walk+0x1cc/0x2e0 > [223090.262555] [] try_to_unmap+0x74/0xa4 > [223090.262557] [] migrate_pages+0x31c/0x5ac > [223090.262561] [] compact_zone+0x3fc/0x7ac > [223090.262563] [] compact_zone_order+0x94/0xb0 > [223090.262564] [] try_to_compact_pages+0x108/0x290 > [223090.262569] [] __alloc_pages_direct_compact+0x70/0x1ac > [223090.262571] [] __alloc_pages_nodemask+0x434/0x9f4 > [223090.262572] [] alloc_pages_vma+0x230/0x254 > [223090.262574] [] do_huge_pmd_anonymous_page+0x114/0x538 > [223090.262576] [] handle_mm_fault+0xd40/0x17a4 > [223090.262577] [] __get_user_pages+0x12c/0x36c > [223090.262578] [] get_user_pages_unlocked+0xa4/0x1b8 > [223090.262579] [] __gfn_to_pfn_memslot+0x280/0x31c > [223090.262580] [] gfn_to_pfn_prot+0x4c/0x5c > [223090.262582] [] kvm_handle_guest_abort+0x240/0x774 > [223090.262584] [] handle_exit+0x11c/0x1ac > [223090.262586] [] kvm_arch_vcpu_ioctl_run+0x31c/0x648 > [223090.262587] [] kvm_vcpu_ioctl+0x378/0x768 > [223090.262590] [] do_vfs_ioctl+0x324/0x5a4 > [223090.262591] [] SyS_ioctl+0x90/0xa4 > [223090.262595] [] el0_svc_naked+0x38/0x3c > > This patch moves the stage2 PGD manipulation under the lock. > > Reported-by: Alexander Graf > Cc: Mark Rutland > Cc: Marc Zyngier > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: stable@vger.kernel.org # 4.10.x and earlier > Reviewed-by: Christoffer Dall > Reviewed-by: Marc Zyngier > Signed-off-by: Suzuki K Poulose > Signed-off-by: Christoffer Dall > > --- > > Hi, > > Looks like we missed sending this to stable. Please apply for 4.10.x and > earlier. 4.11.y and later versions have it already. Only applied to 4.9-stable, can you please provide a backport for 4.4 and 3.18 if you want it there? thanks, greg k-h