Blame SOURCES/rh1495527-0001-hostapd-Avoid-key-reinstallation-in-FT-handshake.patch

d840d9
From cf4cab804c7afd5c45505528a8d16e46163243a2 Mon Sep 17 00:00:00 2001
d840d9
From: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
d840d9
Date: Fri, 14 Jul 2017 15:15:35 +0200
d840d9
Subject: [PATCH 1/8] hostapd: Avoid key reinstallation in FT handshake
d840d9
d840d9
Do not reinstall TK to the driver during Reassociation Response frame
d840d9
processing if the first attempt of setting the TK succeeded. This avoids
d840d9
issues related to clearing the TX/RX PN that could result in reusing
d840d9
same PN values for transmitted frames (e.g., due to CCM nonce reuse and
d840d9
also hitting replay protection on the receiver) and accepting replayed
d840d9
frames on RX side.
d840d9
d840d9
This issue was introduced by the commit
d840d9
0e84c25434e6a1f283c7b4e62e483729085b78d2 ('FT: Fix PTK configuration in
d840d9
authenticator') which allowed wpa_ft_install_ptk() to be called multiple
d840d9
times with the same PTK. While the second configuration attempt is
d840d9
needed with some drivers, it must be done only if the first attempt
d840d9
failed.
d840d9
d840d9
Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
d840d9
---
d840d9
 src/ap/ieee802_11.c  | 16 +++++++++++++---
d840d9
 src/ap/wpa_auth.c    | 11 +++++++++++
d840d9
 src/ap/wpa_auth.h    |  3 ++-
d840d9
 src/ap/wpa_auth_ft.c | 10 ++++++++++
d840d9
 src/ap/wpa_auth_i.h  |  1 +
d840d9
 5 files changed, 37 insertions(+), 4 deletions(-)
d840d9
d840d9
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
d840d9
index 4e04169..333035f 100644
d840d9
--- a/src/ap/ieee802_11.c
d840d9
+++ b/src/ap/ieee802_11.c
d840d9
@@ -1841,6 +1841,7 @@ static int add_associated_sta(struct hostapd_data *hapd,
d840d9
 {
d840d9
 	struct ieee80211_ht_capabilities ht_cap;
d840d9
 	struct ieee80211_vht_capabilities vht_cap;
d840d9
+	int set = 1;
d840d9
 
d840d9
 	/*
d840d9
 	 * Remove the STA entry to ensure the STA PS state gets cleared and
d840d9
@@ -1848,9 +1849,18 @@ static int add_associated_sta(struct hostapd_data *hapd,
d840d9
 	 * FT-over-the-DS, where a station re-associates back to the same AP but
d840d9
 	 * skips the authentication flow, or if working with a driver that
d840d9
 	 * does not support full AP client state.
d840d9
+	 *
d840d9
+	 * Skip this if the STA has already completed FT reassociation and the
d840d9
+	 * TK has been configured since the TX/RX PN must not be reset to 0 for
d840d9
+	 * the same key.
d840d9
 	 */
d840d9
-	if (!sta->added_unassoc)
d840d9
+	if (!sta->added_unassoc &&
d840d9
+	    (!(sta->flags & WLAN_STA_AUTHORIZED) ||
d840d9
+	     !wpa_auth_sta_ft_tk_already_set(sta->wpa_sm))) {
d840d9
 		hostapd_drv_sta_remove(hapd, sta->addr);
d840d9
+		wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
d840d9
+		set = 0;
d840d9
+	}
d840d9
 
d840d9
 #ifdef CONFIG_IEEE80211N
d840d9
 	if (sta->flags & WLAN_STA_HT)
d840d9
@@ -1873,11 +1883,11 @@ static int add_associated_sta(struct hostapd_data *hapd,
d840d9
 			    sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
d840d9
 			    sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
d840d9
 			    sta->vht_opmode, sta->p2p_ie ? 1 : 0,
d840d9
-			    sta->added_unassoc)) {
d840d9
+			    set)) {
d840d9
 		hostapd_logger(hapd, sta->addr,
d840d9
 			       HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
d840d9
 			       "Could not %s STA to kernel driver",
d840d9
-			       sta->added_unassoc ? "set" : "add");
d840d9
+			       set ? "set" : "add");
d840d9
 
d840d9
 		if (sta->added_unassoc) {
d840d9
 			hostapd_drv_sta_remove(hapd, sta->addr);
d840d9
diff --git a/src/ap/wpa_auth.c b/src/ap/wpa_auth.c
d840d9
index 3587086..707971d 100644
d840d9
--- a/src/ap/wpa_auth.c
d840d9
+++ b/src/ap/wpa_auth.c
d840d9
@@ -1745,6 +1745,9 @@ int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event)
d840d9
 #else /* CONFIG_IEEE80211R */
d840d9
 		break;
d840d9
 #endif /* CONFIG_IEEE80211R */
d840d9
+	case WPA_DRV_STA_REMOVED:
d840d9
+		sm->tk_already_set = FALSE;
d840d9
+		return 0;
d840d9
 	}
