Skip to content

Commit 5ccecae

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: fix locking in mptcp_nl_cmd_sf_destroy()
The user-space PM subflow removal path uses a couple of helpers that must be called under the msk socket lock and the current code lacks such requirement. Change the existing lock scope so that the relevant code is under its protection. Fixes: 702c2f6 ("mptcp: netlink: allow userspace-driven subflow establishment") Closes: multipath-tcp/mptcp_net-next#287 Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 44d632d commit 5ccecae

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

net/mptcp/pm_userspace.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,11 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,
306306
const struct mptcp_addr_info *local,
307307
const struct mptcp_addr_info *remote)
308308
{
309-
struct sock *sk = &msk->sk.icsk_inet.sk;
310309
struct mptcp_subflow_context *subflow;
311-
struct sock *found = NULL;
312310

313311
if (local->family != remote->family)
314312
return NULL;
315313

316-
lock_sock(sk);
317-
318314
mptcp_for_each_subflow(msk, subflow) {
319315
const struct inet_sock *issk;
320316
struct sock *ssk;
@@ -347,16 +343,11 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk,
347343
}
348344

349345
if (issk->inet_sport == local->port &&
350-
issk->inet_dport == remote->port) {
351-
found = ssk;
352-
goto found;
353-
}
346+
issk->inet_dport == remote->port)
347+
return ssk;
354348
}
355349

356-
found:
357-
release_sock(sk);
358-
359-
return found;
350+
return NULL;
360351
}
361352

362353
int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
@@ -412,6 +403,7 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
412403
}
413404

414405
sk = &msk->sk.icsk_inet.sk;
406+
lock_sock(sk);
415407
ssk = mptcp_nl_find_ssk(msk, &addr_l, &addr_r);
416408
if (ssk) {
417409
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
@@ -422,8 +414,9 @@ int mptcp_nl_cmd_sf_destroy(struct sk_buff *skb, struct genl_info *info)
422414
} else {
423415
err = -ESRCH;
424416
}
417+
release_sock(sk);
425418

426-
destroy_err:
419+
destroy_err:
427420
sock_put((struct sock *)msk);
428421
return err;
429422
}

0 commit comments

Comments
 (0)