Blame SOURCES/rh1495527-0004-Prevent-installation-of-an-all-zero-TK.patch

9c84ec
From 8f82bc94e8697a9d47fa8774dfdaaede1084912c Mon Sep 17 00:00:00 2001
9c84ec
From: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
9c84ec
Date: Fri, 29 Sep 2017 04:22:51 +0200
9c84ec
Subject: [PATCH 4/8] Prevent installation of an all-zero TK
9c84ec
9c84ec
Properly track whether a PTK has already been installed to the driver
9c84ec
and the TK part cleared from memory. This prevents an attacker from
9c84ec
trying to trick the client into installing an all-zero TK.
9c84ec
9c84ec
This fixes the earlier fix in commit
9c84ec
ad00d64e7d8827b3cebd665a0ceb08adabf15e1e ('Fix TK configuration to the
9c84ec
driver in EAPOL-Key 3/4 retry case') which did not take into account
9c84ec
possibility of an extra message 1/4 showing up between retries of
9c84ec
message 3/4.
9c84ec
9c84ec
Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
9c84ec
---
9c84ec
 src/common/wpa_common.h | 1 +
9c84ec
 src/rsn_supp/wpa.c      | 5 ++---
9c84ec
 src/rsn_supp/wpa_i.h    | 1 -
9c84ec
 3 files changed, 3 insertions(+), 4 deletions(-)
9c84ec
9c84ec
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
9c84ec
index d200285..1021ccb 100644
9c84ec
--- a/src/common/wpa_common.h
9c84ec
+++ b/src/common/wpa_common.h
9c84ec
@@ -215,6 +215,7 @@ struct wpa_ptk {
9c84ec
 	size_t kck_len;
9c84ec
 	size_t kek_len;
9c84ec
 	size_t tk_len;
9c84ec
+	int installed; /* 1 if key has already been installed to driver */
9c84ec
 };
9c84ec
 
9c84ec
 struct wpa_gtk {
9c84ec
diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
9c84ec
index 7a2c68d..0550a41 100644
9c84ec
--- a/src/rsn_supp/wpa.c
9c84ec
+++ b/src/rsn_supp/wpa.c
9c84ec
@@ -510,7 +510,6 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
9c84ec
 		os_memset(buf, 0, sizeof(buf));
9c84ec
 	}
9c84ec
 	sm->tptk_set = 1;
9c84ec
-	sm->tk_to_set = 1;
9c84ec
 
9c84ec
 	kde = sm->assoc_wpa_ie;
9c84ec
 	kde_len = sm->assoc_wpa_ie_len;
9c84ec
@@ -615,7 +614,7 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
9c84ec
 	enum wpa_alg alg;
9c84ec
 	const u8 *key_rsc;
9c84ec
 
9c84ec
-	if (!sm->tk_to_set) {
9c84ec
+	if (sm->ptk.installed) {
9c84ec
 		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
9c84ec
 			"WPA: Do not re-install same PTK to the driver");
9c84ec
 		return 0;
9c84ec
@@ -659,7 +658,7 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
9c84ec
 
9c84ec
 	/* TK is not needed anymore in supplicant */
9c84ec
 	os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN);
9c84ec
-	sm->tk_to_set = 0;
9c84ec
+	sm->ptk.installed = 1;
9c84ec
 
9c84ec
 	if (sm->wpa_ptk_rekey) {
9c84ec
 		eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
9c84ec
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
9c84ec
index 9a54631..41f371f 100644
9c84ec
--- a/src/rsn_supp/wpa_i.h
9c84ec
+++ b/src/rsn_supp/wpa_i.h
9c84ec
@@ -24,7 +24,6 @@ struct wpa_sm {
9c84ec
 	struct wpa_ptk ptk, tptk;
9c84ec
 	int ptk_set, tptk_set;
9c84ec
 	unsigned int msg_3_of_4_ok:1;
9c84ec
-	unsigned int tk_to_set:1;
9c84ec
 	u8 snonce[WPA_NONCE_LEN];
9c84ec
 	u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
9c84ec
 	int renew_snonce;
9c84ec
-- 
9c84ec
2.7.4
9c84ec