mptcp: fix recent failed backports (20260521)
Subsystems (2)
Matthieu Baerts (NGI0)
maintainercover mptcp: fix recent failed backports (20260521)
The following patches could not be applied without conflicts in this tree:
- fcf04b143346 ("mptcp: sync the msk->sndbuf at accept() time")
- 03f324f3f1f7 ("mptcp: pm: ADD_ADDR rtx: allow ID 0")
- 9634cb35af17 ("mptcp: pm: ADD_ADDR rtx: always decrease sk refcount")
- b7b9a4615697 ("mptcp: pm: ADD_ADDR rtx: free sk if last")
Conflicts have been resolved, and documented in each patch.
Gang Yan (1):
mptcp: sync the msk->sndbuf at accept() time
Matthieu Baerts (NGI0) (3):
mptcp: pm: ADD_ADDR rtx: allow ID 0
mptcp: pm: ADD_ADDR rtx: always decrease sk refcount
mptcp: pm: ADD_ADDR rtx: free sk if last
net/mptcp/pm_netlink.c | 35 ++++++++++++++++++----------------- net/mptcp/protocol.c | 3 ++- 2 files changed, 20 insertions(+), 18 deletions(-)
Signature · 1 line
2.53.0
Matthieu Baerts (NGI0)
maintainerPATCH 1/4 mptcp: sync the msk->sndbuf at accept() time
From: Gang Yan <[email protected]>
commit fcf04b14334641f4b0b8647824480935e9416d52 upstream.
On passive MPTCP connections, the msk sndbuf is not updated correctly.
The root cause is an order issue in the accept path:
- tcp_check_req() -> subflow_syn_recv_sock() -> mptcp_sk_clone_init() calls __mptcp_propagate_sndbuf() to copy the ssk sndbuf into msk
- Later, tcp_child_process() -> tcp_init_transfer() -> tcp_sndbuf_expand() grows the ssk sndbuf.
So __mptcp_propagate_sndbuf() runs before the ssk sndbuf has been expanded and the msk ends up with a much smaller sndbuf than the subflow:
MPTCP: msk->sndbuf:20480, msk->first->sndbuf:2626560
Fix this by moving the __mptcp_propagate_sndbuf() call from mptcp_sk_clone_init() -- the ssk sndbuf is not yet finalized there -- to __mptcp_propagate_sndbuf() at accept() time, when the ssk sndbuf has been fully expanded by tcp_sndbuf_expand().
[ No conflicts, but move __mptcp_propagate_sndbuf() above the for-loop
(mptcp_for_each_subflow()) present in this version, which will modify 'subflow' used by __mptcp_propagate_sndbuf() in this new patch. ]
--- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
@@ -3451,7 +3451,6 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,* uses the correct data */ mptcp_copy_inaddrs (nsk, ssk); -__mptcp_propagate_sndbuf (nsk, ssk);mptcp_rcv_space_init (msk, ssk); msk->rcvq_space.time =mptcp_stamp ();
@@ -4064,6 +4063,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, msk =mptcp_sk (newsk); msk->in_accept_queue =0 ; +__mptcp_propagate_sndbuf (newsk,mptcp_subflow_tcp_sock (subflow)); +/* set ssk->sk_socket of accept()ed flows to mptcp socket. * This is needed so NOSPACE flag can be set from tcp stack. */
Signature · 1 line
2.53.0
Matthieu Baerts (NGI0)
maintainerPATCH 2/4 mptcp: pm: ADD_ADDR rtx: allow ID 0
In reply to Matthieu Baerts (NGI0)commit 03f324f3f1f7619a47b9c91282cb12775ab0a2f1 upstream.
ADD_ADDR can be sent for the ID 0, which corresponds to the local address and port linked to the initial subflow.
Indeed, this address could be removed, and re-added later on, e.g. what is done in the "delete re-add signal" MPTCP Join selftests. So no reason to ignore it.
--- net/mptcp/pm_netlink.c | 3 --- 1 file changed, 3 deletions(-)
net/mptcp/pm_netlink.c +0 -3
@@ -305,9 +305,6 @@ static void mptcp_pm_add_timer(struct timer_list *timer)if (inet_sk_state_load (sk) ==TCP_CLOSE )return ; -if (!entry->addr.id) -return ; -bh_lock_sock (sk);if (sock_owned_by_user (sk)) {/* Try again later. */
Signature · 1 line
2.53.0
Matthieu Baerts (NGI0)
maintainerPATCH 3/4 mptcp: pm: ADD_ADDR rtx: always decrease sk refcount
In reply to Matthieu Baerts (NGI0)commit 9634cb35af17019baec21ca648516ce376fa10e6 upstream.
When an ADD_ADDR is retransmitted, the sk is held in sk_reset_timer(). It should then be released in all cases at the end.
Some (unlikely) checks were returning directly instead of calling sock_put() to decrease the refcount. Jump to a new 'exit' label to call __sock_put() (which will become sock_put() in the next commit) to fix this potential leak.
While at it, drop the '!msk' check which cannot happen because it is never reset, and explicitly mark the remaining one as "unlikely".
--- net/mptcp/pm_netlink.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/mptcp/pm_netlink.c +3 -5
@@ -299,11 +299,8 @@ static void mptcp_pm_add_timer(struct timer_list *timer)pr_debug ("msk=%p\n" , msk); -if (!msk) -return ; - -if (inet_sk_state_load (sk) ==TCP_CLOSE ) -return ; +if (unlikely (inet_sk_state_load (sk) ==TCP_CLOSE )) + goto exit;bh_lock_sock (sk);if (sock_owned_by_user (sk)) {
@@ -341,6 +338,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer) out:bh_unlock_sock (sk); +exit:__sock_put (sk); }
Signature · 1 line
2.53.0
Matthieu Baerts (NGI0)
maintainerPATCH 4/4 mptcp: pm: ADD_ADDR rtx: free sk if last
In reply to Matthieu Baerts (NGI0)commit b7b9a461569734d33d3259d58d2507adfac107ed upstream.
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".
[ Applied to net/mptcp/pm_netlink.c instead of upstream's pm_kernel.c.
Also, there were conflicts, because commit 30549eebc4d8 ("mptcp: make ADD_ADDR retransmission timeout adaptive") is not in this version and changed the context. Also, other conflicts were due to newer patches being backported with resolved conflicts before this one. ]
--- net/mptcp/pm_netlink.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
net/mptcp/pm_netlink.c +18 -12
@@ -27,6 +27,7 @@ struct mptcp_pm_add_entry {struct list_head list;struct mptcp_addr_info addr;u8 retrans_times; +bool timer_done;struct timer_list add_timer;struct mptcp_sock *sock;struct rcu_head rcu;
@@ -295,22 +296,22 @@ static void mptcp_pm_add_timer(struct timer_list *timer)struct mptcp_pm_add_entry *entry =from_timer (entry, timer, add_timer);struct mptcp_sock *msk = entry->sock;struct sock *sk = (struct sock *)msk; -unsigned int timeout; +unsigned int timeout =0 ;pr_debug ("msk=%p\n" , msk); -if (unlikely (inet_sk_state_load (sk) ==TCP_CLOSE )) - goto exit; -bh_lock_sock (sk); +if (unlikely (inet_sk_state_load (sk) ==TCP_CLOSE )) + goto out; +if (sock_owned_by_user (sk)) {/* Try again later. */ -sk_reset_timer (sk, timer, jiffies +HZ /20 ); + timeout =HZ /20 ; goto out; }if (mptcp_pm_should_add_signal_addr (msk)) { -sk_reset_timer (sk, timer, jiffies +HZ ); + timeout =HZ ; goto out; }
@@ -327,9 +328,8 @@ static void mptcp_pm_add_timer(struct timer_list *timer) entry->retrans_times++; } -if (entry->retrans_times <ADD_ADDR_RETRANS_MAX ) -sk_reset_timer (sk, timer, - jiffies + timeout); +if (entry->retrans_times >=ADD_ADDR_RETRANS_MAX ) + timeout =0 ;spin_unlock_bh (&msk->pm.lock);
@@ -337,9 +337,13 @@ static void mptcp_pm_add_timer(struct timer_list *timer)mptcp_pm_subflow_established (msk); out: +if (timeout) +sk_reset_timer (sk, timer, jiffies + timeout); +else +/* if sock_put calls sk_free: avoid waiting for this timer */ + entry->timer_done = true;bh_unlock_sock (sk); -exit: -__sock_put (sk); +sock_put (sk); } struct mptcp_pm_add_entry *
@@ -403,6 +407,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,timer_setup (&add_entry->add_timer, mptcp_pm_add_timer,0 ); reset_timer: + add_entry->timer_done = false; timeout =mptcp_get_add_addr_timeout (net);if (timeout)sk_reset_timer (sk, &add_entry->add_timer, jiffies + timeout);
@@ -423,7 +428,8 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk)spin_unlock_bh (&msk->pm.lock);list_for_each_entry_safe (entry, tmp, &free_list, list) { -sk_stop_timer_sync (sk, &entry->add_timer); +if (!entry->timer_done) +sk_stop_timer_sync (sk, &entry->add_timer);kfree_rcu (entry, rcu); } }
Signature · 1 line
2.53.0
Queued for 6.6, thanks.
Signature · 2 lines
Thanks, Sasha