Skip to content

Commit c93df40

Browse files
jmberg-intelgregkh
authored andcommitted
mac80211: don't compare TKIP TX MIC key in reinstall prevention
commit cfbb0d90a7abb289edc91833d0905931f8805f12 upstream. For the reinstall prevention, the code I had added compares the whole key. It turns out though that iwlwifi firmware doesn't provide the TKIP TX MIC key as it's not needed in client mode, and thus the comparison will always return false. For client mode, thus always zero out the TX MIC key part before doing the comparison in order to avoid accepting the reinstall of the key with identical encryption and RX MIC key, but not the same TX MIC key (since the supplicant provides the real one.) Fixes: fdf7cb4185b6 ("mac80211: accept key reinstall without changing anything") Signed-off-by: Johannes Berg <johannes.berg@intel.com> Cc: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cdac202 commit c93df40

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

net/mac80211/key.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,39 @@ void ieee80211_key_free_unused(struct ieee80211_key *key)
608608
ieee80211_key_free_common(key);
609609
}
610610

611+
static bool ieee80211_key_identical(struct ieee80211_sub_if_data *sdata,
612+
struct ieee80211_key *old,
613+
struct ieee80211_key *new)
614+
{
615+
u8 tkip_old[WLAN_KEY_LEN_TKIP], tkip_new[WLAN_KEY_LEN_TKIP];
616+
u8 *tk_old, *tk_new;
617+
618+
if (!old || new->conf.keylen != old->conf.keylen)
619+
return false;
620+
621+
tk_old = old->conf.key;
622+
tk_new = new->conf.key;
623+
624+
/*
625+
* In station mode, don't compare the TX MIC key, as it's never used
626+
* and offloaded rekeying may not care to send it to the host. This
627+
* is the case in iwlwifi, for example.
628+
*/
629+
if (sdata->vif.type == NL80211_IFTYPE_STATION &&
630+
new->conf.cipher == WLAN_CIPHER_SUITE_TKIP &&
631+
new->conf.keylen == WLAN_KEY_LEN_TKIP &&
632+
!(new->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
633+
memcpy(tkip_old, tk_old, WLAN_KEY_LEN_TKIP);
634+
memcpy(tkip_new, tk_new, WLAN_KEY_LEN_TKIP);
635+
memset(tkip_old + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY, 0, 8);
636+
memset(tkip_new + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY, 0, 8);
637+
tk_old = tkip_old;
638+
tk_new = tkip_new;
639+
}
640+
641+
return !crypto_memneq(tk_old, tk_new, new->conf.keylen);
642+
}
643+
611644
int ieee80211_key_link(struct ieee80211_key *key,
612645
struct ieee80211_sub_if_data *sdata,
613646
struct sta_info *sta)
@@ -633,8 +666,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
633666
* Silently accept key re-installation without really installing the
634667
* new version of the key to avoid nonce reuse or replay issues.
635668
*/
636-
if (old_key && key->conf.keylen == old_key->conf.keylen &&
637-
!crypto_memneq(key->conf.key, old_key->conf.key, key->conf.keylen)) {
669+
if (ieee80211_key_identical(sdata, old_key, key)) {
638670
ieee80211_key_free_unused(key);
639671
ret = 0;
640672
goto out;

0 commit comments

Comments
 (0)