Skip to content

Commit

Permalink
mptcp: propagate fastclose error
Browse files Browse the repository at this point in the history
When an mptcp socket is closed due to an incoming FASTCLOSE
option, so specific sk_err is set and later syscall will
fail usually with EPIPE.

Align the current fastclose error handling with TCP reset,
properly setting the socket error according to the current
msk state and propagating such error.

Additionally sendmsg() is currently not handling properly
the sk_err, always returning EPIPE.

Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed Oct 3, 2022
1 parent 7171e8a commit 69800e5
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
goto out;
} else if (ret) {
release_sock(ssk);
goto out;
goto do_error;
}
release_sock(ssk);
}
Expand All @@ -1717,9 +1717,13 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
ret = sk_stream_wait_connect(sk, &timeo);
if (ret)
goto out;
goto do_error;
}

ret = -EPIPE;
if (unlikely(sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)))
goto do_error;

pfrag = sk_page_frag(sk);

while (msg_data_left(msg)) {
Expand All @@ -1728,11 +1732,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
bool dfrag_collapsed;
size_t psize, offset;

if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) {
ret = -EPIPE;
goto out;
}

/* reuse tail pfrag, if possible, or carve a new one from the
* page allocator
*/
Expand Down Expand Up @@ -1764,7 +1763,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (copy_page_from_iter(dfrag->page, offset, psize,
&msg->msg_iter) != psize) {
ret = -EFAULT;
goto out;
goto do_error;
}

/* data successfully copied into the write queue */
Expand Down Expand Up @@ -1796,15 +1795,22 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
__mptcp_push_pending(sk, msg->msg_flags);
ret = sk_stream_wait_memory(sk, &timeo);
if (ret)
goto out;
goto do_error;
}

if (copied)
__mptcp_push_pending(sk, msg->msg_flags);

out:
release_sock(sk);
return copied ? : ret;
return copied;

do_error:
if (copied)
goto out;

copied = sk_stream_error(sk, msg->msg_flags, ret);
goto out;
}

static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
Expand Down Expand Up @@ -2441,12 +2447,31 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
unlock_sock_fast(tcp_sk, slow);
}

/* Mirror the tcp_reset() error propagation */
switch (sk->sk_state) {
case TCP_SYN_SENT:
sk->sk_err = ECONNREFUSED;
break;
case TCP_CLOSE_WAIT:
sk->sk_err = EPIPE;
break;
case TCP_CLOSE:
return;
default:
sk->sk_err = ECONNRESET;
}

inet_sk_state_store(sk, TCP_CLOSE);
sk->sk_shutdown = SHUTDOWN_MASK;
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);

mptcp_close_wake_up(sk);
/* the calling mptcp_worker will properly destroy the socket */
if (sock_flag(sk, SOCK_DEAD))
return;

sk->sk_state_change(sk);
sk_error_report(sk);
}

static void __mptcp_retrans(struct sock *sk)
Expand Down

0 comments on commit 69800e5

Please sign in to comment.