All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <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: Fri, 3 Oct 2025 14:45:50 +0100	[thread overview]
Message-ID: <aN_TjloudttqBUtf@google.com> (raw)
In-Reply-To: <86plb7ync9.wl-maz@kernel.org>

[...]

> > > > > > +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.
> > > > 
> > > > Do you mean allowing something like start == 0xfffffffffffff000 and size ==
> > > > 4096?
> > > 
> > > Yes, this is what I was alluding to on v1.
> > > 
> > > > But I guess that would still put all the following checks using "addr + size" at
> > > > risk. Also, I believe even the code in pgtable.c wouldn't support a such range
> > > > as it is also using a u64 end boundary.
> > > 
> > > I'm not sure I follow. Ranges are pretty commonly expressed as a range
> > > terminated by an exclusive value. This just hasn't been an issue yet as
> > > the page table code is only ever dealing with TTBR0 or VTTBR
> > > translations.
> > 
> > If I do exclude the end boundary, evading checks would be as simple as making
> > sure we overflow the end boundary?
> > 
> > e.g. __pkvm_host_share_guest(phys = 0xfffffffffffff000, size = 4096) 
> > 
> >         check_range_allowed_memory(phys, phys + size) /* nop */
> > 	....
> > 	for_each_hyp_page(page, phys, size) {  /* nop */
> >                ...
> > 	} 
> > 	...
> > 	/* Install a valid mapping to phys */
> > 	kvm_pgtable_stage2_map(&vm->pgt, ipa, size, phys, ...) 
> 
> Why shouldn't this be as simple as this:
> 
> 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 - 1);
> }
> 
> which correctly deals with the boundary issue?

I am concerned about allowing ranges that will still overflow "phys + size".

e.g. phys=0xfffffffffffff000 and size=4096 would pass check_range_args().

But in __pkvm_host_share_guest() that would mean:

  bypassing check_range_allowed_memory()
  bypassing for_each_hyp_page()

  but installing a valid mapping to phys with:
   kvm_pgtable_stage2_map(&vm->pgt, ipa, size, phys, ...) 


> 
> 	M.
> 
> -- 
> Without deviation from the norm, progress is not possible.

      reply	other threads:[~2025-10-03 13:45 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
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 [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=aN_TjloudttqBUtf@google.com \
    --to=vdonnefort@google.com \
    --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=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=sebastianene@google.com \
    --cc=suzuki.poulose@arm.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.