Skip to content

Commit

Permalink
mptcp: fix locking for setsockopt corner-case
Browse files Browse the repository at this point in the history
We need to call the __mptcp_nmpc_socket(), and later subflow socket
access under the msk socket lock, or e.g. a racing connect() could
change the socket status under the hood, with unexpected results.

Fixes: 54635bd ("mptcp: add TCP_FASTOPEN_CONNECT socket option")
Cc: [email protected]
Signed-off-by: Paolo Abeni <[email protected]>
Reviewed-by: Matthieu Baerts <[email protected]>
Signed-off-by: Matthieu Baerts <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Paolo Abeni authored and davem330 committed Feb 8, 2023
1 parent d4e8592 commit 21e4356
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,21 @@ static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,
static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int optname,
sockptr_t optval, unsigned int optlen)
{
struct sock *sk = (struct sock *)msk;
struct socket *sock;
int ret = -EINVAL;

/* Limit to first subflow, before the connection establishment */
lock_sock(sk);
sock = __mptcp_nmpc_socket(msk);
if (!sock)
return -EINVAL;
goto unlock;

return tcp_setsockopt(sock->sk, level, optname, optval, optlen);
ret = tcp_setsockopt(sock->sk, level, optname, optval, optlen);

unlock:
release_sock(sk);
return ret;
}

static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
Expand Down

0 comments on commit 21e4356

Please sign in to comment.