From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x2240RmA0JNuP2WsWGkpaXCVxO3A150lE7f3Pr2ZlZN+oZNudMa6bjcbofpgWcueggNKe6b02 ARC-Seal: i=1; a=rsa-sha256; t=1517256266; cv=none; d=google.com; s=arc-20160816; b=r4ZwtbQZ5hIkv3rRFTv6fVxsWiwTVD0+dtWkAjVNC8H2A7j3Ylfjtx4VjUpjFdq2BS EYjGb2f4FQgEImcstitcGu8kXEyTg3g2cM+RX23pEKnfmbomPlJn0SM09llw1t8khdO1 qDOGwKZqLTsslThy40SfUk9jb56iAST0ZuO9j/xSDjVpaUYGh9mm1cpS+cZaG3rP6gSR fAV37Y2t/H/MyCozvqm2fEVL4iWcnka8kNaeodlSxV7Y381H74hafWdWh13dy1vPzK6E 9YFbDL2Rx8e60dM+vjg0UfX+mIfw7X85cu3/jgUGGpOh7nwA9+1qJl1NHOgm+cygFkzI TIxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hStlxM+uKS9twYsqRaUlTGY4Q7BEwZbpi2gvHmLCOek=; b=J+xop/4NDIGP6qEkH4r+tHyRNHZYKxnNpP2wTXMko5Vvr+omMj6ejH1OjmCk2NaS/v aujORYj0dFSK9aQ4HhHSc7B7jlT9VW50TnO+RsW0QLBOaN+tN30b21HQ8l1JJyn5rU5u Rxt5xMpo4CpuZPEACkTvjnOgLNo/ZOO6l/ihgg5Q8WL3VhytRVJjagMC36J0QitnqsP5 5aZ0sfn/HgUKJ6rMgZrXQwEz1iKQ5cNaYlS1gMq1GzTQEuvcu8JCPXJOBE4cnEYXXqyU 4D8p7lXKHw0ImULHlrsH+R2CwkDqPMTD6+VosOxiY6J2ukL/dSNdS+A2LovBmgEFbOuW jOwA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ac6ea7baa4432811eb50@syzkaller.appspotmail.com, Xin Long , Neil Horman , "David S. Miller" Subject: [PATCH 4.14 38/71] sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf Date: Mon, 29 Jan 2018 13:57:06 +0100 Message-Id: <20180129123829.804024377@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123827.271171825@linuxfoundation.org> References: <20180129123827.271171825@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958497909596692?= X-GMAIL-MSGID: =?utf-8?q?1590958506838007878?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xin Long [ Upstream commit a0ff660058b88d12625a783ce9e5c1371c87951f ] After commit cea0cc80a677 ("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: cea0cc80a677 ("sctp: use the right sk after waking up from wait_buf sleep") Reported-by: syzbot+ac6ea7baa4432811eb50@syzkaller.appspotmail.com Signed-off-by: Xin Long Acked-by: Neil Horman Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/socket.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -84,7 +84,7 @@ static int sctp_writeable(struct sock *sk); static void sctp_wfree(struct sk_buff *skb); static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, - size_t msg_len, struct sock **orig_sk); + size_t msg_len); static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p); static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); static int sctp_wait_for_accept(struct sock *sk, long timeo); @@ -1961,7 +1961,7 @@ static int sctp_sendmsg(struct sock *sk, timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); if (!sctp_wspace(asoc)) { /* sk can be changed by peel off when waiting for buf. */ - err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len, &sk); + err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); if (err) { if (err == -ESRCH) { /* asoc is already dead. */ @@ -7825,12 +7825,12 @@ void sctp_sock_rfree(struct sk_buff *skb /* Helper function to wait for space in the sndbuf. */ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, - size_t msg_len, struct sock **orig_sk) + size_t msg_len) { struct sock *sk = asoc->base.sk; - int err = 0; long current_timeo = *timeo_p; DEFINE_WAIT(wait); + int err = 0; pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__, asoc, *timeo_p, msg_len); @@ -7859,17 +7859,13 @@ static int sctp_wait_for_sndbuf(struct s release_sock(sk); current_timeo = schedule_timeout(current_timeo); lock_sock(sk); - if (sk != asoc->base.sk) { - release_sock(sk); - sk = asoc->base.sk; - lock_sock(sk); - } + if (sk != asoc->base.sk) + goto do_error; *timeo_p = current_timeo; } out: - *orig_sk = sk; finish_wait(&asoc->wait, &wait); /* Release the association's refcnt. */