From patchwork Tue Jun 2 14:48:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 49392 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 3A42620BD1 for ; Tue, 2 Jun 2015 14:50:48 +0000 (UTC) Received: by labpg10 with SMTP id pg10sf12777524lab.2 for ; Tue, 02 Jun 2015 07:50:47 -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=39Tb/LpFTGiieAeoGgXg3/L5hk+ROVPggC3dYh3G/lo=; b=EDl1nvOGhBR5OXoOLj9UxiyGeIEpcrydlzukuODdwi0HmBbR7mMyptY4ENRVSGyc0Q CAZslHy2qPyzyjkXAwbsvLNcnHjiow/Yn/yACj2wKT753K6nnk6IWHqS5LPm5zd0xMGq 59zqKlTnUCoh6MNCzJnIOuMR9ZwfoVcO1tba0Wqw+IE7/Pc7Yxxk/ooMSJWC6WyOtGNd xhv4Fq1T8cOGXClcwc30Dsd+oXaBSLGNXfA9Y1O3931jCDHB2PiQ2LiVmdJFGts1FHKk Fm+R8mDET24qLINwcHRT1PKDvZmJq8S0kmVfjfEi9Yo8eJEvWoLkrzj1md+XlaUtR8/O /dHw== X-Gm-Message-State: ALoCoQlRvBIfY2/wJvQvLopvbvrCj1iGaHTL095tT2raMMXJJ1wYCQ6jCwPTisOPx9EqsMfZCgHT X-Received: by 10.180.19.72 with SMTP id c8mr16843699wie.2.1433256647129; Tue, 02 Jun 2015 07:50:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.36 with SMTP id g4ls814254lah.33.gmail; Tue, 02 Jun 2015 07:50:46 -0700 (PDT) X-Received: by 10.112.72.164 with SMTP id e4mr23072856lbv.113.1433256646961; Tue, 02 Jun 2015 07:50:46 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id ba16si15266844lab.113.2015.06.02.07.50.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 07:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by laew7 with SMTP id w7so35371758lae.1 for ; Tue, 02 Jun 2015 07:50:46 -0700 (PDT) X-Received: by 10.152.4.137 with SMTP id k9mr26268786lak.29.1433256646862; Tue, 02 Jun 2015 07:50:46 -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.108.230 with SMTP id hn6csp3129246lbb; Tue, 2 Jun 2015 07:50:45 -0700 (PDT) X-Received: by 10.66.118.166 with SMTP id kn6mr50211872pab.93.1433256645146; Tue, 02 Jun 2015 07:50:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hv8si26697315pdb.173.2015.06.02.07.50.44; Tue, 02 Jun 2015 07:50:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932360AbbFBOun (ORCPT + 2 others); Tue, 2 Jun 2015 10:50:43 -0400 Received: from mail-ob0-f178.google.com ([209.85.214.178]:33631 "EHLO mail-ob0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759013AbbFBOun (ORCPT ); Tue, 2 Jun 2015 10:50:43 -0400 Received: by obbnx5 with SMTP id nx5so129192817obb.0 for ; Tue, 02 Jun 2015 07:50:42 -0700 (PDT) X-Received: by 10.182.81.229 with SMTP id d5mr4706276oby.28.1433256642778; Tue, 02 Jun 2015 07:50:42 -0700 (PDT) Received: from localhost ([167.160.116.34]) by mx.google.com with ESMTPSA id sn2sm9563922obc.11.2015.06.02.07.50.40 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Jun 2015 07:50:41 -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 17/32] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Tue, 2 Jun 2015 22:48:12 +0800 Message-Id: <1433256507-7856-18-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1433256507-7856-1-git-send-email-shannon.zhao@linaro.org> References: <1433256507-7856-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.51 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..d122772 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; }