[PATCH] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring
From: Priyanka Mani
Date: Fri Oct 09 2026 - 07:35:03 EST
test_mmio_during_vectoring() verifies that KVM reports the faulting GPA in
run->internal.data[3] when an emulated MMIO access occurs during event
vectoring. kvm_prepare_event_vectoring_exit() always fills five entries
(info2, reason, info1, gpa, last_vmentry_cpu), i.e. internal.ndata is 5.
The test, however, checks "ndata != 4" before dereferencing data[3]. That
predicate does not actually validate the array size: it passes for ndata ==
3, where data[3] is out of bounds yet is read just below, and it spuriously
fails if ndata were ever exactly 4. It only happens to work today because
KVM returns 5.
Assert the real expected size, ndata == 5, so that the subsequent data[3]
access is properly guarded and the test enforces the exit's contract.
Fixes: 62e41f6b4f36 ("KVM: selftests: Add test case for MMIO during vectoring on x86")
Signed-off-by: Priyanka Mani <priyankamani2100@xxxxxxxxx>
---
tools/testing/selftests/kvm/set_memory_region_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c
index dffe9654f45b..627ebc2ba024 100644
--- a/tools/testing/selftests/kvm/set_memory_region_test.c
+++ b/tools/testing/selftests/kvm/set_memory_region_test.c
@@ -606,7 +606,7 @@ static void test_mmio_during_vectoring(void)
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
TEST_ASSERT(run->internal.suberror == KVM_INTERNAL_ERROR_DELIVERY_EV,
"Unexpected suberror = %d", vcpu->run->internal.suberror);
- TEST_ASSERT(run->internal.ndata != 4, "Unexpected internal error data array size = %d",
+ TEST_ASSERT(run->internal.ndata == 5, "Unexpected internal error data array size = %d",
run->internal.ndata);
/* The reported GPA should be IDT base + offset of the GP vector */
--
2.43.0