Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4821950ybl; Wed, 22 Jan 2020 05:24:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzgdHI8/5sCbUKGMog2ctm+UAzU/cVjSgWNbrx5cX0+pSOAwVaAZaawyG+KNMJl8qbZnxPv X-Received: by 2002:aca:d0c:: with SMTP id 12mr6905402oin.26.1579699456563; Wed, 22 Jan 2020 05:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699456; cv=none; d=google.com; s=arc-20160816; b=z+RyezBYSFWZTNVRrGYuphVD8SUBe/IAubAsBpw/QnvcEBemsKzuCc35WdQ7S9Ry/m XaxBdKzWoGr3FxNj7ZA4b8Posvyl8XwEMp+MGU2lfnhYyBXisyoU4roJ/X42LcaGq9MF Y/ha9hsoYq7fbg64o4iGEwek0S+WSvDOcoEpvygl9WASzZobj5D5ESmh4NVYSWC3z0/X 7QimxqaJ1cjFQ76L7A+etkkdiCWplklCO8h7+S4Pouq5E0Co6lMwOx1BENJkiZ97fnnf eNi0iGcVuHiLqxwXCN4pSk4KlK8eiYZb1ALPEtm4k+IzPgi4DzpDNz5Xc1Rpb3o5tsiH PIaw== 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=RSKxXx2cqKAG8f31noB3FiFb5iImIIoBeIeqiTccCoE=; b=LjH/vWYU4+lp51F2sbPoMLnXK4gStCTgCM8xYeBdzNsOcxNA0Jo4ubNniHhaeCXySu IUrB18iUsvi1x3suXOCe1N8lYrLw+wXt7QFxsa0e3AgIBcbrcsv3G0mSDNH0ZNZE6Re6 fZu1lADu90UB12xhy/lZLOaqJyu/rO6wTnI9g4B4Oi2QUINyVPFwAjHlwc01Ov7YSij4 5/w6Cc7000u044AvI3vubeRVCi225MjiXF2eBeDAOqv5SSO8FEq3ZMXez8ecf3F5OFR8 HT3DjMOmAwriBOejR2NdmYAaJ4t1B+uGYzS3si0QVI2lRmQr0AuvRjxCA1CpVzFdiXQC zeEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iJXVhUAr; 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 a128si20138940oib.142.2020.01.22.05.24.04; Wed, 22 Jan 2020 05:24:16 -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=iJXVhUAr; 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 S1730346AbgAVNVu (ORCPT + 99 others); Wed, 22 Jan 2020 08:21:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:39038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729858AbgAVNVs (ORCPT ); Wed, 22 Jan 2020 08:21:48 -0500 Received: from localhost (unknown [84.241.205.26]) (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 C5965205F4; Wed, 22 Jan 2020 13:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699307; bh=JjPHG6GkHbdguECzk6PpSjxJAxH4nEN4EflwHtweL7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iJXVhUArGRNf8Qyze12vBEfGncQ2Z5YaOsAjKO7sVfOlRhJtAx8yD8FVyXYawweyz YzT9P32/da24jCpqYfAjauBt0tPCk4oyjNe/ItvoaoQw3Q3UrGPalYnguLEZBRi/zU og1oJe69iX00T6uZQ+IeMKMgE/NM2iKgDwfLZb3A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Maloy , Tuong Lien , "David S. Miller" Subject: [PATCH 5.4 103/222] tipc: fix retrans failure due to wrong destination Date: Wed, 22 Jan 2020 10:28:09 +0100 Message-Id: <20200122092841.116433294@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Tuong Lien commit abc9b4e0549b93fdaff56e9532bc49a2d7b04955 upstream. When a user message is sent, TIPC will check if the socket has faced a congestion at link layer. If that happens, it will make a sleep to wait for the congestion to disappear. This leaves a gap for other users to take over the socket (e.g. multi threads) since the socket is released as well. Also, in case of connectionless (e.g. SOCK_RDM), user is free to send messages to various destinations (e.g. via 'sendto()'), then the socket's preformatted header has to be updated correspondingly prior to the actual payload message building. Unfortunately, the latter action is done before the first action which causes a condition issue that the destination of a certain message can be modified incorrectly in the middle, leading to wrong destination when that message is built. Consequently, when the message is sent to the link layer, it gets stuck there forever because the peer node will simply reject it. After a number of retransmission attempts, the link is eventually taken down and the retransmission failure is reported. This commit fixes the problem by rearranging the order of actions to prevent the race condition from occurring, so the message building is 'atomic' and its header will not be modified by anyone. Fixes: 365ad353c256 ("tipc: reduce risk of user starvation during link congestion") Acked-by: Jon Maloy Signed-off-by: Tuong Lien Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tipc/socket.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1306,8 +1306,8 @@ static int __tipc_sendmsg(struct socket struct tipc_msg *hdr = &tsk->phdr; struct tipc_name_seq *seq; struct sk_buff_head pkts; - u32 dport, dnode = 0; - u32 type, inst; + u32 dport = 0, dnode = 0; + u32 type = 0, inst = 0; int mtu, rc; if (unlikely(dlen > TIPC_MAX_USER_MSG_SIZE)) @@ -1360,23 +1360,11 @@ static int __tipc_sendmsg(struct socket type = dest->addr.name.name.type; inst = dest->addr.name.name.instance; dnode = dest->addr.name.domain; - msg_set_type(hdr, TIPC_NAMED_MSG); - msg_set_hdr_sz(hdr, NAMED_H_SIZE); - msg_set_nametype(hdr, type); - msg_set_nameinst(hdr, inst); - msg_set_lookup_scope(hdr, tipc_node2scope(dnode)); dport = tipc_nametbl_translate(net, type, inst, &dnode); - msg_set_destnode(hdr, dnode); - msg_set_destport(hdr, dport); if (unlikely(!dport && !dnode)) return -EHOSTUNREACH; } else if (dest->addrtype == TIPC_ADDR_ID) { dnode = dest->addr.id.node; - msg_set_type(hdr, TIPC_DIRECT_MSG); - msg_set_lookup_scope(hdr, 0); - msg_set_destnode(hdr, dnode); - msg_set_destport(hdr, dest->addr.id.ref); - msg_set_hdr_sz(hdr, BASIC_H_SIZE); } else { return -EINVAL; } @@ -1387,6 +1375,22 @@ static int __tipc_sendmsg(struct socket if (unlikely(rc)) return rc; + if (dest->addrtype == TIPC_ADDR_NAME) { + msg_set_type(hdr, TIPC_NAMED_MSG); + msg_set_hdr_sz(hdr, NAMED_H_SIZE); + msg_set_nametype(hdr, type); + msg_set_nameinst(hdr, inst); + msg_set_lookup_scope(hdr, tipc_node2scope(dnode)); + msg_set_destnode(hdr, dnode); + msg_set_destport(hdr, dport); + } else { /* TIPC_ADDR_ID */ + msg_set_type(hdr, TIPC_DIRECT_MSG); + msg_set_lookup_scope(hdr, 0); + msg_set_destnode(hdr, dnode); + msg_set_destport(hdr, dest->addr.id.ref); + msg_set_hdr_sz(hdr, BASIC_H_SIZE); + } + __skb_queue_head_init(&pkts); mtu = tipc_node_get_mtu(net, dnode, tsk->portid); rc = tipc_msg_build(hdr, m, 0, dlen, mtu, &pkts);