netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
@ 2012-11-22 13:21 Tommi Rantala
  2012-11-25 21:01 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tommi Rantala @ 2012-11-22 13:21 UTC (permalink / raw)
  To: linux-sctp, netdev
  Cc: Neil Horman, Vlad Yasevich, Sridhar Samudrala, David S. Miller,
	Dave Jones, Tommi Rantala

Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
reproducible e.g. with the sendto() syscall by passing invalid
user space pointer in the second argument:

 #include <string.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>

 int main(void)
 {
         int fd;
         struct sockaddr_in sa;

         fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
         if (fd < 0)
                 return 1;

         memset(&sa, 0, sizeof(sa));
         sa.sin_family = AF_INET;
         sa.sin_addr.s_addr = inet_addr("127.0.0.1");
         sa.sin_port = htons(11111);

         sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));

         return 0;
 }

As far as I can tell, the leak has been around since ~2003.

Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
---
 net/sctp/chunk.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index 7c2df9c..d241ef5 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 			goto errout;
 		err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
 		if (err < 0)
-			goto errout;
+			goto errout_chunk_put;
 
 		offset += len;
 
@@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
 			   - (__u8 *)chunk->skb->data);
 		if (err < 0)
-			goto errout;
+			goto errout_chunk_put;
 
 		sctp_datamsg_assign(msg, chunk);
 		list_add_tail(&chunk->frag_list, &msg->chunks);
@@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 
 	return msg;
 
