[PATCH v2 13/13] KVM: selftests: Verify that reads to inaccessible guest_memfd VMAs SIGBUS

Sean Christopherson
2025-10-03T23:26:35Z

Expand the guest_memfd negative testcases for overflow and MAP_PRIVATE to
verify that reads to inaccessible memory also get a SIGBUS.

Opportunistically fix the write path to use the "val" instead of hardcoding
the literal value a second time, and to use TEST_FAIL(...) instead of
TEST_ASSERT(false, ...).

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/guest_memfd_test.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index f5372fdf096d..e7d9aeb418d3 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -84,6 +84,7 @@ static void test_fault_sigbus(int fd, size_t accessible_size, size_t map_size)
mem = kvm_mmap(map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd);

TEST_EXPECT_SIGBUS(memset(mem, val, map_size));
+ TEST_EXPECT_SIGBUS((void)READ_ONCE(mem[accessible_size]));

for (i = 0; i < accessible_size; i++)
TEST_ASSERT_EQ(READ_ONCE(mem[i]), val);
--
2.51.0.618.g983fd99d29-goog