Skip to content

Commit 1702da7

Browse files
vdonnefortMarc Zyngier
authored andcommitted
KVM: arm64: Fix nVHE/pKVM hyp tracing error on invalid desc
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: 680a04c ("KVM: arm64: Add tracing capability for the nVHE/pKVM hyp") Link: https://lore.kernel.org/r/20260514162624.3477857-1-vdonnefort@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent f19c354 commit 1702da7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/arm64/kvm/hyp/nvhe/trace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,16 @@ static int hyp_trace_buffer_load(struct hyp_trace_buffer *trace_buffer,
164164
return ret;
165165
}
166166

167-
static bool hyp_trace_desc_validate(struct hyp_trace_desc *desc, size_t desc_size)
167+
static bool hyp_trace_desc_is_valid(struct hyp_trace_desc *desc, size_t desc_size)
168168
{
169169
struct ring_buffer_desc *rb_desc;
170170
unsigned int cpu;
171171
size_t nr_bpages;
172172
void *desc_end;
173173

174+
if (!is_protected_kvm_enabled())
175+
return true;
176+
174177
/*
175178
* Both desc_size and bpages_backing_size are untrusted host-provided
176179
* 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)
212215
if (ret)
213216
return ret;
214217

215-
if (!hyp_trace_desc_validate(desc, desc_size))
218+
if (!hyp_trace_desc_is_valid(desc, desc_size)) {
219+
ret = -EINVAL;
216220
goto err_release_desc;
221+
}
217222

218223
hyp_spin_lock(&trace_buffer.lock);
219224

0 commit comments

Comments
 (0)