From patchwork Mon May 4 01:52:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47970 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 817492121F for ; Mon, 4 May 2015 01:56:06 +0000 (UTC) Received: by wghm4 with SMTP id m4sf41042521wgh.2 for ; Sun, 03 May 2015 18:56:05 -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=UOkLIjqAfxxdyxQY8Lr+tRTsKEMEXtEmsV8/js73nMU=; b=YbPPMdB1sYX/Ht8hsfDBEH5IHkkoFOldDUuJC3WbVEZRmGiRwV+Ey45JildHb07Qwg ADvovA5pmphs95jo42XpvWX2UXlOhK7FwsnkEILmb7WzsXcSTxocq5Vqy7PwqpSMr9It 3WL1fAbAelSBbvQ+RoefSly6N6JlPYvJQbnfW+SFNs6H1GWKeAmgc+6x7dwdn7HIJBnH 6Gvq3pCXGTWnXjUAe8D4ULsY99wozVgyHTAMty6/oTi0n5C2iKuj1WfpF5CSH7vKhKdp ltUWiArfSfQpU8oUBPu/kOSIcAVlW/NeuUbcQgg5fq9mQdXHhZQqn0qqSRIOP/XGHLzx GcvA== X-Gm-Message-State: ALoCoQnsto6fQwSS+Skcm3D3BvDt/NpYrK+YLasQU94eYfAyazP8PXseWIMrrfqmJKyc3c+GUZri X-Received: by 10.113.11.3 with SMTP id ee3mr17107296lbd.9.1430704565802; Sun, 03 May 2015 18:56:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.184.8 with SMTP id eq8ls776166lac.91.gmail; Sun, 03 May 2015 18:56:05 -0700 (PDT) X-Received: by 10.112.167.73 with SMTP id zm9mr17490306lbb.89.1430704565619; Sun, 03 May 2015 18:56:05 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id 8si9074965lan.120.2015.05.03.18.56.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by labbd9 with SMTP id bd9so95101645lab.2 for ; Sun, 03 May 2015 18:56:05 -0700 (PDT) X-Received: by 10.152.236.40 with SMTP id ur8mr17716057lac.19.1430704565541; Sun, 03 May 2015 18:56:05 -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 l1csp1413104lbt; Sun, 3 May 2015 18:56:04 -0700 (PDT) X-Received: by 10.68.219.201 with SMTP id pq9mr32970501pbc.97.1430704563840; Sun, 03 May 2015 18:56:03 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ix6si17838787pac.46.2015.05.03.18.56.03; Sun, 03 May 2015 18:56:03 -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 S1751964AbbEDB4B (ORCPT + 2 others); Sun, 3 May 2015 21:56:01 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:36448 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961AbbEDB4B (ORCPT ); Sun, 3 May 2015 21:56:01 -0400 Received: by pdea3 with SMTP id a3so150077482pde.3 for ; Sun, 03 May 2015 18:56:01 -0700 (PDT) X-Received: by 10.68.219.201 with SMTP id pq9mr32970256pbc.97.1430704561039; Sun, 03 May 2015 18:56:01 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id ap9sm8137822pad.42.2015.05.03.18.55.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:55:59 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.14.y stable 32/47] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Mon, 4 May 2015 09:52:27 +0800 Message-Id: <1430704362-6292-33-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430704362-6292-1-git-send-email-shannon.zhao@linaro.org> References: <1430704362-6292-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.44 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 8cd0387..8a677ae 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -926,6 +926,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, memslot, fault_status); if (ret == 0) ret = 1; @@ -1150,6 +1153,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; }