hostapd: return with 80211 codes in handle event function
[oweals/openwrt.git] / package / network / services / hostapd / patches / 003-Prevent-installation-of-an-all-zero-TK.patch
1 From: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
2 Date: Fri, 29 Sep 2017 04:22:51 +0200
3 Subject: [PATCH] Prevent installation of an all-zero TK
4
5 Properly track whether a PTK has already been installed to the driver
6 and the TK part cleared from memory. This prevents an attacker from
7 trying to trick the client into installing an all-zero TK.
8
9 This fixes the earlier fix in commit
10 ad00d64e7d8827b3cebd665a0ceb08adabf15e1e ('Fix TK configuration to the
11 driver in EAPOL-Key 3/4 retry case') which did not take into account
12 possibility of an extra message 1/4 showing up between retries of
13 message 3/4.
14
15 Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
16 ---
17
18 --- a/src/common/wpa_common.h
19 +++ b/src/common/wpa_common.h
20 @@ -216,6 +216,7 @@ struct wpa_ptk {
21         size_t kck_len;
22         size_t kek_len;
23         size_t tk_len;
24 +       int installed; /* 1 if key has already been installed to driver */
25  };
26  
27  struct wpa_gtk {
28 --- a/src/rsn_supp/wpa.c
29 +++ b/src/rsn_supp/wpa.c
30 @@ -594,7 +594,6 @@ static void wpa_supplicant_process_1_of_
31                 os_memset(buf, 0, sizeof(buf));
32         }
33         sm->tptk_set = 1;
34 -       sm->tk_to_set = 1;
35  
36         kde = sm->assoc_wpa_ie;
37         kde_len = sm->assoc_wpa_ie_len;
38 @@ -701,7 +700,7 @@ static int wpa_supplicant_install_ptk(st
39         enum wpa_alg alg;
40         const u8 *key_rsc;
41  
42 -       if (!sm->tk_to_set) {
43 +       if (sm->ptk.installed) {
44                 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
45                         "WPA: Do not re-install same PTK to the driver");
46                 return 0;
47 @@ -745,7 +744,7 @@ static int wpa_supplicant_install_ptk(st
48  
49         /* TK is not needed anymore in supplicant */
50         os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN);
51 -       sm->tk_to_set = 0;
52 +       sm->ptk.installed = 1;
53  
54         if (sm->wpa_ptk_rekey) {
55                 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
56 @@ -4172,6 +4171,7 @@ int fils_process_assoc_resp(struct wpa_s
57          * takes care of association frame encryption/decryption. */
58         /* TK is not needed anymore in supplicant */
59         os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN);
60 +       sm->ptk.installed = 1;
61  
62         /* FILS HLP Container */
63         fils_process_hlp_container(sm, ie_start, end - ie_start);
64 --- a/src/rsn_supp/wpa_i.h
65 +++ b/src/rsn_supp/wpa_i.h
66 @@ -24,7 +24,6 @@ struct wpa_sm {
67         struct wpa_ptk ptk, tptk;
68         int ptk_set, tptk_set;
69         unsigned int msg_3_of_4_ok:1;
70 -       unsigned int tk_to_set:1;
71         u8 snonce[WPA_NONCE_LEN];
72         u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
73         int renew_snonce;