Blame SOURCES/rh1490885-fix-auth-failure-when-the-mac-is-updated-externally.patch

b645d2
From 175c8ec5f46fbe544eb71b80d83ed517a3c81ba4 Mon Sep 17 00:00:00 2001
b645d2
From: Beniamino Galvani <bgalvani@redhat.com>
b645d2
Date: Thu, 15 Feb 2018 11:50:01 +0100
b645d2
Subject: [PATCH] wpa_supplicant: Fix auth failure when the MAC is updated
b645d2
 externally
b645d2
b645d2
When connecting to a WPA-EAP network and the MAC address is changed
b645d2
just before the association (for example by NetworkManager, which sets
b645d2
a random MAC during scans), the authentication sometimes fails in the
b645d2
following way ('####' logs added by me):
b645d2
b645d2
wpa_supplicant logs:
b645d2
 wlan0: WPA: RX message 1 of 4-Way Handshake from 02:00:00:00:01:00 (ver=1)
b645d2
 RSN: msg 1/4 key data - hexdump(len=22): dd 14 00 0f ac 04 d8 21 9d a5 73 98 88 26 ef 03 d2 ce f7 04 7d 23
b645d2
 WPA: PMKID in EAPOL-Key - hexdump(len=22): dd 14 00 0f ac 04 d8 21 9d a5 73 98 88 26 ef 03 d2 ce f7 04 7d 23
b645d2
 RSN: PMKID from Authenticator - hexdump(len=16): d8 21 9d a5 73 98 88 26 ef 03 d2 ce f7 04 7d 23
b645d2
 wlan0: RSN: no matching PMKID found
b645d2
 EAPOL: Successfully fetched key (len=32)
b645d2
 WPA: PMK from EAPOL state machines - hexdump(len=32): [REMOVED]
b645d2
 #### WPA: rsn_pmkid():
b645d2
 #### WPA: aa              - hexdump(len=6): 02 00 00 00 01 00
b645d2
 #### WPA: spa             - hexdump(len=6): 66 20 cf ab 8c dc
b645d2
 #### WPA: PMK             - hexdump(len=32): b5 24 76 4f 6f 50 8c f6 a1 2e 24 b8 07 4e 9a 13 1b 94 c4 a8 1f 7e 22 d6 ed fc 7d 43 c7 77 b6 f7
b645d2
 #### WPA: computed PMKID  - hexdump(len=16): ea 73 67 b1 8e 5f 18 43 58 24 e8 1c 47 23 87 71
b645d2
 RSN: Replace PMKSA entry for the current AP and any PMKSA cache entry that was based on the old PMK
b645d2
 nl80211: Delete PMKID for 02:00:00:00:01:00
b645d2
 wlan0: RSN: PMKSA cache entry free_cb: 02:00:00:00:01:00 reason=1
b645d2
 RSN: Added PMKSA cache entry for 02:00:00:00:01:00 network_ctx=0x5630bf85a270
b645d2
 nl80211: Add PMKID for 02:00:00:00:01:00
b645d2
 wlan0: RSN: PMKID mismatch - authentication server may have derived different MSK?!
b645d2
b645d2
hostapd logs:
b645d2
 WPA: PMK from EAPOL state machine (MSK len=64 PMK len=32)
b645d2
 WPA: 02:00:00:00:00:00 WPA_PTK entering state PTKSTART
b645d2
 wlan1: STA 02:00:00:00:00:00 WPA: sending 1/4 msg of 4-Way Handshake
b645d2
 #### WPA: rsn_pmkid():
b645d2
 #### WPA: aa              - hexdump(len=6): 02 00 00 00 01 00
b645d2
 #### WPA: spa             - hexdump(len=6): 02 00 00 00 00 00
b645d2
 #### WPA: PMK             - hexdump(len=32): b5 24 76 4f 6f 50 8c f6 a1 2e 24 b8 07 4e 9a 13 1b 94 c4 a8 1f 7e 22 d6 ed fc 7d 43 c7 77 b6 f7
b645d2
 #### WPA: computed PMKID  - hexdump(len=16): d8 21 9d a5 73 98 88 26 ef 03 d2 ce f7 04 7d 23
b645d2
 WPA: Send EAPOL(version=1 secure=0 mic=0 ack=1 install=0 pairwise=1 kde_len=22 keyidx=0 encr=0)
b645d2
b645d2
That's because wpa_supplicant computed the PMKID using the wrong (old)
b645d2
MAC address used during the scan. wpa_supplicant updates own_addr when
b645d2
the interface goes up, as the MAC can only change while the interface
b645d2
is down. However, drivers don't report all interface state changes:
b645d2
for example the nl80211 driver may ignore a down-up cycle if the down
b645d2
message is processed later, when the interface is already up. In such
b645d2
cases, wpa_supplicant (and in particular, the EAP state machine) would
b645d2
continue to use the old MAC.
b645d2
b645d2
Add a new driver event that notifies of MAC address changes while the
b645d2
interface is active.
b645d2
b645d2
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
b645d2
(cherry picked from commit 77a020a118168e05e7cc0d28a7bf661772e531af)
b645d2
---
b645d2
 src/drivers/driver.h         |  9 +++++++++