+errout_chunk_put:
+	sctp_chunk_put(chunk);
+
 errout:
 	list_for_each_safe(pos, temp, &msg->chunks) {
 		list_del_init(pos);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-22 13:21 [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails Tommi Rantala
@ 2012-11-25 21:01 ` David Miller
  2012-11-26 14:52 ` Vlad Yasevich
  2012-11-26 15:23 ` Neil Horman
  2 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2012-11-25 21:01 UTC (permalink / raw)
  To: tt.rantala; +Cc: linux-sctp, netdev, nhorman, vyasevich, sri, davej

From: Tommi Rantala <tt.rantala@gmail.com>
Date: Thu, 22 Nov 2012 15:21:31 +0200

> Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
> reproducible e.g. with the sendto() syscall by passing invalid
> user space pointer in the second argument:
 ...
> As far as I can tell, the leak has been around since ~2003.
> 
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>

Looks good to me, Vlad please review.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-22 13:21 [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails Tommi Rantala
  2012-11-25 21:01 ` David Miller
@ 2012-11-26 14:52 ` Vlad Yasevich
  2012-11-26 22:34   ` David Miller
  2012-11-26 15:23 ` Neil Horman
  2 siblings, 1 reply; 8+ messages in thread
From: Vlad Yasevich @ 2012-11-26 14:52 UTC (permalink / raw)
  To: Tommi Rantala
  Cc: linux-sctp, netdev, Neil Horman, Sridhar Samudrala,
	David S. Miller, Dave Jones

On 11/22/2012 08:21 AM, Tommi Rantala wrote:
> Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
> reproducible e.g. with the sendto() syscall by passing invalid
> user space pointer in the second argument:
>
>   #include <string.h>
>   #include <arpa/inet.h>
>   #include <sys/socket.h>
>
>   int main(void)
>   {
>           int fd;
>           struct sockaddr_in sa;
>
>           fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
>           if (fd < 0)
>                   return 1;
>
>           memset(&sa, 0, sizeof(sa));
>           sa.sin_family = AF_INET;
>           sa.sin_addr.s_addr = inet_addr("127.0.0.1");
>           sa.sin_port = htons(11111);
>
>           sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
>
>           return 0;
>   }
>
> As far as I can tell, the leak has been around since ~2003.
>
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
> ---
>   net/sctp/chunk.c |    7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index 7c2df9c..d241ef5 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>   			goto errout;
>   		err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
>   		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_put;
>
>   		offset += len;
>
> @@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>   		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
>   			   - (__u8 *)chunk->skb->data);
>   		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_put;
>
>   		sctp_datamsg_assign(msg, chunk);
>   		list_add_tail(&chunk->frag_list, &msg->chunks);
> @@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
>   	return msg;
>
> +errout_chunk_put:
> +	sctp_chunk_put(chunk);
> +
>   errout:
>   	list_for_each_safe(pos, temp, &msg->chunks) {
>   		list_del_init(pos);
>

Should be using sctp_chunk_free().  Good find.

-vlad

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-22 13:21 [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails Tommi Rantala
  2012-11-25 21:01 ` David Miller
  2012-11-26 14:52 ` Vlad Yasevich
@ 2012-11-26 15:23 ` Neil Horman
  2 siblings, 0 replies; 8+ messages in thread
From: Neil Horman @ 2012-11-26 15:23 UTC (permalink / raw)
  To: Tommi Rantala
  Cc: linux-sctp, netdev, Vlad Yasevich, Sridhar Samudrala,
	David S. Miller, Dave Jones

On Thu, Nov 22, 2012 at 03:21:31PM +0200, Tommi Rantala wrote:
> Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
> reproducible e.g. with the sendto() syscall by passing invalid
> user space pointer in the second argument:
> 
>  #include <string.h>
>  #include <arpa/inet.h>
>  #include <sys/socket.h>
> 
>  int main(void)
>  {
>          int fd;
>          struct sockaddr_in sa;
> 
>          fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
>          if (fd < 0)
>                  return 1;
> 
>          memset(&sa, 0, sizeof(sa));
>          sa.sin_family = AF_INET;
>          sa.sin_addr.s_addr = inet_addr("127.0.0.1");
>          sa.sin_port = htons(11111);
> 
>          sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
> 
>          return 0;
>  }
> 
> As far as I can tell, the leak has been around since ~2003.
> 
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
> ---
>  net/sctp/chunk.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index 7c2df9c..d241ef5 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>  			goto errout;
>  		err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
>  		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_put;
>  
>  		offset += len;
>  
> @@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>  		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
>  			   - (__u8 *)chunk->skb->data);
>  		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_put;
>  
>  		sctp_datamsg_assign(msg, chunk);
>  		list_add_tail(&chunk->frag_list, &msg->chunks);
> @@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>  
>  	return msg;
>  
> +errout_chunk_put:
> +	sctp_chunk_put(chunk);
> +
>  errout:
>  	list_for_each_safe(pos, temp, &msg->chunks) {
>  		list_del_init(pos);
> -- 
> 1.7.9.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

I'm fine with it the way it is, but it might be nicer if you instead just moved
the list_add_tail call up between the if (!chunk) check and the
sctp_user_addto_chunk call.  That way the unwind loop at the errout label can
just free the chunk without the need for an extra label.

Neil

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-26 14:52 ` Vlad Yasevich
@ 2012-11-26 22:34   ` David Miller
  2012-11-27 14:01     ` Tommi Rantala
  0 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2012-11-26 22:34 UTC (permalink / raw)
  To: vyasevich; +Cc: tt.rantala, linux-sctp, netdev, nhorman, sri, davej

From: Vlad Yasevich <vyasevich@gmail.com>
Date: Mon, 26 Nov 2012 09:52:37 -0500

> Should be using sctp_chunk_free().  Good find.

Tommi, please respin your patch to use sctp_chunk_free() as
Vlad has asked.

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-26 22:34   ` David Miller
@ 2012-11-27 14:01     ` Tommi Rantala
  2012-11-27 14:49       ` Vlad Yasevich
  2012-11-28 16:11       ` David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Tommi Rantala @ 2012-11-27 14:01 UTC (permalink / raw)
  To: linux-sctp, netdev
  Cc: Neil Horman, Vlad Yasevich, Sridhar Samudrala, David S. Miller,
	Dave Jones, Tommi Rantala

Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
reproducible e.g. with the sendto() syscall by passing invalid
user space pointer in the second argument:

 #include <string.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>

 int main(void)
 {
         int fd;
         struct sockaddr_in sa;

         fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
         if (fd < 0)
                 return 1;

         memset(&sa, 0, sizeof(sa));
         sa.sin_family = AF_INET;
         sa.sin_addr.s_addr = inet_addr("127.0.0.1");
         sa.sin_port = htons(11111);

         sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));

         return 0;
 }

As far as I can tell, the leak has been around since ~2003.

Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
---
 net/sctp/chunk.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index 7c2df9c..f2aebdb 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 			goto errout;
 		err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
 		if (err < 0)
-			goto errout;
+			goto errout_chunk_free;
 
 		offset += len;
 
@@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
 			   - (__u8 *)chunk->skb->data);
 		if (err < 0)
-			goto errout;
+			goto errout_chunk_free;
 
 		sctp_datamsg_assign(msg, chunk);
 		list_add_tail(&chunk->frag_list, &msg->chunks);
@@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
 
 	return msg;
 
+errout_chunk_free:
+	sctp_chunk_free(chunk);
+
 errout:
 	list_for_each_safe(pos, temp, &msg->chunks) {
 		list_del_init(pos);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-27 14:01     ` Tommi Rantala
@ 2012-11-27 14:49       ` Vlad Yasevich
  2012-11-28 16:11       ` David Miller
  1 sibling, 0 replies; 8+ messages in thread
From: Vlad Yasevich @ 2012-11-27 14:49 UTC (permalink / raw)
  To: Tommi Rantala
  Cc: linux-sctp, netdev, Neil Horman, Sridhar Samudrala,
	David S. Miller, Dave Jones

On 11/27/2012 09:01 AM, Tommi Rantala wrote:
> Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
> reproducible e.g. with the sendto() syscall by passing invalid
> user space pointer in the second argument:
>
>   #include <string.h>
>   #include <arpa/inet.h>
>   #include <sys/socket.h>
>
>   int main(void)
>   {
>           int fd;
>           struct sockaddr_in sa;
>
>           fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/);
>           if (fd < 0)
>                   return 1;
>
>           memset(&sa, 0, sizeof(sa));
>           sa.sin_family = AF_INET;
>           sa.sin_addr.s_addr = inet_addr("127.0.0.1");
>           sa.sin_port = htons(11111);
>
>           sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa));
>
>           return 0;
>   }
>
> As far as I can tell, the leak has been around since ~2003.
>
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>

