Skip to content

Commit ad21710

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: fix locking for in-kernel listener creation
For consistency, in mptcp_pm_nl_create_listen_socket(), we need to call the __mptcp_nmpc_socket() under the msk socket lock. Note that as a side effect, mptcp_subflow_create_socket() needs a 'nested' lockdep annotation, as it will acquire the subflow (kernel) socket lock under the in-kernel listener msk socket lock. The current lack of locking is almost harmless, because the relevant socket is not exposed to the user space, but in future we will add more complexity to the mentioned helper, let's play safe. Fixes: 1729cf1 ("mptcp: create the listening socket for new port") 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]>
1 parent 21e4356 commit ad21710

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

net/mptcp/pm_netlink.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
998998
{
999999
int addrlen = sizeof(struct sockaddr_in);
10001000
struct sockaddr_storage addr;
1001-
struct mptcp_sock *msk;
10021001
struct socket *ssock;
1002+
struct sock *newsk;
10031003
int backlog = 1024;
10041004
int err;
10051005

@@ -1008,11 +1008,13 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
10081008
if (err)
10091009
return err;
10101010

1011-
msk = mptcp_sk(entry->lsk->sk);
1012-
if (!msk)
1011+
newsk = entry->lsk->sk;
1012+
if (!newsk)
10131013
return -EINVAL;
10141014

1015-
ssock = __mptcp_nmpc_socket(msk);
1015+
lock_sock(newsk);
1016+
ssock = __mptcp_nmpc_socket(mptcp_sk(newsk));
1017+
release_sock(newsk);
10161018
if (!ssock)
10171019
return -EINVAL;
10181020

net/mptcp/subflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
16791679
if (err)
16801680
return err;
16811681

1682-
lock_sock(sf->sk);
1682+
lock_sock_nested(sf->sk, SINGLE_DEPTH_NESTING);
16831683

16841684
/* the newly created socket has to be in the same cgroup as its parent */
16851685
mptcp_attach_cgroup(sk, sf->sk);

0 commit comments

Comments
 (0)