b645d2
 src/drivers/driver_common.c  |  1 +
b645d2
 src/drivers/driver_nl80211.c | 11 +++++++----
b645d2
 wpa_supplicant/events.c      |  3 +++
b645d2
 4 files changed, 20 insertions(+), 4 deletions(-)
b645d2
b645d2
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
b645d2
index df996dc21..f8d556133 100644
b645d2
--- a/src/drivers/driver.h
b645d2
+++ b/src/drivers/driver.h
b645d2
@@ -4106,6 +4106,15 @@ enum wpa_event_type {
b645d2
 	 * EVENT_P2P_LO_STOP - Notify that P2P listen offload is stopped
b645d2
 	 */
b645d2
 	EVENT_P2P_LO_STOP,
b645d2
+
b645d2
+	/**
b645d2
+	 * EVENT_INTERFACE_MAC_CHANGED - Notify that interface MAC changed
b645d2
+	 *
b645d2
+	 * This event is emitted when the MAC changes while the interface is
b645d2
+	 * enabled. When an interface was disabled and becomes enabled, it
b645d2
+	 * must be always assumed that the MAC possibly changed.
b645d2
+	 */
b645d2
+	EVENT_INTERFACE_MAC_CHANGED,
b645d2
 };
b645d2
 
b645d2
 
b645d2
diff --git a/src/drivers/driver_common.c b/src/drivers/driver_common.c
b645d2
index c7107ba89..bdddc0a48 100644
b645d2
--- a/src/drivers/driver_common.c
b645d2
+++ b/src/drivers/driver_common.c
b645d2
@@ -81,6 +81,7 @@ const char * event_to_string(enum wpa_event_type event)
b645d2
 	E2S(ACS_CHANNEL_SELECTED);
b645d2
 	E2S(DFS_CAC_STARTED);
b645d2
 	E2S(P2P_LO_STOP);
b645d2
+	E2S(INTERFACE_MAC_CHANGED);
b645d2
 	}
b645d2
 
b645d2
 	return "UNKNOWN";
b645d2
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
b645d2
index f7f3cfebc..d4a879836 100644
b645d2
--- a/src/drivers/driver_nl80211.c
b645d2
+++ b/src/drivers/driver_nl80211.c
b645d2
@@ -923,7 +923,7 @@ nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
b645d2
 
b645d2
 
b645d2
 static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
b645d2
-				int ifindex)
b645d2
+				int ifindex, int notify)
b645d2
 {
b645d2
 	struct i802_bss *bss;
b645d2
 	u8 addr[ETH_ALEN];
b645d2
@@ -942,6 +942,9 @@ static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
b645d2
 			   ifindex, bss->ifname,
b645d2
 			   MAC2STR(bss->addr), MAC2STR(addr));
b645d2
 		os_memcpy(bss->addr, addr, ETH_ALEN);
b645d2
+		if (notify)
b645d2
+			wpa_supplicant_event(drv->ctx,
b645d2
+					     EVENT_INTERFACE_MAC_CHANGED, NULL);
b645d2
 	}
b645d2
 }
b645d2
 
b645d2
@@ -1010,11 +1013,11 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
b645d2
 		namebuf[0] = '\0';
b645d2
 		if (if_indextoname(ifi->ifi_index, namebuf) &&
b645d2
 		    linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
b645d2
-			/* Re-read MAC address as it may have changed */
b645d2
-			nl80211_refresh_mac(drv, ifi->ifi_index);
b645d2
 			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
b645d2
 				   "event since interface %s is up", namebuf);
b645d2
 			drv->ignore_if_down_event = 0;
b645d2
+			/* Re-read MAC address as it may have changed */
b645d2
+			nl80211_refresh_mac(drv, ifi->ifi_index, 1);
b645d2
 			return;
b645d2
 		}
b645d2
 		wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
b645d2
@@ -1060,7 +1063,7 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
b645d2
 				   "removed", drv->first_bss->ifname);
b645d2
 		} else {
b645d2
 			/* Re-read MAC address as it may have changed */
b645d2
-			nl80211_refresh_mac(drv, ifi->ifi_index);
b645d2
+			nl80211_refresh_mac(drv, ifi->ifi_index, 0);
b645d2
 
b645d2
 			wpa_printf(MSG_DEBUG, "nl80211: Interface up");
b645d2
 			drv->if_disabled = 0;
b645d2
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
b645d2
index 4dc044c2b..6eb35104c 100644
b645d2
--- a/wpa_supplicant/events.c
b645d2
+++ b/wpa_supplicant/events.c
b645d2
@@ -3927,6 +3927,9 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
b645d2
 			data->signal_change.current_noise,
b645d2
 			data->signal_change.current_txrate);
b645d2
 		break;
b645d2
+	case EVENT_INTERFACE_MAC_CHANGED:
b645d2
+		wpa_supplicant_update_mac_addr(wpa_s);
b645d2
+		break;
b645d2
 	case EVENT_INTERFACE_ENABLED:
b645d2
 		wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
b645d2
 		if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
b645d2
-- 
b645d2
2.14.3
b645d2