From nobody Sat Feb 7 11:05:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764938; cv=none; d=zohomail.com; s=zohoarc; b=Az5EsdrgKcANS1kQubeFZWReb+1pq8uFU+lAyRNdoBTcMJ36MsfiHM8JccrkPKOYV04UleJB/MGbP8OLKyF+A6RXmB4pnj/gcVBu8WD4tXJONXH68m7lLSPAXBhKI2ngQ8NeG5KO9xQ/oVgwh9Z9E/Hnl+yBKFx+bb3zjXNEQu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764938; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ExHhpnQXdnlWzeq1Ys3fUvyqcnqysdfF/JXQQMPG6+8=; b=MCWHf3RGP+LsZVD/Yljl9N/uqXOdRRc/8diqQjsj0iTZtFZmbzTmTHvz1T9x6Lf+qTnemJ421uWQZDpNvmACxkax0r2xRlQcpG7OqbSbcQ0hAgBbLiY9WaXMt6tGYGYuHZpAXQv/zZZju/qPcwURWXP9k+/wAOlX/P9oTG1sEFw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764938681489.21260110577396; Mon, 4 Jan 2021 04:55:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-bUiG3vRPPdSVOijU4OTOAA-1; Mon, 04 Jan 2021 07:55:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 743A5190A7A3; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F05271C80; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 198DF1809CAD; Mon, 4 Jan 2021 12:55:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtGZY014216 for ; Mon, 4 Jan 2021 07:55:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 89BCD2166B2A; Mon, 4 Jan 2021 12:55:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 841932166B2C for ; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEBB7101A561 for ; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-n5_TkPR4PraurU16u4lxnw-1; Mon, 04 Jan 2021 07:55:13 -0500 Received: by mail-qt1-f181.google.com with SMTP id y15so18324515qtv.5 for ; Mon, 04 Jan 2021 04:55:13 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:12 -0800 (PST) X-MC-Unique: bUiG3vRPPdSVOijU4OTOAA-1 X-MC-Unique: n5_TkPR4PraurU16u4lxnw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ExHhpnQXdnlWzeq1Ys3fUvyqcnqysdfF/JXQQMPG6+8=; b=RNgKZ5xgcS5SXu7DNlM/5RlxIB9a45+kZdr0f4x8x35LkrkZPpYB8phyfWOuf5SEbV 5sQRibmzGMq4kcYRQNMai67fbux0+M0BjzoiO9IEluPVYaF7aqi3LbcS2ziazG9tAnjd o98hnjwxCdbvu0MCULUCWYLKACEHvRbarTMytBKJruiIsJ1DSUPT+6YlZTc/r/4y5pb+ Hn1nFhpLlWVk5dl3QSoV8YXFYeg4eQRy+0nP3WhdkjW4+t/9v9gWQ9fEOWd/ttxjeI6J gy7al1Nl0yqax7TOZzTmUu5MeYP4g0PNqPyLCkaiTkygNa1yzFVGfK/K7ySrnWoMERBJ xvmQ== X-Gm-Message-State: AOAM531kLw5WfFZ7oiAGVCRgyCVfUcieYMIFFeJTGFtluBqo148DsYGW xwkPi/T7tUL2SmZ0LsFBAr2nu/SgmCEDrw== X-Google-Smtp-Source: ABdhPJxd8kovmlkXZt8LTJA4IetnZ5u55ByPq0vmwRoyyCCc9f4veT/Q0vYOrwq6uymT4V690b4ZUw== X-Received: by 2002:a05:622a:301:: with SMTP id q1mr69655741qtw.237.1609764912877; Mon, 04 Jan 2021 04:55:12 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 09/20] dac, selinux: skip setting/restoring label for absent PCI devices Date: Mon, 4 Jan 2021 09:54:33 -0300 Message-Id: <20210104125444.200536-10-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the underlying PCI device of a hostdev does not exist in the host (e.g. a SR-IOV VF that was removed while the domain was running), skip security label handling for it. This will avoid errors that happens during qemuProcessStop() time, where a VF that was being used by the domain is not present anymore. The restore label functions of both DAC and SELinux drivers will trigger errors in virPCIDeviceNew(). Signed-off-by: Daniel Henrique Barboza --- src/security/security_dac.c | 14 ++++++++++++-- src/security/security_selinux.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 0085982bb1..a2528aeb2d 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1266,7 +1266,12 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr = mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -1422,7 +1427,12 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager= Ptr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index bf53932ccc..cf4984d8b1 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2102,7 +2102,12 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityM= anagerPtr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -2330,7 +2335,12 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecur= ityManagerPtr mgr, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci =3D virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; --=20 2.26.2