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 v2 22/22] KVM: arm64: Stage-2 huge mappings for protected VMs
Date: Fri, 11 Sep 2026 14:20:37 +0000	[thread overview]
Message-ID: <20260911142038.56F1C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911135053.146435-23-vdonnefort@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] pkvm_pin_user_pages() returns 0 on -EHWPOISON without initializing output parameters, leading to undefined behavior and potential system compromise in pkvm_mem_abort().
- [Medium] Unprivileged host userspace can trigger a WARN_ON_ONCE in pkvm_pin_user_pages() via TOCTOU, leading to a host-side denial of service.
--

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

KVM: arm64: Stage-2 huge mappings for protected VMs

This commit enables PMD-sized stage-2 block mappings for protected VMs when
the stage-1 mapping is backed by THPs. An entire PMD_SIZE mapping is donated
to the guest upon finding a THP.

> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 9ba86450fe4af..218df096c72ed 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
[ ... ]
> +static int pkvm_pin_user_pages(const struct kvm_s2_fault_desc *s2fd, struct page **__page,
> +			       unsigned long *__size, kvm_pfn_t *__pfn, gfn_t *__gfn)
>  {
>  	unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
>  	struct kvm_vcpu *vcpu = s2fd->vcpu;
>  	struct mm_struct *mm = current->mm;
>  	struct kvm *kvm = vcpu->kvm;
>  	struct page *page;
> +	kvm_pfn_t pfn;
> +	gfn_t gfn;
> +	long ret;
>  
> -	mmap_read_lock(mm);
> +	guard(mmap_read_lock)(mm);
>  
>  	ret = pin_user_pages(s2fd->hva, 1, flags, &page);
> -	mmap_read_unlock(mm);
> -
>  	if (ret == -EHWPOISON) {
>  		kvm_send_hwpoison_signal(s2fd->hva, PAGE_SHIFT);
> -		ret = 0;
> -		goto dec_account;
> +		return 0;

[Severity: Critical]
If pin_user_pages() returns -EHWPOISON, does this return 0 without
initializing the output parameters (__page, __size, __pfn, __gfn)?

>  	} else if (ret != 1) {
> -		ret = -EFAULT;
> -		goto dec_account;
> +		return -EFAULT;
>  	} else if (!folio_test_swapbacked(page_folio(page))) {
[ ... ]
> -		ret = -EIO;
> -		goto unpin;
> +		unpin_user_page(page);
> +		return -EIO;
> +	}
> +
> +	pfn = page_to_pfn(page);
> +	gfn = gpa_to_gfn(s2fd->fault_ipa);
> +
> +	ret = transparent_hugepage_adjust(kvm, s2fd->memslot, s2fd->hva, &pfn, &gfn);
> +	if (ret < 0) {
> +		unpin_user_page(page);
> +		return ret;
> +	} else if (ret == PMD_SIZE && WARN_ON_ONCE(folio_size(page_folio(page)) < PMD_SIZE)) {
> +		unpin_user_page(page);
> +		return -EINVAL;
>  	}

[Severity: Medium]
Could a concurrent page table modification trigger this warning? Since
mmap_read_lock() is held here, if a concurrent thread holding the per-VMA
lock (like madvise MADV_DONTNEED) zaps the page table and faults in a
PMD-mapped THP at the same address, transparent_hugepage_adjust() might
observe the new PMD mapping while the initially pinned page remains 4K.

As this warning is reachable from unprivileged host userspace, could this
be used for a host-side denial of service?

> +
> +	*__page = page;
> +	*__size = ret;
> +	*__pfn = pfn;
> +	*__gfn = gfn;
> +
> +	return 0;
> +}
> +
> +static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
> +{
> +	struct kvm_vcpu *vcpu = s2fd->vcpu;
> +	struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
> +	struct mm_struct *mm = current->mm;
> +	struct kvm *kvm = vcpu->kvm;
> +	unsigned long size;
> +	void *hyp_memcache;
> +	struct page *page;
> +	kvm_pfn_t pfn;
> +	gfn_t gfn;
> +	int ret;
> +
> +	hyp_memcache = get_mmu_memcache(vcpu);
> +	ret = topup_mmu_memcache(vcpu, hyp_memcache);
> +	if (ret)
> +		return -ENOMEM;
> +
> +	ret = pkvm_pin_user_pages(s2fd, &page, &size, &pfn, &gfn);
> +	if (ret)
> +		return ret;
> +
> +	ret = account_locked_vm(mm, size / PAGE_SIZE, true);

[Severity: Critical]
When pkvm_pin_user_pages() encounters a poisoned page, it returns 0. Will
this caller then proceed to use the uninitialized size, page, pfn, and gfn
variables?

It looks like this could result in mapping arbitrary, uninitialized
physical memory frames into the guest's stage-2 page tables. Furthermore,
if the mapping fails, the error path appears to call unpin_user_page()
with a garbage page pointer, which might cause a host kernel panic.

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

      reply	other threads:[~2026-09-11 14:20 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
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 [this message]

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=20260911142038.56F1C1F000FF@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.