From patchwork Fri Apr 24 05:27:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47535 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0554820553 for ; Fri, 24 Apr 2015 05:34:22 +0000 (UTC) Received: by wiun10 with SMTP id n10sf1577133wiu.1 for ; Thu, 23 Apr 2015 22:34:21 -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=jIAEdwkeoK7pQFZ/DKE3Slfjc/GR70b2Cmf3nQQZz1M=; b=L9dRLhoWHH0RFF7kjccvy52yTT73UflwsbXmVQzow5LeHIDtWPsCj6i6NFbxgeeDxE DxkxUYOsg9PiYA/GjTeL05UjISHT1uR8p2Wg3QieCIH2l16iqxjEVprkgPyN+l6EuzGb tYeIMRdEDUjwnnc+C8mT5T00OMvSJXU5jBzKy5s9++JGvJtcPjChG3dA0qf+rgkzJehU PxBQwsS8Yx1FfF64hO1zgLPzNEFN0LNV0KH+FS+kZwTrmPA2CxrELOqTesLm8A7AZL8X Gov/v02yil3cWgyuFUeIiU1g4oMJwXPS69nyr3+yctvCKn/YKZ/YOFfRd2Zqq4DNCAZE Vj0w== X-Gm-Message-State: ALoCoQlEC3Qxm2CuXS5ncvpiLYS88/1NYJOTcUHMFpj2ViOIwf9izn5RHtjsJ/V/W6Cn1eWXzwJM X-Received: by 10.180.106.136 with SMTP id gu8mr168375wib.6.1429853661343; Thu, 23 Apr 2015 22:34:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.164 with SMTP id cz4ls306396lac.3.gmail; Thu, 23 Apr 2015 22:34:21 -0700 (PDT) X-Received: by 10.152.3.130 with SMTP id c2mr5430711lac.81.1429853661091; Thu, 23 Apr 2015 22:34:21 -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 lf3si3019639lbc.136.2015.04.23.22.34.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:34:21 -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 labbd9 with SMTP id bd9so27584491lab.2 for ; Thu, 23 Apr 2015 22:34:21 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr5320182lbb.76.1429853661006; Thu, 23 Apr 2015 22:34:21 -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 l1csp978741lbt; Thu, 23 Apr 2015 22:34:20 -0700 (PDT) X-Received: by 10.70.131.193 with SMTP id oo1mr2972727pdb.63.1429853659169; Thu, 23 Apr 2015 22:34:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd10si15800741pdb.178.2015.04.23.22.34.18; Thu, 23 Apr 2015 22:34:19 -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 S1754564AbbDXFeR (ORCPT + 2 others); Fri, 24 Apr 2015 01:34:17 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:34590 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754559AbbDXFeR (ORCPT ); Fri, 24 Apr 2015 01:34:17 -0400 Received: by oiko83 with SMTP id o83so32508132oik.1 for ; Thu, 23 Apr 2015 22:34:17 -0700 (PDT) X-Received: by 10.60.116.170 with SMTP id jx10mr5797858oeb.7.1429853657094; Thu, 23 Apr 2015 22:34:17 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id zk5sm6068786obc.22.2015.04.23.22.34.15 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:34:16 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.12.y stable 50/63] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Fri, 24 Apr 2015 13:27:48 +0800 Message-Id: <1429853281-6136-51-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> 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: shannon.zhao@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.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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Christoffer Dall 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 --- 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 2e0357d..f974085 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; }