* Re: [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
2012-11-22 13:23 [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall Tommi Rantala
@ 2012-11-25 21:03 ` David Miller
2012-11-26 14:56 ` Vlad Yasevich
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2012-11-25 21:03 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:23:16 +0200
> Consider the following program, that sets the second argument to the
> sendto() syscall incorrectly:
...
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
This also looks good, Vlad please review this.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
2012-11-22 13:23 [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall Tommi Rantala
2012-11-25 21:03 ` David Miller
@ 2012-11-26 14:56 ` Vlad Yasevich
2012-11-26 22:34 ` David Miller
2012-11-26 15:25 ` Neil Horman
2012-11-28 16:12 ` David Miller
3 siblings, 1 reply; 6+ messages in thread
From: Vlad Yasevich @ 2012-11-26 14:56 UTC (permalink / raw)
To: Tommi Rantala
Cc: linux-sctp, netdev, Neil Horman, Sridhar Samudrala,
David S. Miller, Dave Jones
On 11/22/2012 08:23 AM, Tommi Rantala wrote:
> Consider the following program, that sets the second argument to the
> sendto() syscall incorrectly:
>
> #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;
> }
>
> We get -ENOMEM:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
>
> Propagate the error code from sctp_user_addto_chunk(), so that we will
> tell user space what actually went wrong:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
>
> Noticed while running Trinity (the syscall fuzzer).
>
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Looks good
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
-vlad
> ---
> net/sctp/chunk.c | 13 +++++++++----
> net/sctp/socket.c | 4 ++--
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index d241ef5..3952ca9 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -183,7 +183,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> msg = sctp_datamsg_new(GFP_KERNEL);
> if (!msg)
> - return NULL;
> + return ERR_PTR(-ENOMEM);
>
> /* Note: Calculate this outside of the loop, so that all fragments
> * have the same expiration.
> @@ -280,8 +280,11 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0);
>
> - if (!chunk)
> + if (!chunk) {
> + err = -ENOMEM;
> goto errout;
> + }
> +
> err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
> if (err < 0)
> goto errout_chunk_put;
> @@ -315,8 +318,10 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0);
>
> - if (!chunk)
> + if (!chunk) {
> + err = -ENOMEM;
> goto errout;
> + }
>
> err = sctp_user_addto_chunk(chunk, offset, over,msgh->msg_iov);
>
> @@ -342,7 +347,7 @@ errout:
> sctp_chunk_free(chunk);
> }
> sctp_datamsg_put(msg);
> - return NULL;
> + return ERR_PTR(err);
> }
>
> /* Check whether this message has expired. */
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index a60d1f8..406d957 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1915,8 +1915,8 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
>
> /* Break the message into multiple chunks of maximum size. */
> datamsg = sctp_datamsg_from_user(asoc, sinfo, msg, msg_len);
> - if (!datamsg) {
> - err = -ENOMEM;
> + if (IS_ERR(datamsg)) {
> + err = PTR_ERR(datamsg);
> goto out_free;
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
2012-11-26 14:56 ` Vlad Yasevich
@ 2012-11-26 22:34 ` David Miller
0 siblings, 0 replies; 6+ 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:56:57 -0500
> On 11/22/2012 08:23 AM, Tommi Rantala wrote:
>> Consider the following program, that sets the second argument to the
>> sendto() syscall incorrectly:
...
>> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
>
> Looks good
>
> Acked-by: Vlad Yasevich <vyasevich@gmail.com>
I'll apply this after the other SCTP fix is respun, because there
is a dependency.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
2012-11-22 13:23 [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall Tommi Rantala
2012-11-25 21:03 ` David Miller
2012-11-26 14:56 ` Vlad Yasevich
@ 2012-11-26 15:25 ` Neil Horman
2012-11-28 16:12 ` David Miller
3 siblings, 0 replies; 6+ messages in thread
From: Neil Horman @ 2012-11-26 15:25 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:23:16PM +0200, Tommi Rantala wrote:
> Consider the following program, that sets the second argument to the
> sendto() syscall incorrectly:
>
> #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;
> }
>
> We get -ENOMEM:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
>
> Propagate the error code from sctp_user_addto_chunk(), so that we will
> tell user space what actually went wrong:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
>
> Noticed while running Trinity (the syscall fuzzer).
>
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
> ---
> net/sctp/chunk.c | 13 +++++++++----
> net/sctp/socket.c | 4 ++--
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
> index d241ef5..3952ca9 100644
> --- a/net/sctp/chunk.c
> +++ b/net/sctp/chunk.c
> @@ -183,7 +183,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> msg = sctp_datamsg_new(GFP_KERNEL);
> if (!msg)
> - return NULL;
> + return ERR_PTR(-ENOMEM);
>
> /* Note: Calculate this outside of the loop, so that all fragments
> * have the same expiration.
> @@ -280,8 +280,11 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0);
>
> - if (!chunk)
> + if (!chunk) {
> + err = -ENOMEM;
> goto errout;
> + }
> +
> err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
> if (err < 0)
> goto errout_chunk_put;
> @@ -315,8 +318,10 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
>
> chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0);
>
> - if (!chunk)
> + if (!chunk) {
> + err = -ENOMEM;
> goto errout;
> + }
>
> err = sctp_user_addto_chunk(chunk, offset, over,msgh->msg_iov);
>
> @@ -342,7 +347,7 @@ errout:
> sctp_chunk_free(chunk);
> }
> sctp_datamsg_put(msg);
> - return NULL;
> + return ERR_PTR(err);
> }
>
> /* Check whether this message has expired. */
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index a60d1f8..406d957 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -1915,8 +1915,8 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
>
> /* Break the message into multiple chunks of maximum size. */
> datamsg = sctp_datamsg_from_user(asoc, sinfo, msg, msg_len);
> - if (!datamsg) {
> - err = -ENOMEM;
> + if (IS_ERR(datamsg)) {
> + err = PTR_ERR(datamsg);
> goto out_free;
> }
>
> --
> 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
>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall
2012-11-22 13:23 [PATCH] sctp: fix -ENOMEM result with invalid user space pointer in sendto() syscall Tommi Rantala
` (2 preceding siblings ...)
2012-11-26 15:25 ` Neil Horman
@ 2012-11-28 16:12 ` David Miller
3 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2012-11-28 16:12 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:23:16 +0200
> Consider the following program, that sets the second argument to the
> sendto() syscall incorrectly:
...
> We get -ENOMEM:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ENOMEM (Cannot allocate memory)
>
> Propagate the error code from sctp_user_addto_chunk(), so that we will
> tell user space what actually went wrong:
>
> $ strace -e sendto ./demo
> sendto(3, NULL, 1, 0, {sa_family=AF_INET, sin_port=htons(11111), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EFAULT (Bad address)
>
> Noticed while running Trinity (the syscall fuzzer).
>
> Signed-off-by: Tommi Rantala <tt.rantala@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread