Skip to content

Commit 3b04cba

Browse files
committed
Merge branch 'mptcp-properly-clean-up-unaccepted-subflows'
Mat Martineau says: ==================== mptcp: Properly clean up unaccepted subflows Patch 1 factors out part of the mptcp_close() function for use by a caller that already owns the socket lock. This is a prerequisite for patch 2. Patch 2 is the fix that fully cleans up the unaccepted subflow sockets. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3e1308a + 30e51b9 commit 3b04cba

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

net/mptcp/protocol.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,7 @@ static void __mptcp_clear_xmit(struct sock *sk)
26622662
dfrag_clear(sk, dfrag);
26632663
}
26642664

2665-
static void mptcp_cancel_work(struct sock *sk)
2665+
void mptcp_cancel_work(struct sock *sk)
26662666
{
26672667
struct mptcp_sock *msk = mptcp_sk(sk);
26682668

@@ -2802,13 +2802,12 @@ static void __mptcp_destroy_sock(struct sock *sk)
28022802
sock_put(sk);
28032803
}
28042804

2805-
static void mptcp_close(struct sock *sk, long timeout)
2805+
bool __mptcp_close(struct sock *sk, long timeout)
28062806
{
28072807
struct mptcp_subflow_context *subflow;
28082808
struct mptcp_sock *msk = mptcp_sk(sk);
28092809
bool do_cancel_work = false;
28102810

2811-
lock_sock(sk);
28122811
sk->sk_shutdown = SHUTDOWN_MASK;
28132812

28142813
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
@@ -2850,6 +2849,17 @@ static void mptcp_close(struct sock *sk, long timeout)
28502849
} else {
28512850
mptcp_reset_timeout(msk, 0);
28522851
}
2852+
2853+
return do_cancel_work;
2854+
}
2855+
2856+
static void mptcp_close(struct sock *sk, long timeout)
2857+
{
2858+
bool do_cancel_work;
2859+
2860+
lock_sock(sk);
2861+
2862+
do_cancel_work = __mptcp_close(sk, timeout);
28532863
release_sock(sk);
28542864
if (do_cancel_work)
28552865
mptcp_cancel_work(sk);

net/mptcp/protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ void mptcp_subflow_reset(struct sock *ssk);
612612
void mptcp_subflow_queue_clean(struct sock *ssk);
613613
void mptcp_sock_graft(struct sock *sk, struct socket *parent);
614614
struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk);
615+
bool __mptcp_close(struct sock *sk, long timeout);
616+
void mptcp_cancel_work(struct sock *sk);
615617

616618
bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
617619
const struct mptcp_addr_info *b, bool use_port);

net/mptcp/subflow.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -602,30 +602,6 @@ static bool subflow_hmac_valid(const struct request_sock *req,
602602
return !crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN);
603603
}
604604

605-
static void mptcp_sock_destruct(struct sock *sk)
606-
{
607-
/* if new mptcp socket isn't accepted, it is free'd
608-
* from the tcp listener sockets request queue, linked
609-
* from req->sk. The tcp socket is released.
610-
* This calls the ULP release function which will
611-
* also remove the mptcp socket, via
612-
* sock_put(ctx->conn).
613-
*
614-
* Problem is that the mptcp socket will be in
615-
* ESTABLISHED state and will not have the SOCK_DEAD flag.
616-
* Both result in warnings from inet_sock_destruct.
617-
*/
618-
if ((1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
619-
sk->sk_state = TCP_CLOSE;
620-
WARN_ON_ONCE(sk->sk_socket);
621-
sock_orphan(sk);
622-
}
623-
624-
/* We don't need to clear msk->subflow, as it's still NULL at this point */
625-
mptcp_destroy_common(mptcp_sk(sk), 0);
626-
inet_sock_destruct(sk);
627-
}
628-
629605
static void mptcp_force_close(struct sock *sk)
630606
{
631607
/* the msk is not yet exposed to user-space */
@@ -768,7 +744,6 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
768744
/* new mpc subflow takes ownership of the newly
769745
* created mptcp socket
770746
*/
771-
new_msk->sk_destruct = mptcp_sock_destruct;
772747
mptcp_sk(new_msk)->setsockopt_seq = ctx->setsockopt_seq;
773748
mptcp_pm_new_connection(mptcp_sk(new_msk), child, 1);
774749
mptcp_token_accept(subflow_req, mptcp_sk(new_msk));
@@ -1763,13 +1738,19 @@ void mptcp_subflow_queue_clean(struct sock *listener_ssk)
17631738

17641739
for (msk = head; msk; msk = next) {
17651740
struct sock *sk = (struct sock *)msk;
1766-
bool slow;
1741+
bool slow, do_cancel_work;
17671742

1743+
sock_hold(sk);
17681744
slow = lock_sock_fast_nested(sk);
17691745
next = msk->dl_next;
17701746
msk->first = NULL;
17711747
msk->dl_next = NULL;
1748+
1749+
do_cancel_work = __mptcp_close(sk, 0);
17721750
unlock_sock_fast(sk, slow);
1751+
if (do_cancel_work)
1752+
mptcp_cancel_work(sk);
1753+
sock_put(sk);
17731754
}
17741755

17751756
/* we are still under the listener msk socket lock */

0 commit comments

Comments
 (0)