From daad4e2feeb45934eddc4f23bda30dddb30d4a98 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 1 Feb 2021 13:51:18 +0100 Subject: [PATCH] device: check ifindex before changing ethernet link settings During the call to deactivate(), the device can already have lost the ifindex. Add a check for that to prevent assertion: ((src/platform/nm-platform.c:3306)): assertion 'g_return_val_if_fail(ifindex > 0, FALSE)' failed 0 g_logv (libglib-2.0.so.0 + 0x5bf67) 1 g_log (libglib-2.0.so.0 + 0x5c223) 2 _nm_g_return_if_fail_warning.lto_priv.0 (NetworkManager + 0x4c69f) 3 nm_platform_ethtool_set_link_settings (NetworkManager + 0x183418) 4 deactivate.lto_priv.1 (NetworkManager + 0x27dfd1) 5 nm_device_cleanup (NetworkManager + 0x25b047) 6 _set_state_full (NetworkManager + 0x24f4d8) 7 nm_device_unrealize (NetworkManager + 0x259e63) 8 _platform_link_cb_idle (NetworkManager + 0x27097f) 9 g_idle_dispatch (libglib-2.0.so.0 + 0x5305b) 10 g_main_context_dispatch (libglib-2.0.so.0 + 0x53f8f) 11 g_main_context_iterate.constprop.0 (libglib-2.0.so.0 + 0xa74d8) 12 g_main_loop_run (libglib-2.0.so.0 + 0x53673) 13 main (NetworkManager + 0x4bdba) 14 __libc_start_main (libc.so.6 + 0x27b75) 15 _start (NetworkManager + 0x4c3ee) https://bugzilla.redhat.com/show_bug.cgi?id=1923062 (cherry picked from commit 2757da7eacd30e79d7545603ac07283a04f601a0) --- src/devices/nm-device-ethernet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 2569c4262c..2c894ccb0d 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1525,6 +1525,7 @@ deactivate(NMDevice *device) NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE(self); NMSettingDcb * s_dcb; GError * error = NULL; + int ifindex; nm_clear_g_source(&priv->pppoe_wait_id); nm_clear_g_signal_handler(self, &priv->carrier_id); @@ -1553,7 +1554,8 @@ deactivate(NMDevice *device) if (nm_device_get_applied_setting(device, NM_TYPE_SETTING_PPPOE)) priv->last_pppoe_time = nm_utils_get_monotonic_timestamp_sec(); - if (priv->ethtool_prev_set) { + ifindex = nm_device_get_ifindex(device); + if (ifindex > 0 && priv->ethtool_prev_set) { priv->ethtool_prev_set = FALSE; _LOGD(LOGD_DEVICE, @@ -1562,7 +1564,7 @@ deactivate(NMDevice *device) priv->ethtool_prev_speed, nm_platform_link_duplex_type_to_string(priv->ethtool_prev_duplex)); if (!nm_platform_ethtool_set_link_settings(nm_device_get_platform(device), - nm_device_get_ifindex(device), + ifindex, priv->ethtool_prev_autoneg, priv->ethtool_prev_speed, priv->ethtool_prev_duplex)) {