Skip to contentSkip to conversation

eap: warn on too small of buffer

PATCH In review James Prestwood 2 participants 5 messages Feb 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 eap: warn on too small of buffer

In practice a caller will know the contents of their buffer, but just in case it would be nice to print a warning. This may not satisfy static analysis, but at least with this the developer will be informed what they are doing is wrong.

---
 src/eap.c | 3 +++
 1 file changed, 3 insertions(+)
src/eap.c +3 -0
index dea0c3cf..39c950a2 100644
@@ -167,6 +167,9 @@ static void eap_send_response(struct eap_state *eap, enum eap_type type,
 	buf[4] = type;
 
 	if (type == EAP_TYPE_EXPANDED) {
+		if (L_WARN_ON(len < 12))
+			return;
+
 		memcpy(buf + 5, eap->method->vendor_id, 3);
 		l_put_be32(eap->method->vendor_type, buf + 8);
 	}
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/3 fils: check return of ie_parse_rsne_from_data

---
 src/fils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/fils.c +4 -2
index acead506..3917ca40 100644
@@ -108,9 +108,11 @@ static void fils_erp_tx_func(const uint8_t *eap_data, size_t len,
 
 	ie_tlv_builder_init(&builder, ptr, sizeof(data) - 4);
 
-	ie_parse_rsne_from_data(fils->hs->supplicant_ie,
+	if (ie_parse_rsne_from_data(fils->hs->supplicant_ie,
 				fils->hs->supplicant_ie[1] + 2,
-				&rsn_info);
+				&rsn_info) < 0)
+		return;
+
 	rsne = alloca(256);
 	ie_build_rsne(&rsn_info, rsne);
 
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 2/3] fils: check return of ie_parse_rsne_from_data

Hi James,

Quoted 9 lines · James Prestwood
---
  src/fils.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
src/fils.c +0 -0
index acead506..3917ca40 100644

src/fils.c static void fils_erp_tx_func(const uint8_t *eap_data, size_t len, · line 115

Quoted 10 lines
src/fils.c +4 -2
@@ -108,9 +108,11 @@ static void fils_erp_tx_func(const uint8_t *eap_data, size_t len,
 
  	ie_tlv_builder_init(&builder, ptr, sizeof(data) - 4);
 
-	ie_parse_rsne_from_data(fils->hs->supplicant_ie,
+	if (ie_parse_rsne_from_data(fils->hs->supplicant_ie,
  				fils->hs->supplicant_ie[1] + 2,
-				&rsn_info);
+				&rsn_info) < 0)
+		return;
+

This really shouldn't fail. We parse and check the rsne for errors when building the handshake_state ( handshake_state_set_supplicant_ie). So it should be checked then.

If we're paranoid about this, I'd do the checking in fils_sm_new or fils_start or something

src/fils.c static void fils_erp_tx_func(const uint8_t *eap_data, size_t len, · line 118

Quoted 4 lines
src/fils.c +0 -0
  	rsne = alloca(256);
  	ie_build_rsne(&rsn_info, rsne);
 

Regards,
-Denis

#3 lore raw

PATCH 3/3 network: free psk on error

In reply to James Prestwood
---
 src/network.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/network.c +3 -1
index 7cae413f..8f129718 100644
@@ -403,8 +403,10 @@ static int network_load_psk(struct network *network, bool need_passphrase)
 		l_error("%s: invalid PreSharedKey format", path);
 		l_free(path);
 
-		if (!passphrase)
+		if (!passphrase) {
+			l_free(psk);
 			return -EINVAL;
+		}
 	}
 
 	network->psk = l_malloc(32);
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 3/3] network: free psk on error

Hi James,

Quoted 9 lines · James Prestwood
---
  src/network.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
src/network.c +0 -0
index 7cae413f..8f129718 100644

src/network.c static int network_load_psk(struct network *network, bool need_passphrase) · line 409

Quoted 8 lines
src/network.c +3 -1
@@ -403,8 +403,10 @@ static int network_load_psk(struct network *network, bool need_passphrase)
  		l_error("%s: invalid PreSharedKey format", path);
  		l_free(path);
 
-		if (!passphrase)
+		if (!passphrase) {
+			l_free(psk);
  			return -EINVAL;
+		}

That only frees it if there's passphrase. But if we have to re-derive the PSK, it is still leaked...

src/network.c static int network_load_psk(struct network *network, bool need_passphrase) · line 412

Quoted 4 lines
src/network.c +0 -0
  	}
 
  	network->psk = l_malloc(32);

Regards,
-Denis