From 98e9d553f284f385f4a405e0a66330909228cd51 Mon Sep 17 00:00:00 2001 From: Andrzej Ostruszka Date: Mon, 13 Jun 2022 14:09:13 +0200 Subject: [PATCH] nl80211: Check previous MAC address for locally-generated-deauth When using MAC randomization wpa_supplicant can change the local MAC address during roaming scenario: 1. We attach to AP1 (with MAC1/SSID1). 2. Roaming to AP2 (with MAC2/SSID2) is started: a) we send DEAUTH(for AP1, with MAC1) b) we change MAC to MAC2 due to randomization c) we start authentication for AP2 d) we get notification about DEAUTH for AP1 (which we ignore) e) we complete association with AP2 In point 2d we completely ignore the notification which later causes problems. This happens if the deauthentication event is generated by the local driver (e.g., due to beacon loss) instead of AP2 sending an explicit Deauthentication frame. The intended behavior is as follows: during roaming we generate DEAUTH (2a) and signal this event right away. To protect from handling of our own DEAUTH for the 2nd time supplicant marks 'ignore_next_local_deauth' variable. In point 2d we should receive this notification and clear the flag but this does not happen because MAC1 in the notification is not the current MAC address (it has been changed in 2b) so this notification is ignored as a one with a "foreign" address. So we end up successfully at AP2 but with 'ignore_next_local_deauth' still set which causes problems. For example if AP2 shuts down it has been observed on some drivers that the DEAUTH notification is generated as a local one and since we have flag to ignore it nothing is reported over D-Bus. To address the problem let's store the previously used MAC address and use it for checking for foreign address (in combination with the current one). Signed-off-by: Andrzej Ostruszka --- src/drivers/driver_nl80211.c | 2 ++ src/drivers/driver_nl80211.h | 1 + src/drivers/driver_nl80211_event.c | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 86d5dd862..ddf61551b 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -1189,6 +1189,7 @@ static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, MACSTR " to " MACSTR, ifindex, bss->ifname, MAC2STR(bss->addr), MAC2STR(addr)); + os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); os_memcpy(bss->addr, addr, ETH_ALEN); if (notify) wpa_supplicant_event(drv->ctx, @@ -10892,6 +10893,7 @@ static int nl80211_set_mac_addr(void *priv, const u8 *addr) wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, bss->ifname, MAC2STR(addr)); drv->addr_changed = new_addr; + os_memcpy(bss->prev_addr, bss->addr, ETH_ALEN); os_memcpy(bss->addr, addr, ETH_ALEN); if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h index 0b8b0ce11..0740e064a 100644 --- a/src/drivers/driver_nl80211.h +++ b/src/drivers/driver_nl80211.h @@ -68,6 +68,7 @@ struct i802_bss { unsigned int use_nl_connect:1; u8 addr[ETH_ALEN]; + u8 prev_addr[ETH_ALEN]; int freq; int bandwidth; diff --git a/src/drivers/driver_nl80211_event.c b/src/drivers/driver_nl80211_event.c index 619670980..c10c31a37 100644 --- a/src/drivers/driver_nl80211_event.c +++ b/src/drivers/driver_nl80211_event.c @@ -1240,8 +1240,11 @@ static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv, * ignore_next_local_deauth as well, to avoid next local * deauth event be wrongly ignored. */ - if (!os_memcmp(mgmt->sa, drv->first_bss->addr, - ETH_ALEN)) { + if (os_memcmp(mgmt->sa, drv->first_bss->addr, + ETH_ALEN) == 0 || + (!is_zero_ether_addr(drv->first_bss->prev_addr) && + os_memcmp(mgmt->sa, drv->first_bss->prev_addr, + ETH_ALEN) == 0)) { wpa_printf(MSG_DEBUG, "nl80211: Received a locally generated deauth event. Clear ignore_next_local_deauth flag"); drv->ignore_next_local_deauth = 0; @@ -1451,7 +1454,10 @@ static void mlme_event(struct i802_bss *bss, os_memcmp(bss->addr, data + 4, ETH_ALEN) != 0 && (is_zero_ether_addr(bss->rand_addr) || os_memcmp(bss->rand_addr, data + 4, ETH_ALEN) != 0) && - os_memcmp(bss->addr, data + 4 + ETH_ALEN, ETH_ALEN) != 0) { + os_memcmp(bss->addr, data + 4 + ETH_ALEN, ETH_ALEN) != 0 && + (is_zero_ether_addr(drv->first_bss->prev_addr) || + os_memcmp(bss->prev_addr, data + 4 + ETH_ALEN, + ETH_ALEN) != 0)) { wpa_printf(MSG_MSGDUMP, "nl80211: %s: Ignore MLME frame event " "for foreign address", bss->ifname); return;