Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3611171pxb; Mon, 24 Jan 2022 13:29:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKeVNK/r0mJQZ/iJWzmV1gVf/FowRMB6IwsErswQBcs4mr0QzOhQn+Cq+kvqTpNw8CS0HS X-Received: by 2002:a63:7d0c:: with SMTP id y12mr13266929pgc.517.1643059788289; Mon, 24 Jan 2022 13:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059788; cv=none; d=google.com; s=arc-20160816; b=GF2f9i1HLr41/JEH6YBnFVP1E2GaCK9NBK17xYV0iCKx0ZO88LJQzgTUJTDlcYsQab fDKJ1Z0NnUPFziHEANHMItqr/sZGrZEA/0BKIqysMvMHTdggw0YQKcWM6C9XrjrkHG2d YMsRnYSKN9b2SyZwmClM83iiGg1mzK6ZCD+qsQTLdjYwv1uIbt57G+S0QDSu+14c9vDq AgUuDGsikRnSBMN3Z3dZPXj+6KIyLMDRjjlDyUSUUuTazVhzIuzZVjHrdzZdg3CS+gwK bnHcyRSCdFmHi5nQkOcz+SrnG6DfL6H4l7pr6+61h3x75G7SH50MZDftSuiu8QofQ+xS DyEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4m/mQsji+qxuwldhAm33YpAoRZmZlGdh+HnWj4mUuNU=; b=GCRvgs95zWGV8LSxEVwhbNtBcLEnE2P9AkTHYvQ6kC9f6epy1n28XGkxCTUHVdHMI2 2WfuHqu75NcvdpvSEUJ0BpXMVl2vd78riMXuaY+3LJgW1Ls9/ZptO0YjsFOQ01K3AcJm /ty2swBXphkBr7A/S4NisAJc3APQtHanlX06SoYWpYcJrS4NDBkDbM328UGlKzhDIaNm tkyojxmgQ9OfXXpR5xsngMorhwyCoo6HqxbeHHTlpadT2wfYMQVVEjFhh1XtbeFphJ7l gzLoueHWJpZIWKghJoI5BzPS48iLT9IWVssmXjf8OneoEUtKr0UDD+2ilIM9v8hTu/vb y2PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RyUC8CDc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u135si14228483pgc.835.2022.01.24.13.29.34; Mon, 24 Jan 2022 13:29:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RyUC8CDc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1446519AbiAXVIj (ORCPT + 99 others); Mon, 24 Jan 2022 16:08:39 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:40348 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389520AbiAXUlf (ORCPT ); Mon, 24 Jan 2022 15:41:35 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C0643B810BD; Mon, 24 Jan 2022 20:41:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AEC6C340E5; Mon, 24 Jan 2022 20:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056892; bh=lllL1+YSQOwmnLAGhKuxtgJRcS5EeLGylTj5nvLlLTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RyUC8CDcyCO7Q20D/Gkon9hOKwlvIFRhLuqxMsOQv9PNLBS5iPARoo33QUDqjxGsK E+UVfG1XLKgRAWvvikLQEzCNa1UrRgXWA7lK/Qwpdiu8N4JLJdapzLkeKlAfT7w/GZ vLuGDfvxJnQqi4hKoGrk/OuV3j01Un1n01YcxK3c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.15 634/846] KVM: PPC: Book3S: Suppress warnings when allocating too big memory slots Date: Mon, 24 Jan 2022 19:42:31 +0100 Message-Id: <20220124184122.899954773@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Kardashevskiy [ Upstream commit 511d25d6b789fffcb20a3eb71899cf974a31bd9d ] The userspace can trigger "vmalloc size %lu allocation failure: exceeds total pages" via the KVM_SET_USER_MEMORY_REGION ioctl. This silences the warning by checking the limit before calling vzalloc() and returns ENOMEM if failed. This does not call underlying valloc helpers as __vmalloc_node() is only exported when CONFIG_TEST_VMALLOC_MODULE and __vmalloc_node_range() is not exported at all. Spotted by syzkaller. Signed-off-by: Alexey Kardashevskiy [mpe: Use 'size' for the variable rather than 'cb'] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210901084512.1658628-1-aik@ozlabs.ru Signed-off-by: Sasha Levin --- arch/powerpc/kvm/book3s_hv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 7b74fc0a986b8..94da0d25eb125 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4861,8 +4861,12 @@ static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, unsigned long npages = mem->memory_size >> PAGE_SHIFT; if (change == KVM_MR_CREATE) { - slot->arch.rmap = vzalloc(array_size(npages, - sizeof(*slot->arch.rmap))); + unsigned long size = array_size(npages, sizeof(*slot->arch.rmap)); + + if ((size >> PAGE_SHIFT) > totalram_pages()) + return -ENOMEM; + + slot->arch.rmap = vzalloc(size); if (!slot->arch.rmap) return -ENOMEM; } -- 2.34.1