From 5f22c06c53d9ae9003cd17603d6d6ff3e16f195b Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 2 Jul 2020 13:47:22 +0200 Subject: [PATCH] device: don't reset the MAC without ifindex nm_device_cleanup() can be called when the device no longer has an ifindex. In such case, don't try to reset the MAC address as that would lead to an assertion failure. (cherry picked from commit 77b6ce7d04f6c88e78fb7f1972549956e00e1f4b) (cherry picked from commit 791a888cad3d260675781c0ed30acf13cc1194f7) (cherry picked from commit e1f76e70447049487b2d8240ce12007624ab3c29) --- src/devices/nm-device.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8638ce4c40..c84d908659 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -15307,17 +15307,19 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean nm_device_update_metered (self); - /* during device cleanup, we want to reset the MAC address of the device - * to the initial state. - * - * We certainly want to do that when reaching the UNMANAGED state... */ - if (nm_device_get_state (self) <= NM_DEVICE_STATE_UNMANAGED) - nm_device_hw_addr_reset (self, "unmanage"); - else { - /* for other device states (UNAVAILABLE, DISCONNECTED), allow the - * device to overwrite the reset behavior, so that Wi-Fi can set - * a randomized MAC address used during scanning. */ - NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self); + if (ifindex > 0) { + /* during device cleanup, we want to reset the MAC address of the device + * to the initial state. + * + * We certainly want to do that when reaching the UNMANAGED state... */ + if (nm_device_get_state (self) <= NM_DEVICE_STATE_UNMANAGED) + nm_device_hw_addr_reset (self, "unmanage"); + else { + /* for other device states (UNAVAILABLE, DISCONNECTED), allow the + * device to overwrite the reset behavior, so that Wi-Fi can set + * a randomized MAC address used during scanning. */ + NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self); + } } priv->mtu_source = NM_DEVICE_MTU_SOURCE_NONE;