All of lore.kernel.org
 help / color / mirror / Atom feed
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 v6 03/18] KVM: arm64: Add pkvm_map_private_va_range
Date: Thu, 01 Oct 2026 14:49:58 +0000	[thread overview]
Message-ID: <20261001144959.1E7931F00899@smtp.kernel.org> (raw)
In-Reply-To: <20261001142849.3367614-4-vdonnefort@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: page table memory leak on error path in pkvm_map_private_va_range()
--

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

KVM: arm64: Add pkvm_map_private_va_range

In preparation for the pKVM heap allocator, introduce
pkvm_map_private_va_range() to map a physical range into the pKVM
private range.

> diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
> index 9ab7f613fa360..4a22fb74182be 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mm.c
[ ... ]
> @@ -90,6 +91,41 @@ int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr)
>  	return ret;
>  }
>  
> +/**
> + * pkvm_map_private_va_range() - Map a physical range into the private VA range
> + * @haddr:	The virtual address in the private range.
> + * @phys:	The physical address to map.
> + * @size:	The size of the range to map.
> + *
> + * The hypervisor VA @haddr must have been first allocated with
> + * pkvm_alloc_private_va_range(). The created mapping can later be removed
> + * with pkvm_remove_mappings().
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int pkvm_map_private_va_range(void *haddr, phys_addr_t phys, size_t size)
> +{
> +	unsigned long addr = (unsigned long)haddr;
> +	int ret;
> +
> +	if (!PAGE_ALIGNED(addr | phys | size))
> +		return -EINVAL;
> +
> +	guard(hyp_spinlock)(&pkvm_pgd_lock);
> +
> +	if (addr < __io_map_base || addr >= __io_map_next)
> +		return -EINVAL;
> +
> +	if (size > __io_map_next - addr)
> +		return -EINVAL;
> +
> +	ret = kvm_pgtable_hyp_map(&pkvm_pgtable, addr, size, phys, PAGE_HYP);
> +	if (ret)
> +		kvm_pgtable_hyp_unmap(&pkvm_pgtable, addr, size);
[Severity: High]
Does this error path leak hypervisor page table memory?

If kvm_pgtable_hyp_map() fails midway (for instance, due to an out-of-memory
condition), pkvm_map_private_va_range() calls kvm_pgtable_hyp_unmap() to roll
back the partial mapping. The unmap walker will then encounter an invalid PTE
in the unmapped portion:

arch/arm64/kvm/hyp/pgtable.c:hyp_unmap_walker() {
    ...
    if (!kvm_pte_valid(ctx->old))
        return -EINVAL;
    ...
}

This causes the walker to abort. When the walk aborts, __kvm_pgtable_visit()
skips the KVM_PGTABLE_WALK_TABLE_POST callbacks for all parent tables:

arch/arm64/kvm/hyp/pgtable.c:__kvm_pgtable_visit() {
    ...
    if (!kvm_pgtable_walk_continue(data->walker, ret))
        goto out;

    if (ctx.flags & KVM_PGTABLE_WALK_TABLE_POST)
        ret = kvm_pgtable_visitor_cb(data, &ctx, ...);
    ...
}

Because the post-table callback is skipped, any intermediate page tables
allocated during the failed map are not freed. Since the hypervisor uses a
fixed memory pool, if an untrusted host can push the allocator to its limit
to trigger this error path, this leak could permanently deplete EL2 memory and
prevent further VM creation.

> +
> +	return ret;
> +}

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

  reply	other threads:[~2026-10-01 14:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 14:28 [PATCH v6 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 01/18] KVM: arm64: Add pkvm_private_va_range_pa Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 02/18] KVM: arm64: Add pkvm_remove_mappings Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 03/18] KVM: arm64: Add pkvm_map_private_va_range Vincent Donnefort
2026-10-01 14:49   ` sashiko-bot [this message]
2026-10-01 14:28 ` [PATCH v6 04/18] KVM: arm64: Add a heap allocator for the pKVM hyp Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 05/18] KVM: arm64: Allow kvm_hyp_memcache usage outside of stage-2 Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 06/18] KVM: arm64: Add pkvm_hyp_req infrastructure Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 07/18] KVM: arm64: Add PKVM_HYP_REQ_HYP_ALLOC request Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 08/18] KVM: arm64: Add reclaim interface for the pKVM heap alloc Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 09/18] KVM: arm64: Add selftests for the pKVM heap allocator Vincent Donnefort
2026-10-01 15:22   ` sashiko-bot
2026-10-01 14:28 ` [PATCH v6 10/18] KVM: arm64: Add a shrinker for pKVM Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 11/18] KVM: arm64: Filter out non-kernel addresses in kern_hyp_va Vincent Donnefort
2026-10-01 15:35   ` sashiko-bot
2026-10-01 14:28 ` [PATCH v6 12/18] KVM: arm64: Move hyp_vm refcount into the structure Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 13/18] KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator Vincent Donnefort
2026-10-01 15:43   ` sashiko-bot
2026-10-01 14:28 ` [PATCH v6 14/18] KVM: arm64: Alloc pkvm_hyp_vcpu " Vincent Donnefort
2026-10-01 15:46   ` sashiko-bot
2026-10-01 14:28 ` [PATCH v6 15/18] KVM: arm64: Rename vCPU pkvm_memcache to stage2_mc Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 16/18] KVM: arm64: Reject hyp trace descriptors with fewer CPUs than hyp_nr_cpus Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 17/18] KVM: arm64: Reject hyp trace descriptors with fewer than 3 pages Vincent Donnefort
2026-10-01 14:28 ` [PATCH v6 18/18] KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator Vincent Donnefort
2026-10-02 16:39 ` [PATCH v6 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Marc Zyngier

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=20261001144959.1E7931F00899@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.