From patchwork Thu Sep 25 19:42:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 37932 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 00D26202DB for ; Thu, 25 Sep 2014 19:44:37 +0000 (UTC) Received: by mail-we0-f200.google.com with SMTP id w62sf4219503wes.11 for ; Thu, 25 Sep 2014 12:44:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=TvuB71oZnnGOYBLlYbZUv60K8q2H606IalgPx5WkhNo=; b=ljQhPzxN2Sn6f3Ai7QRfZzLXErTIipdaB72UabBE1jD6LMSeh+0+o34U14OOkznmyc ugnS5x4XsWtJb9kIgrfXGstx63BMjNJ7FflR8XQkQxoSfb2ZEZ05hehHOBgJDgORepMn g445iMyOQvedn+XZSk7sD7xp2APHYaTg6TStetCKT8UZP2Hi3o46/nYnlyTc7fV4nZzz yepd/nETrzSQmxl/hdJ9cM0Mal3GXnMPe5YsW3mULWeNn2ZxQGle3CFjzFgrJzoDRnCT LBAY8HNyfiZ5Lpdo2fsz4AXJkZ1wGM9NeKC3pBjIZbKl1HbwT0mIq5ycscdJoXvdD3x6 drcw== X-Gm-Message-State: ALoCoQlwYje3J7aadaHRP5eTWvx4YmXSoQLf2HGRnk9pl42igTffZV7+bWjGsH4pWG2cvrRSGHwq X-Received: by 10.180.88.8 with SMTP id bc8mr2890083wib.0.1411674277216; Thu, 25 Sep 2014 12:44:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.135 with SMTP id k7ls283023lah.78.gmail; Thu, 25 Sep 2014 12:44:37 -0700 (PDT) X-Received: by 10.152.26.101 with SMTP id k5mr15907349lag.74.1411674277063; Thu, 25 Sep 2014 12:44:37 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) by mx.google.com with ESMTPS id pc8si4409048lbc.69.2014.09.25.12.44.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Sep 2014 12:44:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id q1so1575304lam.21 for ; Thu, 25 Sep 2014 12:44:36 -0700 (PDT) X-Received: by 10.112.130.226 with SMTP id oh2mr5020095lbb.100.1411674276651; Thu, 25 Sep 2014 12:44:36 -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.130.169 with SMTP id of9csp814022lbb; Thu, 25 Sep 2014 12:44:35 -0700 (PDT) X-Received: by 10.68.191.134 with SMTP id gy6mr23028734pbc.2.1411674275147; Thu, 25 Sep 2014 12:44:35 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id nx16si5538746pdb.101.2014.09.25.12.44.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Sep 2014 12:44:35 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXEwW-0003ra-OZ; Thu, 25 Sep 2014 19:43:08 +0000 Received: from mail-lb0-f169.google.com ([209.85.217.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXEwO-0003lD-79 for linux-arm-kernel@lists.infradead.org; Thu, 25 Sep 2014 19:43:00 +0000 Received: by mail-lb0-f169.google.com with SMTP id b12so13295827lbj.14 for ; Thu, 25 Sep 2014 12:42:33 -0700 (PDT) X-Received: by 10.152.3.35 with SMTP id 3mr15893116laz.5.1411674153489; Thu, 25 Sep 2014 12:42:33 -0700 (PDT) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id li3sm1107559lab.25.2014.09.25.12.42.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Sep 2014 12:42:32 -0700 (PDT) From: Christoffer Dall To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH 2/2] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Thu, 25 Sep 2014 21:42:54 +0200 Message-Id: <1411674174-30672-3-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1411674174-30672-1-git-send-email-christoffer.dall@linaro.org> References: <1411674174-30672-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140925_124300_470897_39BC15F0 X-CRM114-Status: GOOD ( 11.41 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.169 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.217.169 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Christoffer Dall , kvm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@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.48 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 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. Signed-off-by: Christoffer Dall --- arch/arm/kvm/mmu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 4532f5f..52a311a 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -975,6 +975,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) goto out_unlock; } + /* 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, hva, fault_status); if (ret == 0) ret = 1; @@ -1201,6 +1204,11 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, enum kvm_mr_change change) { + if (change == KVM_MR_CREATE || change == KVM_MR_MOVE) { + if (memslot->base_gfn + memslot->npages >= + (KVM_PHYS_SIZE >> PAGE_SHIFT)) + return -EFAULT; + } return 0; }