[PATCH] wifi: mac80211: handle failure to re-add interface on address change
From: YuanZhe Liu
Date: Sat Nov 21 2026 - 08:33:34 EST
Changing the MAC address of a running station interface makes mac80211
remove the interface from the driver and add it back with the new
address. The code assumes that adding it back cannot fail and only warns
if it does, which is not true: drivers may legitimately refuse to add the
interface, for example a USB driver that has concluded its device has
disappeared. rt2x00 returns -ENODEV from ->add_interface() once it has
seen too many consecutive -EPROTO errors and marked the device as gone,
which produces
WARNING: net/mac80211/iface.c:306 at ieee80211_change_mac
and, worse, the address change still returns success to userspace even
though the interface is now running but no longer present in the driver.
Any further address change then attempts to remove the interface from the
driver again and trips the check_sdata_in_driver() warning.
Handle the error properly: keep the remove/add sequence, but propagate
the driver's error to userspace instead of warning about it, and reject
further address changes on an interface that the driver no longer knows
about.
Fixes: 3c06e91b40db6 ("wifi: mac80211: Support POWERED_ADDR_CHANGE feature")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
net/mac80211/iface.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b6ed6541bc42..f3105d0564de 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -279,6 +279,15 @@ static int _ieee80211_change_mac(struct ieee80211_sub_if_data *sdata,
if (ret)
return ret;
+ /*
+ * The driver may have refused to add the interface back
+ * after a previous address change, e.g. because the device
+ * disappeared. In that case the interface is not in the
+ * driver, so don't try to remove/add it again.
+ */
+ if (!(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
+ return -ENODEV;
+
live = true;
}
@@ -300,10 +309,15 @@ static int _ieee80211_change_mac(struct ieee80211_sub_if_data *sdata,
}
/* Regardless of eth_mac_addr() return we still want to add the
- * interface back. This should not fail...
+ * interface back, but the driver may refuse, e.g. if the device
+ * disappeared in the meantime.
*/
- if (live)
- WARN_ON(drv_add_interface(local, sdata));
+ if (live) {
+ int err = drv_add_interface(local, sdata);
+
+ if (err && !ret)
+ ret = err;
+ }
return ret;
}
--
2.34.1