From patchwork Tue Jun 30 10:48:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 50455 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7BD07229DF for ; Tue, 30 Jun 2015 10:50:32 +0000 (UTC) Received: by wguu7 with SMTP id u7sf2510892wgu.0 for ; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=R97mfM90kVHtN8kQQNn4MrrrCZbab1jsy3KkDROAOBk=; b=ThzybfIlDjYqp9KHs4hn8rLsYn5Dmm23eqV9FLmApOaAe2iajTLPJ6Lw+9N+CDOJkM aSIDB3z3nlBgmMT4rgyJJ/8tklAcGuxqluxK2BBYw5jF6CHU/G8uoPI+Dfk1Y3Opbyzt vf/kH+xsg4MQeSw684NtMwBMVEYgWYCV2hkUiI2e/6Ocm387++lrxvauiAYq8ExxsxT6 qCTElMnfgHutVbT5lX2BTULmFTNmqrW8LkRZBtzAhLvV0/ed4Rek3zUVSQlAYKf802/n J4Jpu+NilpExxy15fMdEMp+fdB4kkGTyj+cO+xyUgVUBfzqFrw8Tc9dQYhjychSgEHs6 mI9Q== X-Gm-Message-State: ALoCoQk1lc61hl7rfF92CkQuPBhyzdC0zF846B36HRHsc4YBX0tIN4OCiXYU/jGI+XBCWyW9VOUo X-Received: by 10.152.88.70 with SMTP id be6mr13704527lab.9.1435661431854; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.36 with SMTP id t4ls25323lal.99.gmail; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) X-Received: by 10.152.28.73 with SMTP id z9mr18831131lag.93.1435661431509; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id h18si37764995lbo.172.2015.06.30.03.50.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2015 03:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lagh6 with SMTP id h6so8095245lag.2 for ; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) X-Received: by 10.112.126.101 with SMTP id mx5mr19294821lbb.35.1435661431286; Tue, 30 Jun 2015 03:50:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2352756lbb; Tue, 30 Jun 2015 03:50:30 -0700 (PDT) X-Received: by 10.70.54.164 with SMTP id k4mr42689411pdp.61.1435661429366; Tue, 30 Jun 2015 03:50:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si66313267par.87.2015.06.30.03.50.28; Tue, 30 Jun 2015 03:50:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751581AbbF3Ku1 (ORCPT + 2 others); Tue, 30 Jun 2015 06:50:27 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:35811 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbbF3Ku0 (ORCPT ); Tue, 30 Jun 2015 06:50:26 -0400 Received: by pdbci14 with SMTP id ci14so4263874pdb.2 for ; Tue, 30 Jun 2015 03:50:26 -0700 (PDT) X-Received: by 10.68.57.206 with SMTP id k14mr22332658pbq.97.1435661426028; Tue, 30 Jun 2015 03:50:26 -0700 (PDT) Received: from localhost ([120.136.36.232]) by mx.google.com with ESMTPSA id k3sm45228294pde.18.2015.06.30.03.50.23 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 03:50:24 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.14.y stable 07/22] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Tue, 30 Jun 2015 18:48:55 +0800 Message-Id: <1435661350-8060-8-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1435661350-8060-1-git-send-email-shannon.zhao@linaro.org> References: <1435661350-8060-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Christoffer Dall Since we don't backport commit 8eef912 (arm/arm64: KVM: map MMIO regions at creation time) for linux-3.14.y, the context of this patch is different, while the change itself is same. commit c3058d5da2222629bc2223c488a4512b59bb4baf upstream. When creating or moving a memslot, make sure the IPA space is within the addressable range of the guest. Otherwise, user space can create too large a memslot and KVM would try to access potentially unallocated page table entries when inserting entries in the Stage-2 page tables. Acked-by: Catalin Marinas Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/kvm/mmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 8cd0387..d122772 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -926,6 +926,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) memslot = gfn_to_memslot(vcpu->kvm, gfn); + /* Userspace should not be able to register out-of-bounds IPAs */ + VM_BUG_ON(fault_ipa >= KVM_PHYS_SIZE); + ret = user_mem_abort(vcpu, fault_ipa, memslot, fault_status); if (ret == 0) ret = 1; @@ -1150,6 +1153,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, enum kvm_mr_change change) { + /* + * Prevent userspace from creating a memory region outside of the IPA + * space addressable by the KVM guest IPA space. + */ + if (memslot->base_gfn + memslot->npages >= + (KVM_PHYS_SIZE >> PAGE_SHIFT)) + return -EFAULT; + return 0; }