]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Check previous MAC address for locally-generated-deauth
authorAndrzej Ostruszka <amo@semihalf.com>
Mon, 13 Jun 2022 12:09:13 +0000 (14:09 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 27 Nov 2022 12:18:53 +0000 (14:18 +0200)
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 <amo@semihalf.com>
src/drivers/driver_nl80211.c
src/drivers/driver_nl80211.h
src/drivers/driver_nl80211_event.c

index 86d5dd862aebcc615e8a27b9dce54687dcfdbaf8..ddf61551b0df269a9d5149d02a4f8fddfa8877d2 100644 (file)
@@ -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)
index 0b8b0ce118b1fe27415d9f3cf0af0d4df8a4e7f6..0740e064ab9eb537ccd46cbb722f2bc17e778db2 100644 (file)
@@ -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;
index 619670980f4ce628efc07694a04ea622e3056dda..c10c31a3760af1876970ea098de80787a925d1e3 100644 (file)
@@ -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;