linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked()
@ 2025-05-01 16:24 Mostafa Saleh
  2025-05-06  8:32 ` Marc Zyngier
  2025-05-07  7:56 ` Oliver Upton
  0 siblings, 2 replies; 4+ messages in thread
From: Mostafa Saleh @ 2025-05-01 16:24 UTC (permalink / raw)
  To: linux-kernel, kvmarm, linux-arm-kernel
  Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, qperret, Mostafa Saleh

I found this simple bug while preparing some patches for pKVM.
AFAICT, it should be harmless (besides crashing the kernel if it
was misbehaving)

Fixes: e94a7dea2972 ("KVM: arm64: Move host page ownership tracking to the hyp vmemmap")
Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
 arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
index 2a5284f749b4..e80f3ebd3e2a 100644
--- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
+++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
@@ -503,7 +503,7 @@ int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id)
 {
 	int ret;
 
-	if (!addr_is_memory(addr))
+	if (!range_is_memory(addr, addr + size))
 		return -EPERM;
 
 	ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_mmu.pgt,
-- 
2.49.0.906.g1f30a19c02-goog



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked()
  2025-05-01 16:24 [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked() Mostafa Saleh
@ 2025-05-06  8:32 ` Marc Zyngier
  2025-05-06  9:22   ` Mostafa Saleh
  2025-05-07  7:56 ` Oliver Upton
  1 sibling, 1 reply; 4+ messages in thread
From: Marc Zyngier @ 2025-05-06  8:32 UTC (permalink / raw)
  To: Mostafa Saleh
  Cc: linux-kernel, kvmarm, linux-arm-kernel, oliver.upton, joey.gouly,
	suzuki.poulose, yuzenghui, catalin.marinas, will, qperret

On Thu, 01 May 2025 17:24:50 +0100,
Mostafa Saleh <smostafa@google.com> wrote:
> 
> I found this simple bug while preparing some patches for pKVM.
> AFAICT, it should be harmless (besides crashing the kernel if it
> was misbehaving)
> 
> Fixes: e94a7dea2972 ("KVM: arm64: Move host page ownership tracking to the hyp vmemmap")
> Signed-off-by: Mostafa Saleh <smostafa@google.com>
> ---
>  arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index 2a5284f749b4..e80f3ebd3e2a 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -503,7 +503,7 @@ int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id)
>  {
>  	int ret;
>  
> -	if (!addr_is_memory(addr))
> +	if (!range_is_memory(addr, addr + size))
>  		return -EPERM;
>  
>  	ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_mmu.pgt,

I vaguely seem to remember that there was an assumption around
addr/size representing a single page, and therefore addr_is_memory()
was doing the right thing.

Has this assumption changed? Or is this only a figment of my imagination?

Thanks,

	M.

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked()
  2025-05-06  8:32 ` Marc Zyngier
@ 2025-05-06  9:22   ` Mostafa Saleh
  0 siblings, 0 replies; 4+ messages in thread
From: Mostafa Saleh @ 2025-05-06  9:22 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-kernel, kvmarm, linux-arm-kernel, oliver.upton, joey.gouly,
	suzuki.poulose, yuzenghui, catalin.marinas, will, qperret

On Tue, May 06, 2025 at 09:32:22AM +0100, Marc Zyngier wrote:
> On Thu, 01 May 2025 17:24:50 +0100,
> Mostafa Saleh <smostafa@google.com> wrote:
> > 
> > I found this simple bug while preparing some patches for pKVM.
> > AFAICT, it should be harmless (besides crashing the kernel if it
> > was misbehaving)
> > 
> > Fixes: e94a7dea2972 ("KVM: arm64: Move host page ownership tracking to the hyp vmemmap")
> > Signed-off-by: Mostafa Saleh <smostafa@google.com>
> > ---
> >  arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > index 2a5284f749b4..e80f3ebd3e2a 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> > @@ -503,7 +503,7 @@ int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id)
> >  {
> >  	int ret;
> >  
> > -	if (!addr_is_memory(addr))
> > +	if (!range_is_memory(addr, addr + size))
> >  		return -EPERM;
> >  
> >  	ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_mmu.pgt,
> 
> I vaguely seem to remember that there was an assumption around
> addr/size representing a single page, and therefore addr_is_memory()
> was doing the right thing.
> 
> Has this assumption changed? Or is this only a figment of my imagination?

From what I see, this might have size exceeding page size in the
following cases:
1- When creating a VM with 4K kernel as the struct pkvm_hyp_vm size
   is at least 0x1130 (without vCPUs)
2- When creating a VM and PGD size is bigger than one page (for cases
   with concatenation as 52 bits and 4K would have 64K PGD)

Thanks,
Mostafa

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked()
  2025-05-01 16:24 [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked() Mostafa Saleh
  2025-05-06  8:32 ` Marc Zyngier
@ 2025-05-07  7:56 ` Oliver Upton
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Upton @ 2025-05-07  7:56 UTC (permalink / raw)
  To: linux-kernel, kvmarm, linux-arm-kernel, Mostafa Saleh
  Cc: Oliver Upton, maz, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, qperret

On Thu, 01 May 2025 16:24:50 +0000, Mostafa Saleh wrote:
> I found this simple bug while preparing some patches for pKVM.
> AFAICT, it should be harmless (besides crashing the kernel if it
> was misbehaving)
> 
> 

Applied to fixes, thanks!

[1/1] KVM: arm64: Fix memory check in host_stage2_set_owner_locked()
      https://git.kernel.org/kvmarm/kvmarm/c/3949e28786cd

--
Best,
Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-07  8:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-01 16:24 [PATCH] KVM: arm64: Fix memory check in host_stage2_set_owner_locked() Mostafa Saleh
2025-05-06  8:32 ` Marc Zyngier
2025-05-06  9:22   ` Mostafa Saleh
2025-05-07  7:56 ` Oliver Upton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).