Skip to contentSkip to conversation

net: esp4: Fix double free on esp4 functions

PATCH In review Ramin Farajpour Cami 4 participants 4 messages Jan 30, 2019 – Jan 31, 2019 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: esp4: Fix double free on esp4 functions

key/tmp is being kfree'd twice,once in the "aalg_desc->uinfo.auth.icv_fullbits / 8 != crypto_aead_authsize(aead)" call to "free_key",twice When "crypto_aead_setauthsize(aead, x->aalg->alg_trunc_len / 8)" fails call to again "free_key",

---
 net/ipv4/esp4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/esp4.c +2 -1
index 5459f41fc26f..5a66e47641b0 100644
@@ -467,6 +467,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 
 error_free:
 	kfree(tmp);
+	tmp = NULL;
 error:
 	return err;
 }
@@ -959,7 +960,7 @@ static int esp_init_authenc(struct xfrm_state *x)
 
 free_key:
 	kfree(key);
-
+	key = NULL;
 error:
 	return err;
 }
Signature · 1 line
2.11.0
#1 lore raw
Quoted 13 lines · Ramin Farajpour Cami

key/tmp is being kfree'd twice,once in the "aalg_desc->uinfo.auth.icv_fullbits / 8 != crypto_aead_authsize(aead)" call to "free_key",twice When "crypto_aead_setauthsize(aead, x->aalg->alg_trunc_len / 8)" fails call to again "free_key",

---
 net/ipv4/esp4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/esp4.c +0 -0
index 5459f41fc26f..5a66e47641b0 100644

net/ipv4/esp4.c int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * · line 470

Quoted 4 lines
net/ipv4/esp4.c +1 -0
@@ -467,6 +467,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 
 error_free:
 	kfree(tmp);
+	tmp = NULL;

Clearing tmp right before a "return err;" has no effect at all.

net/ipv4/esp4.c static int esp_init_authenc(struct xfrm_state *x) · line 963

Quoted 9 lines
net/ipv4/esp4.c +1 -1
 error:
 	return err;
 }
@@ -959,7 +960,7 @@ static int esp_init_authenc(struct xfrm_state *x)
 
 free_key:
 	kfree(key);
-
+	key = NULL;

Same here, this is essentially dead code.

Quoted 4 lines
net/ipv4/esp4.c +0 -0
 error:
 	return err;
 }

A message that is not in the archive (sent off-list or not yet received): CAKEzZ8zyhvJ1Fr6UDOxVqBnUz73xPSLwfnoM4FFGf6wHSTU=Jg@mail.gmail.com

maintainer
#3 lore raw
Quoted 7 lines · Ramin Farajpour Cami

Hi Eric,

I going to for avoid double free of resource identifiers we should set variables initialized in "tmp/key" to NULL if an error occurred int the "esp_init_authenc()" and "esp_output_tail()" attempts to free the memory again.my means like this patch c7055fd15ff46d92eb0dd1c16a4fe010d58224c8
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c7055fd15ff46d92eb0dd1c16a4fe010d58224c8>

There is a big difference between the above-noted patch and your patch. You really have to understand the code you are trying to change.

maintainer
#4 lore raw
In reply to Ramin Farajpour Cami

From: Ramin Farajpour Cami <[email protected]>
Date: Wed, 30 Jan 2019 21:35:42 +0000

Quoted 13 lines

key/tmp is being kfree'd twice,once in the "aalg_desc->uinfo.auth.icv_fullbits / 8 != crypto_aead_authsize(aead)" call to "free_key",twice When "crypto_aead_setauthsize(aead, x->aalg->alg_trunc_len / 8)" fails call to again "free_key",

---
 net/ipv4/esp4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/esp4.c +0 -0
index 5459f41fc26f..5a66e47641b0 100644

net/ipv4/esp4.c int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * · line 473

Quoted 7 lines
net/ipv4/esp4.c +1 -0
@@ -467,6 +467,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 
 error_free:
 	kfree(tmp);
+	tmp = NULL;
 error:
 	return err;
 }

This makes no sense at all, the function returns right after the kfree() and tmp is never referenced again!