From patchwork Sat Oct 18 11:57:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 39014 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D167A202DB for ; Sat, 18 Oct 2014 12:23:15 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id h11sf1344027wiw.7 for ; Sat, 18 Oct 2014 05:23:14 -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=96QdJT1Z92b/FFU1drSogY7sPEwoaBdkykk31lpZM1M=; b=dPLxyjOkjfHRsJD/5THkXcc/FKM34oREWo4R0A2aLvXARU6nCIaNpwKe3Bsy1ZzxuI N1L7yreq25oTKXAqTrcl8V9chzcNY9Gy5Rp3CajOPLUVmAU+gA3XdEpPuNSnXpLgaA5h ZY7g45Qg4snQdKYxG72VtQCQwdRmKXpRtRfxMBF/f2qeVFs4zPpaP//cgkq4AdMbXKo1 ZDFJ8jLTAy5HPiDGhM2K5N4KfB8do3g7yuIlVz6xT/AMq9t//odGIo4P5nwl65a5k6sp OX0Vvu/wduQb2ESONU4bdTTolsnoKB2WzXSsARIEb7T1MKofEyKcND+h7t43Zt1XRaCw 0Inw== X-Gm-Message-State: ALoCoQnMwlJkJquI88w7bZwRMq1PEvEi3bJfOx7AGiYbnmih/VqHQhb28wXzPKp5M0N7BE1pLtty X-Received: by 10.180.36.176 with SMTP id r16mr746019wij.7.1413634994909; Sat, 18 Oct 2014 05:23:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.5 with SMTP id f5ls319658lah.62.gmail; Sat, 18 Oct 2014 05:23:14 -0700 (PDT) X-Received: by 10.112.173.100 with SMTP id bj4mr888877lbc.78.1413634994748; Sat, 18 Oct 2014 05:23:14 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id g8si6046944lae.48.2014.10.18.05.23.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 18 Oct 2014 05:23:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id mc6so1928306lab.30 for ; Sat, 18 Oct 2014 05:23:14 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr6587555lbw.66.1413634994568; Sat, 18 Oct 2014 05:23:14 -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 c5csp40460lbz; Sat, 18 Oct 2014 05:23:13 -0700 (PDT) X-Received: by 10.70.36.3 with SMTP id m3mr14812400pdj.53.1413634991932; Sat, 18 Oct 2014 05:23:11 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bd15si3435475pdb.71.2014.10.18.05.23.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Oct 2014 05:23:11 -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 1XfT0o-0003bT-Jh; Sat, 18 Oct 2014 12:21:34 +0000 Received: from inca-roads.misterjones.org ([213.251.177.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XfT0k-0003aA-ES for linux-arm-kernel@lists.infradead.org; Sat, 18 Oct 2014 12:21:31 +0000 Received: from [90.219.10.17] (helo=zomby-woof.wild-wind.fr.eu.org) by cheepnis.misterjones.org with esmtpsa (TLSv1.2:AES128-SHA256:128) (Exim 4.80) (envelope-from ) id 1XfSdH-0005Fz-K0; Sat, 18 Oct 2014 13:57:15 +0200 From: Marc Zyngier To: Gleb Natapov , Paolo Bonzini Subject: [PATCH 10/12] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Sat, 18 Oct 2014 12:57:00 +0100 Message-Id: <1413633422-14907-11-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1413633422-14907-1-git-send-email-marc.zyngier@arm.com> References: <1413633422-14907-1-git-send-email-marc.zyngier@arm.com> X-SA-Exim-Connect-IP: 90.219.10.17 X-SA-Exim-Rcpt-To: gleb@kernel.org, pbonzini@redhat.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, christoffer.dall@linaro.org X-SA-Exim-Mail-From: marc.zyngier@arm.com X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141018_052130_632917_2488DCAA X-CRM114-Status: UNSURE ( 9.52 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) Cc: linux-arm-kernel@lists.infradead.org, Christoffer Dall , kvmarm@lists.cs.columbia.edu, 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: marc.zyngier@arm.com 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.43 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 From: Christoffer Dall 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 --- 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 ee142ed..8c40829 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -1003,6 +1003,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; @@ -1229,6 +1232,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, return 0; /* + * 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; + + /* * A memory region could potentially cover multiple VMAs, and any holes * between them, so iterate over all of them to find out if we can map * any of them right now.