wok diff wpa_supplicant/stuff/rebased-v2.6-0002-Prevent-reinstallation-of-an-already-in-use-group-ke.patch @ rev 21902

updated shaarli again (0.10.3 -> 0.11.1)
author Hans-G?nter Theisgen
date Fri Oct 04 13:14:23 2019 +0100 (2019-10-04)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/wpa_supplicant/stuff/rebased-v2.6-0002-Prevent-reinstallation-of-an-already-in-use-group-ke.patch	Fri Oct 04 13:14:23 2019 +0100
     1.3 @@ -0,0 +1,250 @@
     1.4 +From 927f891007c402fefd1ff384645b3f07597c3ede Mon Sep 17 00:00:00 2001
     1.5 +From: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
     1.6 +Date: Wed, 12 Jul 2017 16:03:24 +0200
     1.7 +Subject: [PATCH 2/8] Prevent reinstallation of an already in-use group key
     1.8 +
     1.9 +Track the current GTK and IGTK that is in use and when receiving a
    1.10 +(possibly retransmitted) Group Message 1 or WNM-Sleep Mode Response, do
    1.11 +not install the given key if it is already in use. This prevents an
    1.12 +attacker from trying to trick the client into resetting or lowering the
    1.13 +sequence counter associated to the group key.
    1.14 +
    1.15 +Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@cs.kuleuven.be>
    1.16 +---
    1.17 + src/common/wpa_common.h |  11 +++++
    1.18 + src/rsn_supp/wpa.c      | 116 ++++++++++++++++++++++++++++++------------------
    1.19 + src/rsn_supp/wpa_i.h    |   4 ++
    1.20 + 3 files changed, 87 insertions(+), 44 deletions(-)
    1.21 +
    1.22 +diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
    1.23 +index af1d0f0..d200285 100644
    1.24 +--- a/src/common/wpa_common.h
    1.25 ++++ b/src/common/wpa_common.h
    1.26 +@@ -217,6 +217,17 @@ struct wpa_ptk {
    1.27 + 	size_t tk_len;
    1.28 + };
    1.29 + 
    1.30 ++struct wpa_gtk {
    1.31 ++	u8 gtk[WPA_GTK_MAX_LEN];
    1.32 ++	size_t gtk_len;
    1.33 ++};
    1.34 ++
    1.35 ++#ifdef CONFIG_IEEE80211W
    1.36 ++struct wpa_igtk {
    1.37 ++	u8 igtk[WPA_IGTK_MAX_LEN];
    1.38 ++	size_t igtk_len;
    1.39 ++};
    1.40 ++#endif /* CONFIG_IEEE80211W */
    1.41 + 
    1.42 + /* WPA IE version 1
    1.43 +  * 00-50-f2:1 (OUI:OUI type)
    1.44 +diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
    1.45 +index 3c47879..95bd7be 100644
    1.46 +--- a/src/rsn_supp/wpa.c
    1.47 ++++ b/src/rsn_supp/wpa.c
    1.48 +@@ -714,6 +714,15 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
    1.49 + 	const u8 *_gtk = gd->gtk;
    1.50 + 	u8 gtk_buf[32];
    1.51 + 
    1.52 ++	/* Detect possible key reinstallation */
    1.53 ++	if (sm->gtk.gtk_len == (size_t) gd->gtk_len &&
    1.54 ++	    os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) {
    1.55 ++		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
    1.56 ++			"WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
    1.57 ++			gd->keyidx, gd->tx, gd->gtk_len);
    1.58 ++		return 0;
    1.59 ++	}
    1.60 ++
    1.61 + 	wpa_hexdump_key(MSG_DEBUG, "WPA: Group Key", gd->gtk, gd->gtk_len);
    1.62 + 	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
    1.63 + 		"WPA: Installing GTK to the driver (keyidx=%d tx=%d len=%d)",
    1.64 +@@ -748,6 +757,9 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
    1.65 + 	}
    1.66 + 	os_memset(gtk_buf, 0, sizeof(gtk_buf));
    1.67 + 
    1.68 ++	sm->gtk.gtk_len = gd->gtk_len;
    1.69 ++	os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
    1.70 ++
    1.71 + 	return 0;
    1.72 + }
    1.73 + 
    1.74 +@@ -854,6 +866,48 @@ static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
    1.75 + }
    1.76 + 
    1.77 + 
    1.78 ++#ifdef CONFIG_IEEE80211W
    1.79 ++static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
    1.80 ++				       const struct wpa_igtk_kde *igtk)
    1.81 ++{
    1.82 ++	size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
    1.83 ++	u16 keyidx = WPA_GET_LE16(igtk->keyid);
    1.84 ++
    1.85 ++	/* Detect possible key reinstallation */
    1.86 ++	if (sm->igtk.igtk_len == len &&
    1.87 ++	    os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) {
    1.88 ++		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
    1.89 ++			"WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
    1.90 ++			keyidx);
    1.91 ++		return  0;
    1.92 ++	}
    1.93 ++
    1.94 ++	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
    1.95 ++		"WPA: IGTK keyid %d pn %02x%02x%02x%02x%02x%02x",
    1.96 ++		keyidx, MAC2STR(igtk->pn));
    1.97 ++	wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK", igtk->igtk, len);
    1.98 ++	if (keyidx > 4095) {
    1.99 ++		wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
   1.100 ++			"WPA: Invalid IGTK KeyID %d", keyidx);
   1.101 ++		return -1;
   1.102 ++	}
   1.103 ++	if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
   1.104 ++			   broadcast_ether_addr,
   1.105 ++			   keyidx, 0, igtk->pn, sizeof(igtk->pn),
   1.106 ++			   igtk->igtk, len) < 0) {
   1.107 ++		wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
   1.108 ++			"WPA: Failed to configure IGTK to the driver");
   1.109 ++		return -1;
   1.110 ++	}
   1.111 ++
   1.112 ++	sm->igtk.igtk_len = len;
   1.113 ++	os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
   1.114 ++
   1.115 ++	return 0;
   1.116 ++}
   1.117 ++#endif /* CONFIG_IEEE80211W */
   1.118 ++
   1.119 ++
   1.120 + static int ieee80211w_set_keys(struct wpa_sm *sm,
   1.121 + 			       struct wpa_eapol_ie_parse *ie)
   1.122 + {
   1.123 +@@ -864,30 +918,14 @@ static int ieee80211w_set_keys(struct wpa_sm *sm,
   1.124 + 	if (ie->igtk) {
   1.125 + 		size_t len;
   1.126 + 		const struct wpa_igtk_kde *igtk;
   1.127 +-		u16 keyidx;
   1.128 ++
   1.129 + 		len = wpa_cipher_key_len(sm->mgmt_group_cipher);
   1.130 + 		if (ie->igtk_len != WPA_IGTK_KDE_PREFIX_LEN + len)
   1.131 + 			return -1;
   1.132 ++
   1.133 + 		igtk = (const struct wpa_igtk_kde *) ie->igtk;
   1.134 +-		keyidx = WPA_GET_LE16(igtk->keyid);
   1.135 +-		wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: IGTK keyid %d "
   1.136 +-			"pn %02x%02x%02x%02x%02x%02x",
   1.137 +-			keyidx, MAC2STR(igtk->pn));
   1.138 +-		wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK",
   1.139 +-				igtk->igtk, len);
   1.140 +-		if (keyidx > 4095) {
   1.141 +-			wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
   1.142 +-				"WPA: Invalid IGTK KeyID %d", keyidx);
   1.143 +-			return -1;
   1.144 +-		}
   1.145 +-		if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
   1.146 +-				   broadcast_ether_addr,
   1.147 +-				   keyidx, 0, igtk->pn, sizeof(igtk->pn),
   1.148 +-				   igtk->igtk, len) < 0) {
   1.149 +-			wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
   1.150 +-				"WPA: Failed to configure IGTK to the driver");
   1.151 ++		if (wpa_supplicant_install_igtk(sm, igtk) < 0)
   1.152 + 			return -1;
   1.153 +-		}
   1.154 + 	}
   1.155 + 
   1.156 + 	return 0;
   1.157 +@@ -2307,7 +2345,7 @@ void wpa_sm_deinit(struct wpa_sm *sm)
   1.158 +  */
   1.159 + void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
   1.160 + {
   1.161 +-	int clear_ptk = 1;
   1.162 ++	int clear_keys = 1;
   1.163 + 
   1.164 + 	if (sm == NULL)
   1.165 + 		return;
   1.166 +@@ -2333,11 +2371,11 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
   1.167 + 		/* Prepare for the next transition */
   1.168 + 		wpa_ft_prepare_auth_request(sm, NULL);
   1.169 + 
   1.170 +-		clear_ptk = 0;
   1.171 ++		clear_keys = 0;
   1.172 + 	}
   1.173 + #endif /* CONFIG_IEEE80211R */
   1.174 + 
   1.175 +-	if (clear_ptk) {
   1.176 ++	if (clear_keys) {
   1.177 + 		/*
   1.178 + 		 * IEEE 802.11, 8.4.10: Delete PTK SA on (re)association if
   1.179 + 		 * this is not part of a Fast BSS Transition.
   1.180 +@@ -2347,6 +2385,10 @@ void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
   1.181 + 		os_memset(&sm->ptk, 0, sizeof(sm->ptk));
   1.182 + 		sm->tptk_set = 0;
   1.183 + 		os_memset(&sm->tptk, 0, sizeof(sm->tptk));
   1.184 ++		os_memset(&sm->gtk, 0, sizeof(sm->gtk));
   1.185 ++#ifdef CONFIG_IEEE80211W
   1.186 ++		os_memset(&sm->igtk, 0, sizeof(sm->igtk));
   1.187 ++#endif /* CONFIG_IEEE80211W */
   1.188 + 	}
   1.189 + 
   1.190 + #ifdef CONFIG_TDLS
   1.191 +@@ -2877,6 +2919,10 @@ void wpa_sm_drop_sa(struct wpa_sm *sm)
   1.192 + 	os_memset(sm->pmk, 0, sizeof(sm->pmk));
   1.193 + 	os_memset(&sm->ptk, 0, sizeof(sm->ptk));
   1.194 + 	os_memset(&sm->tptk, 0, sizeof(sm->tptk));
   1.195 ++	os_memset(&sm->gtk, 0, sizeof(sm->gtk));
   1.196 ++#ifdef CONFIG_IEEE80211W
   1.197 ++	os_memset(&sm->igtk, 0, sizeof(sm->igtk));
   1.198 ++#endif /* CONFIG_IEEE80211W */
   1.199 + #ifdef CONFIG_IEEE80211R
   1.200 + 	os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
   1.201 + 	os_memset(sm->pmk_r0, 0, sizeof(sm->pmk_r0));
   1.202 +@@ -2949,29 +2995,11 @@ int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
   1.203 + 		os_memset(&gd, 0, sizeof(gd));
   1.204 + #ifdef CONFIG_IEEE80211W
   1.205 + 	} else if (subelem_id == WNM_SLEEP_SUBELEM_IGTK) {
   1.206 +-		struct wpa_igtk_kde igd;
   1.207 +-		u16 keyidx;
   1.208 +-
   1.209 +-		os_memset(&igd, 0, sizeof(igd));
   1.210 +-		keylen = wpa_cipher_key_len(sm->mgmt_group_cipher);
   1.211 +-		os_memcpy(igd.keyid, buf + 2, 2);
   1.212 +-		os_memcpy(igd.pn, buf + 4, 6);
   1.213 +-
   1.214 +-		keyidx = WPA_GET_LE16(igd.keyid);
   1.215 +-		os_memcpy(igd.igtk, buf + 10, keylen);
   1.216 +-
   1.217 +-		wpa_hexdump_key(MSG_DEBUG, "Install IGTK (WNM SLEEP)",
   1.218 +-				igd.igtk, keylen);
   1.219 +-		if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
   1.220 +-				   broadcast_ether_addr,
   1.221 +-				   keyidx, 0, igd.pn, sizeof(igd.pn),
   1.222 +-				   igd.igtk, keylen) < 0) {
   1.223 +-			wpa_printf(MSG_DEBUG, "Failed to install the IGTK in "
   1.224 +-				   "WNM mode");
   1.225 +-			os_memset(&igd, 0, sizeof(igd));
   1.226 ++		const struct wpa_igtk_kde *igtk;
   1.227 ++
   1.228 ++		igtk = (const struct wpa_igtk_kde *) (buf + 2);
   1.229 ++		if (wpa_supplicant_install_igtk(sm, igtk) < 0)
   1.230 + 			return -1;
   1.231 +-		}
   1.232 +-		os_memset(&igd, 0, sizeof(igd));
   1.233 + #endif /* CONFIG_IEEE80211W */
   1.234 + 	} else {
   1.235 + 		wpa_printf(MSG_DEBUG, "Unknown element id");
   1.236 +diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
   1.237 +index f653ba6..afc9e37 100644
   1.238 +--- a/src/rsn_supp/wpa_i.h
   1.239 ++++ b/src/rsn_supp/wpa_i.h
   1.240 +@@ -31,6 +31,10 @@ struct wpa_sm {
   1.241 + 	u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
   1.242 + 	int rx_replay_counter_set;
   1.243 + 	u8 request_counter[WPA_REPLAY_COUNTER_LEN];
   1.244 ++	struct wpa_gtk gtk;
   1.245 ++#ifdef CONFIG_IEEE80211W
   1.246 ++	struct wpa_igtk igtk;
   1.247 ++#endif /* CONFIG_IEEE80211W */
   1.248 + 
   1.249 + 	struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
   1.250 + 
   1.251 +-- 
   1.252 +2.7.4
   1.253 +