From nobody Wed May 15 04:16:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533743178981282.4766617388284; Wed, 8 Aug 2018 08:46:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B1094DB00; Wed, 8 Aug 2018 15:46:16 +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 0D181308BDB5; Wed, 8 Aug 2018 15:46:16 +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 5390218037EF; Wed, 8 Aug 2018 15:46:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w78FkE8p014824 for ; Wed, 8 Aug 2018 11:46:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1710D10EE797; Wed, 8 Aug 2018 15:46:14 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CCE710EE95F; Wed, 8 Aug 2018 15:46:11 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 8 Aug 2018 16:46:09 +0100 Message-Id: <20180808154609.24032-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] network: restrict usage of port management APIs 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 08 Aug 2018 15:46:17 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 The port allocation APIs are currently called unconditionally for all types of NIC, but (mostly) only do anything for NICs with type=3Dnetwork. The exception is the port allocate API which does some validation even for NICs with type!=3Dnetwork. Relying on this validation is flawed, however, since the network driver may not even be installed, so virt drivers must not delegation validation to it for NICs with type!=3Dnetwork. This change allows us to report errors when the virtual network driver is not registered. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 12 +++++------- src/libxl/libxl_domain.c | 6 ++++-- src/libxl/libxl_driver.c | 9 ++++++--- src/lxc/lxc_driver.c | 6 ++++-- src/lxc/lxc_process.c | 10 ++++++++-- src/network/bridge_driver.c | 22 +++++++++++++++------- src/qemu/qemu_hotplug.c | 17 +++++++++++------ src/qemu/qemu_process.c | 9 ++++++--- 8 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index adcd8f41b9..e7d2acdcc9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29947,13 +29947,11 @@ int virDomainNetAllocateActualDevice(virDomainDefPtr dom, virDomainNetDefPtr iface) { - /* Just silently ignore if network driver isn't present. If something - * has tried to use a NIC with type=3Dnetwork, other code will already - * cause an error. This ensures type=3Dbridge doesn't break when - * network driver is compiled out. - */ - if (!netAllocate) - return 0; + if (!netAllocate) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Virtual networking driver is not available")); + return -1; + } =20 return netAllocate(dom, iface); } diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 2ab78ac9a5..c78d5ee96c 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -791,7 +791,8 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, =20 /* cleanup actual device */ virDomainNetRemoveHostdev(vm->def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } } =20 @@ -948,7 +949,8 @@ libxlNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) return -1; =20 actualType =3D virDomainNetGetActualType(net); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5a5e792957..fb5f046ade 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3264,7 +3264,8 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driv= er, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -3314,7 +3315,8 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driv= er, vm->def->nets[vm->def->nnets++] =3D net; } else { virDomainNetRemoveHostdev(vm->def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } virObjectUnref(cfg); return ret; @@ -3737,7 +3739,8 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driv= er, cleanup: libxl_device_nic_dispose(&nic); if (!ret) { - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); } virObjectUnref(cfg); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8867645cdc..8729fc0174 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3871,7 +3871,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) return -1; =20 actualType =3D virDomainNetGetActualType(net); @@ -4425,7 +4426,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm, ret =3D 0; cleanup: if (!ret) { - virDomainNetReleaseActualDevice(vm->def, detach); + if (detach->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, detach); virDomainNetRemove(vm->def, detachidx); virDomainNetDefFree(detach); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 33c806630b..7a6b40d9b8 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -213,7 +213,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, iface->ifname)); ignore_value(virNetDevVethDelete(iface->ifname)); } - virDomainNetReleaseActualDevice(vm->def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, iface); } =20 virDomainConfVMNWFilterTeardown(vm); @@ -547,6 +548,10 @@ static int virLXCProcessSetupInterfaces(virConnectPtr = conn, if (virLXCProcessValidateInterface(net) < 0) goto cleanup; =20 + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) + goto cleanup; + if (virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; =20 @@ -626,7 +631,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr c= onn, ignore_value(virNetDevOpenvswitchRemovePort( virDomainNetGetActualBridgeName(iface), iface->ifname)); - virDomainNetReleaseActualDevice(def, iface); + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(def, iface); } } return ret; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f92cc61e47..c44cb73c5b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4458,8 +4458,11 @@ networkAllocateActualDevice(virDomainDefPtr dom, size_t i; int ret =3D -1; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - goto validate; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; @@ -4778,7 +4781,6 @@ networkAllocateActualDevice(virDomainDefPtr dom, if (virNetDevVPortProfileCheckComplete(virtport, true) < 0) goto error; =20 - validate: /* make sure that everything now specified for the device is * actually supported on this type of network. NB: network, * netdev, and iface->data.network.actual may all be NULL. @@ -4881,8 +4883,11 @@ networkNotifyActualDevice(virDomainDefPtr dom, size_t i; char *master =3D NULL; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - return; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); if (!obj) { @@ -5114,8 +5119,11 @@ networkReleaseActualDevice(virDomainDefPtr dom, size_t i; int ret =3D -1; =20 - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - return 0; + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto error; + } =20 obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); if (!obj) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1488f0a7c2..512fead050 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1062,7 +1062,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(vm->def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(vm->def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -1352,7 +1353,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, =20 virDomainNetRemoveHostdev(vm->def, net); =20 - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } =20 VIR_FREE(nicstr); @@ -3722,7 +3724,8 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, =20 /* this function doesn't work with HOSTDEV networks yet, thus * no need to change the pointer in the hostdev structure */ - virDomainNetReleaseActualDevice(vm->def, olddev); + if (olddev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, olddev); virDomainNetDefFree(olddev); /* move newdev into the nets list, and NULL it out from the * virDomainDeviceDef that we were given so that the caller @@ -3753,7 +3756,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver, * that the changes were minor enough that we didn't need to * replace the entire device object. */ - if (newdev) + if (newdev && newdev->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) virDomainNetReleaseActualDevice(vm->def, newdev); =20 return ret; @@ -4310,7 +4313,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, virDomainHostdevDefFree(hostdev); =20 if (net) { - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); } =20 @@ -4406,7 +4410,8 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, =20 qemuDomainNetDeviceVportRemove(net); =20 - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); virDomainNetDefFree(net); ret =3D 0; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c4e33723d1..440e2b326d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3127,7 +3127,8 @@ qemuProcessNotifyNets(virDomainDefPtr def) if (virDomainNetGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_DIRE= CT) ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); =20 - virDomainNetNotifyActualDevice(def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetNotifyActualDevice(def, net); } } =20 @@ -5326,7 +5327,8 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def) * network's pool of devices, or resolve bridge device name * to the one defined in the network definition. */ - if (virDomainNetAllocateActualDevice(def, net) < 0) + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK && + virDomainNetAllocateActualDevice(def, net) < 0) goto cleanup; =20 actualType =3D virDomainNetGetActualType(net); @@ -7075,7 +7077,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 /* kick the device out of the hostdev list too */ virDomainNetRemoveHostdev(def, net); - virDomainNetReleaseActualDevice(vm->def, net); + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) + virDomainNetReleaseActualDevice(vm->def, net); } =20 retry: --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list