[PATCH 35/55] wpa_supplicant: Use a new MAC address for FT with PMKR0Name privacy

Ilan Peer ilan.peer at intel.com
Thu Dec 3 02:44:34 PST 2026


According to Note 2 in Section 12.16.7.3 in Draft IEEE P802.11bi/D6.0,
the STA needs to use a new MAC address together with the new PMKR0Name.
However, changing the MAC address disconnects and drops the FT key
hierarchy, so the next connection would not use FT.

When the target AP supports PMKSA caching privacy and association frame
encryption, deauthenticate from the current AP only in the driver before
changing the MAC address, so that the FT key hierarchy is kept.

The S1KH-ID is the SPA used when the PMK-R0 was derived, so store it and
use it for the PMK-R1 derivation instead of the current address.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/rsn_supp/wpa.c              |   5 +-
 src/rsn_supp/wpa.h              |   6 ++
 src/rsn_supp/wpa_ft.c           |  29 ++++++++-
 src/rsn_supp/wpa_i.h            |   1 +
 wpa_supplicant/wpa_supplicant.c | 100 ++++++++++++++++++++++++++++----
 5 files changed, 125 insertions(+), 16 deletions(-)

diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
index 4a6df8946ea0..a644e5179166 100644
--- a/src/rsn_supp/wpa.c
+++ b/src/rsn_supp/wpa.c
@@ -6984,6 +6984,9 @@ static int fils_ft_build_assoc_req_rsne(struct wpa_sm *sm, struct wpabuf *buf)
 		wpa_printf(MSG_WARNING, "FILS+FT: Could not derive PMK-R0");
 		return -1;
 	}
+
+	os_memcpy(sm->s0kh_id, sm->own_addr, ETH_ALEN);
+
 	if (wpa_key_mgmt_sae_ext_key(sm->key_mgmt))
 		sm->pmk_r0_len = sm->fils_ft_len;
 	else
@@ -6991,7 +6994,7 @@ static int fils_ft_build_assoc_req_rsne(struct wpa_sm *sm, struct wpabuf *buf)
 	wpa_printf(MSG_DEBUG, "FILS+FT: R1KH-ID: " MACSTR,
 		   MAC2STR(sm->r1kh_id));
 	pos = wpabuf_put(buf, WPA_PMK_NAME_LEN);
-	if (wpa_derive_pmk_r1_name(sm->pmk_r0_name, sm->r1kh_id, sm->own_addr,
+	if (wpa_derive_pmk_r1_name(sm->pmk_r0_name, sm->r1kh_id, sm->s0kh_id,
 				   sm->pmk_r1_name, sm->fils_ft_len) < 0) {
 		wpa_printf(MSG_WARNING, "FILS+FT: Could not derive PMKR1Name");
 		return -1;
diff --git a/src/rsn_supp/wpa.h b/src/rsn_supp/wpa.h
index 3a2e12201549..33eab0286596 100644
--- a/src/rsn_supp/wpa.h
+++ b/src/rsn_supp/wpa.h
@@ -616,6 +616,7 @@ int wpa_sm_802_1x_ft_pmk_to_ptk(struct wpa_sm *sm, const u8 *xxkey,
 				struct wpa_ptk *ptk, size_t kdk_len);
 const u8 * wpa_sm_get_pmk_r1_name(struct wpa_sm *sm);
 const u8 * wpa_sm_get_ft_ies(struct wpa_sm *sm, size_t *len);
+bool wpa_ft_mac_addr_change_allowed(struct wpa_sm *sm);
 int wpa_ft_is_completed(struct wpa_sm *sm);
 void wpa_reset_ft_completed(struct wpa_sm *sm);
 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
@@ -674,6 +675,11 @@ static inline bool wpa_ft_uses_enc_assoc(struct wpa_sm *sm)
 	return false;
 }
 
+static inline bool wpa_ft_mac_addr_change_allowed(struct wpa_sm *sm)
+{
+	return false;
+}
+
 static inline int wpa_ft_is_completed(struct wpa_sm *sm)
 {
 	return 0;
diff --git a/src/rsn_supp/wpa_ft.c b/src/rsn_supp/wpa_ft.c
index d1d33de8b5d6..d08a39a85017 100644
--- a/src/rsn_supp/wpa_ft.c
+++ b/src/rsn_supp/wpa_ft.c
@@ -83,7 +83,7 @@ static int wpa_ft_derive_pmk_r1(struct wpa_sm *sm, const u8 *r1kh_id,
 #endif /* CONFIG_PMKSA_PRIVACY */
 
 	if (wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_len, sm->pmk_r0_name,
-			      r1kh_id, sm->own_addr, pmk_r1, pmk_r1_name) < 0)
+			      r1kh_id, sm->s0kh_id, pmk_r1, pmk_r1_name) < 0)
 		return -1;
 
 #ifdef CONFIG_PMKSA_PRIVACY
@@ -139,9 +139,12 @@ int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
 			      sm->r0kh_id, sm->r0kh_id_len, sm->own_addr,
 			      sm->pmk_r0, sm->pmk_r0_name, sm->key_mgmt) < 0)
 		return -1;
