From patchwork Mon Oct 6 20:30:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 38385 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0184C202E7 for ; Mon, 6 Oct 2014 20:33:02 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf3278168lab.9 for ; Mon, 06 Oct 2014 13:33:01 -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=4KRd8Iu8Okbv1i+OEUArExoaeQsaMAPuPUuF5v2A7kU=; b=V5GSWE9k62cpqonCZ4WOZn85PtRNfagLc7KQgmCXxJ5MnOzBb1AfM9RVquHDZizWJs Fna/QAQI1xrIvBBU1h84BRPlK/DjV+4a6ujkZySUUNBt0B1cmflx3xnWiFTF5ECp0lBV aQhsCN+7gcZls3C70AuCHbJE3bpyX0UO4CnvHt4Idmq60H+nEFUsM7mqn52xUjWOtuZ1 BawwhS6reZeXPH/M5G/aZGj7MKY7g+hFPpS8xR2d0Z53Jv0le7AejowlTDuJYl2HH4Nh IgPmis64F6MbQGI6KXSl+RUce0xnJ+ljXwwMCUTOfbMNgsHrWNxEurR9uGPNcukV54St m9gw== X-Gm-Message-State: ALoCoQnGI6MYWRg1e3OVQNOSOD8vYvHrnV2g9IWDvvsNQC6jSJYxZ4W4LLGEACBu6rO/wFpIV+mO X-Received: by 10.112.182.8 with SMTP id ea8mr716722lbc.11.1412627581720; Mon, 06 Oct 2014 13:33:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.42 with SMTP id k10ls118801lae.66.gmail; Mon, 06 Oct 2014 13:33:01 -0700 (PDT) X-Received: by 10.152.26.133 with SMTP id l5mr28401097lag.4.1412627581419; Mon, 06 Oct 2014 13:33:01 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by mx.google.com with ESMTPS id zw4si25587038lbb.116.2014.10.06.13.33.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Oct 2014 13:33:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id q1so5097672lam.22 for ; Mon, 06 Oct 2014 13:33:01 -0700 (PDT) X-Received: by 10.152.7.145 with SMTP id j17mr17582499laa.67.1412627581301; Mon, 06 Oct 2014 13:33:01 -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 of9csp250844lbb; Mon, 6 Oct 2014 13:33:00 -0700 (PDT) X-Received: by 10.70.20.4 with SMTP id j4mr20729196pde.19.1412627578808; Mon, 06 Oct 2014 13:32:58 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id fe10si14067942pad.167.2014.10.06.13.32.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Oct 2014 13:32:58 -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 1XbEwb-00009y-Cd; Mon, 06 Oct 2014 20:31:45 +0000 Received: from mail-lb0-f178.google.com ([209.85.217.178]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XbEwU-0008Vw-7k for linux-arm-kernel@lists.infradead.org; Mon, 06 Oct 2014 20:31:38 +0000 Received: by mail-lb0-f178.google.com with SMTP id w7so5039944lbi.9 for ; Mon, 06 Oct 2014 13:31:15 -0700 (PDT) X-Received: by 10.152.43.50 with SMTP id t18mr5707659lal.91.1412627475652; Mon, 06 Oct 2014 13:31:15 -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 ua3sm6062953lac.35.2014.10.06.13.31.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Oct 2014 13:31:14 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/3] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Mon, 6 Oct 2014 22:30:26 +0200 Message-Id: <1412627427-28629-3-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1412627427-28629-1-git-send-email-christoffer.dall@linaro.org> References: <1412627427-28629-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141006_133138_468134_5BD39628 X-CRM114-Status: GOOD ( 12.38 ) 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.178 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.178 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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.49 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 3b3e18f..123508d 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -992,6 +992,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; @@ -1216,6 +1219,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; }