Blame SOURCES/rh1495527-0003-Extend-protection-of-GTK-IGTK-reinstallation-of-WNM-.patch

41389a
From 8280294e74846ea342389a0cd17215050fa5afe8 Mon Sep 17 00:00:00 2001
41389a
From: Jouni Malinen <j@w1.fi>
41389a
Date: Sun, 1 Oct 2017 12:12:24 +0300
41389a
Subject: [PATCH 3/8] Extend protection of GTK/IGTK reinstallation of WNM-Sleep
41389a
 Mode cases
41389a
41389a
This extends the protection to track last configured GTK/IGTK value
41389a
separately from EAPOL-Key frames and WNM-Sleep Mode frames to cover a
41389a
corner case where these two different mechanisms may get used when the
41389a
GTK/IGTK has changed and tracking a single value is not sufficient to
41389a
detect a possible key reconfiguration.
41389a
41389a
Signed-off-by: Jouni Malinen <j@w1.fi>
41389a
---
41389a
 src/rsn_supp/wpa.c   | 53 +++++++++++++++++++++++++++++++++++++---------------
41389a
 src/rsn_supp/wpa_i.h |  2 ++
41389a
 2 files changed, 40 insertions(+), 15 deletions(-)
41389a
41389a
diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
41389a
index 95bd7be..7a2c68d 100644
41389a
--- a/src/rsn_supp/wpa.c
41389a
+++ b/src/rsn_supp/wpa.c
41389a
@@ -709,14 +709,17 @@ struct wpa_gtk_data {
41389a
 
41389a
 static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
41389a
 				      const struct wpa_gtk_data *gd,
41389a
-				      const u8 *key_rsc)
41389a
+				      const u8 *key_rsc, int wnm_sleep)
41389a
 {
41389a
 	const u8 *_gtk = gd->gtk;
41389a
 	u8 gtk_buf[32];
41389a
 
41389a
 	/* Detect possible key reinstallation */
41389a
-	if (sm->gtk.gtk_len == (size_t) gd->gtk_len &&
41389a
-	    os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) {
41389a
+	if ((sm->gtk.gtk_len == (size_t) gd->gtk_len &&
41389a
+	     os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) ||
41389a
+	    (sm->gtk_wnm_sleep.gtk_len == (size_t) gd->gtk_len &&
41389a
+	     os_memcmp(sm->gtk_wnm_sleep.gtk, gd->gtk,
41389a
+		       sm->gtk_wnm_sleep.gtk_len) == 0)) {
41389a
 		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
41389a
 			"WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
41389a
 			gd->keyidx, gd->tx, gd->gtk_len);
41389a
@@ -757,8 +760,14 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
41389a
 	}
41389a
 	os_memset(gtk_buf, 0, sizeof(gtk_buf));
41389a
 
41389a
-	sm->gtk.gtk_len = gd->gtk_len;
41389a
-	os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
41389a
+	if (wnm_sleep) {
41389a
+		sm->gtk_wnm_sleep.gtk_len = gd->gtk_len;
41389a
+		os_memcpy(sm->gtk_wnm_sleep.gtk, gd->gtk,
41389a
+			  sm->gtk_wnm_sleep.gtk_len);
41389a
+	} else {
41389a
+		sm->gtk.gtk_len = gd->gtk_len;
41389a
+		os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
41389a
+	}
41389a
 
41389a
 	return 0;
41389a
 }
41389a
@@ -852,7 +861,7 @@ static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
41389a
 	    (wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
41389a
 					       gtk_len, gtk_len,
41389a
 					       &gd.key_rsc_len, &gd.alg) ||
41389a
-	     wpa_supplicant_install_gtk(sm, &gd, key_rsc))) {
41389a
+	     wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0))) {
41389a
 		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
41389a
 			"RSN: Failed to install GTK");
41389a
 		os_memset(&gd, 0, sizeof(gd));
41389a
@@ -868,14 +877,18 @@ static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
41389a
 
41389a
 #ifdef CONFIG_IEEE80211W
41389a
 static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
41389a
-				       const struct wpa_igtk_kde *igtk)
41389a
+				       const struct wpa_igtk_kde *igtk,
41389a
+				       int wnm_sleep)
41389a
 {
41389a
 	size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
41389a
 	u16 keyidx = WPA_GET_LE16(igtk->keyid);
41389a
 
41389a
 	/* Detect possible key reinstallation */
41389a
-	if (sm->igtk.igtk_len == len &&
41389a
-	    os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) {
41389a
+	if ((sm->igtk.igtk_len == len &&
41389a
+	     os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) ||
41389a
+	    (sm->igtk_wnm_sleep.igtk_len == len &&
41389a
+	     os_memcmp(sm->igtk_wnm_sleep.igtk, igtk->igtk,
41389a
+		       sm->igtk_wnm_sleep.igtk_len) == 0)) {
41389a
 		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
41389a
 			"WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
41389a
 			keyidx);
41389a
@@ -900,8 +913,14 @@ static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
41389a
 		return -1;
41389a
 	}
41389a
 
41389a
-	sm->igtk.igtk_len = len;
41389a
-	os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
41389a
+	if (wnm_sleep) {
41389a
+		sm->igtk_wnm_sleep.igtk_len = len;
41389a
+		os_memcpy(sm->igtk_wnm_sleep.igtk, igtk->igtk,
41389a
+			  sm->igtk_wnm_sleep.igtk_len);
41389a
+	} else {
41389a
+		sm->igtk.igtk_len = len;
41389a
+		os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
41389a
+	}
41389a
 
41389a
 	return 0;
41389a
 }
