Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3978970pxb; Tue, 25 Jan 2022 00:31:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW3JNANEwcrvN6aSO2coQWiI4QtclbDeK5gGFYuqQO9XVU8XaGzTbIU9OvrbCP1/CBeCpc X-Received: by 2002:a17:906:6691:: with SMTP id z17mr15389546ejo.763.1643099476860; Tue, 25 Jan 2022 00:31:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099476; cv=none; d=google.com; s=arc-20160816; b=QwEkQPpn7WkiLeF59ECjBQmGsU73fGgV73BI0VQdizEutG2BAEnyWOwNxrTlPRqsGz v66kRKENhHYyrblvSov8ccuXskBrbWSKHVnTO2fl+qwm6n51p1Ehl2GQYZq/Nu7gkwMV vzl2nFU8bxTvTpQInkTi/nqYHwzrhSOVbp2mFA4yxA9/g+WLUwDXA052MPiwajZrp4eK lJ8DgA0NUIdzZQeWUooRiBTgrqdUzQwZziXZBCSgrfEV7KomsErs5pI++S6FbTYNUQmB 0YwMGT0WkhGtMxo4cU1pvH0SlJSLQuJEAGKLA0ye+eA7y90tEUUObYQJuBx0OVH05Cgr 5bog== 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=Vdx6MKHKnXZDS8ntC4P3Bn1iPRpWwjECU5vSW8fnZ54=; b=k/5lAR307rN5dq4CH6KO4vJectf4yoKdMz2FYIcF+SJ1EgcY3RhWoZlN0IqNBKBwtb 2YMIdw1puu56MyK+IEqZgN802vsT0pgwxVcJM83FRrDSjNepoZGuHR0dowfEjIshFtwK ++afQEbIx1AQ+TC6U393krZtb2XtzLOHZukUnCMKmzFECilmsKq4vXhum+XmPv3ASY7c UYYeNbe6qbqhSLmClJSv6zCoKR/WDz826a8ma+zhJyaBoKRLQjj+7xmeWgcBV88vZKZC JbSOK8dRrLM4lFCCzwq1US66J1D0wcC8WLC9AckAbaBjsY4k2yJcoNbOqSxLCu0cmAGB Xs0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MiJRrYFz; 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 r15si10870875edd.229.2022.01.25.00.30.52; Tue, 25 Jan 2022 00:31:16 -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=MiJRrYFz; 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 S1355924AbiAYCoJ (ORCPT + 99 others); Mon, 24 Jan 2022 21:44:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444559AbiAXVBI (ORCPT ); Mon, 24 Jan 2022 16:01:08 -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 9553CC055A84; Mon, 24 Jan 2022 12:02:15 -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 35D076130D; Mon, 24 Jan 2022 20:02:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15E25C340E5; Mon, 24 Jan 2022 20:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054534; bh=LxtqiCU/HnTQBi7Y6RaZ5mzfJ2enE8ac2ayAJ6KDquo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MiJRrYFzm/cSjxF+/wzmcWYO+AbWlh8A3aSmUQx/ANk837ZrX2SaxXwLQhFfb1HOC 1dgc8nL/ZGzupU8ru+akJw40jabh5duKirQVMkkSpO4zwGCTLbpNrU3/Gst7bOgCTF xlTW7ereVAXFoR8l8FO5yxWG8zoIsPgKgrVRDShw= 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.10 419/563] KVM: PPC: Book3S: Suppress warnings when allocating too big memory slots Date: Mon, 24 Jan 2022 19:43:04 +0100 Message-Id: <20220124184038.943871029@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 175967a195c44..527c205d5a5f5 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4557,8 +4557,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