From patchwork Thu Apr 30 09:24:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 47789 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 8943220553 for ; Thu, 30 Apr 2015 09:26:39 +0000 (UTC) Received: by wiun10 with SMTP id n10sf2962670wiu.1 for ; Thu, 30 Apr 2015 02:26:38 -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=gE+aTmFkFpi3S7lIe2LSfSKCl6meiDYXndeZL91v0J4=; b=CKxoEbsDNf3i3AHcoqyYX1/cB0yLpKRQIx6mxqE35YC6mm8hktbKJGwp8CqDd803Pw IvKs5d8K8R8QrR890WO1kQ5hIZ33ihd72LcOgV1tg8hChybQsChrHPYC3mJdMdJhaI0A Dg5bHDdI5sGiAk9qS08Xxwrs0Y43+TqLeOgjs/9i6hduAaWvLTVjEksEDF3dT75s/d1j 4R0eQsDtySJbGeBzKQ93Ky4rpPOz0t7frv1kuQ6YNfTc0le9fhqq0OOneM6KH7oklG4s Ul5Nf9R70+OAByXYIvPifp6Bw8cBSo7SDqrnfuDoSbDLJON+I/RpkRC16A5eG+xiJyoN YsWw== X-Gm-Message-State: ALoCoQk4yliiK8wAw8Id2RhRIjvLifuM1si2Ot/A/IDeEvrQQGsjpB8XF+vsxc7SvR8vD5pEJ0Vu X-Received: by 10.180.105.226 with SMTP id gp2mr1210885wib.1.1430385998809; Thu, 30 Apr 2015 02:26:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.73 with SMTP id lm9ls384122lac.20.gmail; Thu, 30 Apr 2015 02:26:38 -0700 (PDT) X-Received: by 10.112.166.139 with SMTP id zg11mr2919707lbb.93.1430385998672; Thu, 30 Apr 2015 02:26:38 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id p10si1335552lap.75.2015.04.30.02.26.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Apr 2015 02:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbcga7 with SMTP id ga7so39883398lbc.1 for ; Thu, 30 Apr 2015 02:26:38 -0700 (PDT) X-Received: by 10.152.27.1 with SMTP id p1mr2946562lag.112.1430385998587; Thu, 30 Apr 2015 02:26:38 -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.67.65 with SMTP id l1csp2995799lbt; Thu, 30 Apr 2015 02:26:37 -0700 (PDT) X-Received: by 10.68.241.9 with SMTP id we9mr6364414pbc.59.1430385968424; Thu, 30 Apr 2015 02:26:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nf2si2640288pbc.149.2015.04.30.02.26.07; Thu, 30 Apr 2015 02:26:08 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751454AbbD3JZw (ORCPT + 2 others); Thu, 30 Apr 2015 05:25:52 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:53098 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751497AbbD3JZS (ORCPT ); Thu, 30 Apr 2015 05:25:18 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.85) (envelope-from ) id 1YnkiW-0005P7-Co; Thu, 30 Apr 2015 11:25:12 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: Christoffer Dall , Shannon Zhao , Jiri Slaby Subject: [patch added to the 3.12 stable tree] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Thu, 30 Apr 2015 11:24:58 +0200 Message-Id: <1430385911-20480-50-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1430385911-20480-1-git-send-email-jslaby@suse.cz> References: <1430385911-20480-1-git-send-email-jslaby@suse.cz> 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: patch@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.217.173 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 This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== 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 Signed-off-by: Jiri Slaby --- 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 2e0357dd8654..f9740851a6a4 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -772,6 +772,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, gfn, memslot, fault_status); if (ret == 0) ret = 1; @@ -996,6 +999,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; }