From nobody Tue Apr 21 14:36:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776596651; cv=none; d=zohomail.com; s=zohoarc; b=PkAQmvq3YNsKt4e7m4bZjwPQamd6SJoS5Hpb4lF6mZpWGzXRC8V/u5BDwytoVXvPyygCiFrwhiGkbKAbzW4BlayrlCumg0QSSh6ctYW1UTdCwZ4+lbMrj5ALuwbDz5zPM610bLe/dw8U5bK8Hi15ibEk03Kamsb4O3r2LJH2YS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776596651; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=o8V6NT2glw/+GQHYipF/OBuuyIZO/jJlJfWL/hU7am8=; b=glE/IHEEwpLyr1wOXtw63TFXJTouXVeJLwtqL32dL5FVmLU1rD0o6z3rxUkaNVUEb+1N4x5wYAR9YDoPv+X+CWnoLnrNhov9d7LL5rfKTlRagakKQi1ilakzWeOnBztfXaGSreX+UDHSIzwlsf7ocvynDszoxL/KfLMLGiOK/PY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776596651729673.6207781129876; Sun, 19 Apr 2026 04:04:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wEPw1-0006gR-5M; Sun, 19 Apr 2026 07:03:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wEPvr-0006f9-GW for qemu-devel@nongnu.org; Sun, 19 Apr 2026 07:03:20 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wEPvo-0004yq-Uw for qemu-devel@nongnu.org; Sun, 19 Apr 2026 07:03:19 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2aaf59c4f7cso8823615ad.1 for ; Sun, 19 Apr 2026 04:03:16 -0700 (PDT) Received: from localhost.localdomain ([123.19.199.205]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5faa30134sm73517525ad.30.2026.04.19.04.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2026 04:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776596595; x=1777201395; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=o8V6NT2glw/+GQHYipF/OBuuyIZO/jJlJfWL/hU7am8=; b=Ckxnd7PAmGdVfoE0GbRQIBElPYttWrkCo+1AodrsXOVzN08T2/7wZ8duL3xCRHpShb x6N3HWFGoGITgcO6CXILMNByeoUFDEANpeoivkDbWahahUKN1oQdJp7ofX8q+K8h7zhM e87yoFBYj8R/fcDoRKaHQEJa7ueSpruqJRw4EeHcUsxwl+M1pewCKZ+00dxY59rCOPR0 SOyEpVP1v261wbkIz15nmGRFE0qf5WSZLG8Xiw8ZvW4iwFOSIaM55IU7Z/ai346ACw+B rmk0u2OE1deXVVZrkXiEbLQRTmDoQdqOTS2xzty2NuCJV2YY1jjxBFWRgweaM0QIrlob o3OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776596595; x=1777201395; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o8V6NT2glw/+GQHYipF/OBuuyIZO/jJlJfWL/hU7am8=; b=PVdfKzb6KmrpSjZNPuXRuJBpH4TgrTjrhVkrvgJPxkuc/edWawPXc8Mz55HW8LvGgL ZGkAJV1CaAPPZJ4FDod4Cig1DPQdxpMzr9IjOyL5DfxPMrJTy4X+bVjlmR0G8e8QyXeS FRg1g86yNkk6p3hqNp3SeGGjUSBDHLGmvXY6k4G6vSpLl19xlNeUvneiAMGC8naJs0Q/ V2Z3qRMTxrlTTR7A/6YLqNdLm7rexRo/znC7I4OOuwBxdzFrp9rRfqdxuVL715ww1Zvf wRtJdTH2WKQEo1tVVchxsbHKKZnsJv1hgoHbit2iq7fI1SPacreDfh2mH/7VXEKwq6aP nn6A== X-Gm-Message-State: AOJu0YxXwcBIoVU4Wd5rdVpCzK2gpYpYvgmKZucVUYtTM2LDp6I84pid hvNd1m8v1/XnELVV50ZeBfz46kJmv8+wHlhvGrzSdWzgkAybMpdec1oe98OeBkxa X-Gm-Gg: AeBDieucKHpWbUPwtH2gCOBR27FVx94bq7PAB+gVreP0LNiK55yxptcHtF8f60Yr604 qCTedIyecZwDEeIvt+AySPqhBASoHwug5/XpgOLDapOpZeALfCV+vSIJwf7B6ccbb+jdvCqkfod hcdRTQIF/Brfs7jo8zTsOQtfVKiLfsLhvdw/nKSMDxAodQuyZrHJTdtzDoyCghT3oKvTX1tKTgn u7By7hH5/0qyfCKZaQDH3K0MDlH7joVbGmZW55oXUIvwPNwqTOZJwZMxvyrgsZkF1KoFwGcYgSP IwTKkCbxLK4uCAGJeCNv7nN1/zsuYvR7nbfkSxmss4JaqXhzxkAT4yC8YedgzY81wj0hD3I+Jy6 VGKwiUKj2DCh1fW5ObqTbaruty7pj9M/NLQQ9txyzU32kEEM3GlW+6BcPm0htB9AUVoyOJOaQ1S Mzdj3BS/Q1Xp2eOtkjpNnRDjoKqrLrR7jJydXHqISwEW/4jO9M5ZbLTkgFWV4ghwMqsjcs X-Received: by 2002:a17:902:f652:b0:2b0:beb4:3bb with SMTP id d9443c01a7336-2b5f9e7f300mr97170915ad.10.1776596594922; Sun, 19 Apr 2026 04:03:14 -0700 (PDT) From: Trieu Huynh X-Google-Original-From: Trieu Huynh To: qemu-devel@nongnu.org Cc: Trieu Huynh , Peter Xu , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Subject: [PATCH] tests/qtest/migration: fix fd leak in ufd_version_check Date: Sun, 19 Apr 2026 18:03:04 +0700 Message-ID: <20260419110304.8661-1-viking4@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=vikingtc4@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776596653739158500 Content-Type: text/plain; charset="utf-8" From: Trieu Huynh 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 Reviewed-by: Peter Xu --- 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 =3D false; =20 int ufd =3D uffd_open(O_CLOEXEC); =20 @@ -355,7 +356,7 @@ bool ufd_version_check(bool *uffd_feature_thread_id) api_struct.features =3D 0; if (ioctl(ufd, UFFDIO_API, &api_struct)) { g_test_message("Skipping test: UFFDIO_API failed"); - return false; + goto release_ufd; } =20 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) !=3D ioctl_mask) { g_test_message("Skipping test: Missing userfault feature"); - return false; + goto release_ufd; } =20 - return true; + ret =3D true; +release_ufd: + close(ufd); + return ret; } #else bool ufd_version_check(bool *uffd_feature_thread_id) --=20 2.43.0