hostapd: merge fixes for WPA packet number reuse with replayed messages and key reins...
[openwrt/staging/jow.git] / package / network / services / hostapd / patches / 005-TDLS-Reject-TPK-TK-reconfiguration.patch
1 From: Jouni Malinen <j@w1.fi>
2 Date: Fri, 22 Sep 2017 11:03:15 +0300
3 Subject: [PATCH] TDLS: Reject TPK-TK reconfiguration
4
5 Do not try to reconfigure the same TPK-TK to the driver after it has
6 been successfully configured. This is an explicit check to avoid issues
7 related to resetting the TX/RX packet number. There was already a check
8 for this for TPK M2 (retries of that message are ignored completely), so
9 that behavior does not get modified.
10
11 For TPK M3, the TPK-TK could have been reconfigured, but that was
12 followed by immediate teardown of the link due to an issue in updating
13 the STA entry. Furthermore, for TDLS with any real security (i.e.,
14 ignoring open/WEP), the TPK message exchange is protected on the AP path
15 and simple replay attacks are not feasible.
16
17 As an additional corner case, make sure the local nonce gets updated if
18 the peer uses a very unlikely "random nonce" of all zeros.
19
20 Signed-off-by: Jouni Malinen <j@w1.fi>
21 ---
22
23 --- a/src/rsn_supp/tdls.c
24 +++ b/src/rsn_supp/tdls.c
25 @@ -112,6 +112,7 @@ struct wpa_tdls_peer {
26 u8 tk[16]; /* TPK-TK; assuming only CCMP will be used */
27 } tpk;
28 int tpk_set;
29 + int tk_set; /* TPK-TK configured to the driver */
30 int tpk_success;
31 int tpk_in_progress;
32
33 @@ -192,6 +193,20 @@ static int wpa_tdls_set_key(struct wpa_s
34 u8 rsc[6];
35 enum wpa_alg alg;
36
37 + if (peer->tk_set) {
38 + /*
39 + * This same TPK-TK has already been configured to the driver
40 + * and this new configuration attempt (likely due to an
41 + * unexpected retransmitted frame) would result in clearing
42 + * the TX/RX sequence number which can break security, so must
43 + * not allow that to happen.
44 + */
45 + wpa_printf(MSG_INFO, "TDLS: TPK-TK for the peer " MACSTR
46 + " has already been configured to the driver - do not reconfigure",
47 + MAC2STR(peer->addr));
48 + return -1;
49 + }
50 +
51 os_memset(rsc, 0, 6);
52
53 switch (peer->cipher) {
54 @@ -209,12 +224,15 @@ static int wpa_tdls_set_key(struct wpa_s
55 return -1;
56 }
57
58 + wpa_printf(MSG_DEBUG, "TDLS: Configure pairwise key for peer " MACSTR,
59 + MAC2STR(peer->addr));
60 if (wpa_sm_set_key(sm, alg, peer->addr, -1, 1,
61 rsc, sizeof(rsc), peer->tpk.tk, key_len) < 0) {
62 wpa_printf(MSG_WARNING, "TDLS: Failed to set TPK to the "
63 "driver");
64 return -1;
65 }
66 + peer->tk_set = 1;
67 return 0;
68 }
69
70 @@ -695,7 +713,7 @@ static void wpa_tdls_peer_clear(struct w
71 peer->cipher = 0;
72 peer->qos_info = 0;
73 peer->wmm_capable = 0;
74 - peer->tpk_set = peer->tpk_success = 0;
75 + peer->tk_set = peer->tpk_set = peer->tpk_success = 0;
76 peer->chan_switch_enabled = 0;
77 os_memset(&peer->tpk, 0, sizeof(peer->tpk));
78 os_memset(peer->inonce, 0, WPA_NONCE_LEN);
79 @@ -1158,6 +1176,7 @@ skip_rsnie:
80 wpa_tdls_peer_free(sm, peer);
81 return -1;
82 }
83 + peer->tk_set = 0; /* A new nonce results in a new TK */
84 wpa_hexdump(MSG_DEBUG, "TDLS: Initiator Nonce for TPK handshake",
85 peer->inonce, WPA_NONCE_LEN);
86 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
87 @@ -1751,6 +1770,19 @@ static int wpa_tdls_addset_peer(struct w
88 }
89
90
91 +static int tdls_nonce_set(const u8 *nonce)
92 +{
93 + int i;
94 +
95 + for (i = 0; i < WPA_NONCE_LEN; i++) {
96 + if (nonce[i])
97 + return 1;
98 + }
99 +
100 + return 0;
101 +}
102 +
103 +
104 static int wpa_tdls_process_tpk_m1(struct wpa_sm *sm, const u8 *src_addr,
105 const u8 *buf, size_t len)
106 {
107 @@ -2004,7 +2036,8 @@ skip_rsn:
108 peer->rsnie_i_len = kde.rsn_ie_len;
109 peer->cipher = cipher;
110
111 - if (os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) != 0) {
112 + if (os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) != 0 ||
113 + !tdls_nonce_set(peer->inonce)) {
114 /*
115 * There is no point in updating the RNonce for every obtained
116 * TPK M1 frame (e.g., retransmission due to timeout) with the
117 @@ -2020,6 +2053,7 @@ skip_rsn:
118 "TDLS: Failed to get random data for responder nonce");
119 goto error;
120 }
121 + peer->tk_set = 0; /* A new nonce results in a new TK */
122 }
123
124 #if 0