[PATCH] sctp: fix refcount bug in sctp_wfree

From: Qiujun Huang
Date: Sun Mar 15 2020 - 23:53:32 EST


Do accounting for skb's real sk.
In some case skb->sk != asoc->base.sk.

Reported-and-tested-by: syzbot+cea71eec5d6de256d54d@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Qiujun Huang <hqjagain@xxxxxxxxx>
---
net/sctp/socket.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 1b56fc4..5f5c28b 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -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);
}
--
1.8.3.1