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

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