This is a note to let you know that I've just added the patch titled mptcp: fix connect timeout handling to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mptcp-fix-connect-timeout-handling.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 786fc12457268cc9b555dde6c22ae7300d4b40e1 Mon Sep 17 00:00:00 2001 From: Paolo Abeni <pabeni@xxxxxxxxxx> Date: Wed, 31 May 2023 12:37:03 -0700 Subject: mptcp: fix connect timeout handling From: Paolo Abeni <pabeni@xxxxxxxxxx> commit 786fc12457268cc9b555dde6c22ae7300d4b40e1 upstream. Ondrej reported a functional issue WRT timeout handling on connect with a nice reproducer. The problem is that the current mptcp connect waits for both the MPTCP socket level timeout, and the first subflow socket timeout. The latter is not influenced/touched by the exposed setsockopt(). Overall the above makes the SO_SNDTIMEO a no-op on connect. Since mptcp_connect is invoked via inet_stream_connect and the latter properly handle the MPTCP level timeout, we can address the issue making the nested subflow level connect always unblocking. This also allow simplifying a bit the code, dropping an ugly hack to handle the fastopen and custom proto_ops connect. The issues predates the blamed commit below, but the current resolution requires the infrastructure introduced there. Fixes: 54f1944ed6d2 ("mptcp: factor out mptcp_connect()") Reported-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx> Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/399 Cc: stable@xxxxxxxxxxxxxxx Reviewed-by: Mat Martineau <martineau@xxxxxxxxxx> Signed-off-by: Paolo Abeni <pabeni@xxxxxxxxxx> Signed-off-by: Mat Martineau <martineau@xxxxxxxxxx> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/mptcp/protocol.c | 29 +++++++---------------------- net/mptcp/protocol.h | 1 - 2 files changed, 7 insertions(+), 23 deletions(-) --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1683,7 +1683,6 @@ static int mptcp_sendmsg_fastopen(struct lock_sock(ssk); msg->msg_flags |= MSG_DONTWAIT; - msk->connect_flags = O_NONBLOCK; msk->fastopening = 1; ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL); msk->fastopening = 0; @@ -3638,9 +3637,9 @@ static int mptcp_connect(struct sock *sk * acquired the subflow socket lock, too. */ if (msk->fastopening) - err = __inet_stream_connect(ssock, uaddr, addr_len, msk->connect_flags, 1); + err = __inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK, 1); else - err = inet_stream_connect(ssock, uaddr, addr_len, msk->connect_flags); + err = inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK); inet_sk(sk)->defer_connect = inet_sk(ssock->sk)->defer_connect; /* on successful connect, the msk state will be moved to established by @@ -3653,12 +3652,10 @@ static int mptcp_connect(struct sock *sk mptcp_copy_inaddrs(sk, ssock->sk); - /* unblocking connect, mptcp-level inet_stream_connect will error out - * without changing the socket state, update it here. + /* silence EINPROGRESS and let the caller inet_stream_connect + * handle the connection in progress */ - if (err == -EINPROGRESS) - sk->sk_socket->state = ssock->state; - return err; + return 0; } static struct proto mptcp_prot = { @@ -3717,18 +3714,6 @@ unlock: return err; } -static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, - int addr_len, int flags) -{ - int ret; - - lock_sock(sock->sk); - mptcp_sk(sock->sk)->connect_flags = flags; - ret = __inet_stream_connect(sock, uaddr, addr_len, flags, 0); - release_sock(sock->sk); - return ret; -} - static int mptcp_listen(struct socket *sock, int backlog) { struct mptcp_sock *msk = mptcp_sk(sock->sk); @@ -3879,7 +3864,7 @@ static const struct proto_ops mptcp_stre .owner = THIS_MODULE, .release = inet_release, .bind = mptcp_bind, - .connect = mptcp_stream_connect, + .connect = inet_stream_connect, .socketpair = sock_no_socketpair, .accept = mptcp_stream_accept, .getname = inet_getname, @@ -3974,7 +3959,7 @@ static const struct proto_ops mptcp_v6_s .owner = THIS_MODULE, .release = inet6_release, .bind = mptcp_bind, - .connect = mptcp_stream_connect, + .connect = inet_stream_connect, .socketpair = sock_no_socketpair, .accept = mptcp_stream_accept, .getname = inet6_getname, --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -288,7 +288,6 @@ struct mptcp_sock { nodelay:1, fastopening:1, in_accept_queue:1; - int connect_flags; struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; Patches currently in stable-queue which might be from pabeni@xxxxxxxxxx are queue-6.1/net-dsa-mv88e6xxx-increase-wait-after-reset-deactiva.patch queue-6.1/net-smc-don-t-use-rmbs-not-mapped-to-new-link-in-smc.patch queue-6.1/net-smc-scan-from-current-rmb-list-when-no-position-.patch queue-6.1/udp6-fix-race-condition-in-udp6_sendmsg-connect.patch queue-6.1/selftests-mptcp-connect-skip-if-mptcp-is-not-supported.patch queue-6.1/mptcp-add-annotations-around-msk-subflow-accesses.patch queue-6.1/selftests-mptcp-sockopt-skip-if-mptcp-is-not-supported.patch queue-6.1/mptcp-fix-data-race-around-msk-first-access.patch queue-6.1/mptcp-avoid-unneeded-__mptcp_nmpc_socket-usage.patch queue-6.1/selftests-mptcp-join-skip-if-mptcp-is-not-supported.patch queue-6.1/selftests-mptcp-pm-nl-skip-if-mptcp-is-not-supported.patch queue-6.1/tcp-deny-tcp_disconnect-when-threads-are-waiting.patch queue-6.1/selftests-mptcp-userspace-pm-skip-if-mptcp-is-not-supported.patch queue-6.1/net-sched-flower-fix-possible-oob-write-in-fl_set_ge.patch queue-6.1/mptcp-consolidate-passive-msk-socket-initialization.patch queue-6.1/mptcp-fix-active-subflow-finalization.patch queue-6.1/mptcp-avoid-unneeded-address-copy.patch queue-6.1/mptcp-simplify-subflow_syn_recv_sock.patch queue-6.1/mptcp-add-annotations-around-sk-sk_shutdown-accesses.patch queue-6.1/mptcp-fix-connect-timeout-handling.patch queue-6.1/tcp-fix-mishandling-when-the-sack-compression-is-def.patch