Blame SOURCES/rh1500442-wpa_supplicant-Fix-memory-leaks-in-ieee802_1x_create.patch

9c84ec
From 22151b111b493d4604c9490327c40fdac7bc4b37 Mon Sep 17 00:00:00 2001
9c84ec
Message-Id: <22151b111b493d4604c9490327c40fdac7bc4b37.1525684664.git.davide.caratti@gmail.com>
9c84ec
From: Davide Caratti <davide.caratti@gmail.com>
9c84ec
Date: Thu, 8 Mar 2018 17:15:02 +0100
9c84ec
Subject: [PATCH] wpa_supplicant: Fix memory leaks in
9c84ec
 ieee802_1x_create_preshared_mka()
9c84ec
9c84ec
In case MKA is initialized successfully, local copies of CAK and CKN
9c84ec
were allocated, but never freed. Ensure that such memory is released
9c84ec
also when ieee802_1x_kay_create_mka() returns a valid pointer.
9c84ec
9c84ec
Fixes: ad51731abf06 ("wpa_supplicant: Allow pre-shared (CAK,CKN) pair for MKA")
9c84ec
Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
9c84ec
---
9c84ec
 wpa_supplicant/wpas_kay.c | 32 +++++++++++++++-----------------
9c84ec
 1 file changed, 15 insertions(+), 17 deletions(-)
9c84ec
9c84ec
diff --git a/wpa_supplicant/wpas_kay.c b/wpa_supplicant/wpas_kay.c
9c84ec
index 11708b8a6..d3d06b8ae 100644
9c84ec
--- a/wpa_supplicant/wpas_kay.c
9c84ec
+++ b/wpa_supplicant/wpas_kay.c
9c84ec
@@ -392,25 +392,25 @@ void * ieee802_1x_create_preshared_mka(struct wpa_supplicant *wpa_s,
9c84ec
 {
9c84ec
 	struct mka_key *cak;
9c84ec
 	struct mka_key_name *ckn;
9c84ec
-	void *res;
9c84ec
+	void *res = NULL;
9c84ec
 
9c84ec
 	if ((ssid->mka_psk_set & MKA_PSK_SET) != MKA_PSK_SET)
9c84ec
-		return NULL;
9c84ec
-
9c84ec
-	if (ieee802_1x_alloc_kay_sm(wpa_s, ssid) < 0)
9c84ec
-		return NULL;
9c84ec
-
9c84ec
-	if (!wpa_s->kay || wpa_s->kay->policy == DO_NOT_SECURE)
9c84ec
-		return NULL;
9c84ec
+		goto end;
9c84ec
 
9c84ec
 	ckn = os_zalloc(sizeof(*ckn));
9c84ec
 	if (!ckn)
9c84ec
-		goto dealloc;
9c84ec
+		goto end;
9c84ec
 
9c84ec
 	cak = os_zalloc(sizeof(*cak));
9c84ec
 	if (!cak)
9c84ec
 		goto free_ckn;
9c84ec
 
9c84ec
+	if (ieee802_1x_alloc_kay_sm(wpa_s, ssid) < 0 || !wpa_s->kay)
9c84ec
+		goto free_cak;
9c84ec
+
9c84ec
+	if (wpa_s->kay->policy == DO_NOT_SECURE)
9c84ec
+		goto dealloc;
9c84ec
+
9c84ec
 	cak->len = MACSEC_CAK_LEN;
9c84ec
 	os_memcpy(cak->key, ssid->mka_cak, cak->len);
9c84ec
 
9c84ec
@@ -419,17 +419,15 @@ void * ieee802_1x_create_preshared_mka(struct wpa_supplicant *wpa_s,
9c84ec
 
9c84ec
 	res = ieee802_1x_kay_create_mka(wpa_s->kay, ckn, cak, 0, PSK, FALSE);
9c84ec
 	if (res)
9c84ec
-		return res;
9c84ec
+		goto free_cak;
9c84ec
 
9c84ec
+dealloc:
9c84ec
 	/* Failed to create MKA */
9c84ec
+	ieee802_1x_dealloc_kay_sm(wpa_s);
9c84ec
+free_cak:
9c84ec
 	os_free(cak);
9c84ec
-
9c84ec
-	/* fallthrough */
9c84ec
-
9c84ec
 free_ckn:
9c84ec
 	os_free(ckn);
9c84ec
-dealloc:
9c84ec
-	ieee802_1x_dealloc_kay_sm(wpa_s);
9c84ec
-
9c84ec
-	return NULL;
9c84ec
+end:
9c84ec
+	return res;
9c84ec
 }
9c84ec
-- 
9c84ec
2.14.3
9c84ec