d840d9
 
d840d9
 #ifdef CONFIG_IEEE80211R
d840d9
@@ -3250,6 +3253,14 @@ int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm)
d840d9
 }
d840d9
 
d840d9
 
d840d9
+int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm)
d840d9
+{
d840d9
+	if (!sm || !wpa_key_mgmt_ft(sm->wpa_key_mgmt))
d840d9
+		return 0;
d840d9
+	return sm->tk_already_set;
d840d9
+}
d840d9
+
d840d9
+
d840d9
 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
d840d9
 			     struct rsn_pmksa_cache_entry *entry)
d840d9
 {
d840d9
diff --git a/src/ap/wpa_auth.h b/src/ap/wpa_auth.h
d840d9
index 0de8d97..97461b0 100644
d840d9
--- a/src/ap/wpa_auth.h
d840d9
+++ b/src/ap/wpa_auth.h
d840d9
@@ -267,7 +267,7 @@ void wpa_receive(struct wpa_authenticator *wpa_auth,
d840d9
 		 u8 *data, size_t data_len);
d840d9
 enum wpa_event {
d840d9
 	WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
d840d9
-	WPA_REAUTH_EAPOL, WPA_ASSOC_FT
d840d9
+	WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_DRV_STA_REMOVED
d840d9
 };
d840d9
 void wpa_remove_ptk(struct wpa_state_machine *sm);
d840d9
 int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
d840d9
@@ -280,6 +280,7 @@ int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
d840d9
 int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
d840d9
 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
d840d9
 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
d840d9
+int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm);
d840d9
 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
d840d9
 			     struct rsn_pmksa_cache_entry *entry);
d840d9
 struct rsn_pmksa_cache_entry *
d840d9
diff --git a/src/ap/wpa_auth_ft.c b/src/ap/wpa_auth_ft.c
d840d9
index 42242a5..e63b99a 100644
d840d9
--- a/src/ap/wpa_auth_ft.c
d840d9
+++ b/src/ap/wpa_auth_ft.c
d840d9
@@ -780,6 +780,14 @@ void wpa_ft_install_ptk(struct wpa_state_machine *sm)
d840d9
 		return;
d840d9
 	}
d840d9
 
d840d9
+	if (sm->tk_already_set) {
d840d9
+		/* Must avoid TK reconfiguration to prevent clearing of TX/RX
d840d9
+		 * PN in the driver */
d840d9
+		wpa_printf(MSG_DEBUG,
d840d9
+			   "FT: Do not re-install same PTK to the driver");
d840d9
+		return;
d840d9
+	}
d840d9
+
d840d9
 	/* FIX: add STA entry to kernel/driver here? The set_key will fail
d840d9
 	 * most likely without this.. At the moment, STA entry is added only
d840d9
 	 * after association has been completed. This function will be called
d840d9
@@ -792,6 +800,7 @@ void wpa_ft_install_ptk(struct wpa_state_machine *sm)
d840d9
 
d840d9
 	/* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
d840d9
 	sm->pairwise_set = TRUE;
d840d9
+	sm->tk_already_set = TRUE;
d840d9
 }
d840d9
 
d840d9
 
d840d9
@@ -898,6 +907,7 @@ static int wpa_ft_process_auth_req(struct wpa_state_machine *sm,
d840d9
 
d840d9
 	sm->pairwise = pairwise;
d840d9
 	sm->PTK_valid = TRUE;
d840d9
+	sm->tk_already_set = FALSE;
d840d9
 	wpa_ft_install_ptk(sm);
d840d9
 
d840d9
 	buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
d840d9
diff --git a/src/ap/wpa_auth_i.h b/src/ap/wpa_auth_i.h
d840d9
index 72b7eb3..7fd8f05 100644
d840d9
--- a/src/ap/wpa_auth_i.h
d840d9
+++ b/src/ap/wpa_auth_i.h
d840d9
@@ -65,6 +65,7 @@ struct wpa_state_machine {
d840d9
 	struct wpa_ptk PTK;
d840d9
 	Boolean PTK_valid;
d840d9
 	Boolean pairwise_set;
d840d9
+	Boolean tk_already_set;
d840d9
 	int keycount;
d840d9
 	Boolean Pair;
d840d9
 	struct wpa_key_replay_counter {
d840d9
-- 
d840d9
2.7.4
d840d9