All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: oliver.upton@linux.dev, joey.gouly@arm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	catalin.marinas@arm.com, will@kernel.org, qperret@google.com,
	sebastianene@google.com, keirf@google.com,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v2] KVM: arm64: Check range args for pKVM mem transitions
Date: Sun, 21 Sep 2025 12:29:08 +0100	[thread overview]
Message-ID: <87plbkxcvv.wl-maz@kernel.org> (raw)
In-Reply-To: <20250919155056.2648137-1-vdonnefort@google.com>

On Fri, 19 Sep 2025 16:50:56 +0100,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> There's currently no verification for host issued ranges in most of the
> pKVM memory transitions. The subsequent end boundary might therefore be
> subject to overflow and could evade the later checks.
> 
> Close this loophole with an additional check_range_args() check on a per
> public function basis.
> 
> host_unshare_guest transition is already protected via
> __check_host_shared_guest(), while assert_host_shared_guest() callers
> are already ignoring host checks.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> ---
> 
>  v1 -> v2:
>    - Also check for (nr_pages * PAGE_SIZE) overflow. (Quentin)
>    - Rename to check_range_args().
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index 8957734d6183..65fcd2148f59 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -712,6 +712,14 @@ static int __guest_check_page_state_range(struct pkvm_hyp_vm *vm, u64 addr,
>  	return check_page_state_range(&vm->pgt, addr, size, &d);
>  }
>  
> +static bool check_range_args(u64 start, u64 nr_pages, u64 *size)
> +{
> +	if (check_mul_overflow(nr_pages, PAGE_SIZE, size))
> +		return false;
> +
> +	return start < (start + *size);

I will echo Oliver's concern on v1: you probably want to convert the
boundary check to be inclusive of the end of the range. Otherwise, a
range that ends at the top of the 64bit range will be represented as
0, and fail the  check despite being perfectly valid.

That's not a problem for PAs, as we will be stuck with at most 56bit
PAs for quite a while, but VAs are a different story, and this sort of
range check should be valid for VAs as well.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

  reply	other threads:[~2025-09-21 11:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-19 15:50 [PATCH v2] KVM: arm64: Check range args for pKVM mem transitions Vincent Donnefort
2025-09-21 11:29 ` Marc Zyngier [this message]
2025-09-22 21:00   ` Vincent Donnefort
2025-09-22 23:33     ` Oliver Upton
2025-09-23  9:18       ` Vincent Donnefort
2025-10-01  9:37         ` Marc Zyngier
2025-10-03 13:45           ` 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=87plbkxcvv.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=keirf@google.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=sebastianene@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --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 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.