From patchwork Fri Oct 10 10:14:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 38548 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E1ACF205D8 for ; Fri, 10 Oct 2014 10:16:57 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf1907683wgh.5 for ; Fri, 10 Oct 2014 03:16:57 -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=fzhCHpoZWJxNX9xZkoTMlIo7WJhqoWAoSWimmLhQcA0=; b=CsjejOS+3kpPFXZkBHj1U+qPHIwEtT1awXAOBEo0ix/aLz+wdLmOoY0Keb+1jVKaqc JWNQ+HzYDJC336KE3IWoJ0dFntF7b00p3I1bkHzPZMfRneh9ICdxKQvJfXrQBzZRfmLU Ed5U713sQurSzP5giPI9ECeOulDUeoEvcP2oKGe3rVM3Jn5A93SVJKHCZabXMDye8csq op21ydO+T2HY23AYLPH0HtPly8fMSdodfEAgSy3Km0uM9EoPVWG237eyi9arcyoQV+p5 cprUiZop8/v+Z4Q+E3mdJTmqWmSakjyJjYBBr8Is994gXprUpdRWMjY1Iu9YREAhmW0m yqZQ== X-Gm-Message-State: ALoCoQkM67nUPe3B4E5L/2SBuNAiqGfmiC2u+ErotfV6oKKwNHwe0Dx2n9nZU0u2RBBbevOoK5Qg X-Received: by 10.112.140.199 with SMTP id ri7mr288433lbb.17.1412936217019; Fri, 10 Oct 2014 03:16:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.169 with SMTP id r9ls238341laj.57.gmail; Fri, 10 Oct 2014 03:16:56 -0700 (PDT) X-Received: by 10.153.11.166 with SMTP id ej6mr3785992lad.80.1412936216783; Fri, 10 Oct 2014 03:16:56 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx.google.com with ESMTPS id pf1si8372479lbc.94.2014.10.10.03.16.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 03:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id gm9so2833291lab.41 for ; Fri, 10 Oct 2014 03:16:56 -0700 (PDT) X-Received: by 10.152.26.226 with SMTP id o2mr3775542lag.44.1412936216229; Fri, 10 Oct 2014 03:16:56 -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.84.229 with SMTP id c5csp396204lbz; Fri, 10 Oct 2014 03:16:55 -0700 (PDT) X-Received: by 10.70.96.74 with SMTP id dq10mr1236417pdb.165.1412936212746; Fri, 10 Oct 2014 03:16:52 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id d8si3321137pat.120.2014.10.10.03.16.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Oct 2014 03:16:52 -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 1XcXE6-0003Zg-LQ; Fri, 10 Oct 2014 10:15:10 +0000 Received: from mail-lb0-f171.google.com ([209.85.217.171]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XcXE3-0002OI-EB for linux-arm-kernel@lists.infradead.org; Fri, 10 Oct 2014 10:15:08 +0000 Received: by mail-lb0-f171.google.com with SMTP id z12so2753654lbi.16 for ; Fri, 10 Oct 2014 03:14:43 -0700 (PDT) X-Received: by 10.112.130.129 with SMTP id oe1mr3638611lbb.4.1412936083686; Fri, 10 Oct 2014 03:14:43 -0700 (PDT) Received: from localhost.localdomain ([188.178.240.98]) by mx.google.com with ESMTPSA id w8sm1682856lbp.46.2014.10.10.03.14.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Oct 2014 03:14:42 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/3] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Fri, 10 Oct 2014 12:14:29 +0200 Message-Id: <1412936070-18860-3-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1412936070-18860-1-git-send-email-christoffer.dall@linaro.org> References: <1412936070-18860-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141010_031507_664467_165004DF X-CRM114-Status: GOOD ( 12.02 ) 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.171 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.217.171 listed in wl.mailspike.net] Cc: Catalin Marinas , jungseoklee85@gmail.com, Christoffer Dall , kvm@vger.kernel.org, Joel Schopp 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.54 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 Acked-by: Catalin Marinas Acked-by: Marc Zyngier --- 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 6e87233..d664bff 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -994,6 +994,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; @@ -1218,6 +1221,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; }