Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1647237pxy; Mon, 2 Aug 2021 07:02:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO6kYBXxkSsVR6dCf/Yr4RI0ygQCV1WWgfnO1hRcuO3mC4hGzn2zTL4G1TiX9HOD4SW7jb X-Received: by 2002:a2e:b00f:: with SMTP id y15mr11439994ljk.213.1627912943511; Mon, 02 Aug 2021 07:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912943; cv=none; d=google.com; s=arc-20160816; b=wSR9sdM7/C1QsQi+x7JGdrh6YBzFQh8ljPKnGNCqgE3IyaRSVamVL55z0KPFQtM3zP fESjZ4vi0ekzG8MPt3le3Q4sA9f2fBNYg30I9gRlyc27sVZGu/EtFTkjrSkjhUZifMCJ nyQtG4G8l8XvdvuxAFdi5L+5B8xXPgnx+hqRCMdxTBaOVK74ce1qV73BOVcOlbXPUlaT xiR/xzTws9KgIg5uF4dTaCogLrrPYYnFS462wSOqG4vKCfUQyWsxbuandwN1bOzOWUoV FMeQ8ARP+O9HxtQxSqHgh5Rup9/+po/TVbBSuWZkJfugxwf42YOOo2Q7nkZhCvfxqAT0 2tyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CDQItpCK/SkILc2Mude01WsIufPF7RC5ZKrnH9wFmwI=; b=kA4IUYqiDQDxFYjxR0sCv1+BAo1Wm69RP9ruWRyZl9ck+INf5Ox3ZQPzSy67KWjGMT 8NA9bCaHwRHUwSFZhUwVYSvv337mS8u4f/u6frMDPL1R02cGm6xuvMXKiKN7Y3OASLf/ +wug9ym8CYylmkMjTrlAvO4ZpooIGaRCGmwJU45KJlDSV6NigGtyMrq/KOK/XVw6WJPR 9//HBijgtI7YKlzTOorGYjK1jvXAUg29NdidRZ94OlZo6GBC4gfO5vtf/7uZxqMuWiK1 w10d2M8pheDnDwr/qsKioEJUYNdYq5cRXBfqhcNzQZkmIlvDIh9rD69ZOXd1Po/dYklf 1Aug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZEQaYCpG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h37si13371706lfv.123.2021.08.02.07.01.55; Mon, 02 Aug 2021 07:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZEQaYCpG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234036AbhHBOAI (ORCPT + 99 others); Mon, 2 Aug 2021 10:00:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:40684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236077AbhHBNy5 (ORCPT ); Mon, 2 Aug 2021 09:54:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8530B611CE; Mon, 2 Aug 2021 13:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912387; bh=uQA00636DhftkDXnt8Orn9kC8cnTw9fDbYKzxjacgvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEQaYCpGSr+MCEl7i/osykaZKQaIthdXC5H7hlzloJKJAzGlnkDcWMmM4S50lZOY/ XDx92RP1V+w+eadVrS2IivCgN57mwM1OopVm4oxoGFcCCToa6vB+pZb4fNKwhA99pD mzJ1eiN3PekWt/jJmtr+ps7kaOcsKfYCqSzIHAz4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , Jon Maloy , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 37/67] tipc: fix implicit-connect for SYN+ Date: Mon, 2 Aug 2021 15:45:00 +0200 Message-Id: <20210802134340.287944875@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134339.023067817@linuxfoundation.org> References: <20210802134339.023067817@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit f8dd60de194817c86bf812700980762bb5a8d9a4 ] For implicit-connect, when it's either SYN- or SYN+, an ACK should be sent back to the client immediately. It's not appropriate for the client to enter established state only after receiving data from the server. On client side, after the SYN is sent out, tipc_wait_for_connect() should be called to wait for the ACK if timeout is set. This patch also restricts __tipc_sendstream() to call __sendmsg() only when it's in TIPC_OPEN state, so that the client can program in a single loop doing both connecting and data sending like: for (...) sendmsg(dest, buf); This makes the implicit-connect more implicit. Fixes: b97bf3fd8f6a ("[TIPC] Initial merge") Signed-off-by: Xin Long Acked-by: Jon Maloy Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/tipc/socket.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 9f7cc9e1e4ef..694c432b9710 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -148,6 +148,7 @@ static void tipc_sk_remove(struct tipc_sock *tsk); static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dsz); static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz); static void tipc_sk_push_backlog(struct tipc_sock *tsk, bool nagle_ack); +static int tipc_wait_for_connect(struct socket *sock, long *timeo_p); static const struct proto_ops packet_ops; static const struct proto_ops stream_ops; @@ -1508,8 +1509,13 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) rc = 0; } - if (unlikely(syn && !rc)) + if (unlikely(syn && !rc)) { tipc_set_sk_state(sk, TIPC_CONNECTING); + if (timeout) { + timeout = msecs_to_jiffies(timeout); + tipc_wait_for_connect(sock, &timeout); + } + } return rc ? rc : dlen; } @@ -1557,7 +1563,7 @@ static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dlen) return -EMSGSIZE; /* Handle implicit connection setup */ - if (unlikely(dest)) { + if (unlikely(dest && sk->sk_state == TIPC_OPEN)) { rc = __tipc_sendmsg(sock, m, dlen); if (dlen && dlen == rc) { tsk->peer_caps = tipc_node_get_capabilities(net, dnode); @@ -2686,9 +2692,10 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, bool kern) { struct sock *new_sk, *sk = sock->sk; - struct sk_buff *buf; struct tipc_sock *new_tsock; + struct msghdr m = {NULL,}; struct tipc_msg *msg; + struct sk_buff *buf; long timeo; int res; @@ -2733,19 +2740,17 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, } /* - * Respond to 'SYN-' by discarding it & returning 'ACK'-. - * Respond to 'SYN+' by queuing it on new socket. + * Respond to 'SYN-' by discarding it & returning 'ACK'. + * Respond to 'SYN+' by queuing it on new socket & returning 'ACK'. */ if (!msg_data_sz(msg)) { - struct msghdr m = {NULL,}; - tsk_advance_rx_queue(sk); - __tipc_sendstream(new_sock, &m, 0); } else { __skb_dequeue(&sk->sk_receive_queue); __skb_queue_head(&new_sk->sk_receive_queue, buf); skb_set_owner_r(buf, new_sk); } + __tipc_sendstream(new_sock, &m, 0); release_sock(new_sk); exit: release_sock(sk); -- 2.30.2