Skip to content

Commit 5da972e

Browse files
matttbegregkh
authored andcommitted
mptcp: pm: ADD_ADDR rtx: free sk if last
[ Upstream commit b7b9a46 ] When an ADD_ADDR is retransmitted, the sk is held in sk_reset_timer(), and released at the end. If at that moment, it was the last reference being held, the sk would not be freed. sock_put() should then be called instead of __sock_put(). But that's not enough: if it is the last reference, sock_put() will call sk_free(), which will end up calling sk_stop_timer_sync() on the same timer, and waiting indefinitely to finish. So it is needed to mark that the timer is done at the end of the timer handler when it has not been rescheduled, not to call sk_stop_timer_sync() on "itself". Fixes: 00cfd77 ("mptcp: retransmit ADD_ADDR when timeout") Cc: stable@vger.kernel.org Reviewed-by: Mat Martineau <martineau@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20260505-net-mptcp-pm-fixes-7-1-rc3-v1-5-fca8091060a4@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: a7aad5b ("mptcp: pm: fix data race in add_addr timer callback") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 81d8142 commit 5da972e

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

net/mptcp/pm_netlink.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct mptcp_pm_add_entry {
2828
struct timer_list add_timer;
2929
struct mptcp_sock *sock;
3030
u8 retrans_times;
31+
bool timer_done;
3132
struct rcu_head rcu;
3233
};
3334

@@ -305,22 +306,22 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
305306
struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer);
306307
struct mptcp_sock *msk = entry->sock;
307308
struct sock *sk = (struct sock *)msk;
308-
unsigned int timeout;
309+
unsigned int timeout = 0;
309310

310311
pr_debug("msk=%p\n", msk);
311312

313+
bh_lock_sock(sk);
312314
if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
313-
goto exit;
315+
goto out;
314316

315-
bh_lock_sock(sk);
316317
if (sock_owned_by_user(sk)) {
317318
/* Try again later. */
318-
sk_reset_timer(sk, timer, jiffies + HZ / 20);
319+
timeout = HZ / 20;
319320
goto out;
320321
}
321322

322323
if (mptcp_pm_should_add_signal_addr(msk)) {
323-
sk_reset_timer(sk, timer, jiffies + HZ);
324+
timeout = HZ;
324325
goto out;
325326
}
326327

@@ -343,19 +344,22 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
343344
entry->retrans_times++;
344345
}
345346

346-
if (entry->retrans_times < ADD_ADDR_RETRANS_MAX)
347-
sk_reset_timer(sk, timer,
348-
jiffies + timeout);
347+
if (entry->retrans_times >= ADD_ADDR_RETRANS_MAX)
348+
timeout = 0;
349349

350350
spin_unlock_bh(&msk->pm.lock);
351351

352352
if (entry->retrans_times == ADD_ADDR_RETRANS_MAX)
353353
mptcp_pm_subflow_established(msk);
354354

355355
out:
356+
if (timeout)
357+
sk_reset_timer(sk, timer, jiffies + timeout);
358+
else
359+
/* if sock_put calls sk_free: avoid waiting for this timer */
360+
entry->timer_done = true;
356361
bh_unlock_sock(sk);
357-
exit:
358-
__sock_put(sk);
362+
sock_put(sk);
359363
}
360364

361365
struct mptcp_pm_add_entry *
@@ -423,6 +427,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
423427

424428
timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0);
425429
reset_timer:
430+
add_entry->timer_done = false;
426431
timeout = mptcp_get_add_addr_timeout(net);
427432
if (timeout)
428433
sk_reset_timer(sk, &add_entry->add_timer, jiffies + timeout);
@@ -443,7 +448,8 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk)
443448
spin_unlock_bh(&msk->pm.lock);
444449

445450
list_for_each_entry_safe(entry, tmp, &free_list, list) {
446-
sk_stop_timer_sync(sk, &entry->add_timer);
451+
if (!entry->timer_done)
452+
sk_stop_timer_sync(sk, &entry->add_timer);
447453
kfree_rcu(entry, rcu);
448454
}
449455
}

0 commit comments

Comments
 (0)