hostapd: Avoid key reinstallation in FT handshake

Do not reinstall TK to the driver during Reassociation Response frame
processing if the first attempt of setting the TK succeeded. This avoids
issues related to clearing the TX/RX PN that could result in reusing
same PN values for transmitted frames (e.g., due to CCM nonce reuse and
also hitting replay protection on the receiver) and accepting replayed
frames on RX side.

This issue was introduced by the commit
0e84c25434 ('FT: Fix PTK configuration in
authenticator') which allowed wpa_ft_install_ptk() to be called multiple
times with the same PTK. While the second configuration attempt is
needed with some drivers, it must be done only if the first attempt
failed.

Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
This commit is contained in:
Mathy Vanhoef 2017-07-14 15:15:35 +02:00 committed by Jouni Malinen
parent 89c343e887
commit 0e3bd7ac68
5 changed files with 37 additions and 4 deletions

View file

@ -2630,6 +2630,7 @@ static int add_associated_sta(struct hostapd_data *hapd,
{ {
struct ieee80211_ht_capabilities ht_cap; struct ieee80211_ht_capabilities ht_cap;
struct ieee80211_vht_capabilities vht_cap; struct ieee80211_vht_capabilities vht_cap;
int set = 1;
/* /*
* Remove the STA entry to ensure the STA PS state gets cleared and * Remove the STA entry to ensure the STA PS state gets cleared and
@ -2637,9 +2638,18 @@ static int add_associated_sta(struct hostapd_data *hapd,
* FT-over-the-DS, where a station re-associates back to the same AP but * FT-over-the-DS, where a station re-associates back to the same AP but
* skips the authentication flow, or if working with a driver that * skips the authentication flow, or if working with a driver that
* does not support full AP client state. * does not support full AP client state.
*
* Skip this if the STA has already completed FT reassociation and the
* TK has been configured since the TX/RX PN must not be reset to 0 for
* the same key.
*/ */
if (!sta->added_unassoc) if (!sta->added_unassoc &&
(!(sta->flags & WLAN_STA_AUTHORIZED) ||
!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm))) {
hostapd_drv_sta_remove(hapd, sta->addr); hostapd_drv_sta_remove(hapd, sta->addr);
wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
set = 0;
}
#ifdef CONFIG_IEEE80211N #ifdef CONFIG_IEEE80211N
if (sta->flags & WLAN_STA_HT) if (sta->flags & WLAN_STA_HT)
@ -2662,11 +2672,11 @@ static int add_associated_sta(struct hostapd_data *hapd,
sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
sta->flags | WLAN_STA_ASSOC, sta->qosinfo, sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
sta->vht_opmode, sta->p2p_ie ? 1 : 0, sta->vht_opmode, sta->p2p_ie ? 1 : 0,
sta->added_unassoc)) { set)) {
hostapd_logger(hapd, sta->addr, hostapd_logger(hapd, sta->addr,
HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
"Could not %s STA to kernel driver", "Could not %s STA to kernel driver",
sta->added_unassoc ? "set" : "add"); set ? "set" : "add");
if (sta->added_unassoc) { if (sta->added_unassoc) {
hostapd_drv_sta_remove(hapd, sta->addr); hostapd_drv_sta_remove(hapd, sta->addr);

View file

@ -1784,6 +1784,9 @@ int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event)
#else /* CONFIG_FILS */ #else /* CONFIG_FILS */
break; break;
#endif /* CONFIG_FILS */ #endif /* CONFIG_FILS */
case WPA_DRV_STA_REMOVED:
sm->tk_already_set = FALSE;
return 0;
} }
#ifdef CONFIG_IEEE80211R_AP #ifdef CONFIG_IEEE80211R_AP
@ -3941,6 +3944,14 @@ int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm)
} }
int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm)
{
if (!sm || !wpa_key_mgmt_ft(sm->wpa_key_mgmt))
return 0;
return sm->tk_already_set;
}
int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm, int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
struct rsn_pmksa_cache_entry *entry) struct rsn_pmksa_cache_entry *entry)
{ {

View file

@ -300,7 +300,7 @@ void wpa_receive(struct wpa_authenticator *wpa_auth,
u8 *data, size_t data_len); u8 *data, size_t data_len);
enum wpa_event { enum wpa_event {
WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH, WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_ASSOC_FILS WPA_REAUTH_EAPOL, WPA_ASSOC_FT, WPA_ASSOC_FILS, WPA_DRV_STA_REMOVED
}; };
void wpa_remove_ptk(struct wpa_state_machine *sm); void wpa_remove_ptk(struct wpa_state_machine *sm);
int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event); int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
@ -313,6 +313,7 @@ int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
int wpa_auth_get_pairwise(struct wpa_state_machine *sm); int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm); int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm); int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm);
int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm, int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
struct rsn_pmksa_cache_entry *entry); struct rsn_pmksa_cache_entry *entry);
struct rsn_pmksa_cache_entry * struct rsn_pmksa_cache_entry *

View file

@ -1937,6 +1937,14 @@ void wpa_ft_install_ptk(struct wpa_state_machine *sm)
return; return;
} }
if (sm->tk_already_set) {
/* Must avoid TK reconfiguration to prevent clearing of TX/RX
* PN in the driver */
wpa_printf(MSG_DEBUG,
"FT: Do not re-install same PTK to the driver");
return;
}
/* FIX: add STA entry to kernel/driver here? The set_key will fail /* FIX: add STA entry to kernel/driver here? The set_key will fail
* most likely without this.. At the moment, STA entry is added only * most likely without this.. At the moment, STA entry is added only
* after association has been completed. This function will be called * after association has been completed. This function will be called
@ -1949,6 +1957,7 @@ void wpa_ft_install_ptk(struct wpa_state_machine *sm)
/* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */ /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
sm->pairwise_set = TRUE; sm->pairwise_set = TRUE;
sm->tk_already_set = TRUE;
} }
@ -2152,6 +2161,7 @@ static int wpa_ft_process_auth_req(struct wpa_state_machine *sm,
sm->pairwise = pairwise; sm->pairwise = pairwise;
sm->PTK_valid = TRUE; sm->PTK_valid = TRUE;
sm->tk_already_set = FALSE;
wpa_ft_install_ptk(sm); wpa_ft_install_ptk(sm);
buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) + buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +

View file

@ -61,6 +61,7 @@ struct wpa_state_machine {
struct wpa_ptk PTK; struct wpa_ptk PTK;
Boolean PTK_valid; Boolean PTK_valid;
Boolean pairwise_set; Boolean pairwise_set;
Boolean tk_already_set;
int keycount; int keycount;
Boolean Pair; Boolean Pair;
struct wpa_key_replay_counter { struct wpa_key_replay_counter {