Skip to content

Commit e1a2e59

Browse files
Paolo Abenigregkh
authored andcommitted
mptcp: subflows garbage collection
[ Upstream commit 0e4f35d ] The msk can close MP_JOIN subflows if the initial handshake fails. Currently such subflows are kept alive in the conn_list until the msk itself is closed. Beyond the wasted memory, we could end-up sending the DATA_FIN and the DATA_FIN ack on such socket, even after a reset. Fixes: 43b54c6 ("mptcp: Use full MPTCP-level disconnect state machine") Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ea20fe4 commit e1a2e59

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

net/mptcp/protocol.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,20 @@ static void pm_work(struct mptcp_sock *msk)
13831383
spin_unlock_bh(&msk->pm.lock);
13841384
}
13851385

1386+
static void __mptcp_close_subflow(struct mptcp_sock *msk)
1387+
{
1388+
struct mptcp_subflow_context *subflow, *tmp;
1389+
1390+
list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
1391+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
1392+
1393+
if (inet_sk_state_load(ssk) != TCP_CLOSE)
1394+
continue;
1395+
1396+
__mptcp_close_ssk((struct sock *)msk, ssk, subflow, 0);
1397+
}
1398+
}
1399+
13861400
static void mptcp_worker(struct work_struct *work)
13871401
{
13881402
struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work);
@@ -1400,6 +1414,9 @@ static void mptcp_worker(struct work_struct *work)
14001414
mptcp_clean_una(sk);
14011415
mptcp_check_data_fin_ack(sk);
14021416
__mptcp_flush_join_list(msk);
1417+
if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
1418+
__mptcp_close_subflow(msk);
1419+
14031420
__mptcp_move_skbs(msk);
14041421

14051422
if (msk->pm.status)

net/mptcp/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#define MPTCP_WORK_RTX 2
9191
#define MPTCP_WORK_EOF 3
9292
#define MPTCP_FALLBACK_DONE 4
93+
#define MPTCP_WORK_CLOSE_SUBFLOW 5
9394

9495
struct mptcp_options_received {
9596
u64 sndr_key;

net/mptcp/subflow.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,15 @@ static bool subflow_thmac_valid(struct mptcp_subflow_context *subflow)
272272

273273
void mptcp_subflow_reset(struct sock *ssk)
274274
{
275+
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
276+
struct sock *sk = subflow->conn;
277+
275278
tcp_set_state(ssk, TCP_CLOSE);
276279
tcp_send_active_reset(ssk, GFP_ATOMIC);
277280
tcp_done(ssk);
281+
if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &mptcp_sk(sk)->flags) &&
282+
schedule_work(&mptcp_sk(sk)->work))
283+
sock_hold(sk);
278284
}
279285

280286
static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)

0 commit comments

Comments
 (0)