Skip to contentSkip to conversation

Free cookie before we memdup a new one

PATCH Superseded Neil Horman 4 participants 18 messages Jun 10, 2019 – Jun 15, 2019

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

PATCH 1/1 Free cookie before we memdup a new one

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 2 ++
 1 file changed, 2 insertions(+)
net/sctp/sm_make_chunk.c +2 -0
index f17908f5c4f3..21f7faf032e5 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
Signature · 1 line
2.20.1
maintainer
#1 lore raw

From: Neil Horman <[email protected]>
Date: Mon, 10 Jun 2019 12:34:56 -0400

Quoted 8 lines

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Please post with an appropriate subsystem prefix in the Subject.

Thank you.

maintainer
#2 lore raw
In reply to Neil Horman
Quoted 7 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Hi, Neil,

I think we should also do the same thing to the other 2 kmemdups in sctp_process_param():
asoc->peer.peer_random
asoc->peer.peer_hmacs

Quoted 25 lines
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 2 ++
 1 file changed, 2 insertions(+)
net/sctp/sm_make_chunk.c +2 -1
index f17908f5c4f3..21f7faf032e5 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
        case SCTP_PARAM_STATE_COOKIE:
                asoc->peer.cookie_len >                         ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+               if (asoc->peer.cookie)
+                       kfree(asoc->peer.cookie);
                asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
                if (!asoc->peer.cookie)
                        retval = 0;
--

2.20.1

#3 lore raw

PATCH v2 1/1 Free cookie before we memdup a new one

In reply to Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/sctp/sm_make_chunk.c +6 -0
index f17908f5c4f3..0992ec0395f8 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
Signature · 1 line
2.20.1
#4 lore raw
Quoted 4 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

Quoted 8 lines

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

They are actually 4 vars. The 4th one being peer_chunks. And a syzkaller Fixes tag would be welcomed as well, so that if someone backports the fix for it will have a hint to backport this patch also.

Quoted 43 lines
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/sctp/sm_make_chunk.c +6 -0
index f17908f5c4f3..0992ec0395f8 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len >  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
Signature · 1 line
2.20.1
maintainer
#6 lore raw
In reply to Neil Horman

From: Neil Horman <[email protected]>
Date: Tue, 11 Jun 2019 07:21:28 -0400

Quoted 11 lines

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)

Subsystem tag is "sctp: " which still isn't there :-)

#7 lore raw

PATCH v3 1/1 Free cookie before we memdup a new one

In reply to Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/sctp/sm_make_chunk.c +8 -0
index f17908f5c4f3..9b0e5b0d701a 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
@@ -2675,6 +2681,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 		if (!ep->auth_enable)
 			goto fall_through;
 
+		if (asoc->peer.peer_chunks)
+			kfree(asoc->peer.peer_chunks);
 		asoc->peer.peer_chunks = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_chunks)
Signature · 1 line
2.20.1
maintainer
#8 lore raw

From: Neil Horman <[email protected]>
Date: Tue, 11 Jun 2019 15:22:45 -0400

Quoted 3 lines

v2->v3
net->sctp
also free peer_chunks

Neil this isn't the first time you're submitting sctp patches right? ;-)

Subject: "[PATCH v3 net] sctp: Free cookie before we memdup a new one"

It's "subsystem_prefix: " and I even stated this explicitly yesterday.

#9 lore raw
Quoted 7 lines · David Miller

From: Neil Horman <[email protected]>
Date: Tue, 11 Jun 2019 15:22:45 -0400

Quoted 3 lines

v2->v3
net->sctp
also free peer_chunks

Quoted 6 lines

Neil this isn't the first time you're submitting sctp patches right? ;-)

Subject: "[PATCH v3 net] sctp: Free cookie before we memdup a new one"

It's "subsystem_prefix: " and I even stated this explicitly yesterday.

No, sorry, I'm trying to do this while I get a CI mess sorted out at the same time, and I'm not close attention here.

If you want to take over a few dozen user space packages for me in RHEL, I'll gladly get this right on the first try :)

Neil

#10 lore raw

PATCH v4 1/1 sctp: Free cookie before we memdup a new one

In reply to Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/sctp/sm_make_chunk.c +8 -0
index f17908f5c4f3..9b0e5b0d701a 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
@@ -2675,6 +2681,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 		if (!ep->auth_enable)
 			goto fall_through;
 
+		if (asoc->peer.peer_chunks)
+			kfree(asoc->peer.peer_chunks);
 		asoc->peer.peer_chunks = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_chunks)
Signature · 1 line
2.20.1
maintainer Reviewed-by on v4 1/1
#11 lore raw

Re: [PATCH v4 net] sctp: Free cookie before we memdup a new one

Quoted 71 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---
Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/sctp/sm_make_chunk.c +8 -1
index f17908f5c4f3..9b0e5b0d701a 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
        case SCTP_PARAM_STATE_COOKIE:
                asoc->peer.cookie_len >                         ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+               if (asoc->peer.cookie)
+                       kfree(asoc->peer.cookie);
                asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
                if (!asoc->peer.cookie)
                        retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                        goto fall_through;
 
                /* Save peer's random parameter */
+               if (asoc->peer.peer_random)
+                       kfree(asoc->peer.peer_random);
                asoc->peer.peer_random = kmemdup(param.p,
                                            ntohs(param.p->length), gfp);
                if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                        goto fall_through;
 
                /* Save peer's HMAC list */
