On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
I've attached a reproducer that might help to figure out the reason.
It triggers the UAF for me in ~10 seconds of running as:
$ gcc -lpthread sctp-connect-uaf-poc.c
$ while true; do ./a.out; done
You need to have KASAN enabled.
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
wait_for_connect is only used in two places, we can move the ref to a
broader scope and cover that read too, instead of holding another ref.
sendmsg path won't read anything from the asoc after waiting, so this
should be enough for it too.
---8<---
commit 7f7ba9b4fb834a61ab097dfd7c1f267e6a6d70a8
Author: Marcelo Ricardo Leitner [off-list ref]
Date: Thu Nov 3 15:47:45 2016 -0200
sctp: hold the asoc longer when associating
@@ -1214,9 +1214,11 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);+sctp_association_hold(asoc);err=sctp_wait_for_connect(asoc,&timeo);if((err==0||err==-EINPROGRESS)&&assoc_id)*assoc_id=asoc->assoc_id;+sctp_association_put(asoc);/* Don't free association on exit. */asoc=NULL;
@@ -1985,7 +1987,9 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)if(unlikely(wait_connect)){timeo=sock_sndtimeo(sk,msg_flags&MSG_DONTWAIT);+sctp_association_hold(asoc);sctp_wait_for_connect(asoc,&timeo);+sctp_association_put(asoc);}/* If we are already past ASSOCIATE, the lower
@@ -7501,6 +7505,7 @@ static int sctp_writeable(struct sock *sk)/* Wait for an association to go into ESTABLISHED state. If timeout is 0,*returnsimmediatelywithEINPROGRESS.+*Note:callermustholdarefonasocbeforecallingthisfunction.*/staticintsctp_wait_for_connect(structsctp_association*asoc,long*timeo_p){
@@ -7511,9 +7516,6 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)pr_debug("%s: asoc:%p, timeo:%ld\n",__func__,asoc,*timeo_p);-/* Increment the association's refcnt. */-sctp_association_hold(asoc);-for(;;){prepare_to_wait_exclusive(&asoc->wait,&wait,TASK_INTERRUPTIBLE);
@@ -7543,9 +7545,6 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)out:finish_wait(&asoc->wait,&wait);-/* Release the association's refcnt. */-sctp_association_put(asoc);-returnerr;do_error:
On Thu, Nov 3, 2016 at 6:52 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
quoted
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
quoted
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
Yes, it fixes the issue.
Tested-by: Andrey Konovalov <redacted>
Thanks for the fix!
quoted hunk
wait_for_connect is only used in two places, we can move the ref to a
broader scope and cover that read too, instead of holding another ref.
sendmsg path won't read anything from the asoc after waiting, so this
should be enough for it too.
---8<---
commit 7f7ba9b4fb834a61ab097dfd7c1f267e6a6d70a8
Author: Marcelo Ricardo Leitner [off-list ref]
Date: Thu Nov 3 15:47:45 2016 -0200
sctp: hold the asoc longer when associating
@@ -1214,9 +1214,11 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);+sctp_association_hold(asoc);err=sctp_wait_for_connect(asoc,&timeo);if((err==0||err==-EINPROGRESS)&&assoc_id)*assoc_id=asoc->assoc_id;+sctp_association_put(asoc);/* Don't free association on exit. */asoc=NULL;
@@ -1985,7 +1987,9 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)if(unlikely(wait_connect)){timeo=sock_sndtimeo(sk,msg_flags&MSG_DONTWAIT);+sctp_association_hold(asoc);sctp_wait_for_connect(asoc,&timeo);+sctp_association_put(asoc);}/* If we are already past ASSOCIATE, the lower
@@ -7501,6 +7505,7 @@ static int sctp_writeable(struct sock *sk)/* Wait for an association to go into ESTABLISHED state. If timeout is 0,*returnsimmediatelywithEINPROGRESS.+*Note:callermustholdarefonasocbeforecallingthisfunction.*/staticintsctp_wait_for_connect(structsctp_association*asoc,long*timeo_p){
@@ -7511,9 +7516,6 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)pr_debug("%s: asoc:%p, timeo:%ld\n",__func__,asoc,*timeo_p);-/* Increment the association's refcnt. */-sctp_association_hold(asoc);-for(;;){prepare_to_wait_exclusive(&asoc->wait,&wait,TASK_INTERRUPTIBLE);
@@ -7543,9 +7545,6 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)out:finish_wait(&asoc->wait,&wait);-/* Release the association's refcnt. */-sctp_association_put(asoc);-returnerr;do_error:
On Thu, Nov 03, 2016 at 07:02:47PM +0100, Andrey Konovalov wrote:
On Thu, Nov 3, 2016 at 6:52 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
quoted
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
quoted
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
Yes, it fixes the issue.
Tested-by: Andrey Konovalov <redacted>
Thanks for the fix!
Ahm this other fix looks better: do the read before calling
sctp_wait_for_connect() as that id won't change in this call and the
application shouldn't trust this number if an error is returned, so
there should be no issues by returning it in such situation.
Can you please confirm this one also works? Thanks!
---8<---
@@ -1214,9 +1214,12 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);-err=sctp_wait_for_connect(asoc,&timeo);-if((err==0||err==-EINPROGRESS)&&assoc_id)+if(assoc_id)*assoc_id=asoc->assoc_id;+err=sctp_wait_for_connect(asoc,&timeo);+/* Note: the asoc may be freed after the return of+*sctp_wait_for_connect.+*//* Don't free association on exit. */asoc=NULL;
On Thu, Nov 3, 2016 at 7:35 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
On Thu, Nov 03, 2016 at 07:02:47PM +0100, Andrey Konovalov wrote:
quoted
On Thu, Nov 3, 2016 at 6:52 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
quoted
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
quoted
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
Yes, it fixes the issue.
Tested-by: Andrey Konovalov <redacted>
Thanks for the fix!
Ahm this other fix looks better: do the read before calling
sctp_wait_for_connect() as that id won't change in this call and the
application shouldn't trust this number if an error is returned, so
there should be no issues by returning it in such situation.
Can you please confirm this one also works? Thanks!
Sure!
This one also works.
Tested-by: Andrey Konovalov <redacted>
@@ -1214,9 +1214,12 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);-err=sctp_wait_for_connect(asoc,&timeo);-if((err==0||err==-EINPROGRESS)&&assoc_id)+if(assoc_id)*assoc_id=asoc->assoc_id;+err=sctp_wait_for_connect(asoc,&timeo);+/* Note: the asoc may be freed after the return of+*sctp_wait_for_connect.+*//* Don't free association on exit. */asoc=NULL;
From: Neil Horman <nhorman@tuxdriver.com> Date: 2016-11-04 13:00:24
On Thu, Nov 03, 2016 at 04:35:33PM -0200, Marcelo Ricardo Leitner wrote:
quoted hunk
On Thu, Nov 03, 2016 at 07:02:47PM +0100, Andrey Konovalov wrote:
quoted
On Thu, Nov 3, 2016 at 6:52 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
quoted
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
quoted
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
Yes, it fixes the issue.
Tested-by: Andrey Konovalov <redacted>
Thanks for the fix!
Ahm this other fix looks better: do the read before calling
sctp_wait_for_connect() as that id won't change in this call and the
application shouldn't trust this number if an error is returned, so
there should be no issues by returning it in such situation.
Can you please confirm this one also works? Thanks!
---8<---
@@ -1214,9 +1214,12 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);-err=sctp_wait_for_connect(asoc,&timeo);-if((err==0||err==-EINPROGRESS)&&assoc_id)+if(assoc_id)*assoc_id=asoc->assoc_id;+err=sctp_wait_for_connect(asoc,&timeo);+/* Note: the asoc may be freed after the return of+*sctp_wait_for_connect.+*//* Don't free association on exit. */asoc=NULL;
Agreed, this version looks better. Please repost it with a proper changelog and
I'll ack it.
Neil
On Fri, Nov 04, 2016 at 08:59:58AM -0400, Neil Horman wrote:
On Thu, Nov 03, 2016 at 04:35:33PM -0200, Marcelo Ricardo Leitner wrote:
quoted
On Thu, Nov 03, 2016 at 07:02:47PM +0100, Andrey Konovalov wrote:
quoted
On Thu, Nov 3, 2016 at 6:52 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Thu, Nov 03, 2016 at 06:11:01PM +0100, Andrey Konovalov wrote:
quoted
On Wed, Nov 2, 2016 at 11:42 PM, Andrey Konovalov [off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 6:57 PM, Marcelo Ricardo Leitner
[off-list ref] wrote:
quoted
On Wed, Oct 19, 2016 at 02:25:24PM +0200, Andrey Konovalov wrote:
quoted
Hi,
I've got the following error report while running the syzkaller fuzzer:
==================================================================
BUG: KASAN: use-after-free in __sctp_connect+0xabe/0xbf0 at addr
ffff88006b1dc610
Seems this is the same that Dmitry Vyukov had reported back in Jan 13th.
So far I couldn't identify the reason.
"Good" to know it's still there, thanks for reporting it.
Hi Marcelo,
Hi
quoted
So I've looked at the code.
As far as I understand, the problem is a race condition between
setsockopt(SCTP_SOCKOPT_CONNECTX) and shutdown on an sctp socket.
setsockopt() calls sctp_wait_for_connect(), which exits the for loop
on the sk->sk_shutdown & RCV_SHUTDOWN if clause, and then frees asoc
with sctp_association_put() and returns err = 0.
Then __sctp_connect() checks that err == 0 and reads asoc->assoc_id
from the freed asoc.
Suddenly this seems familiar. Your description makes sense, thanks for
looking deeper into this, Andrey.
This fix should do it, can you please try it? I'll post it properly
if it works.
Yes, it fixes the issue.
Tested-by: Andrey Konovalov <redacted>
Thanks for the fix!
Ahm this other fix looks better: do the read before calling
sctp_wait_for_connect() as that id won't change in this call and the
application shouldn't trust this number if an error is returned, so
there should be no issues by returning it in such situation.
Can you please confirm this one also works? Thanks!
---8<---
@@ -1214,9 +1214,12 @@ static int __sctp_connect(struct sock *sk,timeo=sock_sndtimeo(sk,f_flags&O_NONBLOCK);-err=sctp_wait_for_connect(asoc,&timeo);-if((err==0||err==-EINPROGRESS)&&assoc_id)+if(assoc_id)*assoc_id=asoc->assoc_id;+err=sctp_wait_for_connect(asoc,&timeo);+/* Note: the asoc may be freed after the return of+*sctp_wait_for_connect.+*//* Don't free association on exit. */asoc=NULL;
Agreed, this version looks better. Please repost it with a proper changelog and
I'll ack it.
Neil
It already is. :-)
Please look for
Subject: [PATCH net] sctp: assign assoc_id earlier in __sctp_connect
Thanks,
Marcelo