Skip to content

Commit 6847670

Browse files
Shreyas0-7espressif-bot
authored andcommitted
fix(wifi): Fixed memory leak occurring in SAE PK connection
1 parent 700e41f commit 6847670

File tree

1 file changed

+30
-9
lines changed
  • components/wpa_supplicant/src/common

1 file changed

+30
-9
lines changed

components/wpa_supplicant/src/common/sae_pk.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
620620
int group;
621621
struct wpa_supplicant *wpa_s = &g_wpa_supp;
622622
struct sae_pk_elems elems;
623+
int ret = 0;
623624

624625
if (!tmp) {
625626
return -1;
@@ -650,15 +651,17 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
650651
if (!elems.fils_pk || !elems.fils_key_confirm || !elems.sae_pk) {
651652
wpa_printf(MSG_INFO,
652653
"SAE-PK: Not all mandatory IEs included in confirm");
653-
return -1;
654+
ret = -1;
655+
goto done;
654656
}
655657

656658
/* TODO: Fragment reassembly */
657659

658660
if (elems.sae_pk_len < SAE_PK_M_LEN + AES_BLOCK_SIZE) {
659661
wpa_printf(MSG_INFO,
660662
"SAE-PK: No room for EncryptedModifier in SAE-PK element");
661-
return -1;
663+
ret = -1;
664+
goto done;
662665
}
663666

664667
wpa_hexdump(MSG_DEBUG, "SAE-PK: EncryptedModifier",
@@ -669,14 +672,16 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
669672
0, NULL, NULL, m) < 0) {
670673
wpa_printf(MSG_INFO,
671674
"SAE-PK: Failed to decrypt EncryptedModifier");
672-
return -1;
675+
ret = -1;
676+
goto done;
673677
}
674678
wpa_hexdump_key(MSG_DEBUG, "SAE-PK: Modifier M", m, SAE_PK_M_LEN);
675679

676680
if (elems.fils_pk[0] != 2) {
677681
wpa_printf(MSG_INFO, "SAE-PK: Unsupported public key type %u",
678682
elems.fils_pk[0]);
679-
return -1;
683+
ret = -1;
684+
goto done;
680685
}
681686
k_ap_len = elems.fils_pk_len - 1;
682687
k_ap = elems.fils_pk + 1;
@@ -686,13 +691,15 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
686691
key = crypto_ec_key_parse_pub(k_ap, k_ap_len);
687692
if (!key) {
688693
wpa_printf(MSG_INFO, "SAE-PK: Failed to parse K_AP");
689-
return -1;
694+
ret = -1;
695+
goto done;
690696
}
691697
group = crypto_ec_key_group(key);
692698
if (!sae_pk_valid_fingerprint(sae, m, SAE_PK_M_LEN, k_ap, k_ap_len,
693699
group)) {
694700
crypto_ec_key_deinit(key);
695-
return -1;
701+
ret = -1;
702+
goto done;
696703
}
697704

698705
wpa_hexdump(MSG_DEBUG, "SAE-PK: Received KeyAuth",
@@ -702,7 +709,8 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
702709
if (sae_pk_hash_sig_data(sae, hash_len, false, m, SAE_PK_M_LEN,
703710
k_ap, k_ap_len, hash) < 0) {
704711
crypto_ec_key_deinit(key);
705-
return -1;
712+
ret = -1;
713+
goto done;
706714
}
707715

708716
res = crypto_ec_key_verify_signature(key, hash, hash_len,
@@ -713,12 +721,25 @@ int sae_check_confirm_pk(struct sae_data *sae, const u8 *ies, size_t ies_len)
713721
if (res != 1) {
714722
wpa_printf(MSG_INFO,
715723
"SAE-PK: Invalid or incorrect signature in KeyAuth");
716-
return -1;
724+
ret = -1;
725+
goto done;
717726
}
718727

719728
wpa_printf(MSG_DEBUG, "SAE-PK: Valid KeyAuth signature received");
720729

721730
/* TODO: Store validated public key into network profile */
722-
return 0;
731+
done:
732+
if (wpa_s->sae_pk_elems.fils_pk) {
733+
os_free(wpa_s->sae_pk_elems.fils_pk);
734+
}
735+
if (wpa_s->sae_pk_elems.sae_pk) {
736+
os_free(wpa_s->sae_pk_elems.sae_pk);
737+
}
738+
if (wpa_s->sae_pk_elems.fils_key_confirm) {
739+
os_free(wpa_s->sae_pk_elems.fils_key_confirm);
740+
}
741+
os_memset(&wpa_s->sae_pk_elems, 0, sizeof(wpa_s->sae_pk_elems));
742+
743+
return ret;
723744
}
724745
#endif /* CONFIG_SAE_PK */

0 commit comments

Comments
 (0)