1: f05a019de669 ! 1: 343afab7a8ee wifi: ath11k: replace a pairwise key in place @@ Commit message firmware as an install of cipher NONE followed by an install of the new key. Commit 97acb0259cc9 ("wifi: ath11k: fix group data packet drops during rekey") stopped this clear-then-install sequence for group keys, - and it fails the same way for a pairwise key: on an IPQ8074 AP, the - station stopped receiving at its first PTK rekey in 6 of 6 runs, with a - Broadcom and a Qualcomm client, the REO counted up to 165 PN check - failures per run, and hostapd deauthenticated the station at the next - rekey. Because ath11k does not set NL80211_EXT_FEATURE_CAN_REPLACE_PTK0, - mac80211 also warns "Rekeying PTK for STA ... but driver can't safely do - that" and flushes the queues, which waits ATH11K_FLUSH_TIMEOUT (5 s) for - the whole radio whenever a busy station keeps frames pending. + and the same sequence fails for a pairwise key. ath11k does not set + NL80211_EXT_FEATURE_CAN_REPLACE_PTK0, so mac80211 warns "Rekeying PTK + for STA ... but driver can't safely do that" and flushes the queues, + which waits ATH11K_FLUSH_TIMEOUT (5 s) for the whole radio whenever a + busy station keeps frames pending. On an IPQ8074 AP with a station + downloading at full rate and a rekey every 20 s, the first run of each of + two attempts logged 7 and 2 of these warnings and 2 and 1 flush timeouts, + and the station lost the link in both.  Keep the old pairwise key in the firmware when mac80211 disables it for - a station, so that the following SET_KEY overwrites it in place, as the - group key path already does. Outside raw mode the hardware encrypts a - frame with the key it holds for the peer and generates the PN, so a - frame queued across the replace leaves with the old key or the new one - and never in the clear, and the SET_KEY resets the REO PN state. A - pairwise key removed without a replacement is cleared when the station - leaves the authorized state, and peer deletion drops it with the peer. - With this, advertise NL80211_EXT_FEATURE_CAN_REPLACE_PTK0. + an authorized station, so that the following SET_KEY overwrites it in + place, as the group key path already does. Outside raw mode the hardware + encrypts a frame with the key it holds for the peer and generates the + PN, so a frame queued across the replace leaves with the old key or the + new one, and the SET_KEY resets the REO PN state. A pairwise key removed + without a replacement is cleared when the station leaves the authorized + state; a removal outside that state, as hostapd does for a leaving + station after closing its port, clears the key at once as before. A TKIP + fragment chain completed while the host holds no key for the peer is + dropped, as its MIC cannot be checked. With this, advertise + NL80211_EXT_FEATURE_CAN_REPLACE_PTK0 outside raw mode, where mac80211 + assigns the PN itself.  - With hostapd rekeying the PTK every 20 s, a download to a FastConnect - 7800 station holds 914 to 945 Mbit/s through four rekeys, with no - second below 854 Mbit/s (3 runs); before, the station lost the - connection in 3 of 3 runs. + Tested on an IPQ8074 AP with the same load: three runs with this patch + completed 3 to 4 handshakes each at 847, 828 and 851 Mbit/s, with no + warning and no flush timeout, and five station leave and re-association + cycles each cleared the key and completed the 4-way handshake on the + first attempt.  - Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 + Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460  Fixes: 436a4e886598 ("ath11k: clear the keys properly via DISABLE_KEY") Signed-off-by: Julius Bairaktaris  @@ drivers/net/wireless/ath/ath11k/core.h: struct ath11k_sta {  + */  + bool ptk_clear_pending;  + u8 ptk_clear_idx; ++ u8 ptk_clear_keylen;  + u32 ptk_clear_cipher;  + /* Protected with ar->data_lock */ enum ath11k_wmi_peer_ps_state peer_ps_state; u64 ps_start_time;  + ## drivers/net/wireless/ath/ath11k/dp_rx.c ## +@@ drivers/net/wireless/ath/ath11k/dp_rx.c: static int ath11k_dp_rx_h_verify_tkip_mic(struct ath11k *ar, struct ath11k_peer + key_idx = peer->mcast_keyidx; +  + key_conf = peer->keys[key_idx]; ++ if (!key_conf) { ++ dev_kfree_skb_any(msdu); ++ return -ENOKEY; ++ } +  + data = msdu->data + head_len; + data_len = msdu->len - head_len - tail_len; + ## drivers/net/wireless/ath/ath11k/mac.c ##  @@ drivers/net/wireless/ath/ath11k/mac.c: static int ath11k_set_group_keys(struct ath11k_vif *arvif) return first_errno; @@ drivers/net/wireless/ath/ath11k/mac.c: static int ath11k_set_group_keys(struct a  + struct ieee80211_key_conf key = {  + .cipher = arsta->ptk_clear_cipher,  + .keyidx = arsta->ptk_clear_idx, ++ .keylen = arsta->ptk_clear_keylen,  + .flags = IEEE80211_KEY_FLAG_PAIRWISE,  + };  + int ret; @@ drivers/net/wireless/ath/ath11k/mac.c: static int ath11k_mac_op_set_key(struct i  + * every unicast frame to the peer. mac80211 replaces a PTK by  + * DISABLE_KEY on the old key and SET_KEY on the new one, so keep  + * the old key until the new one overwrites it in place. Frames -+ * queued in the hardware leave with the old key or the new one, -+ * never in the clear. A removal not followed by an install is -+ * completed when the port closes, and peer deletion drops the -+ * key with the peer. ++ * queued in the hardware leave with the old key or the new one. ++ * Only an authorized station gets a rekey, and a removal not ++ * followed by an install is completed when its port closes.  + */ -+ keep_ptk = sta && flags == WMI_KEY_PAIRWISE && cmd == DISABLE_KEY; ++ keep_ptk = sta && flags == WMI_KEY_PAIRWISE && cmd == DISABLE_KEY && ++ peer->is_authorized;  +  + if (!keep_ptk &&  + (flags == WMI_KEY_PAIRWISE || cmd == SET_KEY || is_ap_with_no_sta)) { @@ drivers/net/wireless/ath/ath11k/mac.c: static int ath11k_mac_op_set_key(struct i  + if (flags == WMI_KEY_PAIRWISE) {  + arsta->ptk_clear_pending = keep_ptk;  + arsta->ptk_clear_idx = key->keyidx; ++ arsta->ptk_clear_keylen = key->keylen;  + arsta->ptk_clear_cipher = key->cipher;  + }  + @@ drivers/net/wireless/ath/ath11k/mac.c: static int __ath11k_mac_register(struct a  wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); -+ wiphy_ext_feature_set(ar->hw->wiphy, -+ NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); ++ /* In raw mode mac80211 assigns the PN, which the hardware must not ++ * encrypt with a newer key ++ */ ++ if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) ++ wiphy_ext_feature_set(ar->hw->wiphy, ++ NL80211_EXT_FEATURE_CAN_REPLACE_PTK0); if (test_bit(WMI_TLV_SERVICE_BSS_COLOR_OFFLOAD, ar->ab->wmi_ab.svc_map)) { wiphy_ext_feature_set(ar->hw->wiphy,