+               if (asoc->peer.peer_hmacs)
+                       kfree(asoc->peer.peer_hmacs);
                asoc->peer.peer_hmacs = kmemdup(param.p,
                                            ntohs(param.p->length), gfp);
                if (!asoc->peer.peer_hmacs) {
@@ -2675,6 +2681,8 @@ static int sctp_process_param(struct sctp_association *asoc,
                if (!ep->auth_enable)
                        goto fall_through;
 
+               if (asoc->peer.peer_chunks)
+                       kfree(asoc->peer.peer_chunks);
                asoc->peer.peer_chunks = kmemdup(param.p,
                                            ntohs(param.p->length), gfp);
                if (!asoc->peer.peer_chunks)
--
Quoted 2 lines

2.20.1

maintainer Acked-by on v4 1/1
#12 lore raw

Re: [PATCH v4 net] sctp: Free cookie before we memdup a new one

In reply to Neil Horman
Quoted 8 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---

This marker can't be here, as it causes git to loose everything below.

Quoted 12 lines

Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

Quoted 6 lines
Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>

Anyhow, LGTM and reproducer didn't give any hits in 2 runs of 50mins.

#13 lore raw

Re: [PATCH v4 net] sctp: Free cookie before we memdup a new one

Quoted 5 lines · Marcelo Ricardo Leitner
Quoted 4 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

Quoted 7 lines
Quoted 4 lines

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

---

This marker can't be here, as it causes git to loose everything below.

thats intentional so that, when Dave commits it, the change notes arent carried into the changelog (I.e. the change notes are useful for email review, but not especially useful in the permanent commit history).

Neil

Quoted 22 lines
Quoted 12 lines

Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

Quoted 6 lines
Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>

Anyhow, LGTM and reproducer didn't give any hits in 2 runs of 50mins.

maintainer
#14 lore raw

Re: [PATCH v4 net] sctp: Free cookie before we memdup a new one

From: Neil Horman <[email protected]>
Date: Wed, 12 Jun 2019 16:32:30 -0400

Quoted 9 lines · Marcelo Ricardo Leitner
Quoted 8 lines · Neil Horman
Quoted 7 lines

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

---

This marker can't be here, as it causes git to loose everything below.

thats intentional so that, when Dave commits it, the change notes arent carried into the changelog (I.e. the change notes are useful for email review, but not especially useful in the permanent commit history).

1) I like the changelog notes to be included

2) Your signoff etc. was in that area too so would have been lost as well

#15 lore raw

PATCH v5 1/1 sctp: Free cookie before we memdup a new one

In reply to Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

v4->v5
remove cut line

Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
---
 net/sctp/sm_make_chunk.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/sctp/sm_make_chunk.c +8 -0
index f17908f5c4f3..9b0e5b0d701a 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
@@ -2675,6 +2681,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 		if (!ep->auth_enable)
 			goto fall_through;
 
+		if (asoc->peer.peer_chunks)
+			kfree(asoc->peer.peer_chunks);
 		asoc->peer.peer_chunks = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_chunks)
Signature · 1 line
2.20.1
maintainer Acked-by on v5 1/1
#16 lore raw

Re: [PATCH v5 net] sctp: Free cookie before we memdup a new one

Quoted 22 lines · Neil Horman

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

v3->v4
fix subject tags

v4->v5
remove cut line

Quoted 6 lines
Reported-by [email protected]
CC Marcelo Ricardo Leitner <[email protected]>
CC Xin Long <[email protected]>
CC "David S. Miller" <[email protected]>
Quoted 46 lines
---
 net/sctp/sm_make_chunk.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/sctp/sm_make_chunk.c +8 -0
index f17908f5c4f3..9b0e5b0d701a 100644
@@ -2583,6 +2583,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 	case SCTP_PARAM_STATE_COOKIE:
 		asoc->peer.cookie_len >  			ntohs(param.p->length) - sizeof(struct sctp_paramhdr);
+		if (asoc->peer.cookie)
+			kfree(asoc->peer.cookie);
 		asoc->peer.cookie = kmemdup(param.cookie->body, asoc->peer.cookie_len, gfp);
 		if (!asoc->peer.cookie)
 			retval = 0;
@@ -2647,6 +2649,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's random parameter */
+		if (asoc->peer.peer_random)
+			kfree(asoc->peer.peer_random);
 		asoc->peer.peer_random = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_random) {
@@ -2660,6 +2664,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 			goto fall_through;
 
 		/* Save peer's HMAC list */
+		if (asoc->peer.peer_hmacs)
+			kfree(asoc->peer.peer_hmacs);
 		asoc->peer.peer_hmacs = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_hmacs) {
@@ -2675,6 +2681,8 @@ static int sctp_process_param(struct sctp_association *asoc,
 		if (!ep->auth_enable)
 			goto fall_through;
 
+		if (asoc->peer.peer_chunks)
+			kfree(asoc->peer.peer_chunks);
 		asoc->peer.peer_chunks = kmemdup(param.p,
 					    ntohs(param.p->length), gfp);
 		if (!asoc->peer.peer_chunks)
Signature · 1 line
2.20.1
maintainer Applied
#17 lore raw

Re: [PATCH v5 net] sctp: Free cookie before we memdup a new one

In reply to Neil Horman

From: Neil Horman <[email protected]>
Date: Thu, 13 Jun 2019 06:35:59 -0400

Quoted 16 lines

Based on comments from Xin, even after fixes for our recent syzbot report of cookie memory leaks, its possible to get a resend of an INIT chunk which would lead to us leaking cookie memory.

To ensure that we don't leak cookie memory, free any previously allocated cookie first.

Change notes
v1->v2
update subsystem tag in subject (davem)
repeat kfree check for peer_random and peer_hmacs (xin)

v2->v3
net->sctp
also free peer_chunks

Quoted 8 lines

v3->v4
fix subject tags

v4->v5
remove cut line

Applied, thanks.