Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev
Subject: Re: [PATCH v5 09/18] KVM: arm64: Add selftests for the pKVM heap allocator
Date: Tue, 01 Sep 2026 08:27:13 +0000	[thread overview]
Message-ID: <20260901082714.3DA3D1F00A3F@smtp.kernel.org> (raw)
In-Reply-To: <20260901080941.997769-10-vdonnefort@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Improper Trust Boundary: Selftest hypercall is exposed in the always-on SMCCC band.
- [Medium] Data race and missing mutual exclusion in `hyp_allocator_selftest()` against concurrent reclaim.
--

commit 75aa2a47b5c2aac4b561278263e6a43bfd0479e2
Author: Vincent Donnefort <vdonnefort@google.com>

KVM: arm64: Add selftests for the pKVM heap allocator

This commit introduces a comprehensive runtime selftest for the pKVM
hypervisor heap allocator, executed during init when CONFIG_NVHE_EL2_DEBUG
is enabled.

> diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> index fc3c52b031541..0a8df74a7b4e6 100644
> --- a/arch/arm64/include/asm/kvm_asm.h
> +++ b/arch/arm64/include/asm/kvm_asm.h

[ ... ]

> @@ -92,6 +92,7 @@ enum __kvm_host_smccc_func {
>  	__KVM_HOST_SMCCC_FUNC___pkvm_hyp_topup,
>  	__KVM_HOST_SMCCC_FUNC___pkvm_hyp_reclaim,
>  	__KVM_HOST_SMCCC_FUNC___pkvm_hyp_reclaimable,
> +	__KVM_HOST_SMCCC_FUNC___pkvm_hyp_alloc_selftest,
>  
>  	MARKER(__KVM_HOST_SMCCC_FUNC_PKVM_ONLY),

[Severity: Medium]
Does placing the selftest hypercall here expose it to the host kernel
after deprivilege? 

By placing it before the PKVM_ONLY marker instead of before the MIN_PKVM
marker, this hypercall becomes always available rather than init-only.

This appears to expose boot-only test code and its memory management
operations to the untrusted host kernel at runtime, which expands the
attack surface and violates the pKVM least-privilege security model.

> diff --git a/arch/arm64/kvm/hyp/nvhe/alloc.c b/arch/arm64/kvm/hyp/nvhe/alloc.c
> index 32435782030bc..3b83de90472a8 100644
> --- a/arch/arm64/kvm/hyp/nvhe/alloc.c
> +++ b/arch/arm64/kvm/hyp/nvhe/alloc.c

[ ... ]

> +int hyp_allocator_selftest(void)
> +{
> +	struct hyp_allocator *allocator = &selftest_allocator;
> +	static DEFINE_HYP_SPINLOCK(selftest_lock);
> +	struct kvm_hyp_memcache host_mc = { };
> +	void *addr1, *addr2, *addr3, *addr4;
> +	int ret;
> +
> +	guard(hyp_spinlock)(&selftest_lock);
> +
> +	if (allocator->mc.nr_pages < SELFTEST_MAX_PAGES) {

[Severity: Medium]
Could this read of mc.nr_pages race with concurrent reclaim or topup
operations? 

It looks like this accesses the allocator state locklessly because
allocator->lock is not held here, only the local selftest_lock.

> +		*this_cpu_ptr(allocator->topup_needed) = SELFTEST_MAX_PAGES -
> +							 allocator->mc.nr_pages;
> +		return -ENOMEM;
> +	}
> +
> +	selftest_alloc(SELFTEST_MAX_SIZE);
> +	if (selftest_errno() != -E2BIG)
> +		return -EINVAL;
> +
> +	selftest_alloc(SIZE_MAX);
> +	if (selftest_errno() != -E2BIG)
> +		return -EINVAL;
> +
> +	/* Test first chunk */
> +	addr1 = selftest_alloc(0);
> +	if (!addr1 || addr1 != (void *)allocator->start + chunk_hdr_size())
> +		return -EINVAL;
> +
> +	/* Test second contiguous chunk with unaligned size */
> +	addr2 = selftest_alloc(MIN_ALLOC_SIZE + 1);

[Severity: Medium]
Because the selftest hypercall is exposed post-deprivilege, could a
concurrent host hypercall steal chunks from the selftest allocator while
this test is running?

Since allocator->lock is not held across this sequence of allocations and
frees, a concurrent reclaim operation might mutate the allocator state. This
would break the selftest's deterministic layout sequence and result in
spurious failures.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901080941.997769-1-vdonnefort@google.com?part=9

  reply	other threads:[~2026-09-01  8:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  8:09 [PATCH v5 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 01/18] KVM: arm64: Add pkvm_private_va_range_pa Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 02/18] KVM: arm64: Add pkvm_remove_mappings Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 03/18] KVM: arm64: Add pkvm_map_private_va_range Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 04/18] KVM: arm64: Add a heap allocator for the pKVM hyp Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 05/18] KVM: arm64: Allow kvm_hyp_memcache usage outside of stage-2 Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 06/18] KVM: arm64: Add pkvm_hyp_req infrastructure Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 07/18] KVM: arm64: Add PKVM_HYP_REQ_HYP_ALLOC request Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 08/18] KVM: arm64: Add reclaim interface for the pKVM heap alloc Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 09/18] KVM: arm64: Add selftests for the pKVM heap allocator Vincent Donnefort
2026-09-01  8:27   ` sashiko-bot [this message]
2026-09-01  8:09 ` [PATCH v5 10/18] KVM: arm64: Add a shrinker for pKVM Vincent Donnefort
2026-09-01 17:30   ` Fuad Tabba
2026-09-01  8:09 ` [PATCH v5 11/18] KVM: arm64: Filter out non-kernel addresses in kern_hyp_va Vincent Donnefort
2026-09-01  8:23   ` sashiko-bot
2026-09-01  8:09 ` [PATCH v5 12/18] KVM: arm64: Move hyp_vm refcount into the structure Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 13/18] KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator Vincent Donnefort
2026-09-01  8:34   ` sashiko-bot
2026-09-01  8:09 ` [PATCH v5 14/18] KVM: arm64: Alloc pkvm_hyp_vcpu " Vincent Donnefort
2026-09-01  8:34   ` sashiko-bot
2026-09-01  8:09 ` [PATCH v5 15/18] KVM: arm64: Rename vCPU pkvm_memcache to stage2_mc Vincent Donnefort
2026-09-01 17:59   ` Fuad Tabba
2026-09-01  8:09 ` [PATCH v5 16/18] KVM: arm64: Reject hyp trace descriptors with fewer CPUs than hyp_nr_cpus Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 17/18] KVM: arm64: Reject hyp trace descriptors with fewer than 3 pages Vincent Donnefort
2026-09-01  8:09 ` [PATCH v5 18/18] KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator Vincent Donnefort
2026-09-01  8:35   ` 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=20260901082714.3DA3D1F00A3F@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox