mac80211: backport kernel fix for CVE-2017-13080
[openwrt/staging/mkresin.git] / package / kernel / mac80211 / patches / 327-mac80211-accept-key-reinstall-without-changing-anyth.patch
1 From fdf7cb4185b60c68e1a75e61691c4afdc15dea0e Mon Sep 17 00:00:00 2001
2 From: Johannes Berg <johannes.berg@intel.com>
3 Date: Tue, 5 Sep 2017 14:54:54 +0200
4 Subject: [PATCH] mac80211: accept key reinstall without changing anything
5
6 When a key is reinstalled we can reset the replay counters
7 etc. which can lead to nonce reuse and/or replay detection
8 being impossible, breaking security properties, as described
9 in the "KRACK attacks".
10
11 In particular, CVE-2017-13080 applies to GTK rekeying that
12 happened in firmware while the host is in D3, with the second
13 part of the attack being done after the host wakes up. In
14 this case, the wpa_supplicant mitigation isn't sufficient
15 since wpa_supplicant doesn't know the GTK material.
16
17 In case this happens, simply silently accept the new key
18 coming from userspace but don't take any action on it since
19 it's the same key; this keeps the PN replay counters intact.
20
21 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
22 ---
23 net/mac80211/key.c | 21 +++++++++++++++++----
24 1 file changed, 17 insertions(+), 4 deletions(-)
25
26 diff --git a/net/mac80211/key.c b/net/mac80211/key.c
27 index a98fc2b5e0dc..ae995c8480db 100644
28 --- a/net/mac80211/key.c
29 +++ b/net/mac80211/key.c
30 @@ -4,7 +4,7 @@
31 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
32 * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net>
33 * Copyright 2013-2014 Intel Mobile Communications GmbH
34 - * Copyright 2015 Intel Deutschland GmbH
35 + * Copyright 2015-2017 Intel Deutschland GmbH
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License version 2 as
39 @@ -620,9 +620,6 @@ int ieee80211_key_link(struct ieee80211_key *key,
40
41 pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
42 idx = key->conf.keyidx;
43 - key->local = sdata->local;
44 - key->sdata = sdata;
45 - key->sta = sta;
46
47 mutex_lock(&sdata->local->key_mtx);
48
49 @@ -633,6 +630,21 @@ int ieee80211_key_link(struct ieee80211_key *key,
50 else
51 old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
52
53 + /*
54 + * Silently accept key re-installation without really installing the
55 + * new version of the key to avoid nonce reuse or replay issues.
56 + */
57 + if (old_key && key->conf.keylen == old_key->conf.keylen &&
58 + !memcmp(key->conf.key, old_key->conf.key, key->conf.keylen)) {
59 + ieee80211_key_free_unused(key);
60 + ret = 0;
61 + goto out;
62 + }
63 +
64 + key->local = sdata->local;
65 + key->sdata = sdata;
66 + key->sta = sta;
67 +
68 increment_tailroom_need_count(sdata);
69
70 ieee80211_key_replace(sdata, sta, pairwise, old_key, key);
71 @@ -648,6 +660,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
72 ret = 0;
73 }
74
75 + out:
76 mutex_unlock(&sdata->local->key_mtx);
77
78 return ret;
79 --
80 2.13.6
81