diff options
author | Paolo Abeni <pabeni@redhat.com> | 2023-02-07 14:04:14 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-02-22 12:59:40 +0100 |
commit | 03edc4a27dad21f787ce294c23786858b83b34a3 (patch) | |
tree | 5ad7f52483398e23dbe13c8aa893ef41ee7d8a18 /net | |
parent | 94ed108bf18cb045a40a42661c093a579770c831 (diff) | |
download | linux-stable-03edc4a27dad21f787ce294c23786858b83b34a3.tar.gz linux-stable-03edc4a27dad21f787ce294c23786858b83b34a3.tar.bz2 linux-stable-03edc4a27dad21f787ce294c23786858b83b34a3.zip |
mptcp: fix locking for setsockopt corner-case
[ Upstream commit 21e43569685de4ad773fb060c11a15f3fd5e7ac4 ]
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: 54635bd04701 ("mptcp: add TCP_FASTOPEN_CONNECT socket option")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/mptcp/sockopt.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 8d3b09d75c3a..696ba398d699 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -772,14 +772,21 @@ static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optv 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, |