Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp818985ybl; Wed, 11 Dec 2019 08:00:38 -0800 (PST) X-Google-Smtp-Source: APXvYqy6LNeZFZJB2y1lezZD8jv6ISa6u6mViFnEHyWHLp7/G2Cz5Co6XCr19/768YehwmUEJYh6 X-Received: by 2002:a54:4896:: with SMTP id r22mr3402674oic.30.1576080038175; Wed, 11 Dec 2019 08:00:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080038; cv=none; d=google.com; s=arc-20160816; b=hy5g8dkdaEfT4gCIr10KRgkvLVxiA/LL/0l+qE8L/CXmk+ZyiIJchNVEA+vW4i4Ph2 X/o8+AFmC1n+V0EqpRumkmk8/INYjpJgdclySP7MzZrTFjir5orm5vOfjb5jB8BVkjpg cGobs3v+ByI/VHYjU/sKmB5vsBHrfbVuh1pW//XWJAFPyRslHUkyglpIZW6mxkb8D9MG t+TjeODwvL5QxmnD7FrpijUZis678ostpd4WByrXBtA3T1x3u3SFudo36IGKSZW9B2ZM QnivlHwK/krkKc7TQYn2WtCHqAlVSFcQDFI4wnT/ObcMDbnb8xSMywMYSMc5xvMRX+8t 1w7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vaec/9YNsh37X1k+jRBtaFuwJBQV1/BrLk3fEInzz+w=; b=1ElEI35WLGONpSnrPjND62m9Oh4nasssR5liczxGxViayKDzqrnG+oILZRcJX4bDtD 8rCg4YkqSiCil809KCvS7fd4tugkFiqAdHuhEBjbpN1tDW7sselRuaiT//Reakc+V3FH M6/6eXcQakQWAPU4Wz5sk0dGaT/Olm15I9uakPpDuxaTf2is2IRSeYlK3iTGq70pvpqU 7Rb7rHcFibHlKlYOjfnfuWtYe2KN7Mf/q1ONRF9PbDbnOGEnPY1hiu0MIkLrYKp2XRHh dc45htZMuzuoy6PuEOOAo0S3S9Amt8L7/wNoTT/dc5jI7Ij4N56ToZPicu4q0t3tmOb4 Ovmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tyl9MfwX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si1265220oix.233.2019.12.11.08.00.25; Wed, 11 Dec 2019 08:00:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tyl9MfwX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731798AbfLKP60 (ORCPT + 99 others); Wed, 11 Dec 2019 10:58:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:39710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731622AbfLKPOX (ORCPT ); Wed, 11 Dec 2019 10:14:23 -0500 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 8412024658; Wed, 11 Dec 2019 15:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077262; bh=+cME4i6w/HOFktWu1TlD6KxQeCzpussbdm5Do3MnTqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tyl9MfwXBvpxg1V4YzqTuVdHcIxuW4mC0nwXdh62WGasmg6TJYfS6iV2sxhzRiG6/ awFKwLXYoe9+KUT+i4h34fbGRoBxf1J0doICI7wAGQdHU1p9+p7lz1OX6HKXvB8fut YldzVThHE5IGct7L2AGj4gC5M4lXFNtHwoDDs380= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Greg Kurz , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Paul Mackerras Subject: [PATCH 5.3 077/105] KVM: PPC: Book3S HV: XIVE: Fix potential page leak on error path Date: Wed, 11 Dec 2019 16:06:06 +0100 Message-Id: <20191211150256.520751612@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kurz commit 30486e72093ea2e594f44876b7a445c219449bce upstream. We need to check the host page size is big enough to accomodate the EQ. Let's do this before taking a reference on the EQ page to avoid a potential leak if the check fails. Cc: stable@vger.kernel.org # v5.2 Fixes: 13ce3297c576 ("KVM: PPC: Book3S HV: XIVE: Add controls for the EQ configuration") Signed-off-by: Greg Kurz Reviewed-by: Cédric Le Goater Signed-off-by: Paul Mackerras Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kvm/book3s_xive_native.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/arch/powerpc/kvm/book3s_xive_native.c +++ b/arch/powerpc/kvm/book3s_xive_native.c @@ -637,12 +637,6 @@ static int kvmppc_xive_native_set_queue_ srcu_idx = srcu_read_lock(&kvm->srcu); gfn = gpa_to_gfn(kvm_eq.qaddr); - page = gfn_to_page(kvm, gfn); - if (is_error_page(page)) { - srcu_read_unlock(&kvm->srcu, srcu_idx); - pr_err("Couldn't get queue page %llx!\n", kvm_eq.qaddr); - return -EINVAL; - } page_size = kvm_host_page_size(kvm, gfn); if (1ull << kvm_eq.qshift > page_size) { @@ -651,6 +645,13 @@ static int kvmppc_xive_native_set_queue_ return -EINVAL; } + page = gfn_to_page(kvm, gfn); + if (is_error_page(page)) { + srcu_read_unlock(&kvm->srcu, srcu_idx); + pr_err("Couldn't get queue page %llx!\n", kvm_eq.qaddr); + return -EINVAL; + } + qaddr = page_to_virt(page) + (kvm_eq.qaddr & ~PAGE_MASK); srcu_read_unlock(&kvm->srcu, srcu_idx);