From patchwork Thu Apr 30 12:12:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 47824 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 4A5232121F for ; Thu, 30 Apr 2015 12:19:24 +0000 (UTC) Received: by lamp14 with SMTP id p14sf14994795lam.3 for ; Thu, 30 Apr 2015 05:19:23 -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: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=vIxWcrtNc0EpL/HbJtI7ZUED2BtjWEelMP4W0oWNAsY=; b=K7ArMUmBT7E6YLMT1py9bF5yGdRcj8+qC+B4XNgstBsn3Qb5fv9hAw89w+t4hw17J0 AV87qjkSyYr8pKwqK88L3iiCZELLI3/50DgkCUFL7n4n75FqugdkjklNP3KhrLelEi+A VatKobNtvI3V4JfCy8cD835K0RBNhast/9yc2Lw7RNS+iu4Xh3aKwBiRiYVKMaF367K+ zGAuv2DjJPKjn7zJVQfRxZfgdF1vJ4TcmLZy4mtE7/HYH/z6K5MhgfVhaJwppEYyopMk C8QwkHJ8QmDnFs64w753evs8JoQ3yBlubb0Cr6EYB6HG34HZtnqHhqkGRKp8deFZc5ZH 8knw== X-Gm-Message-State: ALoCoQmd+4xNqWO3FOeCyoMpTsbncBburYUV1Wp9Y9agJG4Kmk4gGyibz3dXUP7iFDJ1F98Y7BoF X-Received: by 10.112.122.39 with SMTP id lp7mr2372848lbb.5.1430396363268; Thu, 30 Apr 2015 05:19:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.66 with SMTP id i2ls373857lah.19.gmail; Thu, 30 Apr 2015 05:19:23 -0700 (PDT) X-Received: by 10.112.148.101 with SMTP id tr5mr3706078lbb.0.1430396362986; Thu, 30 Apr 2015 05:19:22 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id n6si1613251lah.177.2015.04.30.05.19.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Apr 2015 05:19:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labbd9 with SMTP id bd9so42705972lab.2 for ; Thu, 30 Apr 2015 05:19:22 -0700 (PDT) X-Received: by 10.152.4.72 with SMTP id i8mr3727340lai.32.1430396362900; Thu, 30 Apr 2015 05:19:22 -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 l1csp3078036lbt; Thu, 30 Apr 2015 05:19:18 -0700 (PDT) X-Received: by 10.68.222.167 with SMTP id qn7mr7704524pbc.136.1430396305567; Thu, 30 Apr 2015 05:18:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iv3si3290936pbd.69.2015.04.30.05.18.24; Thu, 30 Apr 2015 05:18:25 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S1752213AbbD3MSF (ORCPT + 28 others); Thu, 30 Apr 2015 08:18:05 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:53668 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751435AbbD3MMf (ORCPT ); Thu, 30 Apr 2015 08:12:35 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.85) (envelope-from ) id 1YnnKT-0008DI-CT; Thu, 30 Apr 2015 14:12:33 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Christoffer Dall , Shannon Zhao , Jiri Slaby Subject: [PATCH 3.12 50/63] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Date: Thu, 30 Apr 2015 14:12:19 +0200 Message-Id: <91a82540f3e417f9fb908bcacffc8c8d27c59078.1430387326.git.jslaby@suse.cz> X-Mailer: git-send-email 2.3.5 In-Reply-To: <45aaf85687dd6ac119c55c5ec0dbe0bef0e62235.1430387326.git.jslaby@suse.cz> References: <45aaf85687dd6ac119c55c5ec0dbe0bef0e62235.1430387326.git.jslaby@suse.cz> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.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.42 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 3.12-stable review patch. If anyone has any objections, please let me 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; }