* [PATCH] tests/qtest/migration: fix fd leak in ufd_version_check
@ 2026-04-19 11:03 Trieu Huynh
2026-04-20 19:57 ` Peter Xu
0 siblings, 1 reply; 2+ messages in thread
From: Trieu Huynh @ 2026-04-19 11:03 UTC (permalink / raw)
To: qemu-devel
Cc: Trieu Huynh, Peter Xu, Fabiano Rosas, Laurent Vivier,
Paolo Bonzini
From: Trieu Huynh <vikingtc4@gmail.com>
ufd_version_check() opens a userfaultfd via uffd_open() but never closes
it on any path where the open succeeded: the UFFDIO_API failure path,
the missing-ioctls path, and the success path all returned without
calling close(ufd).
Convert to a goto-out pattern consistent with uffd_open() used in
util/userfaultfd.c and migration/postcopy-ram.c, ensuring the fd is
always closed before returning.
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
tests/qtest/migration/migration-util.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tests/qtest/migration/migration-util.c b/tests/qtest/migration/migration-util.c
index 2648ad7f61..db66d8b24f 100644
--- a/tests/qtest/migration/migration-util.c
+++ b/tests/qtest/migration/migration-util.c
@@ -343,6 +343,7 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
{
struct uffdio_api api_struct;
uint64_t ioctl_mask;
+ bool ret = false;
int ufd = uffd_open(O_CLOEXEC);
@@ -355,7 +356,7 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
api_struct.features = 0;
if (ioctl(ufd, UFFDIO_API, &api_struct)) {
g_test_message("Skipping test: UFFDIO_API failed");
- return false;
+ goto release_ufd;
}
if (uffd_feature_thread_id) {
@@ -366,10 +367,13 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
1ULL << _UFFDIO_UNREGISTER);
if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
g_test_message("Skipping test: Missing userfault feature");
- return false;
+ goto release_ufd;
}
- return true;
+ ret = true;
+release_ufd:
+ close(ufd);
+ return ret;
}
#else
bool ufd_version_check(bool *uffd_feature_thread_id)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tests/qtest/migration: fix fd leak in ufd_version_check
2026-04-19 11:03 [PATCH] tests/qtest/migration: fix fd leak in ufd_version_check Trieu Huynh
@ 2026-04-20 19:57 ` Peter Xu
0 siblings, 0 replies; 2+ messages in thread
From: Peter Xu @ 2026-04-20 19:57 UTC (permalink / raw)
To: Trieu Huynh; +Cc: qemu-devel, Fabiano Rosas, Laurent Vivier, Paolo Bonzini
On Sun, Apr 19, 2026 at 06:03:04PM +0700, Trieu Huynh wrote:
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> ufd_version_check() opens a userfaultfd via uffd_open() but never closes
> it on any path where the open succeeded: the UFFDIO_API failure path,
> the missing-ioctls path, and the success path all returned without
> calling close(ufd).
>
> Convert to a goto-out pattern consistent with uffd_open() used in
> util/userfaultfd.c and migration/postcopy-ram.c, ensuring the fd is
> always closed before returning.
>
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
Thanks,
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-20 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 11:03 [PATCH] tests/qtest/migration: fix fd leak in ufd_version_check Trieu Huynh
2026-04-20 19:57 ` Peter Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.