Skip to content

Commit fc2ea6a

Browse files
committed
Merge branch 'mptcp-more-fixes-for-v6-5'
Matthieu Baerts says: ==================== mptcp: more fixes for v6.5 Here is a new batch of fixes related to MPTCP for v6.5 and older. Patches 1 and 2 fix issues with MPTCP Join selftest when manually launched with '-i' parameter to use 'ip mptcp' tool instead of the dedicated one (pm_nl_ctl). The issues have been there since v5.18. Thank you Andrea for your first contributions to MPTCP code in the upstream kernel! Patch 3 avoids corrupting the data stream when trying to reset connections that have fallen back to TCP. This can happen from v6.1. Patch 4 fixes a race when doing a disconnect() and an accept() in parallel on a listener socket. The issue only happens in rare cases if the user is really unlucky since a fix that landed in v6.3 but backported up to v6.1. ==================== Link: https://lore.kernel.org/r/20230803-upstream-net-20230803-misc-fixes-6-5-v1-0-6671b1ab11cc@tessares.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents ec93518 + 511b90e commit fc2ea6a

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

net/mptcp/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
23352335

23362336
lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
23372337

2338-
if (flags & MPTCP_CF_FASTCLOSE) {
2338+
if ((flags & MPTCP_CF_FASTCLOSE) && !__mptcp_check_fallback(msk)) {
23392339
/* be sure to force the tcp_disconnect() path,
23402340
* to generate the egress reset
23412341
*/

net/mptcp/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ struct mptcp_sock {
325325
u32 subflow_id;
326326
u32 setsockopt_seq;
327327
char ca_name[TCP_CA_NAME_MAX];
328-
struct mptcp_sock *dl_next;
329328
};
330329

331330
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)

net/mptcp/subflow.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,49 +1793,42 @@ static void subflow_state_change(struct sock *sk)
17931793
void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_ssk)
17941794
{
17951795
struct request_sock_queue *queue = &inet_csk(listener_ssk)->icsk_accept_queue;
1796-
struct mptcp_sock *msk, *next, *head = NULL;
1797-
struct request_sock *req;
1798-
struct sock *sk;
1796+
struct request_sock *req, *head, *tail;
1797+
struct mptcp_subflow_context *subflow;
1798+
struct sock *sk, *ssk;
17991799

1800-
/* build a list of all unaccepted mptcp sockets */
1800+
/* Due to lock dependencies no relevant lock can be acquired under rskq_lock.
1801+
* Splice the req list, so that accept() can not reach the pending ssk after
1802+
* the listener socket is released below.
1803+
*/
18011804
spin_lock_bh(&queue->rskq_lock);
1802-
for (req = queue->rskq_accept_head; req; req = req->dl_next) {
1803-
struct mptcp_subflow_context *subflow;
1804-
struct sock *ssk = req->sk;
1805+
head = queue->rskq_accept_head;
1806+
tail = queue->rskq_accept_tail;
1807+
queue->rskq_accept_head = NULL;
1808+
queue->rskq_accept_tail = NULL;
1809+
spin_unlock_bh(&queue->rskq_lock);
1810+
1811+
if (!head)
1812+
return;
18051813

1814+
/* can't acquire the msk socket lock under the subflow one,
1815+
* or will cause ABBA deadlock
1816+
*/
1817+
release_sock(listener_ssk);
1818+
1819+
for (req = head; req; req = req->dl_next) {
1820+
ssk = req->sk;
18061821
if (!sk_is_mptcp(ssk))
18071822
continue;
18081823

18091824
subflow = mptcp_subflow_ctx(ssk);
18101825
if (!subflow || !subflow->conn)
18111826
continue;
18121827

1813-
/* skip if already in list */
18141828
sk = subflow->conn;
1815-
msk = mptcp_sk(sk);
1816-
if (msk->dl_next || msk == head)
1817-
continue;
1818-
18191829
sock_hold(sk);
1820-
msk->dl_next = head;
1821-
head = msk;
1822-
}
1823-
spin_unlock_bh(&queue->rskq_lock);
1824-
if (!head)
1825-
return;
1826-
1827-
/* can't acquire the msk socket lock under the subflow one,
1828-
* or will cause ABBA deadlock
1829-
*/
1830-
release_sock(listener_ssk);
1831-
1832-
for (msk = head; msk; msk = next) {
1833-
sk = (struct sock *)msk;
18341830

18351831
lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
1836-
next = msk->dl_next;
1837-
msk->dl_next = NULL;
1838-
18391832
__mptcp_unaccepted_force_close(sk);
18401833
release_sock(sk);
18411834

@@ -1859,6 +1852,13 @@ void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_s
18591852

18601853
/* we are still under the listener msk socket lock */
18611854
lock_sock_nested(listener_ssk, SINGLE_DEPTH_NESTING);
1855+
1856+
/* restore the listener queue, to let the TCP code clean it up */
1857+
spin_lock_bh(&queue->rskq_lock);
1858+
WARN_ON_ONCE(queue->rskq_accept_head);
1859+
queue->rskq_accept_head = head;
1860+
queue->rskq_accept_tail = tail;
1861+
spin_unlock_bh(&queue->rskq_lock);
18621862
}
18631863

18641864
static int subflow_ulp_init(struct sock *sk)

tools/testing/selftests/net/mptcp/mptcp_join.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ pm_nl_del_endpoint()
705705
local addr=$3
706706

707707
if [ $ip_mptcp -eq 1 ]; then
708+
[ $id -ne 0 ] && addr=''
708709
ip -n $ns mptcp endpoint delete id $id $addr
709710
else
710711
ip netns exec $ns ./pm_nl_ctl del $id $addr
@@ -795,10 +796,11 @@ pm_nl_check_endpoint()
795796
fi
796797

797798
if [ $ip_mptcp -eq 1 ]; then
799+
# get line and trim trailing whitespace
798800
line=$(ip -n $ns mptcp endpoint show $id)
801+
line="${line% }"
799802
# the dump order is: address id flags port dev
800-
expected_line="$addr"
801-
[ -n "$addr" ] && expected_line="$expected_line $addr"
803+
[ -n "$addr" ] && expected_line="$addr"
802804
expected_line="$expected_line $id"
803805
[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
804806
[ -n "$dev" ] && expected_line="$expected_line $dev"

0 commit comments

Comments
 (0)