From nobody Tue Sep 9 03:11:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1749732749; cv=none; d=zohomail.com; s=zohoarc; b=YV3GO/z3m62Un8AXiZU6dUvJNynGb/d+AHoEnF+Kt7OTCEqHCap2Q3uO0vIoIwEZl0e7ceS883QLZQSAcZTfVtlrl2fUtnjQ8tfCrL8MCimL2yFhQmSf+nKRxKmyOyOBxJLhHBBaLPzuN7ALvALnFIj9REREVPtTiZKijQLaPvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732749; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=jdym9xEWUbwSQ6nMJWNX+3Lvc5fFEyJc932mbNw9NIE=; b=G0woNbb10wZo42N/1kmR4tOMuhLrhAMvKIb/P0rtd+5HUdEB2UNaPBYydcUNX6KocrtnMFCTPAoSPcDl5SJkaAX2zwAm6Ap9gP9miMBKY282m3Wuhtng8ghrbJxABFPaKQLsCiy18G8adqIT/uRWJvk7oH6PvmmgTSWM7oNKFfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1749732749450701.3911914552667; Thu, 12 Jun 2025 05:52:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7CCD8D44; Thu, 12 Jun 2025 08:52:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D2B1113B1; Thu, 12 Jun 2025 08:49:23 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EC57711B6; Thu, 12 Jun 2025 08:49:17 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A07D41300 for ; Thu, 12 Jun 2025 08:49:04 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-VrHQCFiHO7y7LPywaXfXcA-1; Thu, 12 Jun 2025 08:49:02 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 92D6B195608B for ; Thu, 12 Jun 2025 12:49:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C22B3195609D for ; Thu, 12 Jun 2025 12:49:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749732544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=97lZ4XG8WJj0wQEALiTF/hTCtGMe9MwNQQgFnN8ZwsE=; b=Fx8tYpjTKC/cI6iL8DMStvWUihw3b8cKaRJI7/OZdxp9DH93Esk1IuUsrrH7NYSPH9y+9k mkDMuZiQocYvwRFgS0j78W5LnMnSrjrLG0pg1Fsxg8zF0LkeQGyZyFCwMTidOso2Hcf3/g AjNRe+krSA8VCoRYKrsiLCLz7Dri0Xk= X-MC-Unique: VrHQCFiHO7y7LPywaXfXcA-1 X-Mimecast-MFC-AGG-ID: VrHQCFiHO7y7LPywaXfXcA_1749732541 To: devel@lists.libvirt.org Subject: [PATCH 09/15] virt-aa-helper: Rework USB hostdev handling Date: Thu, 12 Jun 2025 14:48:41 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VKKFCwYxupDOE7PyM_TMjj_gyepzXTN4fCu8EwTLI-g_1749732541 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5E4UWIIGCN5DN4263MSEBMKKGLZ6TESC X-Message-ID-Hash: 5E4UWIIGCN5DN4263MSEBMKKGLZ6TESC X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732750693116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik For an USB device, the virt-aa-helper must put that /dev/bus/usb/... path associated with given device. The way the code is currently written not only leads to a memleak (the @usb variable is allocated only to be overwritten right away), but is needlessly cumbersome. We can use virHostdevFindUSBDevice() to find the USB device, check if its missing and if not add the path associated with it into the profile. While at it, also use automatic memory freeing for the variable. Signed-off-by: Michal Privoznik --- src/security/virt-aa-helper.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index d4358ebf9c..a56d7e9062 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1040,24 +1040,21 @@ get_files(vahControl * ctl) for (i =3D 0; i < ctl->def->nhostdevs; i++) if (ctl->def->hostdevs[i]) { virDomainHostdevDef *dev =3D ctl->def->hostdevs[i]; - virDomainHostdevSubsysUSB *usbsrc =3D &dev->source.subsys.u.us= b; =20 if (dev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; =20 switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevice *usb =3D - virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL); - - if (usb =3D=3D NULL) - continue; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (virHostdevFindUSBDevice(dev, true, &usb) < 0) continue; =20 + if (dev->missing) + continue; + rc =3D virUSBDeviceFileIterate(usb, file_iterate_hostdev_c= b, &buf); - virUSBDeviceFree(usb); if (rc !=3D 0) goto cleanup; break; --=20 2.49.0