Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5902317imb; Fri, 8 Mar 2019 05:07:28 -0800 (PST) X-Google-Smtp-Source: APXvYqxAEqVuq/lHRlQypjkp+8s/eXH2f+riDT/sMHFoKtkLukJRM8c338PfNrW+aUtLry6GSpJm X-Received: by 2002:a17:902:be15:: with SMTP id r21mr18186975pls.143.1552050448093; Fri, 08 Mar 2019 05:07:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552050448; cv=none; d=google.com; s=arc-20160816; b=0fVd/72Tts9mgohxY6zx6EekX9i8K025HlGUDCH089sZpawXaHmxqxSZ4zf9OjBaMo mOw7L7Gm4oveGe30tUaVHuLYIUf7tq2yFb26JKlEs9ljvO3CQyLGOEK34EnjgTKEFVUF Hrq7z6vUEZ7Wi6r0oH0h0dw08oZ7V1u++eGHxSUDjgqkGT8vuG9tUsJwA3Nb+47soVH4 slxazK4r4w47W6QfjH9KBwQeOrOTbhEpUUzY7r/ySG0m8HXOmPxF45/HjmHXccjzKIms amkVQEBVIAlsz+LvSgDppQt7vSFTGqkfI0/n7vI2kBFj1k6IAzyNoggtU1caH1rKrklM CZTg== 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=brtHO/sXVtfwZWM7/2ZgNujy9pZiLg5+bGQbu2KUC/k=; b=Op0ctC1jS9+XWaRilRo/I4o4R0VYiVSqeJMeh/VguUhQb9IYxVmgBHgYM022ur69ae EZCQCrB+oIDvmQmIO63hO+WsYjPCYZy2WBBXzXwq74Gq11AViT2fX3aSOv4EToImkOcH 6Eqv1K/veSzQl8qMO7PpRP1jkiO+fdZA+rEBRDjA93gTTHNjxlo1SeE/rfcMhTNZMO5i GooCQP64kwoNtzqSoq7UIWrvn3KBnLgm4YD9TTRt400jI14/GGaLbEvd2zPjTA0Y2cep 6KDfHz8FuVoud1Wcrh/F+p/E91yoNPbhhrgtIs41H+dNOqNhgd30Y5Tv6HTDiMlvo4hl IO6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="K/LA+n01"; 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 m3si7014835pld.425.2019.03.08.05.07.12; Fri, 08 Mar 2019 05:07:28 -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="K/LA+n01"; 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 S1727493AbfCHMzY (ORCPT + 99 others); Fri, 8 Mar 2019 07:55:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:59390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727488AbfCHMzW (ORCPT ); Fri, 8 Mar 2019 07:55:22 -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 424392085A; Fri, 8 Mar 2019 12:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552049721; bh=mcYFfNv44XvfdF/A6GCKikNdO/9MYXOThIaV5NLujH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/LA+n01BptBa/l6VGdeQl76pcPIL2sc+Ih5iqyTqPHZ97K3fRv1hFL4xHCIkvVeb MqWm4yGqY9uYfgmvnXDSIcI1OPfazLvUEJUcHANnILOMLVAGfJQTm20wKF0wqKgfwz QQJ6ZAVav/YHqWb0lNr6oHgJ36xojcyLUtae6q+Q= 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.20 44/76] tipc: fix race condition causing hung sendto Date: Fri, 8 Mar 2019 13:49:56 +0100 Message-Id: <20190308124916.378083107@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308124914.789210760@linuxfoundation.org> References: <20190308124914.789210760@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.20-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 @@ -376,11 +376,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_) \ @@ -1968,6 +1970,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;