* [PATCH gmem FIXUP] selftests/kvm: guestmem: check fstat results on guestmem fd
@ 2023-10-12 14:07 Paolo Bonzini
2023-10-18 14:36 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2023-10-12 14:07 UTC (permalink / raw)
To: linux-kernel, kvm; +Cc: seanjc
Do a basic sanity cheeck for the st_size and st_ino fields of
a guestmem file descriptor. The test would fail for example
if guestmem.c used the innocuous-sounding function
anon_inode_getfile() instead of the correct one,
anon_inode_getfile_secure().
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
.../testing/selftests/kvm/guest_memfd_test.c | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index 75073645aaa1..9805b0f8f26a 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -91,6 +91,31 @@ static void test_fallocate(int fd, size_t page_size, size_t total_size)
TEST_ASSERT(!ret, "fallocate to restore punched hole should succeed");
}
+static void test_create_guest_memfd_multiple(struct kvm_vm *vm)
+{
+ int fd1, fd2, ret;
+ struct stat st1, st2;
+
+ fd1 = __vm_create_guest_memfd(vm, 4096, 0);
+ TEST_ASSERT(fd1 != -1, "memfd creation should succeed");
+
+ ret = fstat(fd1, &st1);
+ TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ TEST_ASSERT(st1.st_size == 4096, "memfd st_size should match requested size");
+
+ fd2 = __vm_create_guest_memfd(vm, 8192, 0);
+ TEST_ASSERT(fd2 != -1, "memfd creation should succeed");
+
+ ret = fstat(fd2, &st2);
+ TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ TEST_ASSERT(st2.st_size == 8192, "second memfd st_size should match requested size");
+
+ ret = fstat(fd1, &st1);
+ TEST_ASSERT(ret != -1, "memfd fstat should succeed");
+ TEST_ASSERT(st1.st_size == 4096, "first memfd st_size should still match requested size");
+ TEST_ASSERT(st1.st_ino != st2.st_ino, "different memfd should have different inode numbers");
+}
+
static void test_create_guest_memfd_invalid(struct kvm_vm *vm)
{
uint64_t valid_flags = 0;
@@ -153,6 +178,7 @@ int main(int argc, char *argv[])
vm = vm_create_barebones();
test_create_guest_memfd_invalid(vm);
+ test_create_guest_memfd_multiple(vm);
fd = vm_create_guest_memfd(vm, total_size, 0);
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH gmem FIXUP] selftests/kvm: guestmem: check fstat results on guestmem fd
2023-10-12 14:07 [PATCH gmem FIXUP] selftests/kvm: guestmem: check fstat results on guestmem fd Paolo Bonzini
@ 2023-10-18 14:36 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2023-10-18 14:36 UTC (permalink / raw)
To: Sean Christopherson, linux-kernel, kvm, Paolo Bonzini
On Thu, 12 Oct 2023 10:07:15 -0400, Paolo Bonzini wrote:
> Do a basic sanity cheeck for the st_size and st_ino fields of
> a guestmem file descriptor. The test would fail for example
> if guestmem.c used the innocuous-sounding function
> anon_inode_getfile() instead of the correct one,
> anon_inode_getfile_secure().
>
>
> [...]
Applied to kvm-x86 guest_memfd, thanks!
[1/1] selftests/kvm: guestmem: check fstat results on guestmem fd
https://github.com/kvm-x86/linux/commit/911b515af3ec
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-18 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 14:07 [PATCH gmem FIXUP] selftests/kvm: guestmem: check fstat results on guestmem fd Paolo Bonzini
2023-10-18 14:36 ` 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®