mptcp: Fixes for v5.12
Subsystems (3)
cover mptcp: Fixes for v5.12
These patches from the MPTCP tree fix a few multipath TCP issues:
Patches 1 and 5 clear some stale pointers when subflows close.
Patches 2, 4, and 9 plug some memory leaks.
Patch 3 fixes a memory accounting error identified by syzkaller.
Patches 6 and 7 fix a race condition that slowed data transmission.
Patch 8 adds missing wakeups when write buffer space is freed.
Florian Westphal (4):
mptcp: reset last_snd on subflow close
mptcp: put subflow sock on connect error
mptcp: dispose initial struct socket when its subflow is closed
mptcp: reset 'first' and ack_hint on subflow close
Geliang Tang (1):
mptcp: free resources when the port number is mismatched
Paolo Abeni (4):
mptcp: fix memory accounting on allocation error
mptcp: factor out __mptcp_retrans helper()
mptcp: fix race in release_cb
mptcp: fix missing wakeup
net/mptcp/protocol.c | 165 +++++++++++++++++++++++++++---------------- net/mptcp/subflow.c | 14 ++-- 2 files changed, 112 insertions(+), 67 deletions(-)
base-commit: a9ecb0cbf03746b17a7c13bd8e3464e6789f73e8
Signature · 1 line
2.30.1
PATCH 1/9 mptcp: reset last_snd on subflow close
From: Florian Westphal <fw(a)strlen.de>
Send logic caches last active subflow in the msk, so it needs to be cleared when the cached subflow is closed.
--- net/mptcp/protocol.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mptcp/protocol.c +5 -0
@@ -2126,6 +2126,8 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)static void __mptcp_close_ssk (struct sock *sk,struct sock *ssk,struct mptcp_subflow_context *subflow) { +struct mptcp_sock *msk =mptcp_sk (sk); +list_del (&subflow->node);lock_sock_nested (ssk,SINGLE_DEPTH_NESTING );
@@ -2154,6 +2156,9 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,release_sock (ssk);sock_put (ssk); + +if (ssk == msk->last_snd) + msk->last_snd =NULL ; } void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
Signature · 1 line
2.30.1
PATCH 2/9 mptcp: put subflow sock on connect error
In reply to Mat MartineauFrom: Florian Westphal <fw(a)strlen.de>
mptcp_add_pending_subflow() performs a sock_hold() on the subflow, then adds the subflow to the join list.
Without a sock_put the subflow sk won't be freed in case connect() fails.
unreferenced object 0xffff88810c03b100 (size 3000):
[..]
sk_prot_alloc.isra.0+0x2f/0x110
sk_alloc+0x5d/0xc20
inet6_create+0x2b7/0xd30
__sock_create+0x17f/0x410
mptcp_subflow_create_socket+0xff/0x9c0
__mptcp_subflow_connect+0x1da/0xaf0
mptcp_pm_nl_work+0x6e0/0x1120
mptcp_worker+0x508/0x9a0--- net/mptcp/subflow.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/subflow.c +1 -0
@@ -1297,6 +1297,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,spin_lock_bh (&msk->join_list_lock);list_del (&subflow->node);spin_unlock_bh (&msk->join_list_lock); +sock_put (mptcp_subflow_tcp_sock (subflow)); failed: subflow->disposable =1 ;
Signature · 1 line
2.30.1
PATCH 3/9 mptcp: fix memory accounting on allocation error
In reply to Mat MartineauFrom: Paolo Abeni <pabeni(a)redhat.com>
In case of memory pressure the MPTCP xmit path keeps at most a single skb in the tx cache, eventually freeing additional ones.
The associated counter for forward memory is not update accordingly, and that causes the following splat:
WARNING: CPU: 0 PID: 12 at net/core/stream.c:208 sk_stream_kill_queues+0x3ca/0x530 net/core/stream.c:208 Modules linked in: CPU: 0 PID: 12 Comm: kworker/0:1 Not tainted 5.11.0-rc2 #59 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 Workqueue: events mptcp_worker RIP: 0010:sk_stream_kill_queues+0x3ca/0x530 net/core/stream.c:208 Code: 03 0f b6 04 02 84 c0 74 08 3c 03 0f 8e 63 01 00 00 8b ab 00 01 00 00 e9 60 ff ff ff e8 2f 24 d3 fe 0f 0b eb 97 e8 26 24 d3 fe <0f> 0b eb a0 e8 1d 24 d3 fe 0f 0b e9 a5 fe ff ff 4c 89 e7 e8 0e d0 RSP: 0018:ffffc900000c7bc8 EFLAGS: 00010293 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: ffff88810030ac40 RSI: ffffffff8262ca4a RDI: 0000000000000003 RBP: 0000000000000d00 R08: 0000000000000000 R09: ffffffff85095aa7 R10: ffffffff8262c9ea R11: 0000000000000001 R12: ffff888108908100 R13: ffffffff85095aa0 R14: ffffc900000c7c48 R15: 1ffff92000018f85 FS: 0000000000000000(0000) GS:ffff88811b200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fa7444baef8 CR3: 0000000035ee9005 CR4: 0000000000170ef0 Call Trace: __mptcp_destroy_sock+0x4a7/0x6c0 net/mptcp/protocol.c:2547 mptcp_worker+0x7dd/0x1610 net/mptcp/protocol.c:2272 process_one_work+0x896/0x1170 kernel/workqueue.c:2275 worker_thread+0x605/0x1350 kernel/workqueue.c:2421 kthread+0x344/0x410 kernel/kthread.c:292 ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:296
At close time, as reported by syzkaller/Christoph.
This change address the issue properly updating the fwd allocated memory counter in the error path.
--- net/mptcp/protocol.c | 1 + 1 file changed, 1 insertion(+)
net/mptcp/protocol.c +1 -0
@@ -1189,6 +1189,7 @@ static bool mptcp_tx_cache_refill(struct sock *sk, int size,*/ while (skbs->qlen >1 ) { skb =__skb_dequeue_tail (skbs); + *total_ts -= skb->truesize;__kfree_skb (skb); }return skbs->qlen >0 ;
Signature · 1 line
2.30.1
PATCH 4/9 mptcp: dispose initial struct socket when its subflow is closed
In reply to Mat MartineauFrom: Florian Westphal <fw(a)strlen.de>
Christoph Paasch reported following crash:dst_release underflow
WARNING: CPU: 0 PID: 1319 at net/core/dst.c:175 dst_release+0xc1/0xd0 net/core/dst.c:175 CPU: 0 PID: 1319 Comm: syz-executor217 Not tainted 5.11.0-rc6af8e85128b4d0d24083c5cac646e891227052e0c #70 Call Trace: rt_cache_route+0x12e/0x140 net/ipv4/route.c:1503 rt_set_nexthop.constprop.0+0x1fc/0x590 net/ipv4/route.c:1612 __mkroute_output net/ipv4/route.c:2484 [inline]
...
The worker leaves msk->subflow alone even when it happened to close the subflow ssk associated with it.
--- net/mptcp/protocol.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +12 -6
@@ -2116,6 +2116,14 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)return backup; } +static void mptcp_dispose_initial_subflow (struct mptcp_sock *msk) +{ +if (msk->subflow) { +iput (SOCK_INODE (msk->subflow)); + msk->subflow =NULL ; + } +} +/* subflow sockets can be either outgoing (connect) or incoming * (accept). *
@@ -2160,6 +2168,9 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,if (ssk == msk->last_snd) msk->last_snd =NULL ; + +if (msk->subflow && ssk == msk->subflow->sk) +mptcp_dispose_initial_subflow (msk); } void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
@@ -2529,12 +2540,6 @@ static void __mptcp_destroy_sock(struct sock *sk)might_sleep (); -/* dispose the ancillatory tcp socket, if any */ -if (msk->subflow) { -iput (SOCK_INODE (msk->subflow)); - msk->subflow =NULL ; - } -/* be sure to always acquire the join list lock, to sync vs * mptcp_finish_join(). */
@@ -2559,6 +2564,7 @@ static void __mptcp_destroy_sock(struct sock *sk)sk_stream_kill_queues (sk);xfrm_sk_free_policy (sk);sk_refcnt_debug_release (sk); +mptcp_dispose_initial_subflow (msk);sock_put (sk); }
Signature · 1 line
2.30.1
PATCH 5/9 mptcp: reset 'first' and ack_hint on subflow close
In reply to Mat MartineauFrom: Florian Westphal <fw(a)strlen.de>
Just like with last_snd, we have to NULL 'first' on subflow close.
ack_hint isn't strictly required (its never dereferenced), but better to clear this explicitly as well instead of making it an exception.
msk->first is dereferenced unconditionally at accept time, but at that point the ssk is not on the conn_list yet -- this means worker can't see it when iterating the conn_list.
--- net/mptcp/protocol.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/mptcp/protocol.c +9 -0
@@ -2169,6 +2169,12 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,if (ssk == msk->last_snd) msk->last_snd =NULL ; +if (ssk == msk->ack_hint) + msk->ack_hint =NULL ; + +if (ssk == msk->first) + msk->first =NULL ; +if (msk->subflow && ssk == msk->subflow->sk)mptcp_dispose_initial_subflow (msk); }
@@ -3297,6 +3303,9 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,/* PM/worker can now acquire the first subflow socket * lock without racing with listener queue cleanup, * we can notify it, if needed. +* +* Even if remote has reset the initial subflow by now +* the refcnt is still at least one. */ subflow =mptcp_subflow_ctx (msk->first);list_add (&subflow->node, &msk->conn_list);
Signature · 1 line
2.30.1
PATCH 6/9 mptcp: factor out __mptcp_retrans helper()
In reply to Mat MartineauFrom: Paolo Abeni <pabeni(a)redhat.com>
Will simplify the following patch, no functional change intended.
--- net/mptcp/protocol.c | 93 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 43 deletions(-)
net/mptcp/protocol.c +50 -43
@@ -2261,59 +2261,23 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)mptcp_close_wake_up (sk); } -static void mptcp_worker (struct work_struct *work) +static void __mptcp_retrans (struct sock *sk) { - struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work); -struct sock *ssk, *sk = &msk->sk.icsk_inet.sk; +struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_sendmsg_info info = {};struct mptcp_data_frag *dfrag;size_t copied =0 ; -int state, ret; - -lock_sock (sk); - state = sk->sk_state; -if (unlikely (state ==TCP_CLOSE )) - goto unlock; - -mptcp_check_data_fin_ack (sk); -__mptcp_flush_join_list (msk); - -mptcp_check_fastclose (msk); - -if (msk->pm.status) -mptcp_pm_nl_work (msk); - -if (test_and_clear_bit (MPTCP_WORK_EOF , &msk->flags)) -mptcp_check_for_eof (msk); - -__mptcp_check_send_data_fin (sk); -mptcp_check_data_fin (sk); - -/* There is no point in keeping around an orphaned sk timedout or -* closed, but we need the msk around to reply to incoming DATA_FIN, -* even if it is orphaned and in FIN_WAIT2 state -*/ -if (sock_flag (sk,SOCK_DEAD ) && - (mptcp_check_close_timeout (sk) || sk->sk_state ==TCP_CLOSE )) { -inet_sk_state_store (sk,TCP_CLOSE ); -__mptcp_destroy_sock (sk); - goto unlock; - } - -if (test_and_clear_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) -__mptcp_close_subflow (msk); - -if (!test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags)) - goto unlock; +struct sock *ssk; +int ret;__mptcp_clean_una (sk); dfrag =mptcp_rtx_head (sk);if (!dfrag) - goto unlock; +return ; ssk =mptcp_subflow_get_retrans (msk);if (!ssk) - goto reset_unlock; + goto reset_timer;lock_sock (ssk);
@@ -2339,9 +2303,52 @@ static void mptcp_worker(struct work_struct *work)mptcp_set_timeout (sk, ssk);release_sock (ssk); -reset_unlock: +reset_timer:if (!mptcp_timer_pending (sk))mptcp_reset_timer (sk); +} + +static void mptcp_worker (struct work_struct *work) +{ + struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work); +struct sock *sk = &msk->sk.icsk_inet.sk; +int state; + +lock_sock (sk); + state = sk->sk_state; +if (unlikely (state ==TCP_CLOSE )) + goto unlock; + +mptcp_check_data_fin_ack (sk); +__mptcp_flush_join_list (msk); + +mptcp_check_fastclose (msk); + +if (msk->pm.status) +mptcp_pm_nl_work (msk); + +if (test_and_clear_bit (MPTCP_WORK_EOF , &msk->flags)) +mptcp_check_for_eof (msk); + +__mptcp_check_send_data_fin (sk); +mptcp_check_data_fin (sk); + +/* There is no point in keeping around an orphaned sk timedout or +* closed, but we need the msk around to reply to incoming DATA_FIN, +* even if it is orphaned and in FIN_WAIT2 state +*/ +if (sock_flag (sk,SOCK_DEAD ) && + (mptcp_check_close_timeout (sk) || sk->sk_state ==TCP_CLOSE )) { +inet_sk_state_store (sk,TCP_CLOSE ); +__mptcp_destroy_sock (sk); + goto unlock; + } + +if (test_and_clear_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) +__mptcp_close_subflow (msk); + +if (test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags)) +__mptcp_retrans (sk); unlock:release_sock (sk);
Signature · 1 line
2.30.1
PATCH 7/9 mptcp: fix race in release_cb
In reply to Mat MartineauFrom: Paolo Abeni <pabeni(a)redhat.com>
If we receive a MPTCP_PUSH_PENDING even from a subflow when mptcp_release_cb() is serving the previous one, the latter will be delayed up to the next release_sock(msk).
Address the issue implementing a test/serve loop for such event.
Additionally rename the push helper to __mptcp_push_pending() to be more consistent with the existing code.
--- net/mptcp/protocol.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
net/mptcp/protocol.c +21 -12
@@ -1445,7 +1445,7 @@ static void mptcp_push_release(struct sock *sk, struct sock *ssk,release_sock (ssk); } -static void mptcp_push_pending (struct sock *sk,unsigned int flags) +static void __mptcp_push_pending (struct sock *sk,unsigned int flags) {struct sock *prev_ssk =NULL , *ssk =NULL ;struct mptcp_sock *msk =mptcp_sk (sk);
@@ -1697,14 +1697,14 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) wait_for_memory:mptcp_set_nospace (sk); -mptcp_push_pending (sk, msg->msg_flags); +__mptcp_push_pending (sk, msg->msg_flags); ret =sk_stream_wait_memory (sk, &timeo);if (ret) goto out; }if (copied) -mptcp_push_pending (sk, msg->msg_flags); +__mptcp_push_pending (sk, msg->msg_flags); out:release_sock (sk);
@@ -2959,13 +2959,14 @@ static void mptcp_release_cb(struct sock *sk) {unsigned long flags, nflags; -/* push_pending may touch wmem_reserved, do it before the later -* cleanup -*/ -if (test_and_clear_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->flags)) -__mptcp_clean_una (sk); -if (test_and_clear_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags)) { -/* mptcp_push_pending() acquires the subflow socket lock +for (;;) { + flags =0 ; +if (test_and_clear_bit (MPTCP_PUSH_PENDING , &mptcp_sk (sk)->flags)) + flags |=MPTCP_PUSH_PENDING ; +if (!flags) +break ; + +/* the following actions acquire the subflow socket lock * * 1) can't be invoked in atomic scope * 2) must avoid ABBA deadlock with msk socket spinlock: the RX
@@ -2974,13 +2975,21 @@ static void mptcp_release_cb(struct sock *sk)*/ spin_unlock_bh (&sk->sk_lock.slock); -mptcp_push_pending (sk,0 ); +if (flags &MPTCP_PUSH_PENDING ) +__mptcp_push_pending (sk,0 ); + +cond_resched ();spin_lock_bh (&sk->sk_lock.slock); } + +if (test_and_clear_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->flags)) +__mptcp_clean_una (sk);if (test_and_clear_bit (MPTCP_ERROR_REPORT , &mptcp_sk (sk)->flags))__mptcp_error_report (sk); -/* clear any wmem reservation and errors */ +/* push_pending may touch wmem_reserved, ensure we do the cleanup +* later +*/ __mptcp_update_wmem (sk);__mptcp_update_rmem (sk);
Signature · 1 line
2.30.1
PATCH 8/9 mptcp: fix missing wakeup
In reply to Mat MartineauFrom: Paolo Abeni <pabeni(a)redhat.com>
__mptcp_clean_una() can free write memory and should wake-up user-space processes when needed.
When such function is invoked by the MPTCP receive path, the wakeup is not needed, as the TCP stack will later trigger subflow_write_space which will do the wakeup as needed.
Other __mptcp_clean_una() call sites need an additional wakeup check Let's bundle the relevant code in a new helper and use it.
--- net/mptcp/protocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +8 -2
@@ -1061,6 +1061,12 @@ static void __mptcp_clean_una(struct sock *sk) } } +static void __mptcp_clean_una_wakeup (struct sock *sk) +{ +__mptcp_clean_una (sk); +mptcp_write_space (sk); +} +static void mptcp_enter_memory_pressure (struct sock *sk) {struct mptcp_subflow_context *subflow;
@@ -2270,7 +2276,7 @@ static void __mptcp_retrans(struct sock *sk)struct sock *ssk;int ret; -__mptcp_clean_una (sk); +__mptcp_clean_una_wakeup (sk); dfrag =mptcp_rtx_head (sk);if (!dfrag)return ;
@@ -2983,7 +2989,7 @@ static void mptcp_release_cb(struct sock *sk) }if (test_and_clear_bit (MPTCP_CLEAN_UNA , &mptcp_sk (sk)->flags)) -__mptcp_clean_una (sk); +__mptcp_clean_una_wakeup (sk);if (test_and_clear_bit (MPTCP_ERROR_REPORT , &mptcp_sk (sk)->flags))__mptcp_error_report (sk);
Signature · 1 line
2.30.1
PATCH 9/9 mptcp: free resources when the port number is mismatched
In reply to Mat MartineauFrom: Geliang Tang <geliangtang(a)gmail.com>
When the port number is mismatched with the announced ones, use 'goto dispose_child' to free the resources instead of using 'goto out'.
This patch also moves the port number checking code in subflow_syn_recv_sock before mptcp_finish_join, otherwise subflow_drop_ctx will fail in dispose_child.
--- net/mptcp/subflow.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/mptcp/subflow.c +7 -6
@@ -687,11 +687,6 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,/* move the msk reference ownership to the subflow */ subflow_req->msk =NULL ; ctx->conn = (struct sock *)owner; -if (!mptcp_finish_join (child)) - goto dispose_child; - -SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX ); -tcp_rsk (req)->drop_req = true;if (subflow_use_different_sport (owner, sk)) { pr_debug("ack inet_sport=%d %d",
@@ -699,10 +694,16 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, ntohs(inet_sk((struct sock *)owner)->inet_sport));if (!mptcp_pm_sport_in_anno_list (owner, sk)) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_MISMATCHPORTACKRX ); - goto out; + goto dispose_child; }SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINPORTACKRX ); } + +if (!mptcp_finish_join (child)) + goto dispose_child; + +SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINACKRX ); +tcp_rsk (req)->drop_req = true; } }
Signature · 1 line
2.30.1
[email protected]
AppliedHello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 8 lines · On Thu, 4 Mar 2021 13:32:07 -0800 you wrote:
These patches from the MPTCP tree fix a few multipath TCP issues:
Patches 1 and 5 clear some stale pointers when subflows close.
Patches 2, 4, and 9 plug some memory leaks.
[...]
Here is the summary with links:
- [net,1/9] mptcp: reset last_snd on subflow close
https://git.kernel.org/netdev/net/c/e0be4931f3fe - [net,2/9] mptcp: put subflow sock on connect error https://git.kernel.org/netdev/net/c/f07157792c63 - [net,3/9] mptcp: fix memory accounting on allocation error https://git.kernel.org/netdev/net/c/eaeef1ce55ec - [net,4/9] mptcp: dispose initial struct socket when its subflow is closed https://git.kernel.org/netdev/net/c/17aee05dc882 - [net,5/9] mptcp: reset 'first' and ack_hint on subflow close https://git.kernel.org/netdev/net/c/c8fe62f0768c - [net,6/9] mptcp: factor out __mptcp_retrans helper() https://git.kernel.org/netdev/net/c/2948d0a1e5ae - [net,7/9] mptcp: fix race in release_cb https://git.kernel.org/netdev/net/c/c2e6048fa1cf - [net,8/9] mptcp: fix missing wakeup https://git.kernel.org/netdev/net/c/417789df4a03 - [net,9/9] mptcp: free resources when the port number is mismatched https://git.kernel.org/netdev/net/c/9238e900d6ec
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html