mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuheng Li via B4 Relay <devnull+xuheng.cs.columbia.edu@kernel.org>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Quentin Perret <qperret@google.com>,
	Will Deacon <will@kernel.org>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	 Mark Rutland <mark.rutland@arm.com>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	 Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	 Suzuki K Poulose <suzuki.poulose@arm.com>,
	 Zenghui Yu <yuzenghui@huawei.com>,
	kvmarm@lists.linux.dev,  linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  Xuheng Li <xuheng@cs.columbia.edu>
Subject: [PATCH v2 2/3] KVM: arm64: Check the host stage-2 PGD allocation for NULL
Date: Thu, 05 Nov 2026 22:59:49 +0000	[thread overview]
Message-ID: <20261105-hyp-pool-and-map-v2-2-44a6ca90190b@cs.columbia.edu> (raw)
In-Reply-To: <20261105-hyp-pool-and-map-v2-0-44a6ca90190b@cs.columbia.edu>

From: Xuheng Li <xuheng@cs.columbia.edu>

host_s2_zalloc_pages_exact() passes the result of hyp_alloc_pages() to
hyp_split_page(hyp_virt_to_page(addr)) without checking it for NULL.
If the host stage-2 pool cannot supply the PGD, hyp_virt_to_page(NULL)
yields a bogus struct hyp_page, and hyp_split_page() reads and writes
through it, which ends in a hyp panic during pKVM initialisation
although kvm_pgtable_stage2_init() is prepared to fail with -ENOMEM.

The pool is sized so that this allocation, the first one made from it,
cannot fail, so nothing in mainline reaches this path once the pool
size is computed correctly.  Return NULL early anyway, so that a
mis-sized pool makes initialisation fail cleanly.

Signed-off-by: Xuheng Li <xuheng@cs.columbia.edu>
---
 arch/arm64/kvm/hyp/nvhe/mem_protect.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
index d4c332a91..ee0848f2e 100644
--- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
+++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
@@ -85,6 +85,9 @@ static void *host_s2_zalloc_pages_exact(size_t size)
 {
 	void *addr = hyp_alloc_pages(&host_s2_pool, get_order(size));
 
+	if (!addr)
+		return NULL;
+
 	hyp_split_page(hyp_virt_to_page(addr));
 
 	/*

-- 
2.53.0



  parent reply	other threads:[~2026-11-05 22:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 22:59 [PATCH v2 0/3] KVM: arm64: Fix the hyp pool size on large machines, plus two hardening patches Xuheng Li via B4 Relay
2026-11-05 22:59 ` [PATCH v2 1/3] KVM: arm64: Compute hyp early-allocation and pool sizes in 64 bits Xuheng Li via B4 Relay
2026-11-06 11:31   ` Fuad Tabba
2026-11-06 14:02     ` Mostafa Saleh
2026-11-06 14:31       ` Xuheng Li
2026-11-05 22:59 ` Xuheng Li via B4 Relay [this message]
2026-11-06 11:39   ` [PATCH v2 2/3] KVM: arm64: Check the host stage-2 PGD allocation for NULL Fuad Tabba
2026-11-06 14:31     ` Xuheng Li
2026-11-05 22:59 ` [PATCH v2 3/3] KVM: arm64: Don't replace a valid hyp block mapping with a table Xuheng Li via B4 Relay
2026-11-06 12:03   ` Fuad Tabba
2026-11-06 14:33     ` Vincent Donnefort
2026-11-06 14:33     ` Xuheng Li
2026-11-06 14:34       ` Fuad Tabba
2026-11-06 17:17         ` Xuheng Li
2026-11-06 18:53           ` Vincent Donnefort

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=20261105-hyp-pool-and-map-v2-2-44a6ca90190b@cs.columbia.edu \
    --to=devnull+xuheng.cs.columbia.edu@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=qperret@google.com \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=xuheng@cs.columbia.edu \
    --cc=yuzenghui@huawei.com \
    /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

all inboxes | Powered by JetHome®