+
+	os_memcpy(sm->s0kh_id, sm->own_addr, ETH_ALEN);
+
 	sm->pmk_r1_len = sm->pmk_r0_len;
 	if (wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_len, sm->pmk_r0_name,
-			      sm->r1kh_id, sm->own_addr, sm->pmk_r1,
+			      sm->r1kh_id, sm->s0kh_id, sm->pmk_r1,
 			      sm->pmk_r1_name) < 0)
 		return -1;
 
@@ -204,9 +207,10 @@ int wpa_sm_802_1x_ft_pmk_to_ptk(struct wpa_sm *sm, const u8 *xxkey,
 			      sm->pmk_r0, sm->pmk_r0_name, akmp) < 0)
 		return -1;
 
+	os_memcpy(sm->s0kh_id, sm->own_addr, ETH_ALEN);
 	sm->pmk_r1_len = sm->pmk_r0_len;
 	if (wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_len, sm->pmk_r0_name,
-			      sm->r1kh_id, sm->own_addr, sm->pmk_r1,
+			      sm->r1kh_id, sm->s0kh_id, sm->pmk_r1,
 			      sm->pmk_r1_name) < 0)
 		return -1;
 
@@ -710,6 +714,25 @@ bool wpa_ft_uses_enc_assoc(struct wpa_sm *sm)
 	return false;
 }
 
+
+bool wpa_ft_mac_addr_change_allowed(struct wpa_sm *sm)
+{
+#ifdef CONFIG_PMKSA_PRIVACY
+	/*
+	 * With PMKR0Name privacy, the STA can use a new MAC address for the
+	 * next FT.
+	 */
+	return sm && sm->pmksa_privacy && sm->pmk_r0_len && sm->xxkey_len &&
+		wpa_key_mgmt_ft(sm->key_mgmt) &&
+		!wpa_key_mgmt_fils(sm->key_mgmt) &&
+		wpa_ft_uses_enc_assoc(sm) &&
+		ieee802_11_rsnx_capab(sm->ap_rsnxe,
+				      WLAN_RSNX_CAPAB_PMKSA_CACHING_PRIVACY);
+#endif /* CONFIG_PMKSA_PRIVACY */
+
+	return false;
+}
+
 #ifdef CONFIG_ENC_ASSOC
 
 static u8 * wpa_ft_add_dh_param(struct wpa_sm *sm, u8 *ft_ies,
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
index c2d17bda4b7f..a15b8cd599aa 100644
--- a/src/rsn_supp/wpa_i.h
+++ b/src/rsn_supp/wpa_i.h
@@ -182,6 +182,7 @@ struct wpa_sm {
 	u8 pmk_r0[PMK_LEN_MAX];
 	size_t pmk_r0_len;
 	u8 pmk_r0_name[WPA_PMK_NAME_LEN];
+	u8 s0kh_id[ETH_ALEN]; /* SPA when the PMK-R0 was derived */
 	u8 pmk_r1[PMK_LEN_MAX];
 	size_t pmk_r1_len;
 	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 54cf0ff8c033..19160c45755a 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -3386,12 +3386,11 @@ void wpas_connect_work_done(struct wpa_supplicant *wpa_s)
 }
 
 
-int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
-			    enum wpas_mac_addr_style style,
-			    struct wpa_ssid *ssid, bool update_lifetime)
+static bool wpas_random_addr_valid(struct wpa_supplicant *wpa_s,
+				   enum wpas_mac_addr_style style,
+				   struct wpa_ssid *ssid)
 {
 	struct os_reltime now;
-	u8 addr[ETH_ALEN];
 	bool same_ess;
 
 	os_get_reltime(&now);
@@ -3408,17 +3407,32 @@ int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
 			 * might have changed, so let's check that. */
 			if (ssid &&
 			    ether_addr_equal(wpa_s->own_addr, ssid->mac_value))
-				return 0;
+				return true;
 		} else if ((wpa_s->last_mac_addr_change.sec != 0 ||
 			    wpa_s->last_mac_addr_change.usec != 0) &&
 			   !os_reltime_expired(
 				   &now,
 				   &wpa_s->last_mac_addr_change,
 				   wpa_s->conf->rand_addr_lifetime)) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+
