Skip to content

Commit fdf7cb4

Browse files
committed
mac80211: accept key reinstall without changing anything
When a key is reinstalled we can reset the replay counters etc. which can lead to nonce reuse and/or replay detection being impossible, breaking security properties, as described in the "KRACK attacks". In particular, CVE-2017-13080 applies to GTK rekeying that happened in firmware while the host is in D3, with the second part of the attack being done after the host wakes up. In this case, the wpa_supplicant mitigation isn't sufficient since wpa_supplicant doesn't know the GTK material. In case this happens, simply silently accept the new key coming from userspace but don't take any action on it since it's the same key; this keeps the PN replay counters intact. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent c0576e3 commit fdf7cb4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

net/mac80211/key.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
55
* Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net>
66
* Copyright 2013-2014 Intel Mobile Communications GmbH
7-
* Copyright 2015 Intel Deutschland GmbH
7+
* Copyright 2015-2017 Intel Deutschland GmbH
88
*
99
* This program is free software; you can redistribute it and/or modify
1010
* it under the terms of the GNU General Public License version 2 as
@@ -620,9 +620,6 @@ int ieee80211_key_link(struct ieee80211_key *key,
620620

621621
pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
622622
idx = key->conf.keyidx;
623-
key->local = sdata->local;
624-
key->sdata = sdata;
625-
key->sta = sta;
626623

627624
mutex_lock(&sdata->local->key_mtx);
628625

@@ -633,6 +630,21 @@ int ieee80211_key_link(struct ieee80211_key *key,
633630
else
634631
old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
635632

633+
/*
634+
* Silently accept key re-installation without really installing the
635+
* new version of the key to avoid nonce reuse or replay issues.
636+
*/
637+
if (old_key && key->conf.keylen == old_key->conf.keylen &&
638+
!memcmp(key->conf.key, old_key->conf.key, key->conf.keylen)) {
639+
ieee80211_key_free_unused(key);
640+
ret = 0;
641+
goto out;
642+
}
643+
644+
key->local = sdata->local;
645+
key->sdata = sdata;
646+
key->sta = sta;
647+
636648
increment_tailroom_need_count(sdata);
637649

638650
ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
@@ -648,6 +660,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
648660
ret = 0;
649661
}
650662

663+
out:
651664
mutex_unlock(&sdata->local->key_mtx);
652665

653666
return ret;

0 commit comments

Comments
 (0)