[PATCH 6/7] TDLS: remove peer from global peer-list on free
Ilan Peer
ilan.peer
Tue Jun 10 11:19:09 PDT 2014
From: Arik Nemtsov <arik at wizery.com>
Also fix a small bug where a peer was used after free.
Signed-off-by: Arik Nemtsov <arikx.nemtsov at intel.com>
---
src/rsn_supp/tdls.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/rsn_supp/tdls.c b/src/rsn_supp/tdls.c
index d8f7a47..96417d2 100644
--- a/src/rsn_supp/tdls.c
+++ b/src/rsn_supp/tdls.c
@@ -635,6 +635,28 @@ static void wpa_tdls_tpk_timeout(void *eloop_ctx, void *timeout_ctx)
}
+static void wpa_tdls_peer_remove_from_list(struct wpa_sm *sm,
+ struct wpa_tdls_peer *peer)
+{
+ struct wpa_tdls_peer *cur, *prev;
+
+ for (cur = sm->tdls, prev = NULL; cur && cur != peer;
+ prev = cur, cur = cur->next)
+ ;
+
+ if (cur != peer) {
+ wpa_printf(MSG_ERROR, "TDLS: could not find peer " MACSTR,
+ MAC2STR(peer->addr));
+ return;
+ }
+
+ if (prev)
+ prev->next = peer->next;
+ else
+ sm->tdls = peer->next;
+}
+
+
static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
{
wpa_printf(MSG_DEBUG, "TDLS: Clear state for peer " MACSTR,
@@ -664,6 +686,9 @@ static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
os_memset(&peer->tpk, 0, sizeof(peer->tpk));
os_memset(peer->inonce, 0, WPA_NONCE_LEN);
os_memset(peer->rnonce, 0, WPA_NONCE_LEN);
+
+ wpa_tdls_peer_remove_from_list(sm, peer);
+ os_free(peer);
}
@@ -2619,13 +2644,14 @@ int wpa_tdls_init(struct wpa_sm *sm)
void wpa_tdls_teardown_peers(struct wpa_sm *sm)
{
- struct wpa_tdls_peer *peer;
+ struct wpa_tdls_peer *peer, *tmp;
peer = sm->tdls;
wpa_printf(MSG_DEBUG, "TDLS: Tear down peers");
while (peer) {
+ tmp = peer->next;
wpa_printf(MSG_DEBUG, "TDLS: Tear down peer " MACSTR,
MAC2STR(peer->addr));
if (sm->tdls_external_setup)
@@ -2634,7 +2660,7 @@ void wpa_tdls_teardown_peers(struct wpa_sm *sm)
else
wpa_sm_tdls_oper(sm, TDLS_TEARDOWN, peer->addr);
- peer = peer->next;
+ peer = tmp;
}
}
@@ -2644,7 +2670,6 @@ static void wpa_tdls_remove_peers(struct wpa_sm *sm)
struct wpa_tdls_peer *peer, *tmp;
peer = sm->tdls;
- sm->tdls = NULL;
while (peer) {
int res;
@@ -2653,7 +2678,6 @@ static void wpa_tdls_remove_peers(struct wpa_sm *sm)
wpa_printf(MSG_DEBUG, "TDLS: Remove peer " MACSTR " (res=%d)",
MAC2STR(peer->addr), res);
wpa_tdls_peer_free(sm, peer);
- os_free(peer);
peer = tmp;
}
}
--
1.7.10.4
More information about the Hostap
mailing list