Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5898252imb; Fri, 8 Mar 2019 05:02:59 -0800 (PST) X-Google-Smtp-Source: APXvYqwk/Os+PReT+hwBg3svXpAdiAHHNg87bShWQL4rGDWvof/P2U3vcetEYacdyUJ/P0kmauI3 X-Received: by 2002:a65:60cb:: with SMTP id r11mr16809448pgv.143.1552050179345; Fri, 08 Mar 2019 05:02:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552050179; cv=none; d=google.com; s=arc-20160816; b=J3GL8++ehPLJw/nCRJC6RpoIW2Gar2Ur4UT15/lEHVGCeI8xf4u5nnsY+HcDmpnip2 1lgggSY76OjR6Pxdp85WjzzT24EprQ2wA5mzDRdw7VZ7yAPbH2snrUB6LP7iIx2ymVJP KIN05Im3P+n5a4GtCbfaN6Zc2v5qnh0mUUHzzeHOHbXo2BtSyA+/v3sYoDRxRnekydvt Fr4YdVUBwbE0W03J7PZtZ5Oxr2OEdKA8gh+aaMuvWYmj0VWpovtZpeZR/u8ZVmVEWiGl 0pSVEZrNjuSakn8UWj7QlTbA+r/mhJhYJihQY3yoFvMCEcVyQjOBzL0fhBNo5yAx5V5d Bi1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PRnj6HSxclI2Ck0eXPAya5LgrNeGu2F1utpjmgPnCik=; b=vE3F9h+cU3OI7m4zMyOimRvtuFd7mE9dzOFGG4LD2BA3Lbs4gUVcURKZjcE0jfpcNI vIDwshUBtCXUpTQCRUm78y+TQNy5mintfc9wmj9KPEgyV6ncWKujRQov2ljpRD0aYDaT nV+ot4+ksIb5dliGJWMhU72VDUjWH8K8jM/0ReGhS45kCvWk8e20Qr8mdoTlwcz95a1z AZC5uh2XMpTrMrs5D/MtbOfVcRQ72JofqP+uZRmtRrwmI5heyeoMWwxUkzCNvA2fp5Rb JOv9ZvzENYFLHtQzhPHRXzQnFht62SagWjEFdRA6O8OBXYzuzDaCc2LvUU8dIwoTSufr UyXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kNOq0WND; 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 b13si7311118plz.22.2019.03.08.05.02.42; Fri, 08 Mar 2019 05:02:59 -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; dkim=pass header.i=@kernel.org header.s=default header.b=kNOq0WND; 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 S1728415AbfCHNBX (ORCPT + 99 others); Fri, 8 Mar 2019 08:01:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:38578 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfCHNBS (ORCPT ); Fri, 8 Mar 2019 08:01:18 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8C83220811; Fri, 8 Mar 2019 13:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552050078; bh=Cfe2JxJjz4nphg2+LzU/jaWhWLCri+zNrqPUim8TL0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNOq0WNDQCQtEXjTsIaW0pOgrFgJC1OmqoZBi1zERMkLL9TOhzBUtLG2pomWAH8c6 E1xcKDHKJz/19vW740WLE/owVjtp642GBkutzx/46UT9+s/heLRKrsMxPEczO+YLT3 ZacJ/hCgG440mBLSPmG4IrlXdurVfOTvNtHRWhO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Maloy , Tung Nguyen , "David S. Miller" Subject: [PATCH 4.19 37/68] tipc: fix race condition causing hung sendto Date: Fri, 8 Mar 2019 13:50:07 +0100 Message-Id: <20190308124912.561575178@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308124910.696595153@linuxfoundation.org> References: <20190308124910.696595153@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tung Nguyen [ Upstream commit bfd07f3dd4f111b884d7922b37eb239280f83d8c ] When sending multicast messages via blocking socket, if sending link is congested (tsk->cong_link_cnt is set to 1), the sending thread will be put into sleeping state. However, tipc_sk_filter_rcv() is called under socket spin lock but tipc_wait_for_cond() is not. So, there is no guarantee that the setting of tsk->cong_link_cnt to 0 in tipc_sk_proto_rcv() in CPU-1 will be perceived by CPU-0. If that is the case, the sending thread in CPU-0 after being waken up, will continue to see tsk->cong_link_cnt as 1 and put the sending thread into sleeping state again. The sending thread will sleep forever. CPU-0 | CPU-1 tipc_wait_for_cond() | { | // condition_ = !tsk->cong_link_cnt | while ((rc_ = !(condition_))) { | ... | release_sock(sk_); | wait_woken(); | | if (!sock_owned_by_user(sk)) | tipc_sk_filter_rcv() | { | ... | tipc_sk_proto_rcv() | { | ... | tsk->cong_link_cnt--; | ... | sk->sk_write_space(sk); | ... | } | ... | } sched_annotate_sleep(); | lock_sock(sk_); | remove_wait_queue(); | } | } | This commit fixes it by adding memory barrier to tipc_sk_proto_rcv() and tipc_wait_for_cond(). Acked-by: Jon Maloy Signed-off-by: Tung Nguyen Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/socket.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -377,11 +377,13 @@ static int tipc_sk_sock_err(struct socke #define tipc_wait_for_cond(sock_, timeo_, condition_) \ ({ \ + DEFINE_WAIT_FUNC(wait_, woken_wake_function); \ struct sock *sk_; \ int rc_; \ \ while ((rc_ = !(condition_))) { \ - DEFINE_WAIT_FUNC(wait_, woken_wake_function); \ + /* coupled with smp_wmb() in tipc_sk_proto_rcv() */ \ + smp_rmb(); \ sk_ = (sock_)->sk; \ rc_ = tipc_sk_sock_err((sock_), timeo_); \ if (rc_) \ @@ -1961,6 +1963,8 @@ static void tipc_sk_proto_rcv(struct soc return; case SOCK_WAKEUP: tipc_dest_del(&tsk->cong_links, msg_orignode(hdr), 0); + /* coupled with smp_rmb() in tipc_wait_for_cond() */ + smp_wmb(); tsk->cong_link_cnt--; wakeup = true; break;