+int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
+			    enum wpas_mac_addr_style style,
+			    struct wpa_ssid *ssid, bool update_lifetime)
+{
+	u8 addr[ETH_ALEN];
+
+	if (wpas_random_addr_valid(wpa_s, style, ssid)) {
+		if (style != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS)
 			wpa_msg(wpa_s, MSG_DEBUG,
 				"Previously selected random MAC address has not yet expired");
-			return 0;
-		}
+		return 0;
 	}
 
 	switch (style) {
@@ -3600,6 +3614,53 @@ int wpas_restore_permanent_mac_addr(struct wpa_supplicant *wpa_s)
 
 static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit);
 
+
+static bool wpas_ft_roam_new_mac_addr(struct wpa_supplicant *wpa_s,
+				      enum wpas_mac_addr_style style,
+				      struct wpa_ssid *ssid,
+				      struct wpa_bss *bss)
+{
+#if defined(CONFIG_IEEE80211R) && defined(CONFIG_SME)
+	const u8 *mdie, *rsnxe;
+
+	if (wpas_random_addr_valid(wpa_s, style, ssid) ||
+	    !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || wpa_s->valid_links ||
+	    wpa_s->wpa_state != WPA_COMPLETED || !bss ||
+	    !wpa_s->current_bss || wpa_s->current_bss == bss ||
+	    !wpa_s->sme.prev_bssid_set || !wpa_s->sme.ft_used ||
+	    !wpa_ft_mac_addr_change_allowed(wpa_s->wpa))
+		return false;
+
+	mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
+	if (!mdie || mdie[1] < MOBILITY_DOMAIN_ID_LEN ||
+	    !wpa_sm_has_ft_keys(wpa_s->wpa, mdie + 2))
+		return false;
+
+	/* The target AP has to accept the PMK-R0 with the new MAC address */
+	rsnxe = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
+	if (!ieee802_11_rsnx_capab(rsnxe,
+				   WLAN_RSNX_CAPAB_PMKSA_CACHING_PRIVACY) ||
+	    !ieee802_11_rsnx_capab(rsnxe,
+				   WLAN_RSNX_CAPAB_ASSOC_FRAME_ENCRYPTION))
+		return false;
+
+	/*
+	 * Leave the current AP before using a new MAC address for a fast BSS
+	 * transition, so that the FT key hierarchy is kept.
+	 */
+	wpa_dbg(wpa_s, MSG_DEBUG,
+		"FT: Leave " MACSTR " before the MAC address change",
+		MAC2STR(wpa_s->bssid));
+
+	wpa_drv_deauthenticate(wpa_s, wpa_s->bssid, WLAN_REASON_DEAUTH_LEAVING);
+	return true;
+
+#endif /* CONFIG_IEEE80211R && CONFIG_SME */
+
+	return false;
+}
+
+
 /**
  * wpa_supplicant_associate - Request association
  * @wpa_s: Pointer to wpa_supplicant data
@@ -3667,14 +3728,29 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_SAE */
 
 	if (rand_style > WPAS_MAC_ADDR_STYLE_PERMANENT) {
-		int status = wpas_update_random_addr(wpa_s, rand_style, ssid,
-						     true);
-
-		if (status < 0)
+		bool ft_roam = false;
+		int status;
+
+		if (rand_style != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS)
+			ft_roam = wpas_ft_roam_new_mac_addr(wpa_s, rand_style,
+							    ssid, bss);
+
+		status = wpas_update_random_addr(wpa_s, rand_style, ssid, true);
+		if (status < 0) {
+			if (ft_roam)
+				wpa_supplicant_deauthenticate(
+					wpa_s, WLAN_REASON_DEAUTH_LEAVING);
 			return;
+		}
+
 		if (rand_style != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS &&
-		    status > 0) /* MAC changed */
+		    status > 0) { /* MAC changed */
+			/* Flushing the current PMKSA would deauthenticate */
+			if (ft_roam)
+				pmksa_cache_clear_current(wpa_s->wpa);
+
 			wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
+		}
 	} else if (rand_style == WPAS_MAC_ADDR_STYLE_PERMANENT &&
 		   wpa_s->mac_addr_changed) {
 		if (wpas_restore_permanent_mac_addr(wpa_s) < 0)
-- 
2.55.0




More information about the Hostap mailing list