From: Qiujun Huang <hqjagain@gmail.com>
To: marcelo.leitner@gmail.com, davem@davemloft.net
Cc: vyasevich@gmail.com, nhorman@tuxdriver.com, kuba@kernel.org,
linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, anenbupt@gmail.com,
Qiujun Huang <hqjagain@gmail.com>
Subject: [PATCH v3] sctp: fix refcount bug in sctp_wfree
Date: Fri, 20 Mar 2020 11:09:59 +0000 [thread overview]
Message-ID: <20200320110959.2114-1-hqjagain@gmail.com> (raw)
Do accounting for skb's real sk.
In some case skb->sk != asoc->base.sk:
for the trouble SKB, it was in outq->transmitted queue
sctp_outq_sack
sctp_check_transmitted
SKB was moved to outq->sack
then throw away the sack queue
SKB was deleted from outq->sack
(but the datamsg held SKB at sctp_datamsg_to_asoc
So, sctp_wfree was not called to destroy SKB)
then migrate happened
sctp_for_each_tx_datachunk(
sctp_clear_owner_w);
sctp_assoc_migrate();
sctp_for_each_tx_datachunk(
sctp_set_owner_w);
SKB was not in the outq, and was not changed to newsk
finally
__sctp_outq_teardown
sctp_chunk_put (for another skb)
sctp_datamsg_put
__kfree_skb(msg->frag_list)
sctp_wfree (for SKB)
this case in sctp_wfree SKB->sk was oldsk.
It looks only trouble here so handling it in sctp_wfree is enough.
Reported-and-tested-by: syzbot+cea71eec5d6de256d54d@syzkaller.appspotmail.com
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
---
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 1b56fc440606..5f5c28b30e25 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);
}
--
2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Qiujun Huang <hqjagain@gmail.com>
To: marcelo.leitner@gmail.com, davem@davemloft.net
Cc: vyasevich@gmail.com, nhorman@tuxdriver.com, kuba@kernel.org,
linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, anenbupt@gmail.com,
Qiujun Huang <hqjagain@gmail.com>
Subject: [PATCH v3] sctp: fix refcount bug in sctp_wfree
Date: Fri, 20 Mar 2020 19:09:59 +0800 [thread overview]
Message-ID: <20200320110959.2114-1-hqjagain@gmail.com> (raw)
Do accounting for skb's real sk.
In some case skb->sk != asoc->base.sk:
for the trouble SKB, it was in outq->transmitted queue
sctp_outq_sack
sctp_check_transmitted
SKB was moved to outq->sack
then throw away the sack queue
SKB was deleted from outq->sack
(but the datamsg held SKB at sctp_datamsg_to_asoc
So, sctp_wfree was not called to destroy SKB)
then migrate happened
sctp_for_each_tx_datachunk(
sctp_clear_owner_w);
sctp_assoc_migrate();
sctp_for_each_tx_datachunk(
sctp_set_owner_w);
SKB was not in the outq, and was not changed to newsk
finally
__sctp_outq_teardown
sctp_chunk_put (for another skb)
sctp_datamsg_put
__kfree_skb(msg->frag_list)
sctp_wfree (for SKB)
this case in sctp_wfree SKB->sk was oldsk.
It looks only trouble here so handling it in sctp_wfree is enough.
Reported-and-tested-by: syzbot+cea71eec5d6de256d54d@syzkaller.appspotmail.com
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
---
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 1b56fc440606..5f5c28b30e25 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);
}
--
2.17.1
next reply other threads:[~2020-03-20 11:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 11:09 Qiujun Huang [this message]
2020-03-20 11:09 ` [PATCH v3] sctp: fix refcount bug in sctp_wfree Qiujun Huang
2020-03-20 17:10 ` Eric Dumazet
2020-03-20 17:10 ` Eric Dumazet
2020-03-20 23:36 ` Qiujun Huang
2020-03-20 23:36 ` Qiujun Huang
2020-03-20 18:52 ` Marcelo Ricardo Leitner
2020-03-20 18:52 ` Marcelo Ricardo Leitner
2020-03-20 23:48 ` Qiujun Huang
2020-03-20 23:48 ` Qiujun Huang
2020-03-20 23:53 ` Qiujun Huang
2020-03-20 23:53 ` Qiujun Huang
2020-03-21 1:02 ` Marcelo Ricardo Leitner
2020-03-21 1:02 ` Marcelo Ricardo Leitner
2020-03-21 1:23 ` Qiujun Huang
2020-03-21 1:23 ` Qiujun Huang
2020-03-21 1:33 ` Marcelo Ricardo Leitner
2020-03-21 1:33 ` Marcelo Ricardo Leitner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200320110959.2114-1-hqjagain@gmail.com \
--to=hqjagain@gmail.com \
--cc=anenbupt@gmail.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sctp@vger.kernel.org \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=vyasevich@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.