Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc
@ 2026-05-14 16:26 Vincent Donnefort
  2026-05-15 10:21 ` Marc Zyngier
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Donnefort @ 2026-05-14 16:26 UTC (permalink / raw)
  To: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will
  Cc: linux-arm-kernel, kvmarm, kernel-team, Vincent Donnefort

pKVM must validate the host-provided tracing buffer descriptor.
However, if an error is found, the hypervisor would just return 0 to the
host. Fix the return value on validation failure.

While at it, rename the function to hyp_trace_desc_is_valid() and skip
validation for the nVHE mode as we trust host-provided data in that
case.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/arch/arm64/kvm/hyp/nvhe/trace.c b/arch/arm64/kvm/hyp/nvhe/trace.c
index a6ca27b18e15..e7e150ab265f 100644
--- a/arch/arm64/kvm/hyp/nvhe/trace.c
+++ b/arch/arm64/kvm/hyp/nvhe/trace.c
@@ -164,13 +164,16 @@ static int hyp_trace_buffer_load(struct hyp_trace_buffer *trace_buffer,
 	return ret;
 }
 
-static bool hyp_trace_desc_validate(struct hyp_trace_desc *desc, size_t desc_size)
+static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_size)
 {
 	struct ring_buffer_desc *rb_desc;
 	unsigned int cpu;
 	size_t nr_bpages;
 	void *desc_end;
 
+	if (!is_protected_kvm_enabled())
+		return true;
+
 	/*
 	 * Both desc_size and bpages_backing_size are untrusted host-provided
 	 * values. We rely on __pkvm_host_donate_hyp() to enforce their validity.
@@ -212,8 +215,10 @@ int __tracing_load(unsigned long desc_hva, size_t desc_size)
 	if (ret)
 		return ret;
 
-	if (!hyp_trace_desc_validate(desc, desc_size))
+	if (!hyp_trace_desc_is_valid(desc, desc_size)) {
+		ret = -EINVAL;
 		goto err_release_desc;
+	}
 
 	hyp_spin_lock(&trace_buffer.lock);
 

base-commit: 5d6919055dec134de3c40167a490f33c74c12581
-- 
2.54.0.563.g4f69b47b94-goog



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

* Re: [PATCH] KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc
  2026-05-14 16:26 [PATCH] KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc Vincent Donnefort
@ 2026-05-15 10:21 ` Marc Zyngier
  2026-05-15 12:58   ` Vincent Donnefort
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Zyngier @ 2026-05-15 10:21 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, linux-arm-kernel, kvmarm, kernel-team

On Thu, 14 May 2026 17:26:24 +0100,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> pKVM must validate the host-provided tracing buffer descriptor.
> However, if an error is found, the hypervisor would just return 0 to the
> host. Fix the return value on validation failure.
> 
> While at it, rename the function to hyp_trace_desc_is_valid() and skip
> validation for the nVHE mode as we trust host-provided data in that
> case.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

Fixes: tag? Should it be considered as a Cc: to stable?

	M.

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


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

* Re: [PATCH] KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc
  2026-05-15 10:21 ` Marc Zyngier
@ 2026-05-15 12:58   ` Vincent Donnefort
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Donnefort @ 2026-05-15 12:58 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: oliver.upton, joey.gouly, suzuki.poulose, yuzenghui,
	catalin.marinas, will, linux-arm-kernel, kvmarm, kernel-team

On Fri, May 15, 2026 at 11:21:15AM +0100, Marc Zyngier wrote:
> On Thu, 14 May 2026 17:26:24 +0100,
> Vincent Donnefort <vdonnefort@google.com> wrote:
> > 
> > pKVM must validate the host-provided tracing buffer descriptor.
> > However, if an error is found, the hypervisor would just return 0 to the
> > host. Fix the return value on validation failure.
> > 
> > While at it, rename the function to hyp_trace_desc_is_valid() and skip
> > validation for the nVHE mode as we trust host-provided data in that
> > case.
> > 
> > Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> Fixes: tag? Should it be considered as a Cc: to stable?
> 
> 	M.

Fixes: 680a04c333fa ("KVM: arm64: Add tracing capability for the nVHE/pKVM hyp")

It is only from 7.1 so no stable to fix.

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


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

end of thread, other threads:[~2026-05-15 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14 16:26 [PATCH] KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc Vincent Donnefort
2026-05-15 10:21 ` Marc Zyngier
2026-05-15 12:58   ` Vincent Donnefort

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox