linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems.
@ 2022-10-27 12:09 Ryan Roberts
  2022-10-27 14:52 ` Steven Price
  2022-10-27 18:52 ` Marc Zyngier
  0 siblings, 2 replies; 3+ messages in thread
From: Ryan Roberts @ 2022-10-27 12:09 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Ryan Roberts, Steven Price, James Morse, Alexandru Elisei,
	Suzuki K Poulose, Oliver Upton, Catalin Marinas, Will Deacon,
	linux-arm-kernel, kvmarm, kvmarm

enter_exception64() performs an MTE check, which involves dereferencing
vcpu->kvm. While vcpu has already been fixed up for hyp va, kvm is still
a kern va pointer.

Fix this by first converting kvm to a hyp va pointer. If the system does
not support MTE, the dereference is avoided in the first place.

Fixes: ea7fc1bb1cd1 ("KVM: arm64: Introduce MTE VM feature")

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 arch/arm64/kvm/hyp/exception.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
index b7557b25ed56..791d3de76771 100644
--- a/arch/arm64/kvm/hyp/exception.c
+++ b/arch/arm64/kvm/hyp/exception.c
@@ -13,6 +13,7 @@
 #include <hyp/adjust_pc.h>
 #include <linux/kvm_host.h>
 #include <asm/kvm_emulate.h>
+#include <asm/kvm_mmu.h>

 #if !defined (__KVM_NVHE_HYPERVISOR__) && !defined (__KVM_VHE_HYPERVISOR__)
 #error Hypervisor code only!
@@ -115,7 +116,7 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
 	new |= (old & PSR_C_BIT);
 	new |= (old & PSR_V_BIT);

-	if (kvm_has_mte(vcpu->kvm))
+	if (kvm_has_mte(kern_hyp_va(vcpu->kvm)))
 		new |= PSR_TCO_BIT;

 	new |= (old & PSR_DIT_BIT);
--
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems.
  2022-10-27 12:09 [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems Ryan Roberts
@ 2022-10-27 14:52 ` Steven Price
  2022-10-27 18:52 ` Marc Zyngier
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Price @ 2022-10-27 14:52 UTC (permalink / raw)
  To: Ryan Roberts, Marc Zyngier
  Cc: James Morse, Alexandru Elisei, Suzuki K Poulose, Oliver Upton,
	Catalin Marinas, Will Deacon, linux-arm-kernel, kvmarm, kvmarm

On 27/10/2022 13:09, Ryan Roberts wrote:
> enter_exception64() performs an MTE check, which involves dereferencing
> vcpu->kvm. While vcpu has already been fixed up for hyp va, kvm is still
> a kern va pointer.
> 
> Fix this by first converting kvm to a hyp va pointer. If the system does
> not support MTE, the dereference is avoided in the first place.
> 
> Fixes: ea7fc1bb1cd1 ("KVM: arm64: Introduce MTE VM feature")
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>

It's worth pointing out this only affects non-VHE mode, which is unusual
on hardware which supports MTE (and therefore VHE). But, of course,
about to get more usual with pKVM.

Reviewed-by: Steven Price <steven.price@arm.com>

> ---
>  arch/arm64/kvm/hyp/exception.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
> index b7557b25ed56..791d3de76771 100644
> --- a/arch/arm64/kvm/hyp/exception.c
> +++ b/arch/arm64/kvm/hyp/exception.c
> @@ -13,6 +13,7 @@
>  #include <hyp/adjust_pc.h>
>  #include <linux/kvm_host.h>
>  #include <asm/kvm_emulate.h>
> +#include <asm/kvm_mmu.h>
> 
>  #if !defined (__KVM_NVHE_HYPERVISOR__) && !defined (__KVM_VHE_HYPERVISOR__)
>  #error Hypervisor code only!
> @@ -115,7 +116,7 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
>  	new |= (old & PSR_C_BIT);
>  	new |= (old & PSR_V_BIT);
> 
> -	if (kvm_has_mte(vcpu->kvm))
> +	if (kvm_has_mte(kern_hyp_va(vcpu->kvm)))
>  		new |= PSR_TCO_BIT;
> 
>  	new |= (old & PSR_DIT_BIT);
> --
> 2.17.1
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems.
  2022-10-27 12:09 [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems Ryan Roberts
  2022-10-27 14:52 ` Steven Price
@ 2022-10-27 18:52 ` Marc Zyngier
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2022-10-27 18:52 UTC (permalink / raw)
  To: Ryan Roberts
  Cc: Steven Price, Catalin Marinas, kvmarm, linux-arm-kernel, kvmarm,
	Will Deacon

On Thu, 27 Oct 2022 13:09:45 +0100, Ryan Roberts wrote:
> enter_exception64() performs an MTE check, which involves dereferencing
> vcpu->kvm. While vcpu has already been fixed up for hyp va, kvm is still
> a kern va pointer.
> 
> Fix this by first converting kvm to a hyp va pointer. If the system does
> not support MTE, the dereference is avoided in the first place.
> 
> [...]

Applied to fixes with minor commit message fixes, thanks!

[1/1] KVM: arm64: Fix bad dereference on MTE-enabled systems.
      commit: b6bcdc9f6b8321e4471ff45413b6410e16762a8d

Cheers,

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



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-10-27 18:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-27 12:09 [PATCH v1] KVM: arm64: Fix bad dereference on MTE-enabled systems Ryan Roberts
2022-10-27 14:52 ` Steven Price
2022-10-27 18:52 ` Marc Zyngier

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).