mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring
@ 2026-10-09 11:30 Priyanka Mani
  2026-11-13 13:47 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Priyanka Mani @ 2026-10-09 11:30 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Shuah Khan, Ivan Orlov, kvm, linux-kselftest, linux-kernel

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@gmail.com>
---
 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


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

* Re: [PATCH] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring
  2026-10-09 11:30 [PATCH] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring Priyanka Mani
@ 2026-11-13 13:47 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-11-13 13:47 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Priyanka Mani
  Cc: Shuah Khan, Ivan Orlov, kvm, linux-kselftest, linux-kernel

On Fri, 09 Oct 2026 11:30:17 +0000, Priyanka Mani wrote:
> 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.
> 
> [...]

Applied to kvm-x86 selftests, thanks!

[1/1] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring
      https://github.com/kvm-x86/linux/commit/509f344f9480

--
https://github.com/kvm-x86/linux/tree/next

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

end of thread, other threads:[~2026-11-13 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 11:30 [PATCH] KVM: selftests: Fix ndata size check in test_mmio_during_vectoring Priyanka Mani
2026-11-13 13:47 ` Sean Christopherson

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

all inboxes | Powered by JetHome®