ed7d79ec1b728e92abd08836f418562a6f3243c7
[openwrt/staging/lynxis.git] /
1 From b488a12948751f57871f09baa345e59b23959a41 Mon Sep 17 00:00:00 2001
2 From: Jouni Malinen <j@w1.fi>
3 Date: Sun, 8 Oct 2017 13:18:02 +0300
4 Subject: [PATCH] Clear PMK length and check for this when deriving PTK
5
6 Instead of setting the default PMK length for the cleared PMK, set the
7 length to 0 and explicitly check for this when deriving PTK to avoid
8 unexpected key derivation with an all-zeroes key should it be possible
9 to somehow trigger PTK derivation to happen before PMK derivation.
10
11 Signed-off-by: Jouni Malinen <j@w1.fi>
12 ---
13 src/common/wpa_common.c | 5 +++++
14 src/rsn_supp/wpa.c | 7 ++++---
15 2 files changed, 9 insertions(+), 3 deletions(-)
16
17 --- a/src/common/wpa_common.c
18 +++ b/src/common/wpa_common.c
19 @@ -225,6 +225,11 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t
20 u8 tmp[WPA_KCK_MAX_LEN + WPA_KEK_MAX_LEN + WPA_TK_MAX_LEN];
21 size_t ptk_len;
22
23 + if (pmk_len == 0) {
24 + wpa_printf(MSG_ERROR, "WPA: No PMK set for PT derivation");
25 + return -1;
26 + }
27 +
28 if (os_memcmp(addr1, addr2, ETH_ALEN) < 0) {
29 os_memcpy(data, addr1, ETH_ALEN);
30 os_memcpy(data + ETH_ALEN, addr2, ETH_ALEN);
31 --- a/src/rsn_supp/wpa.c
32 +++ b/src/rsn_supp/wpa.c
33 @@ -584,7 +584,8 @@ static void wpa_supplicant_process_1_of_
34 /* Calculate PTK which will be stored as a temporary PTK until it has
35 * been verified when processing message 3/4. */
36 ptk = &sm->tptk;
37 - wpa_derive_ptk(sm, src_addr, key, ptk);
38 + if (wpa_derive_ptk(sm, src_addr, key, ptk) < 0)
39 + goto failed;
40 if (sm->pairwise_cipher == WPA_CIPHER_TKIP) {
41 u8 buf[8];
42 /* Supplicant: swap tx/rx Mic keys */
43 @@ -2705,8 +2706,8 @@ void wpa_sm_set_pmk_from_pmksa(struct wp
44 sm->pmk_len = sm->cur_pmksa->pmk_len;
45 os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len);
46 } else {
47 - sm->pmk_len = PMK_LEN;
48 - os_memset(sm->pmk, 0, PMK_LEN);
49 + sm->pmk_len = 0;
50 + os_memset(sm->pmk, 0, PMK_LEN_MAX);
51 }
52 }
53