Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3722901pxb; Mon, 24 Jan 2022 16:20:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKGx6HRmDGw8sY9cFmuksozpoxEsj6VajzGRyVeV9/+t8+1Cel+uNHjYZIGM56PLsoMcFZ X-Received: by 2002:a17:90a:f89:: with SMTP id 9mr793962pjz.138.1643069935721; Mon, 24 Jan 2022 16:18:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069935; cv=none; d=google.com; s=arc-20160816; b=Q2urjYjgnp4j1K3h2K03A2E9enOVFcz8h8fo9DhrqyUynCThrERmwd/mIWdGSRU64F AfIzvUAD8+rNEJJM2Sxe6LpvKqxpMLub479QZULbz6JWSXmZVYoRuCfCCT+4BDRW/sja vEsl8EB2N/ATNlMGlMF6LsvJTduELmP8hkpj8gjFCDYn4lKnpGEOh++MXjEK/LRq90Nf cc306Dx6LTIN5E7MMttulc6jjBSbxmvOmV1/+syUrZofyvPMLIYhvb0fH7tBxv5fuXhD o5N0WHuFfLIkQzuWf22Zl4c9abV1wYLxDNmH4P19jSfOt6Yy58jHXFzhp2PC6z8r4A3v IvPQ== 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=PcLCpbbNCjCA2nass6ujeEA6MDxQc/ruU+9WpdptHp4OmabSLx8pVX/3dkCrN924qm 8yVh0QbGVUqC0aYMAgeiWS7XU1vlU0FYLvuXV9bPSk2mfiVtLSAFQZNs3WKYMtaL1KiA zybTs1sdQjE+5S34kIXjSxiOyglM5EjKGriyHFvB2mCKFRt/4nAmV/WONITxcctgYPYH msC2vQOAZtTkRSN6FHQA6ty6dUA0EjFC346fQrsL2dKHT01Ru4vDoenIELAHnZUhmYUJ D/mZi/sZP4lxtd8CZY7sN/yKfQKthLxpwrWk4fLtEv2GPs5Nt7W33tyM2ayTHC38Ipdf l+PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WJ8/GY6s"; 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 z21si674320pjq.133.2022.01.24.16.18.43; Mon, 24 Jan 2022 16:18:55 -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="WJ8/GY6s"; 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 S2372724AbiAYAMX (ORCPT + 99 others); Mon, 24 Jan 2022 19:12:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1849616AbiAXX0Q (ORCPT ); Mon, 24 Jan 2022 18:26:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8696EC01D7E6; Mon, 24 Jan 2022 13:30:22 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 25DA061028; Mon, 24 Jan 2022 21:30:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0928EC340E4; Mon, 24 Jan 2022 21:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059821; bh=lllL1+YSQOwmnLAGhKuxtgJRcS5EeLGylTj5nvLlLTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WJ8/GY6sIcVe2o0US7HfiGCL3OO/A31BHmp3fjIwhfxXjnvqt75drupp3VL52GXp5 Fl2Jga4OUmwO2aXn5iRpGtMtP0edt+Ho8EY3Smoam4gGKaMEqGdzaQ7TzRypUYeL04 NdghAi6xK/AxEdGBqN+LQ883IjgKaE/0l+idwoT8= 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.16 0745/1039] KVM: PPC: Book3S: Suppress warnings when allocating too big memory slots Date: Mon, 24 Jan 2022 19:42:14 +0100 Message-Id: <20220124184150.376175438@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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