From 63a248ecb29cc0782d08ecbebc28f6876d10b6f9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 13 Jul 2021 14:41:25 +0200 Subject: [PATCH] device: avoid crash setting VPN config during unrealize During nm_device_unrealize(), we first clear the device's ifindex. Then we call _set_state_full(NM_DEVICE_STATE_UNMANAGED). NMVpnConnection are subclasses of NMActiveConnection, it is that way connected to NM_DEVICE_STATE_CHANGED signal. And this leads to a call to _set_vpn_state(), which then calls nm_device_replace_vpn6_config() to unregister the config. Thereby an assertion fails because the ifindex no longer matches. Fix that by relaxing the assertion. Also, don't apply the IP configuration in unexpected device states. https://bugzilla.redhat.com/show_bug.cgi?id=1912423 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/927 --- src/core/devices/nm-device.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 922e779bef..6230bb38bb 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -13800,18 +13800,24 @@ void nm_device_replace_vpn6_config(NMDevice *self, NMIP6Config *old, NMIP6Config *config) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + NMDeviceState state; nm_assert(!old || NM_IS_IP6_CONFIG(old)); + nm_assert(!old || nm_ip6_config_get_ifindex(old) > 0); + nm_assert(!old || nm_device_get_ip_ifindex(self) == 0 + || nm_device_get_ip_ifindex(self) == nm_ip6_config_get_ifindex(old)); nm_assert(!config || NM_IS_IP6_CONFIG(config)); - nm_assert(!old || nm_ip6_config_get_ifindex(old) == nm_device_get_ip_ifindex(self)); - nm_assert(!config || nm_ip6_config_get_ifindex(config) == nm_device_get_ip_ifindex(self)); + nm_assert(!config || nm_ip6_config_get_ifindex(config) > 0); + nm_assert(!config || nm_device_get_ip_ifindex(self) == nm_ip6_config_get_ifindex(config)); if (!_replace_vpn_config_in_list(&priv->vpn_configs_6, (GObject *) old, (GObject *) config)) return; - /* NULL to use existing configs */ - if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) - _LOGW(LOGD_IP6, "failed to set VPN routes for device"); + state = nm_device_get_state(self); + if (state >= NM_DEVICE_STATE_IP_CONFIG && state <= NM_DEVICE_STATE_ACTIVATED) { + if (!ip_config_merge_and_apply(self, AF_INET6, TRUE)) + _LOGW(LOGD_IP6, "failed to set VPN routes for device"); + } } NMIP6Config *