41389a
@@ -924,7 +943,7 @@ static int ieee80211w_set_keys(struct wpa_sm *sm,
41389a
 			return -1;
41389a
 
41389a
 		igtk = (const struct wpa_igtk_kde *) ie->igtk;
41389a
-		if (wpa_supplicant_install_igtk(sm, igtk) < 0)
41389a
+		if (wpa_supplicant_install_igtk(sm, igtk, 0) < 0)
41389a
 			return -1;
41389a
 	}
41389a
 
41389a
@@ -1574,7 +1593,7 @@ static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
41389a
 	if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc))
41389a
 		key_rsc = null_rsc;
41389a
 
41389a
-	if (wpa_supplicant_install_gtk(sm, &gd, key_rsc) ||
41389a
+	if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0) ||
41389a
 	    wpa_supplicant_send_2_of_2(sm, key, ver, key_info) < 0)
41389a
 		goto failed;
41389a
 	os_memset(&gd, 0, sizeof(gd));
41389a
@@ -2386,8 +2405,10 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
41389a
 		sm->tptk_set = 0;
41389a
 		os_memset(&sm->tptk, 0, sizeof(sm->tptk));
41389a
 		os_memset(&sm->gtk, 0, sizeof(sm->gtk));
41389a
+		os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
41389a
 #ifdef CONFIG_IEEE80211W
41389a
 		os_memset(&sm->igtk, 0, sizeof(sm->igtk));
41389a
+		os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
41389a
 #endif /* CONFIG_IEEE80211W */
41389a
 	}
41389a
 
41389a
@@ -2920,8 +2941,10 @@ void wpa_sm_drop_sa(struct wpa_sm *sm)
41389a
 	os_memset(&sm->ptk, 0, sizeof(sm->ptk));
41389a
 	os_memset(&sm->tptk, 0, sizeof(sm->tptk));
41389a
 	os_memset(&sm->gtk, 0, sizeof(sm->gtk));
41389a
+	os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
41389a
 #ifdef CONFIG_IEEE80211W
41389a
 	os_memset(&sm->igtk, 0, sizeof(sm->igtk));
41389a
+	os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
41389a
 #endif /* CONFIG_IEEE80211W */
41389a
 #ifdef CONFIG_IEEE80211R
41389a
 	os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
41389a
@@ -2986,7 +3009,7 @@ int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
41389a
 
41389a
 		wpa_hexdump_key(MSG_DEBUG, "Install GTK (WNM SLEEP)",
41389a
 				gd.gtk, gd.gtk_len);
41389a
-		if (wpa_supplicant_install_gtk(sm, &gd, key_rsc)) {
41389a
+		if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 1)) {
41389a
 			os_memset(&gd, 0, sizeof(gd));
41389a
 			wpa_printf(MSG_DEBUG, "Failed to install the GTK in "
41389a
 				   "WNM mode");
41389a
@@ -2998,7 +3021,7 @@ int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
41389a
 		const struct wpa_igtk_kde *igtk;
41389a
 
41389a
 		igtk = (const struct wpa_igtk_kde *) (buf + 2);
41389a
-		if (wpa_supplicant_install_igtk(sm, igtk) < 0)
41389a
+		if (wpa_supplicant_install_igtk(sm, igtk, 1) < 0)
41389a
 			return -1;
41389a
 #endif /* CONFIG_IEEE80211W */
41389a
 	} else {
41389a
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
41389a
index afc9e37..9a54631 100644
41389a
--- a/src/rsn_supp/wpa_i.h
41389a
+++ b/src/rsn_supp/wpa_i.h
41389a
@@ -32,8 +32,10 @@ struct wpa_sm {
41389a
 	int rx_replay_counter_set;
41389a
 	u8 request_counter[WPA_REPLAY_COUNTER_LEN];
41389a
 	struct wpa_gtk gtk;
41389a
+	struct wpa_gtk gtk_wnm_sleep;
41389a
 #ifdef CONFIG_IEEE80211W
41389a
 	struct wpa_igtk igtk;
41389a
+	struct wpa_igtk igtk_wnm_sleep;
41389a
 #endif /* CONFIG_IEEE80211W */
41389a
 
41389a
 	struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
41389a
-- 
41389a
2.7.4
41389a