From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
farosas@linux.ibm.com, Alexey Kardashevskiy <aik@ozlabs.ru>,
npiggin@gmail.com, linuxppc-dev@lists.ozlabs.org
Subject: [PATCH AUTOSEL 5.15 13/44] KVM: PPC: Book3S: Suppress warnings when allocating too big memory slots
Date: Mon, 17 Jan 2022 12:00:56 -0500 [thread overview]
Message-ID: <20220117170127.1471115-13-sashal@kernel.org> (raw)
In-Reply-To: <20220117170127.1471115-1-sashal@kernel.org>
From: Alexey Kardashevskiy <aik@ozlabs.ru>
[ 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 <aik@ozlabs.ru>
[mpe: Use 'size' for the variable rather than 'cb']
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210901084512.1658628-1-aik@ozlabs.ru
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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
next prev parent reply other threads:[~2022-01-17 17:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220117170127.1471115-1-sashal@kernel.org>
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 02/44] powerpc/6xx: add missing of_node_put Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 03/44] powerpc/powernv: " Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 04/44] powerpc/cell: " Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 05/44] powerpc/btext: " Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 06/44] powerpc/watchdog: Fix missed watchdog reset due to memory ordering race Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 07/44] ASoC: imx-hdmi: add put_device() after of_find_device_by_node() Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 09/44] powerpc/smp: Move setup_profiling_timer() under CONFIG_PROFILING Sasha Levin
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 12/44] powerpc/powermac: Add missing lockdep_register_key() Sasha Levin
2022-01-17 17:00 ` Sasha Levin [this message]
2022-01-17 17:00 ` [PATCH AUTOSEL 5.15 14/44] KVM: PPC: Book3S: Suppress failed alloc warning in H_COPY_TOFROM_GUEST Sasha Levin
2022-01-17 17:01 ` [PATCH AUTOSEL 5.15 24/44] powerpc/40x: Map 32Mbytes of memory at startup Sasha Levin
2022-01-17 17:01 ` [PATCH AUTOSEL 5.15 25/44] selftests/powerpc/spectre_v2: Return skip code when miss_percent is high Sasha Levin
2022-01-17 17:01 ` [PATCH AUTOSEL 5.15 26/44] powerpc: handle kdump appropriately with crash_kexec_post_notifiers option Sasha Levin
2022-01-17 17:01 ` [PATCH AUTOSEL 5.15 27/44] powerpc/fadump: Fix inaccurate CPU state info in vmcore generated with panic Sasha Levin
2022-01-17 17:01 ` [PATCH AUTOSEL 5.15 33/44] selftests/powerpc: Add a test of sigreturning to the kernel Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220117170127.1471115-13-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=aik@ozlabs.ru \
--cc=farosas@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).