From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <010701a110ca5e16-e0bfb332-8818-4308-8146-781f79e101dd-000000@eu-central-1.amazonses.com> Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11021117.outbound.protection.outlook.com [52.101.65.117]) by lore.virtuozzo.com (Postfix) with ESMTPS id C16878017D for ; Tue, 6 Oct 2026 10:37:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T8hGplErRY4Q0YIeq+ukJfmMWm/hSivGtDCCVxEbjtZvHWDbY1mfkQ2c54pzyuCQYvu8K1CLAcJxnoLS07Kujx1JUEjUrZICi5MzG8zunfvKyxhwUoNrUv1W11ZhAd7879ncS3o1Q+bGI2AvSidVQeRqu1q7OvB51y2xgRxtBeKmeZqJQ/gppuPXG6ct0ruLYh5JdCiXZ2K+3mxm/IOvCa4fb0J5/vldNdXLxOS9gphAtUKmxWv//5xQ7bKXqWQE8ZGdwz7v0DCh7ddyCmhsFY0stgOx7J/bOARNpEv5h5Fjjlp+sjDBwnfHkDk1AiNSzCg4x4qio1Y2ppRPsQ+okw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aR9AWuB268RhlFpVOZiadHV9+fR6uRvc9YhueZ9+pKQ=; b=WklB8gnWL2yXcHio1cZJh5T8xgs2diKbwcKj9e0hn4bOul9bb5ziZ1hU4pocv74RsheFAyqlGfUeWwAO33vpjiTZ9ZMltrWnt99LUx5aP+sLrmahjKLc/TiccIHAuJPcgFqI2wlf0Emh5evEPj6yJnainW8OP58Vva5+VpF7UK3GEuRg+HhyDK/CYP7GqxlGbWKffpU1PQdIyh+AipaUBGu7T6yKbBk8+t817C4eoNkwNpVFzQ7438+GyFLd+YaqAefmjKRUOpZekic9z9b+op+UpV6ZFVGN2a5iUoN5UVph9EQTz/dDJUymqunvOQpynYGb2jU7Xke6H06ePqNsNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 69.169.224.5) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=eu-central-1.amazonses.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=sashiko.virtuozzo.com; dkim=pass (signature was verified) header.d=sashiko.virtuozzo.com; dkim=pass (signature was verified) header.d=amazonses.com; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.onmicrosoft.com; s=selector2-virtuozzo-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aR9AWuB268RhlFpVOZiadHV9+fR6uRvc9YhueZ9+pKQ=; b=h8wH/A1+3rARnkUyrqIv9u5HQMWpSq1ipujoG/DXCPUU44dfSSXIp7rxfwS9kLeaH9xJLyKvw6Hi33+9eJO/+UaNgoEMgm4ac+13IQyQXkfLRQVsWE5ma4H4vF158CppINyMneFwE4OJD+oTvDCa4+7flUZRU6dKQ3v1ZnFUcGA= Received: from AS9PR07CA0017.eurprd07.prod.outlook.com (2603:10a6:20b:46c::13) by MIWPR08MB092276.eurprd08.prod.outlook.com (2603:10a6:290:d9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.14; Tue, 6 Oct 2026 10:37:40 +0000 Received: from AMS1EPF00000094.eurprd05.prod.outlook.com (2603:10a6:20b:46c:cafe::32) by AS9PR07CA0017.outlook.office365.com (2603:10a6:20b:46c::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.496.5 via Frontend Transport; Tue, 6 Oct 2026 10:37:40 +0000 Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 69.169.224.5) smtp.mailfrom=eu-central-1.amazonses.com; dkim=pass (signature was verified) header.d=sashiko.virtuozzo.com;dkim=pass (signature was verified) header.d=amazonses.com;dmarc=pass action=none header.from=sashiko.virtuozzo.com; Received-SPF: Pass (protection.outlook.com: domain of eu-central-1.amazonses.com designates 69.169.224.5 as permitted sender) receiver=protection.outlook.com; client-ip=69.169.224.5; helo=b224-5.smtp-out.eu-central-1.amazonses.com; pr=C Received: from b224-5.smtp-out.eu-central-1.amazonses.com (69.169.224.5) by AMS1EPF00000094.mail.protection.outlook.com (10.167.242.91) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.496.14 via Frontend Transport; Tue, 6 Oct 2026 10:37:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=23yjbh4k34hwzfubhuiim7m4inbd3ick; d=sashiko.virtuozzo.com; t=1791283060; h=From:Subject:To:Cc:In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date:Message-ID; bh=LllW91qwRY3Fm8it+KoIALLnLf2kYCPyiBSv9frZ5nM=; b=oacHQPJKdNNoqlTr4I29sRahO39U3+iLY1JLIKdJ946w54oZngSbcD7NCQAOrfF/ a0s8u08Tg4Yup4o16bzuDJD7bxBtr3lbKc4yt//DJqYd1m8MnKOVQiQMI4RIPCx/sdp UYKfOcK4jcFKXbNzAooJIcuBWm6dg46jD3M3Dv1xlBHHpIJRBKYbzVZKhEbHEkCCSVg 2JBJFEV3Oibe6B6xPoznYP8edaraCS0hjwfcB0UdvopouQpOdhojTf9i+NeW4heRIL2 cgU13WfcQ3EGbMKQzoAC2B+HZFwawqimoucho6w5PrEfC8gjHoCtUZgUaQ5oxlL6Mw9 vEgLzvbMwQ== DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=sokbgaaqhfgd6qjht2wmdajpuuanpimv; d=amazonses.com; t=1791283060; h=From:Subject:To:Cc:In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID; bh=LllW91qwRY3Fm8it+KoIALLnLf2kYCPyiBSv9frZ5nM=; b=PYubGxtr3XQcx26qRgdy7f9u4rDAJajFsn1c65UsMnXGHA1s54wHDW+auc3Rw903 y9T/VSSjrw5rTv/Ugp65BFoz/1uPtrz0k7mppiiBHE4FlhEsYsnB92QhQ78dIJowj2f K4CmJajxWarhL8a11sPrWs12rfrjT9q1YPQ8UJig= From: no-reply@sashiko.virtuozzo.com Subject: Re: [PATCH QEMU HCI-8.0 v6 01/12] usb-host: don't leak hostdev FD on open failure #VSTOR-137800 To: svt-core@virtuozzo.com, Andrey Drobyshev Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org In-Reply-To: <20261006-usb-host_v3-v6-1-8688ec9576d1@virtuozzo.com> References: <20261006-usb-host_v3-v6-0-8688ec9576d1@virtuozzo.com> <20261006-usb-host_v3-v6-1-8688ec9576d1@virtuozzo.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 6 Oct 2026 10:37:40 +0000 Message-ID: <010701a110ca5e16-e0bfb332-8818-4308-8146-781f79e101dd-000000@eu-central-1.amazonses.com> Feedback-ID: ::1.eu-central-1.2wRQJBpg9g1fGRYexx3dUuYGS25Bux+2TEOx72/m6U4=:AmazonSES X-SES-Outgoing: 2026.10.06-69.169.224.5 X-EOPAttributedMessage: 0 X-EOPTenantAttributedMessage: 0bc7f26d-0264-416e-a6fc-8352af79c58f:0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS1EPF00000094:EE_|MIWPR08MB092276:EE_ MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: c8dd238b-c5c7-4967-4f9e-08df2395d904 X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-MS-Exchange-AtpMessageProperties: SA List-Id: svt-core@virtuozzo.com X-MS-Exchange-Transport-Rules-Loop: 1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|704161411799003|376014|48200799018|32142699015|9140799003|61400799027|16102099003|18002099003|22082099003|55112099003|56012099006|5113699003|4113699003|4143699003|5063699009|10067099003; X-Microsoft-Antispam-Message-Info: 9kixPycwd6fV76W6pixRYu3TiKdDauAqHf0AqZtjo9tqsw5CLSRBZma2zt+cxhT5+FA7eizIKomLld1GfflQQHCDDA1T2BJrGXPskPCr/Wq2KC5+FXFtbe6Dw3WNZqbiOYAvWC5i8ac9F4FKyJpXcq913KQ06oMBMyq3peG3+uKXlf61Fr/MXAznYvZDpMkajTNToI/slWGQlo68nIDKDOO/7Wy2E5ysSIih3Z5KQHcmmVjrgpBsbJsrXW+6VRFtTBgULKJMF1qIYEkX9L1Ii9g+Pm5RB0ZdLWTKY1RZC18/2fvKj/rA1znIDbyDJUFwY3khRKxEoOp4vbvz5LVp6DHkPcCabEjb53Vq/yMk+T5dFd+UhTaSQeaV/V8UTclqvpvHPpZJCzA3hFza7B2txhWqxp8lTo0dobJzJJM54G95mjLBSbNzAXj8kEQJ/iGLwKrRW8wEu8LipRLRxqQCedfYM+p6yy0ALfC3KtX6tLPvhHmnrbfTBW1bApdhYaYKG92elmqmoTNkLjIjrk7O87KJQsCZ+O6j3dzSSpZe/7dm0NixTV3fgL1lbnslct57wTK3ASfmfTYYq0OAC3N9MnjLjgbFu3gakj4jOn221bKiF0QQe+Q/Htb1uPqbVBrcaREPp6IFjSXcsCsTW4cEC+OAcl2HUMZuzczEZwG0Nr/42cDAD/fOGVt9kJyScT4WgRayAitnp03WKT1wQTRHRatnKwZed1BCXl9/AqtWRB9fcon2j6vqMwjF64QFxeSeSL2kIcNgEIgcWcENqEkmt5bJQ/rQx36QlfLq+jYx8TU= X-Forefront-Antispam-Report: CIP:69.169.224.5;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:b224-5.smtp-out.eu-central-1.amazonses.com;PTR:b224-5.smtp-out.eu-central-1.amazonses.com;CAT:NONE;SFS:(13230040)(704161411799003)(376014)(48200799018)(32142699015)(9140799003)(61400799027)(16102099003)(18002099003)(22082099003)(55112099003)(56012099006)(5113699003)(4113699003)(4143699003)(5063699009)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vpMSk1GgXcjg0qhCcjVy+oOa7cno3lRbShfLqPXUSSevh7LrIjLnk8kTd/tdqdkwNQcT0qy95SKYpv7L6CfG0mFaIn6RsVf+8K+Oz3NVV3ETIA2rR5sV9oggyJffcWOiPoY73Wi1nhgGz2n+3WSX6M7/iOfwXmFM4d6N5ty5c96hite3ZBmCLMLYgYmB8D6MC+VpDpnZNdkQXsVSfUW6m0hNJL1VlDoq1lmWT+waIZwhGszSvVeZjQ0Uq8RcLgjxST8pJbrqzsijxxNDjRmo6kJ/qF8XFQA7rtbO+Zk6iysjr+iaVXbw5EeBz/zCIGNgll8PW4k7wq5V6Wi6XcM+ycAr5A03/YWjDIS7iLj+1ywSNwhnN7cgElyWMHgrxzgbkJ5b51uuYBabSBYjfhvTKR5401Fxao8k/nwMmk4XTVmiF08NDK4Yj2TIJ14SSLAd X-ExternalRecipientOutboundConnectors: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2026 10:37:40.7264 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8dd238b-c5c7-4967-4f9e-08df2395d904 X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-AuthSource: AMS1EPF00000094.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-Transport-CrossTenantHeadersStamped: MIWPR08MB092276 Thank you for your contribution! Sashiko AI review found 1 potential issue(= s) to consider: - [Medium] usb-host: usb_host_open() stores hostfd before early checks that= skip the new close -- commit 0fc31623dd0ee74837ec2c01d3f3ced2e30b7f95 Author: Andrey Drobyshev usb-host: don't leak hostdev FD on open failure #VSTOR-137800 This patch stores the caller-supplied hostfd in s->hostfd at the top of usb_host_open() when no libusb_device is given. It also closes s->hostfd on the fail: path, so the FD is released when libusb_wrap_sys_device() or a later open step fails. > diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c > index b74670ae25696..83645fbe0ced0 100644 > --- a/hw/usb/host-libusb.c > +++ b/hw/usb/host-libusb.c > @@ -954,6 +954,11 @@ static int usb_host_open(USBHostDevice *s, libusb_de= vice *dev, int hostfd) > int rc; > Error *local_err =3D NULL; > =20 > + /* Make sure failure path frees caller-owned FD */ > + if (!dev) { > + s->hostfd =3D hostfd; > + } > + > if (s->bh_postld_pending) { > return -1; > } > if (s->dh !=3D NULL) { > goto fail; > } [Severity: Medium] Can this leak the FD when usb_host_open() returns early? The store of s->hostfd happens before the bh_postld_pending check: if (!dev) { s->hostfd =3D hostfd; } if (s->bh_postld_pending) { return -1; } That early return bypasses the fail: label and its new close(s->hostfd) block. The caller-owned FD is then neither closed nor released, and s->hostfd keeps holding it. usb_host_realize() does not close the FD either. It only calls error_setg() and returns: rc =3D usb_host_open(s, NULL, fd); if (rc < 0) { error_setg(errp, "failed to open host usb device %s", s->hostdevice= ); return; } The s->dh !=3D NULL case has a related problem. It does jump to fail:, but s->hostfd has already been overwritten. The FD that s->hostfd previously owned is lost, and the new caller's FD is closed instead. Today the only caller that passes a real FD is usb_host_realize(). There s->hostfd starts at -1 and s->dh is NULL, so both early exits look unreachable and the problem is latent. I also checked the end of the series. The store is still placed before the bh_postld_pending check, so a later patch does not fix this. Would it be better to assign s->hostfd only after those two early checks? Alternatively, the early checks could be routed through the fail: path in a way that does not clobber an FD that is already owned. > @@ -978,7 +983,6 @@ static int usb_host_open(USBHostDevice *s, libusb_dev= ice *dev, int hostfd) > if (rc !=3D 0) { > goto fail; > } > - s->hostfd =3D hostfd; > dev =3D libusb_get_device(s->dh); [ ... ] > @@ -1066,6 +1070,10 @@ fail: > s->dh =3D NULL; > s->dev =3D NULL; > } > + if (s->hostfd !=3D -1) { > + close(s->hostfd); > + s->hostfd =3D -1; > + } > return -1; > } --=20 Sashiko AI review =C2=B7 https://sashiko.vzint.dev/#/patchset/20261006-usb-= host_v3-v6-0-8688ec9576d1@virtuozzo.com?part=3D1