Acked-by: Vlad Yasevich <vyasevich@gmail.com>

-vlad

> ---
>   net/sctp/chunk.c |    7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index 7c2df9c..f2aebdb 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>   			goto errout;
>   		err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
>   		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_free;
>
>   		offset += len;
>
> @@ -324,7 +324,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>   		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
>   			   - (__u8 *)chunk->skb->data);
>   		if (err < 0)
> -			goto errout;
> +			goto errout_chunk_free;
>
>   		sctp_datamsg_assign(msg, chunk);
>   		list_add_tail(&chunk->frag_list, &msg->chunks);
> @@ -332,6 +332,9 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
>   	return msg;
>
> +errout_chunk_free:
> +	sctp_chunk_free(chunk);
> +
>   errout:
>   	list_for_each_safe(pos, temp, &msg->chunks) {
>   		list_del_init(pos);
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
  2012-11-27 14:01     ` Tommi Rantala
  2012-11-27 14:49       ` Vlad Yasevich
@ 2012-11-28 16:11       ` David Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David Miller @ 2012-11-28 16:11 UTC (permalink / raw)
  To: tt.rantala; +Cc: linux-sctp, netdev, nhorman, vyasevich, sri, davej

From: Tommi Rantala <tt.rantala@gmail.com>
Date: Tue, 27 Nov 2012 16:01:46 +0200

> Trinity (the syscall fuzzer) discovered a memory leak in SCTP,
> reproducible e.g. with the sendto() syscall by passing invalid
> user space pointer in the second argument:
...
> As far as I can tell, the leak has been around since ~2003.
> 
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-28 16:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-22 13:21 [PATCH] sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails Tommi Rantala
2012-11-25 21:01 ` David Miller
2012-11-26 14:52 ` Vlad Yasevich
2012-11-26 22:34   ` David Miller
2012-11-27 14:01     ` Tommi Rantala
2012-11-27 14:49       ` Vlad Yasevich
2012-11-28 16:11       ` David Miller
2012-11-26 15:23 ` Neil Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).