rev |
line source |
mojo@20131
|
1 From 927f891007c402fefd1ff384645b3f07597c3ede Mon Sep 17 00:00:00 2001
|
mojo@20131
|
2 From: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
|
mojo@20131
|
3 Date: Wed, 12 Jul 2017 16:03:24 +0200
|
mojo@20131
|
4 Subject: [PATCH 2/8] Prevent reinstallation of an already in-use group key
|
mojo@20131
|
5
|
mojo@20131
|
6 Track the current GTK and IGTK that is in use and when receiving a
|
mojo@20131
|
7 (possibly retransmitted) Group Message 1 or WNM-Sleep Mode Response, do
|
mojo@20131
|
8 not install the given key if it is already in use. This prevents an
|
mojo@20131
|
9 attacker from trying to trick the client into resetting or lowering the
|
mojo@20131
|
10 sequence counter associated to the group key.
|
mojo@20131
|
11
|
mojo@20131
|
12 Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
|
mojo@20131
|
13 ---
|
mojo@20131
|
14 src/common/wpa_common.h | 11 +++++
|
mojo@20131
|
15 src/rsn_supp/wpa.c | 116 ++++++++++++++++++++++++++++++------------------
|
mojo@20131
|
16 src/rsn_supp/wpa_i.h | 4 ++
|
mojo@20131
|
17 3 files changed, 87 insertions(+), 44 deletions(-)
|
mojo@20131
|
18
|
mojo@20131
|
19 diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
|
mojo@20131
|
20 index af1d0f0..d200285 100644
|
mojo@20131
|
21 --- a/src/common/wpa_common.h
|
mojo@20131
|
22 +++ b/src/common/wpa_common.h
|
mojo@20131
|
23 @@ -217,6 +217,17 @@ struct wpa_ptk {
|
mojo@20131
|
24 size_t tk_len;
|
mojo@20131
|
25 };
|
mojo@20131
|
26
|
mojo@20131
|
27 +struct wpa_gtk {
|
mojo@20131
|
28 + u8 gtk[WPA_GTK_MAX_LEN];
|
mojo@20131
|
29 + size_t gtk_len;
|
mojo@20131
|
30 +};
|
mojo@20131
|
31 +
|
mojo@20131
|
32 +#ifdef CONFIG_IEEE80211W
|
mojo@20131
|
33 +struct wpa_igtk {
|
mojo@20131
|
34 + u8 igtk[WPA_IGTK_MAX_LEN];
|
mojo@20131
|
35 + size_t igtk_len;
|
mojo@20131
|
36 +};
|
mojo@20131
|
37 +#endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
38
|
mojo@20131
|
39 /* WPA IE version 1
|
mojo@20131
|
40 * 00-50-f2:1 (OUI:OUI type)
|
mojo@20131
|
41 diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
|
mojo@20131
|
42 index 3c47879..95bd7be 100644
|
mojo@20131
|
43 --- a/src/rsn_supp/wpa.c
|
mojo@20131
|
44 +++ b/src/rsn_supp/wpa.c
|
mojo@20131
|
45 @@ -714,6 +714,15 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
|
mojo@20131
|
46 const u8 *_gtk = gd->gtk;
|
mojo@20131
|
47 u8 gtk_buf[32];
|
mojo@20131
|
48
|
mojo@20131
|
49 + /* Detect possible key reinstallation */
|
mojo@20131
|
50 + if (sm->gtk.gtk_len == (size_t) gd->gtk_len &&
|
mojo@20131
|
51 + os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) {
|
mojo@20131
|
52 + wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
|
mojo@20131
|
53 + "WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
|
mojo@20131
|
54 + gd->keyidx, gd->tx, gd->gtk_len);
|
mojo@20131
|
55 + return 0;
|
mojo@20131
|
56 + }
|
mojo@20131
|
57 +
|
mojo@20131
|
58 wpa_hexdump_key(MSG_DEBUG, "WPA: Group Key", gd->gtk, gd->gtk_len);
|
mojo@20131
|
59 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
|
mojo@20131
|
60 "WPA: Installing GTK to the driver (keyidx=%d tx=%d len=%d)",
|
mojo@20131
|
61 @@ -748,6 +757,9 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
|
mojo@20131
|
62 }
|
mojo@20131
|
63 os_memset(gtk_buf, 0, sizeof(gtk_buf));
|
mojo@20131
|
64
|
mojo@20131
|
65 + sm->gtk.gtk_len = gd->gtk_len;
|
mojo@20131
|
66 + os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
|
mojo@20131
|
67 +
|
mojo@20131
|
68 return 0;
|
mojo@20131
|
69 }
|
mojo@20131
|
70
|
mojo@20131
|
71 @@ -854,6 +866,48 @@ static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
|
mojo@20131
|
72 }
|
mojo@20131
|
73
|
mojo@20131
|
74
|
mojo@20131
|
75 +#ifdef CONFIG_IEEE80211W
|
mojo@20131
|
76 +static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
|
mojo@20131
|
77 + const struct wpa_igtk_kde *igtk)
|
mojo@20131
|
78 +{
|
mojo@20131
|
79 + size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
|
mojo@20131
|
80 + u16 keyidx = WPA_GET_LE16(igtk->keyid);
|
mojo@20131
|
81 +
|
mojo@20131
|
82 + /* Detect possible key reinstallation */
|
mojo@20131
|
83 + if (sm->igtk.igtk_len == len &&
|
mojo@20131
|
84 + os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) {
|
mojo@20131
|
85 + wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
|
mojo@20131
|
86 + "WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
|
mojo@20131
|
87 + keyidx);
|
mojo@20131
|
88 + return 0;
|
mojo@20131
|
89 + }
|
mojo@20131
|
90 +
|
mojo@20131
|
91 + wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
|
mojo@20131
|
92 + "WPA: IGTK keyid %d pn %02x%02x%02x%02x%02x%02x",
|
mojo@20131
|
93 + keyidx, MAC2STR(igtk->pn));
|
mojo@20131
|
94 + wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK", igtk->igtk, len);
|
mojo@20131
|
95 + if (keyidx > 4095) {
|
mojo@20131
|
96 + wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
|
mojo@20131
|
97 + "WPA: Invalid IGTK KeyID %d", keyidx);
|
mojo@20131
|
98 + return -1;
|
mojo@20131
|
99 + }
|
mojo@20131
|
100 + if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
|
mojo@20131
|
101 + broadcast_ether_addr,
|
mojo@20131
|
102 + keyidx, 0, igtk->pn, sizeof(igtk->pn),
|
mojo@20131
|
103 + igtk->igtk, len) < 0) {
|
mojo@20131
|
104 + wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
|
mojo@20131
|
105 + "WPA: Failed to configure IGTK to the driver");
|
mojo@20131
|
106 + return -1;
|
mojo@20131
|
107 + }
|
mojo@20131
|
108 +
|
mojo@20131
|
109 + sm->igtk.igtk_len = len;
|
mojo@20131
|
110 + os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
|
mojo@20131
|
111 +
|
mojo@20131
|
112 + return 0;
|
mojo@20131
|
113 +}
|
mojo@20131
|
114 +#endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
115 +
|
mojo@20131
|
116 +
|
mojo@20131
|
117 static int ieee80211w_set_keys(struct wpa_sm *sm,
|
mojo@20131
|
118 struct wpa_eapol_ie_parse *ie)
|
mojo@20131
|
119 {
|
mojo@20131
|
120 @@ -864,30 +918,14 @@ static int ieee80211w_set_keys(struct wpa_sm *sm,
|
mojo@20131
|
121 if (ie->igtk) {
|
mojo@20131
|
122 size_t len;
|
mojo@20131
|
123 const struct wpa_igtk_kde *igtk;
|
mojo@20131
|
124 - u16 keyidx;
|
mojo@20131
|
125 +
|
mojo@20131
|
126 len = wpa_cipher_key_len(sm->mgmt_group_cipher);
|
mojo@20131
|
127 if (ie->igtk_len != WPA_IGTK_KDE_PREFIX_LEN + len)
|
mojo@20131
|
128 return -1;
|
mojo@20131
|
129 +
|
mojo@20131
|
130 igtk = (const struct wpa_igtk_kde *) ie->igtk;
|
mojo@20131
|
131 - keyidx = WPA_GET_LE16(igtk->keyid);
|
mojo@20131
|
132 - wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: IGTK keyid %d "
|
mojo@20131
|
133 - "pn %02x%02x%02x%02x%02x%02x",
|
mojo@20131
|
134 - keyidx, MAC2STR(igtk->pn));
|
mojo@20131
|
135 - wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK",
|
mojo@20131
|
136 - igtk->igtk, len);
|
mojo@20131
|
137 - if (keyidx > 4095) {
|
mojo@20131
|
138 - wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
|
mojo@20131
|
139 - "WPA: Invalid IGTK KeyID %d", keyidx);
|
mojo@20131
|
140 - return -1;
|
mojo@20131
|
141 - }
|
mojo@20131
|
142 - if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
|
mojo@20131
|
143 - broadcast_ether_addr,
|
mojo@20131
|
144 - keyidx, 0, igtk->pn, sizeof(igtk->pn),
|
mojo@20131
|
145 - igtk->igtk, len) < 0) {
|
mojo@20131
|
146 - wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
|
mojo@20131
|
147 - "WPA: Failed to configure IGTK to the driver");
|
mojo@20131
|
148 + if (wpa_supplicant_install_igtk(sm, igtk) < 0)
|
mojo@20131
|
149 return -1;
|
mojo@20131
|
150 - }
|
mojo@20131
|
151 }
|
mojo@20131
|
152
|
mojo@20131
|
153 return 0;
|
mojo@20131
|
154 @@ -2307,7 +2345,7 @@ void wpa_sm_deinit(struct wpa_sm *sm)
|
mojo@20131
|
155 */
|
mojo@20131
|
156 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
|
mojo@20131
|
157 {
|
mojo@20131
|
158 - int clear_ptk = 1;
|
mojo@20131
|
159 + int clear_keys = 1;
|
mojo@20131
|
160
|
mojo@20131
|
161 if (sm == NULL)
|
mojo@20131
|
162 return;
|
mojo@20131
|
163 @@ -2333,11 +2371,11 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
|
mojo@20131
|
164 /* Prepare for the next transition */
|
mojo@20131
|
165 wpa_ft_prepare_auth_request(sm, NULL);
|
mojo@20131
|
166
|
mojo@20131
|
167 - clear_ptk = 0;
|
mojo@20131
|
168 + clear_keys = 0;
|
mojo@20131
|
169 }
|
mojo@20131
|
170 #endif /* CONFIG_IEEE80211R */
|
mojo@20131
|
171
|
mojo@20131
|
172 - if (clear_ptk) {
|
mojo@20131
|
173 + if (clear_keys) {
|
mojo@20131
|
174 /*
|
mojo@20131
|
175 * IEEE 802.11, 8.4.10: Delete PTK SA on (re)association if
|
mojo@20131
|
176 * this is not part of a Fast BSS Transition.
|
mojo@20131
|
177 @@ -2347,6 +2385,10 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
|
mojo@20131
|
178 os_memset(&sm->ptk, 0, sizeof(sm->ptk));
|
mojo@20131
|
179 sm->tptk_set = 0;
|
mojo@20131
|
180 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
|
mojo@20131
|
181 + os_memset(&sm->gtk, 0, sizeof(sm->gtk));
|
mojo@20131
|
182 +#ifdef CONFIG_IEEE80211W
|
mojo@20131
|
183 + os_memset(&sm->igtk, 0, sizeof(sm->igtk));
|
mojo@20131
|
184 +#endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
185 }
|
mojo@20131
|
186
|
mojo@20131
|
187 #ifdef CONFIG_TDLS
|
mojo@20131
|
188 @@ -2877,6 +2919,10 @@ void wpa_sm_drop_sa(struct wpa_sm *sm)
|
mojo@20131
|
189 os_memset(sm->pmk, 0, sizeof(sm->pmk));
|
mojo@20131
|
190 os_memset(&sm->ptk, 0, sizeof(sm->ptk));
|
mojo@20131
|
191 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
|
mojo@20131
|
192 + os_memset(&sm->gtk, 0, sizeof(sm->gtk));
|
mojo@20131
|
193 +#ifdef CONFIG_IEEE80211W
|
mojo@20131
|
194 + os_memset(&sm->igtk, 0, sizeof(sm->igtk));
|
mojo@20131
|
195 +#endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
196 #ifdef CONFIG_IEEE80211R
|
mojo@20131
|
197 os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
|
mojo@20131
|
198 os_memset(sm->pmk_r0, 0, sizeof(sm->pmk_r0));
|
mojo@20131
|
199 @@ -2949,29 +2995,11 @@ int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
|
mojo@20131
|
200 os_memset(&gd, 0, sizeof(gd));
|
mojo@20131
|
201 #ifdef CONFIG_IEEE80211W
|
mojo@20131
|
202 } else if (subelem_id == WNM_SLEEP_SUBELEM_IGTK) {
|
mojo@20131
|
203 - struct wpa_igtk_kde igd;
|
mojo@20131
|
204 - u16 keyidx;
|
mojo@20131
|
205 -
|
mojo@20131
|
206 - os_memset(&igd, 0, sizeof(igd));
|
mojo@20131
|
207 - keylen = wpa_cipher_key_len(sm->mgmt_group_cipher);
|
mojo@20131
|
208 - os_memcpy(igd.keyid, buf + 2, 2);
|
mojo@20131
|
209 - os_memcpy(igd.pn, buf + 4, 6);
|
mojo@20131
|
210 -
|
mojo@20131
|
211 - keyidx = WPA_GET_LE16(igd.keyid);
|
mojo@20131
|
212 - os_memcpy(igd.igtk, buf + 10, keylen);
|
mojo@20131
|
213 -
|
mojo@20131
|
214 - wpa_hexdump_key(MSG_DEBUG, "Install IGTK (WNM SLEEP)",
|
mojo@20131
|
215 - igd.igtk, keylen);
|
mojo@20131
|
216 - if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
|
mojo@20131
|
217 - broadcast_ether_addr,
|
mojo@20131
|
218 - keyidx, 0, igd.pn, sizeof(igd.pn),
|
mojo@20131
|
219 - igd.igtk, keylen) < 0) {
|
mojo@20131
|
220 - wpa_printf(MSG_DEBUG, "Failed to install the IGTK in "
|
mojo@20131
|
221 - "WNM mode");
|
mojo@20131
|
222 - os_memset(&igd, 0, sizeof(igd));
|
mojo@20131
|
223 + const struct wpa_igtk_kde *igtk;
|
mojo@20131
|
224 +
|
mojo@20131
|
225 + igtk = (const struct wpa_igtk_kde *) (buf + 2);
|
mojo@20131
|
226 + if (wpa_supplicant_install_igtk(sm, igtk) < 0)
|
mojo@20131
|
227 return -1;
|
mojo@20131
|
228 - }
|
mojo@20131
|
229 - os_memset(&igd, 0, sizeof(igd));
|
mojo@20131
|
230 #endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
231 } else {
|
mojo@20131
|
232 wpa_printf(MSG_DEBUG, "Unknown element id");
|
mojo@20131
|
233 diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
|
mojo@20131
|
234 index f653ba6..afc9e37 100644
|
mojo@20131
|
235 --- a/src/rsn_supp/wpa_i.h
|
mojo@20131
|
236 +++ b/src/rsn_supp/wpa_i.h
|
mojo@20131
|
237 @@ -31,6 +31,10 @@ struct wpa_sm {
|
mojo@20131
|
238 u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
|
mojo@20131
|
239 int rx_replay_counter_set;
|
mojo@20131
|
240 u8 request_counter[WPA_REPLAY_COUNTER_LEN];
|
mojo@20131
|
241 + struct wpa_gtk gtk;
|
mojo@20131
|
242 +#ifdef CONFIG_IEEE80211W
|
mojo@20131
|
243 + struct wpa_igtk igtk;
|
mojo@20131
|
244 +#endif /* CONFIG_IEEE80211W */
|
mojo@20131
|
245
|
mojo@20131
|
246 struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
|
mojo@20131
|
247
|
mojo@20131
|
248 --
|
mojo@20131
|
249 2.7.4
|
mojo@20131
|
250
|