From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>, Shuah Khan <shuah@kernel.org>
Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Bibo Mao <maobibo@loongson.cn>,
Sean Christopherson <seanjc@google.com>,
Fuad Tabba <tabba@google.com>,
Ackerley Tng <ackerleytng@google.com>
Subject: [PATCH 1/2] KVM: selftests: Cast guest_memfd fd to a signed int when checking for >= 0
Date: Fri, 22 May 2026 10:15:34 -0700 [thread overview]
Message-ID: <20260522171535.3525890-2-seanjc@google.com> (raw)
In-Reply-To: <20260522171535.3525890-1-seanjc@google.com>
When conditionally closing a memory region's guest_memfd file descriptor,
cast the field to a signed it so that negative values are correctly
detected. Because selftests reuse "struct kvm_userspace_memory_region2"
instead of providing custom storage, they pick up the kernel uAPI's __u32
definition of the file descriptor, not the more common "int" definition,
e.g. that's used for userspace_mem_region.fd.
Fixes: bb2968ad6c33 ("KVM: selftests: Add support for creating private memslots")
Reported-by: Bibo Mao <maobibo@loongson.cn>
Closes: https://lore.kernel.org/all/20260508015013.4108345-1-maobibo@loongson.cn
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kvm/lib/kvm_util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index e08967ef7b7b..4ad015c6c44f 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -817,7 +817,7 @@ static void __vm_mem_region_delete(struct kvm_vm *vm,
kvm_munmap(region->mmap_alias, region->mmap_size);
close(region->fd);
}
- if (region->region.guest_memfd >= 0)
+ if ((int)region->region.guest_memfd >= 0)
close(region->region.guest_memfd);
free(region);
--
2.54.0.794.g4f17f83d09-goog
next prev parent reply other threads:[~2026-05-22 17:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 17:15 [PATCH 0/2] KVM: selftests: guest_memfd close() fix and hardening Sean Christopherson
2026-05-22 17:15 ` Sean Christopherson [this message]
2026-05-22 17:49 ` [PATCH 1/2] KVM: selftests: Cast guest_memfd fd to a signed int when checking for >= 0 Ackerley Tng
2026-05-25 3:00 ` Bibo Mao
2026-05-22 17:15 ` [PATCH 2/2] KVM: selftests: Add and use kvm_free_fd() to harden against fd goofs Sean Christopherson
2026-05-22 17:50 ` Ackerley Tng
2026-05-27 18:10 ` [PATCH 0/2] KVM: selftests: guest_memfd close() fix and hardening Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260522171535.3525890-2-seanjc@google.com \
--to=seanjc@google.com \
--cc=ackerleytng@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maobibo@loongson.cn \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
--cc=tabba@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox