Skip to content

Commit a940c19

Browse files
lxingregkh
authored andcommitted
sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf
[ Upstream commit a0ff660 ] After commit cea0cc8 ("sctp: use the right sk after waking up from wait_buf sleep"), it may change to lock another sk if the asoc has been peeled off in sctp_wait_for_sndbuf. However, the asoc's new sk could be already closed elsewhere, as it's in the sendmsg context of the old sk that can't avoid the new sk's closing. If the sk's last one refcnt is held by this asoc, later on after putting this asoc, the new sk will be freed, while under it's own lock. This patch is to revert that commit, but fix the old issue by returning error under the old sk's lock. Fixes: cea0cc8 ("sctp: use the right sk after waking up from wait_buf sleep") Reported-by: syzbot+ac6ea7baa4432811eb50@syzkaller.appspotmail.com Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f2e9570 commit a940c19

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎net/sctp/socket.c‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
static int sctp_writeable(struct sock *sk);
8585
static void sctp_wfree(struct sk_buff *skb);
8686
static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
87-
size_t msg_len, struct sock **orig_sk);
87+
size_t msg_len);
8888
static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p);
8989
static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p);
9090
static int sctp_wait_for_accept(struct sock *sk, long timeo);
@@ -1961,7 +1961,7 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
19611961
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
19621962
if (!sctp_wspace(asoc)) {
19631963
/* sk can be changed by peel off when waiting for buf. */
1964-
err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len, &sk);
1964+
err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
19651965
if (err) {
19661966
if (err == -ESRCH) {
19671967
/* asoc is already dead. */
@@ -7825,12 +7825,12 @@ void sctp_sock_rfree(struct sk_buff *skb)
78257825

78267826
/* Helper function to wait for space in the sndbuf. */
78277827
static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
7828-
size_t msg_len, struct sock **orig_sk)
7828+
size_t msg_len)
78297829
{
78307830
struct sock *sk = asoc->base.sk;
7831-
int err = 0;
78327831
long current_timeo = *timeo_p;
78337832
DEFINE_WAIT(wait);
7833+
int err = 0;
78347834

78357835
pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__, asoc,
78367836
*timeo_p, msg_len);
@@ -7859,17 +7859,13 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
78597859
release_sock(sk);
78607860
current_timeo = schedule_timeout(current_timeo);
78617861
lock_sock(sk);
7862-
if (sk != asoc->base.sk) {
7863-
release_sock(sk);
7864-
sk = asoc->base.sk;
7865-
lock_sock(sk);
7866-
}
7862+
if (sk != asoc->base.sk)
7863+
goto do_error;
78677864

78687865
*timeo_p = current_timeo;
78697866
}
78707867

78717868
out:
7872-
*orig_sk = sk;
78737869
finish_wait(&asoc->wait, &wait);
78747870

78757871
/* Release the association's refcnt. */

0 commit comments

Comments
 (0)