From patchwork Tue Apr 28 18:24:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 226917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F0EC83007 for ; Tue, 28 Apr 2020 18:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4205521841 for ; Tue, 28 Apr 2020 18:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098791; bh=gjLy/9Q4lOrc2IYZnLt4y2P7wQ1MuFdp0dajvQe2jNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=fLkT/xP6kcrfXWtutlCPV7JaqEmX8k2vVOloerUTF+rNnB2kRItbq3On3eljD4fe0 0SrbgvsqBtIxRSOLP+jNu3HV3B3qErUy+0RdUCGzRvwLD5R8l42+uu/WkH9tYdfFwX VraW0p7Dhj3aaUfgdLA5h4sZ5/n0v/aI2LhvmCMs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729874AbgD1SdJ (ORCPT ); Tue, 28 Apr 2020 14:33:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:49478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729899AbgD1SdI (ORCPT ); Tue, 28 Apr 2020 14:33:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F58421841; Tue, 28 Apr 2020 18:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098788; bh=gjLy/9Q4lOrc2IYZnLt4y2P7wQ1MuFdp0dajvQe2jNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THpQLavcgfKaEDVZrSg3zun0byd1yTj05nMyNrkno2btFLPWIIDuINy/m7uz5cxr8 HOF6rFKBb6jrNR8GYPtL4GTZ5bHeXQ8hUf5qyu+0JnD26d8PegwcsbLCnPKN+SKcED J1hiC3VcNL/bhecjnhwkZ5oXSXynU/EUrEfINqbA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Cornelia Huck , Paolo Bonzini Subject: [PATCH 5.6 112/167] KVM: s390: Return last valid slot if approx index is out-of-bounds Date: Tue, 28 Apr 2020 20:24:48 +0200 Message-Id: <20200428182239.352037251@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182225.451225420@linuxfoundation.org> References: <20200428182225.451225420@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sean Christopherson commit 97daa028f3f621adff2c4f7b15fe0874e5b5bd6c upstream. Return the index of the last valid slot from gfn_to_memslot_approx() if its binary search loop yielded an out-of-bounds index. The index can be out-of-bounds if the specified gfn is less than the base of the lowest memslot (which is also the last valid memslot). Note, the sole caller, kvm_s390_get_cmma(), ensures used_slots is non-zero. Fixes: afdad61615cc3 ("KVM: s390: Fix storage attributes migration with memory slots") Cc: stable@vger.kernel.org # 4.19.x: 0774a964ef56: KVM: Fix out of range accesses to memslots Cc: stable@vger.kernel.org # 4.19.x Signed-off-by: Sean Christopherson Message-Id: <20200408064059.8957-3-sean.j.christopherson@intel.com> Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/s390/kvm/kvm-s390.c | 3 +++ 1 file changed, 3 insertions(+) --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1930,6 +1930,9 @@ static int gfn_to_memslot_approx(struct start = slot + 1; } + if (start >= slots->used_slots) + return slots->used_slots - 1; + if (gfn >= memslots[start].base_gfn && gfn < memslots[start].base_gfn + memslots[start].npages) { atomic_set(&slots->lru_slot, start);