From 08f5f630be0fa5f8ae7585352e804f75ca3c13a4 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 30 Jul 2019 11:03:59 +0200 Subject: [PATCH] device: check platform link compatibility when setting nm-owned flag We set nm-owned to indicate whether a software device was created by NM or it was pre-existing. When checking the existence, we must verify also whether the link type is compatible with the device, otherwise it is possible to match unrelated interfaces. For example, when checking for the existence of an ovs-bridge (which is not compatible with any platform link) we could match a unrelated platform link with the same name. https://bugzilla.redhat.com/show_bug.cgi?id=1733709 (cherry picked from commit 3cb4b36261684aa3d2676f922c6d53bc31085153) (cherry picked from commit cb20d0791a6daf20d64f4cd57d6bd4b60e35a9a0) (cherry picked from commit 511ef27d5eaf6fd0577b867d9d31de3bee0440fe) (cherry picked from commit 33309f7c9f125171d3239103316d88dbd7e606c0) (cherry picked from commit 1240565e482d02df19c34b845a1cd93433f01986) --- src/devices/nm-device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4af51ea37f..6a7dac083b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -3848,13 +3848,14 @@ nm_device_create_and_realize (NMDevice *self, { nm_auto_nmpobj const NMPObject *plink_keep_alive = NULL; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - const NMPlatformLink *plink = NULL; + const NMPlatformLink *plink; /* Must be set before device is realized */ - priv->nm_owned = !nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface); - + plink = nm_platform_link_get_by_ifname (nm_device_get_platform (self), priv->iface); + priv->nm_owned = !plink || !link_type_compatible (self, plink->type, NULL, NULL); _LOGD (LOGD_DEVICE, "create (is %snm-owned)", priv->nm_owned ? "" : "not "); + plink = NULL; /* Create any resources the device needs */ if (NM_DEVICE_GET_CLASS (self)->create_and_realize) { if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error))