From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v2 05/22] KVM: arm64: Make pKVM ownership selftest an HVC
Date: Fri, 11 Sep 2026 14:14:31 +0000 [thread overview]
Message-ID: <20260911141431.9CA051F008A2@smtp.kernel.org> (raw)
In-Reply-To: <20260911135053.146435-6-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Exposing the pKVM ownership selftest as an HVC allows the untrusted host to trigger an Out-Of-Bounds (OOB) write in hypervisor memory.
- [Medium] Missing NULL check on `init_selftest_vm()` return value leads to an EL2 panic on malicious host input.
--
commit 8fb13365545b2fb6e99ef459c949f368c81f9f88
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Make pKVM ownership selftest an HVC
In preparation for testing the pKVM ownership with huge mappings,
refactor the selftest to be triggered via an HVC using dynamically
allocated memory from the host. This avoids wasting memory which would
be even worse for testing ownership transitions for huge stage-2
mappings.
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -1748,24 +1748,36 @@ static void assert_page_state(void)
[ ... ]
> +int __pkvm_ownership_selftest(u64 pfn, u64 pgtable_pfn, unsigned long pgtable_nr_pages)
> {
[ ... ]
> + selftest_vcpu = vcpu = init_selftest_vm(hyp_phys_to_virt(hyp_pfn_to_phys(pgtable_pfn)),
> + pgtable_nr_pages);
> vm = pkvm_hyp_vcpu_to_hyp_vm(vcpu);
[Severity: Medium]
Is there a possibility of a NULL pointer dereference leading to an EL2 panic
here? If the host issues the selftest HVC with pgtable_nr_pages set to 0,
init_selftest_vm() evaluates seeded < min_pages as true and returns NULL.
This NULL return is then unconditionally assigned to vcpu and immediately
dereferenced in pkvm_hyp_vcpu_to_hyp_vm(vcpu).
Should there be a check on the return value of init_selftest_vm() before
using it?
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -762,7 +762,7 @@ static struct pkvm_hyp_vcpu selftest_vcpu = {
[ ... ]
> -struct pkvm_hyp_vcpu *init_selftest_vm(void *virt)
> +struct pkvm_hyp_vcpu *init_selftest_vm(void *virt, u64 nr_pages)
> {
[ ... ]
> selftest_vm.kvm.arch.pkvm.handle = __pkvm_reserve_vm();
> insert_vm_table_entry(selftest_vm.kvm.arch.pkvm.handle, &selftest_vm);
> return &selftest_vcpu;
> }
>
> void teardown_selftest_vm(void)
> {
> + struct kvm_hyp_memcache *vcpu_mc = &selftest_vcpu.vcpu.arch.pkvm_memcache;
> + struct kvm_hyp_memcache mc = { 0 };
> +
> + while (vcpu_mc->nr_pages)
> + hyp_put_page(&selftest_vm.pool, pop_hyp_memcache(vcpu_mc, hyp_phys_to_virt));
> +
> hyp_spin_lock(&vm_table_lock);
> remove_vm_table_entry(selftest_vm.kvm.arch.pkvm.handle);
[Severity: High]
Can this sequence cause an out-of-bounds write in hypervisor memory?
If the host calls the __pkvm_ownership_selftest HVC when the VM table is
full, __pkvm_reserve_vm() fails and returns -ENOMEM. In init_selftest_vm(),
this negative error code is assigned blindly to the handle.
While insert_vm_table_entry() safely rejects the negative handle,
teardown_selftest_vm() unconditionally calls remove_vm_table_entry()
with it. Inside remove_vm_table_entry(), vm_handle_to_idx() converts
the negative handle into a massive 32-bit unsigned index without bounds
checking, resulting in an out-of-bounds write when vm_table[idx] = NULL
executes.
> hyp_spin_unlock(&vm_table_lock);
> +
> + reclaim_pgtable_pages(&selftest_vm, &mc);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911135053.146435-1-vdonnefort@google.com?part=5
next prev parent reply other threads:[~2026-09-11 14:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 13:50 [PATCH v2 00/22] Huge mapping support for protected VMs Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 01/22] KVM: arm64: Prefault host stage-2 entries on block split Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 02/22] KVM: arm64: Propagate host stage-2 annotated " Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 03/22] KVM: arm64: Allow block-level stage-2 annotation Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 04/22] KVM: arm64: Use block-level annotations when setting up the host stage-2 Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 05/22] KVM: arm64: Make pKVM ownership selftest an HVC Vincent Donnefort
2026-09-11 14:14 ` sashiko-bot [this message]
2026-09-11 13:50 ` [PATCH v2 06/22] KVM: arm64: Add a range to __pkvm_host_share/unshare_hyp() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 07/22] KVM: arm64: Add a range to __pkvm_host_donate_guest() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 08/22] KVM: arm64: Add a range to hyp_poison_page() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 09/22] KVM: arm64: Add a range to __pkvm_host_reclaim_guest() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 10/22] KVM: arm64: Add a range to __pkvm_guest_share_host() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 11/22] KVM: arm64: Add a range to __pkvm_guest_unshare_host() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 12/22] KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 13/22] KVM: arm64: Handle huge mappings in __pkvm_vcpu_in_poison_fault() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 14/22] KVM: arm64: Add a range to pKVM ownership selftest Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 15/22] KVM: arm64: Warn on pKVM guest stage-2 block collapse Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 16/22] KVM: arm64: Add pkvm_hyp_req infrastructure Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 17/22] KVM: arm64: Introduce kvm_pgtable_stage2_table_install() Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 18/22] KVM: arm64: Add __pkvm_host_split_guest HVC Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 19/22] KVM: arm64: Extend pKVM page ownership selftests to cover guest block split Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 20/22] KVM: arm64: Add PKVM_HYP_REQ_SPLIT Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 21/22] KVM: arm64: Raise PKVM_HYP_REQ_SPLIT on guest to host sharing Vincent Donnefort
2026-09-11 13:50 ` [PATCH v2 22/22] KVM: arm64: Stage-2 huge mappings for protected VMs Vincent Donnefort
2026-09-11 14:20 ` sashiko-bot
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=20260911141431.9CA051F008A2@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.