From nobody Tue Mar 3 04:55:51 2026 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=1772457530; cv=none; d=zohomail.com; s=zohoarc; b=XKjrKDchuD0GUyp1QcrQoHpi85Dokqi3tHPoxZMyi5GkAWvzeaLpgWPDSYjXsTpqlMWmOMOrmXUhJbF3dO0FA0fRSyym9fOFYiPAZErTjqrVY6S+c2eUZrXoSL0v/MgoUS54d6H2QRbTNd577GDndjkTfo76Hzxd6GftPbsh3ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772457530; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner: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=zOj3odxGxkGxd7GlyzQ5+fUN7Au+MxdgyuFeBcUoKvg=; b=DdBeC5FaT0G3GluB2E7005Jj3I0h/RKJVQa9lfSjRlM3jD0ZqCz8FdQu1YGwWVg45MRhwQx9RbK3kMYfkmHp+O8VynCKwtDi5CFq9VwnMV/hBKcsM5eXjIDnb0tx3czUCav4BG01OvVbOt4A/Dcyd2xXCuBYV3bnQFuZThJW0+4= 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 1772457530806208.95562693344652; Mon, 2 Mar 2026 05:18:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id EEF6B417CE; Mon, 2 Mar 2026 08:18:49 -0500 (EST) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id AD4E441CF3; Mon, 2 Mar 2026 08:15:19 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id CF01D41C99; Mon, 2 Mar 2026 08:15:14 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B29EC41935 for ; Mon, 2 Mar 2026 08:15:06 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-KpSZhVchPSOr0pzK9nLpoA-1; Mon, 02 Mar 2026 08:15:04 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 05CD918002EB for ; Mon, 2 Mar 2026 13:15:04 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.44.33.137]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 530D71800576 for ; Mon, 2 Mar 2026 13:15:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772457306; 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=zOj3odxGxkGxd7GlyzQ5+fUN7Au+MxdgyuFeBcUoKvg=; b=eSFlQVUxzXKW0ViGIqgi0tW+bM6oTHdTRNHW8bUUYu3KBAFBC3spR1R2K9HDJ3yOI4T9bX ofQIM8ENuODV6Q9Z2VAPsHB09GskQSpur+yQ7TtpDC/fH4yknhSddyL2Xs4OuJkrwTRgmJ mQJc782V9u9oiu1A8XpSw1RRCK8tPp8= X-MC-Unique: KpSZhVchPSOr0pzK9nLpoA-1 X-Mimecast-MFC-AGG-ID: KpSZhVchPSOr0pzK9nLpoA_1772457304 To: devel@lists.libvirt.org Subject: [libvirt PATCH 3/3] qemu: Fix IOMMUFD and VFIO security labels Date: Mon, 2 Mar 2026 14:14:58 +0100 Message-ID: <27a6674893d7f8e1c499d2d09e722d1c117fd8b6.1772457270.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4ufLsVPvZ-CffIx2wNdQGSlaGOzdiLlMBuwAk3W2TU4_1772457304 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CAVPCDWRA4XD5Y3H6KOIKYATRVBV26C4 X-Message-ID-Hash: CAVPCDWRA4XD5Y3H6KOIKYATRVBV26C4 X-MailFrom: phrdina@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Pavel Hrdina via Devel Reply-To: Pavel Hrdina X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1772457531107158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Pavel Hrdina When IOMMUFD support was introduced it incorrectly tried to lable `/dev/iommu` and `/dev/vfio/devices/vfioX` but they are not added to QEMU namespace because libvirt opens FDs and passes these FDs to QEMU. We need to label these FDs instead. Fixes: 7d2f91f9cb572ab95d0916bdd1a46dd198874529 Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 16 ++++++++++++---- src/qemu/qemu_process.h | 3 ++- src/security/security_apparmor.c | 12 ------------ src/security/security_dac.c | 27 --------------------------- src/security/security_selinux.c | 23 ----------------------- 6 files changed, 15 insertions(+), 68 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 40489b84db..b3f2a173a8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1613,7 +1613,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, } =20 if (virHostdevIsPCIDeviceWithIOMMUFD(hostdev)) { - if (qemuProcessOpenVfioDeviceFd(hostdev) < 0) + if (qemuProcessOpenVfioDeviceFd(vm, hostdev) < 0) goto error; =20 if (!priv->iommufdState) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a82ee4b15e..ab7cf03c0e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7728,13 +7728,16 @@ int qemuProcessOpenIommuFd(virDomainObj *vm) { qemuDomainObjPrivate *priv =3D vm->privateData; - int iommufd; + VIR_AUTOCLOSE iommufd =3D -1; =20 VIR_DEBUG("Opening IOMMU FD for domain %s", vm->def->name); =20 if ((iommufd =3D virIOMMUFDOpenDevice()) < 0) return -1; =20 + if (qemuSecuritySetImageFDLabel(priv->driver->securityManager, vm->def= , iommufd) < 0) + return -1; + priv->iommufd =3D qemuFDPassDirectNew("iommufd", &iommufd); =20 return 0; @@ -7749,16 +7752,21 @@ qemuProcessOpenIommuFd(virDomainObj *vm) * Returns: 0 on success, -1 on failure */ int -qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *hostdev) +qemuProcessOpenVfioDeviceFd(virDomainObj *vm, + virDomainHostdevDef *hostdev) { + qemuDomainObjPrivate *priv =3D vm->privateData; qemuDomainHostdevPrivate *hostdevPriv =3D QEMU_DOMAIN_HOSTDEV_PRIVATE(= hostdev); virDomainHostdevSubsysPCI *pci =3D &hostdev->source.subsys.u.pci; g_autofree char *name =3D g_strdup_printf("hostdev-%s-fd", hostdev->in= fo->alias); - int vfioDeviceFd; + VIR_AUTOCLOSE vfioDeviceFd =3D -1; =20 if ((vfioDeviceFd =3D virPCIDeviceOpenVfioFd(&pci->addr)) < 0) return -1; =20 + if (qemuSecuritySetImageFDLabel(priv->driver->securityManager, vm->def= , vfioDeviceFd) < 0) + return -1; + hostdevPriv->vfioDeviceFd =3D qemuFDPassDirectNew(name, &vfioDeviceFd); =20 return 0; @@ -7776,7 +7784,7 @@ qemuProcessPrepareHostHostdev(virDomainObj *vm) case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (virHostdevIsPCIDeviceWithIOMMUFD(hostdev)) { /* Open VFIO device FD */ - if (qemuProcessOpenVfioDeviceFd(hostdev) < 0) + if (qemuProcessOpenVfioDeviceFd(vm, hostdev) < 0) return -1; } break; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index fccd41e1a6..5874214596 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -136,7 +136,8 @@ int qemuProcessPrepareHostBackendChardevHotplug(virDoma= inObj *vm, =20 int qemuProcessOpenIommuFd(virDomainObj *vm); =20 -int qemuProcessOpenVfioDeviceFd(virDomainHostdevDef *hostdev); +int qemuProcessOpenVfioDeviceFd(virDomainObj *vm, + virDomainHostdevDef *hostdev); =20 int qemuProcessPrepareHost(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 1c3496893c..40f13ec1a5 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -45,7 +45,6 @@ #include "virstring.h" #include "virscsi.h" #include "virmdev.h" -#include "viriommufd.h" =20 #define VIR_FROM_THIS VIR_FROM_SECURITY =20 @@ -856,17 +855,6 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mg= r, =20 if (AppArmorSetSecurityPCILabel(pci, vfioGroupDev, ptr) < = 0) return -1; - } else { - g_autofree char *vfiofdDev =3D NULL; - - if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) - return -1; - - if (AppArmorSetSecurityPCILabel(pci, vfiofdDev, ptr) < 0) - return -1; - - if (AppArmorSetSecurityPCILabel(pci, VIR_IOMMU_DEV_PATH, p= tr) < 0) - return -1; } } else { if (virPCIDeviceFileIterate(pci, AppArmorSetSecurityPCILabel, = ptr) < 0) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index dc6dac0fb1..5aa13741e6 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -41,7 +41,6 @@ #include "virscsivhost.h" #include "virstring.h" #include "virutil.h" -#include "viriommufd.h" =20 #define VIR_FROM_THIS VIR_FROM_SECURITY =20 @@ -1295,17 +1294,6 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mg= r, &cbdata) < 0) { return -1; } - } else { - g_autofree char *vfiofdDev =3D NULL; - - if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) - return -1; - - if (virSecurityDACSetHostdevLabelHelper(vfiofdDev, false, = &cbdata) < 0) - return -1; - - if (virSecurityDACSetHostdevLabelHelper(VIR_IOMMU_DEV_PATH= , false, &cbdata) < 0) - return -1; } } else { if (virPCIDeviceFileIterate(pci, @@ -1476,21 +1464,6 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager= *mgr, vfioGroupDev, f= alse) < 0) { return -1; } - } else { - g_autofree char *vfiofdDev =3D NULL; - - if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) - return -1; - - if (virSecurityDACRestoreFileLabelInternal(mgr, NULL, - vfiofdDev, fals= e) < 0) { - return -1; - } - - if (virSecurityDACRestoreFileLabelInternal(mgr, NULL, - VIR_IOMMU_DEV_P= ATH, false) < 0) { - return -1; - } } } else { if (virPCIDeviceFileIterate(pci, virSecurityDACRestorePCILabel= , mgr) < 0) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 94a796ec49..89546e3316 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -41,7 +41,6 @@ #include "virconf.h" #include "virtpm.h" #include "virstring.h" -#include "viriommufd.h" =20 #define VIR_FROM_THIS VIR_FROM_SECURITY =20 @@ -2267,17 +2266,6 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityM= anager *mgr, &data) < 0) { return -1; } - } else { - g_autofree char *vfiofdDev =3D NULL; - - if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) - return -1; - - if (virSecuritySELinuxSetHostdevLabelHelper(vfiofdDev, fal= se, &data) < 0) - return -1; - - if (virSecuritySELinuxSetHostdevLabelHelper(VIR_IOMMU_DEV_= PATH, false, &data) < 0) - return -1; } } else { if (virPCIDeviceFileIterate(pci, virSecuritySELinuxSetPCILabel= , &data) < 0) @@ -2519,17 +2507,6 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecur= ityManager *mgr, =20 if (virSecuritySELinuxRestoreFileLabel(mgr, vfioGroupDev, = false, false) < 0) return -1; - } else { - g_autofree char *vfiofdDev =3D NULL; - - if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) - return -1; - - if (virSecuritySELinuxRestoreFileLabel(mgr, vfiofdDev, fal= se, false) < 0) - return -1; - - if (virSecuritySELinuxRestoreFileLabel(mgr, VIR_IOMMU_DEV_= PATH, false, false) < 0) - return -1; } } else { if (virPCIDeviceFileIterate(pci, virSecuritySELinuxRestorePCIL= abel, mgr) < 0) --=20 2.53.0