sctp: fix refcount bug in sctp_wfree
Subsystems (3)
PATCH 1/1 sctp: fix refcount bug in sctp_wfree
Do accounting for skb's real sk.
In some case skb->sk != asoc->base.sk.
--- net/sctp/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/socket.c +2 -2
@@ -9080,7 +9080,7 @@ static void sctp_wfree(struct sk_buff *skb) {struct sctp_chunk *chunk =skb_shinfo (skb)->destructor_arg;struct sctp_association *asoc = chunk->asoc; -struct sock *sk = asoc->base.sk; +struct sock *sk = skb->sk;sk_mem_uncharge (sk, skb->truesize); sk->sk_wmem_queued -= skb->truesize +sizeof (struct sctp_chunk );
@@ -9109,7 +9109,7 @@ static void sctp_wfree(struct sk_buff *skb) }sock_wfree (skb); -sctp_wake_up_waiters (sk, asoc); +sctp_wake_up_waiters (asoc->base.sk, asoc);sctp_association_put (asoc); }
Signature · 1 line
1.8.3.1
David Miller
maintainerFrom: Qiujun Huang <[email protected]>
Date: Mon, 16 Mar 2020 11:53:24 +0800
Quoted 5 lines
Do accounting for skb's real sk.
In some caseskb->sk!=asoc->base.sk.Reported-and-tested-by [email protected]Signed-off-by Qiujun Huang <[email protected]>
SCTP folks, please review.
Marcelo Ricardo Leitner
maintainerQuoted 2 lines · Qiujun Huang
Do accounting for skb's real sk.
In some caseskb->sk!=asoc->base.sk.
This is a too simple description. Please elaborate how this can happen in sctp_wfree. Especially considering the construct for migrating the tx queue on sctp_sock_migrate(), as both sockets are locked while moving the chunks around and the asoc itself is only moved in between decrementing and incrementing the refcount:
lock_sock_nested(newsk, SINGLE_DEPTH_NESTING);
sctp_for_each_tx_datachunk(assoc, sctp_clear_owner_w);
sctp_assoc_migrate(assoc, newsk);
sctp_for_each_tx_datachunk(assoc, sctp_set_owner_w);
...Quoted 2 lines
Reported-and-tested-by [email protected]
I can't see a positive test result, though. If I didn't loose any
email, your last test with a patch similar to this one actually
failed.
I'm talking about syzbot test result at Message-ID: <[email protected]>
Quoted 30 lines
Signed-off-by Qiujun Huang <[email protected]>--- net/sctp/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/sctp/socket.c +2
-2@@ -9080,7 +9080,7 @@ static void sctp_wfree(struct sk_buff *skb) {struct sctp_chunk *chunk =skb_shinfo (skb)->destructor_arg;struct sctp_association *asoc = chunk->asoc; -struct sock *sk = asoc->base.sk; +struct sock *sk = skb->sk;sk_mem_uncharge (sk, skb->truesize); sk->sk_wmem_queued -= skb->truesize +sizeof (struct sctp_chunk );@@ -9109,7 +9109,7 @@ static void sctp_wfree(struct sk_buff *skb) }sock_wfree (skb); -sctp_wake_up_waiters (sk, asoc); +sctp_wake_up_waiters (asoc->base.sk, asoc);sctp_association_put (asoc); }Signature · 1 line
1.8.3.1
Quoted 11 lines · Marcelo Ricardo Leitner
Quoted 2 lines · Qiujun Huang
Do accounting for skb's real sk.
In some caseskb->sk!=asoc->base.sk.This is a too simple description. Please elaborate how this can happen in
sctp_wfree. Especially considering the construct for migrating the tx queue onsctp_sock_migrate(), as both sockets are locked while moving the chunks around and the asoc itself is only moved in between decrementing and incrementing the refcount:
Quoted 5 lines
lock_sock_nested(newsk, SINGLE_DEPTH_NESTING);
sctp_for_each_tx_datachunk(assoc, sctp_clear_owner_w);
sctp_assoc_migrate(assoc, newsk);
sctp_for_each_tx_datachunk(assoc, sctp_set_owner_w);
...Yeah, the description is too simple. I'll send v2.
Quoted 8 lines
Quoted 3 lines
Reported-and-tested-by [email protected]I can't see a positive test result, though. If I didn't loose any
email, your last test with a patch similar to this one actually
failed.
I'm talking about syzbot test result at Message-ID: <[email protected]>
I told with syzbot privately avoiding noise :p
Thanks!