Received: by 10.223.176.5 with SMTP id f5csp3421167wra; Mon, 29 Jan 2018 12:57:11 -0800 (PST) X-Google-Smtp-Source: AH8x224Tw1McGk2oljKQPsFlhZzFJISOrTyr7VAYtnFoGV3CIFJUPRWsHh9kWYO4aNvZHnzSwkws X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr22680647plj.411.1517259430956; Mon, 29 Jan 2018 12:57:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517259430; cv=none; d=google.com; s=arc-20160816; b=pzzeO0ja8dAPuRDsVk0PpUzD6vhTnt1fAEsS6Kbqlei7dJQBYxZsU7IZaJD5Sh4Jvv z1GHEgrwrMHrHeAjD5hCryHMJ/AT979PLua5j9QTiEfUKvT+vXle4dcZw8TPpk2sRFgP rlmbBcJLJIGgesc1h2Zgjq1+j394/x9WWJsI5ektldtCJz3WuinLHK3qqUwbI6NYbV7r TdVqn7B414+84P8x9vPUCH0Zp3ejIFDwE77gtvd7xGeG86h3XoyR4tdjSb5rzQKCJjn7 t/eAYEFDSOIz4GU5s9quYttwyXRK0kEAEi/mpAc85ZKExVLXKjQU7xOiYeR2Usf6og0L yIcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NVVPFvvkEXqlwwrwjYNqjmX2JG5h94cEr62KBeY9qmo=; b=JLDRI/mqKZtl/imzp9FesXx+OkeYE2Y662R/XzamjgKTYGNypq4kfuVYzuroUEirod LM3SjA2ayXK4f6lWez2cOL5sDHD9nRQQxe8HtRSVwrjx1xXJ1fJw283CNgL3aRvtrZzL 5j+2BcVNEWuFb6j5RCJZEpSKxzzLkWn0pGtOvSzL41JVfEV/U0RswB284GZQiAj7Gqm1 gfHS24QXBkb1fUaTQ251012pRORv8RB4N39G9uVHBC5RRLCj3O+wIegDRbsff0QZxjhH AXHYWUF44A/4JTUM/uWYpOgHYm8BGFfkWq7NyL3+Vp9S7uobMIHe+fOB+lBOPmTUUZNa GF7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9-v6si2042632plr.411.2018.01.29.12.56.56; Mon, 29 Jan 2018 12:57:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbeA2Uz0 (ORCPT + 99 others); Mon, 29 Jan 2018 15:55:26 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56108 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753379AbeA2UKB (ORCPT ); Mon, 29 Jan 2018 15:10:01 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3E8AA2ECF; Mon, 29 Jan 2018 13:00:22 +0000 (UTC) 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 3.18 48/52] 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: <20180129123630.270180446@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123628.168904217@linuxfoundation.org> References: <20180129123628.168904217@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-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 @@ -83,7 +83,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); @@ -1948,7 +1948,7 @@ static int sctp_sendmsg(struct kiocb *io 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. */ @@ -6981,12 +6981,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); @@ -7015,17 +7015,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. */