--- /dev/null
+From 14c56686a64c65ba716ff48f1f4b19c85f4cb2a9 Mon Sep 17 00:00:00 2001
+From: Geliang Tang <geliang.tang@suse.com>
+Date: Wed, 18 Oct 2023 11:23:55 -0700
+Subject: mptcp: avoid sending RST when closing the initial subflow
+
+From: Geliang Tang <geliang.tang@suse.com>
+
+commit 14c56686a64c65ba716ff48f1f4b19c85f4cb2a9 upstream.
+
+When closing the first subflow, the MPTCP protocol unconditionally
+calls tcp_disconnect(), which in turn generates a reset if the subflow
+is established.
+
+That is unexpected and different from what MPTCP does with MPJ
+subflows, where resets are generated only on FASTCLOSE and other edge
+scenarios.
+
+We can't reuse for the first subflow the same code in place for MPJ
+subflows, as MPTCP clean them up completely via a tcp_close() call,
+while must keep the first subflow socket alive for later re-usage, due
+to implementation constraints.
+
+This patch adds a new helper __mptcp_subflow_disconnect() that
+encapsulates, a logic similar to tcp_close, issuing a reset only when
+the MPTCP_CF_FASTCLOSE flag is set, and performing a clean shutdown
+otherwise.
+
+Fixes: c2b2ae3925b6 ("mptcp: handle correctly disconnect() failures")
+Cc: stable@vger.kernel.org
+Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
+Co-developed-by: Paolo Abeni <pabeni@redhat.com>
+Signed-off-by: Paolo Abeni <pabeni@redhat.com>
+Signed-off-by: Geliang Tang <geliang.tang@suse.com>
+Signed-off-by: Mat Martineau <martineau@kernel.org>
+Link: https://lore.kernel.org/r/20231018-send-net-20231018-v1-4-17ecb002e41d@kernel.org
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/mptcp/protocol.c | 28 ++++++++++++++++++++++------
+ 1 file changed, 22 insertions(+), 6 deletions(-)
+
+--- a/net/mptcp/protocol.c
++++ b/net/mptcp/protocol.c
+@@ -2368,6 +2368,26 @@ bool __mptcp_retransmit_pending_data(str
+ #define MPTCP_CF_PUSH BIT(1)
+ #define MPTCP_CF_FASTCLOSE BIT(2)
+
++/* be sure to send a reset only if the caller asked for it, also
++ * clean completely the subflow status when the subflow reaches
++ * TCP_CLOSE state
++ */
++static void __mptcp_subflow_disconnect(struct sock *ssk,
++ struct mptcp_subflow_context *subflow,
++ unsigned int flags)
++{
++ if (((1 << ssk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
++ (flags & MPTCP_CF_FASTCLOSE)) {
++ /* The MPTCP code never wait on the subflow sockets, TCP-level
++ * disconnect should never fail
++ */
++ WARN_ON_ONCE(tcp_disconnect(ssk, 0));
++ mptcp_subflow_ctx_reset(subflow);
++ } else {
++ tcp_shutdown(ssk, SEND_SHUTDOWN);
++ }
++}
++
+ /* subflow sockets can be either outgoing (connect) or incoming
+ * (accept).
+ *
+@@ -2405,7 +2425,7 @@ static void __mptcp_close_ssk(struct soc
+ lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
+
+ if ((flags & MPTCP_CF_FASTCLOSE) && !__mptcp_check_fallback(msk)) {
+- /* be sure to force the tcp_disconnect() path,
++ /* be sure to force the tcp_close path
+ * to generate the egress reset
+ */
+ ssk->sk_lingertime = 0;
+@@ -2415,12 +2435,8 @@ static void __mptcp_close_ssk(struct soc
+
+ need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
+ if (!dispose_it) {
+- /* The MPTCP code never wait on the subflow sockets, TCP-level
+- * disconnect should never fail
+- */
+- WARN_ON_ONCE(tcp_disconnect(ssk, 0));
++ __mptcp_subflow_disconnect(ssk, subflow, flags);
+ msk->subflow->state = SS_UNCONNECTED;
+- mptcp_subflow_ctx_reset(subflow);
+ release_sock(ssk);
+
+ goto out;
--- /dev/null
+From b134a5805455d1886662a6516c965cdb9df9fbcc Mon Sep 17 00:00:00 2001
+From: Matthieu Baerts <matttbe@kernel.org>
+Date: Wed, 18 Oct 2023 11:23:52 -0700
+Subject: selftests: mptcp: join: correctly check for no RST
+
+From: Matthieu Baerts <matttbe@kernel.org>
+
+commit b134a5805455d1886662a6516c965cdb9df9fbcc upstream.
+
+The commit mentioned below was more tolerant with the number of RST seen
+during a test because in some uncontrollable situations, multiple RST
+can be generated.
+
+But it was not taking into account the case where no RST are expected:
+this validation was then no longer reporting issues for the 0 RST case
+because it is not possible to have less than 0 RST in the counter. This
+patch fixes the issue by adding a specific condition.
+
+Fixes: 6bf41020b72b ("selftests: mptcp: update and extend fastclose test-cases")
+Cc: stable@vger.kernel.org
+Reviewed-by: Mat Martineau <martineau@kernel.org>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Mat Martineau <martineau@kernel.org>
+Link: https://lore.kernel.org/r/20231018-send-net-20231018-v1-1-17ecb002e41d@kernel.org
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/mptcp_join.sh | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
++++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
+@@ -1413,7 +1413,9 @@ chk_rst_nr()
+ count=$(get_counter ${ns_tx} "MPTcpExtMPRstTx")
+ if [ -z "$count" ]; then
+ echo -n "[skip]"
+- elif [ $count -lt $rst_tx ]; then
++ # accept more rst than expected except if we don't expect any
++ elif { [ $rst_tx -ne 0 ] && [ $count -lt $rst_tx ]; } ||
++ { [ $rst_tx -eq 0 ] && [ $count -ne 0 ]; }; then
+ echo "[fail] got $count MP_RST[s] TX expected $rst_tx"
+ fail_test
+ dump_stats=1
+@@ -1425,7 +1427,9 @@ chk_rst_nr()
+ count=$(get_counter ${ns_rx} "MPTcpExtMPRstRx")
+ if [ -z "$count" ]; then
+ echo -n "[skip]"
+- elif [ "$count" -lt "$rst_rx" ]; then
++ # accept more rst than expected except if we don't expect any
++ elif { [ $rst_rx -ne 0 ] && [ $count -lt $rst_rx ]; } ||
++ { [ $rst_rx -eq 0 ] && [ $count -ne 0 ]; }; then
+ echo "[fail] got $count MP_RST[s] RX expected $rst_rx"
+ fail_test
+ dump_stats=1
--- /dev/null
+From 2cfaa8b3b7aece3c7b13dd10db20dcea65875692 Mon Sep 17 00:00:00 2001
+From: Matthieu Baerts <matttbe@kernel.org>
+Date: Wed, 18 Oct 2023 11:23:56 -0700
+Subject: selftests: mptcp: join: no RST when rm subflow/addr
+
+From: Matthieu Baerts <matttbe@kernel.org>
+
+commit 2cfaa8b3b7aece3c7b13dd10db20dcea65875692 upstream.
+
+Recently, we noticed that some RST were wrongly generated when removing
+the initial subflow.
+
+This patch makes sure RST are not sent when removing any subflows or any
+addresses.
+
+Fixes: c2b2ae3925b6 ("mptcp: handle correctly disconnect() failures")
+Cc: stable@vger.kernel.org
+Acked-by: Paolo Abeni <pabeni@redhat.com>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Mat Martineau <martineau@kernel.org>
+Link: https://lore.kernel.org/r/20231018-send-net-20231018-v1-5-17ecb002e41d@kernel.org
+Signed-off-by: Jakub Kicinski <kuba@kernel.org>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/mptcp_join.sh | 13 +++++++++++++
+ 1 file changed, 13 insertions(+)
+
+--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
++++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
+@@ -2263,6 +2263,7 @@ remove_tests()
+ run_tests $ns1 $ns2 10.0.1.1 0 0 -1 slow
+ chk_join_nr 1 1 1
+ chk_rm_nr 1 1
++ chk_rst_nr 0 0
+ fi
+
+ # multiple subflows, remove
+@@ -2274,6 +2275,7 @@ remove_tests()
+ run_tests $ns1 $ns2 10.0.1.1 0 0 -2 slow
+ chk_join_nr 2 2 2
+ chk_rm_nr 2 2
++ chk_rst_nr 0 0
+ fi
+
+ # single address, remove
+@@ -2285,6 +2287,7 @@ remove_tests()
+ chk_join_nr 1 1 1
+ chk_add_nr 1 1
+ chk_rm_nr 1 1 invert
++ chk_rst_nr 0 0
+ fi
+
+ # subflow and signal, remove
+@@ -2297,6 +2300,7 @@ remove_tests()
+ chk_join_nr 2 2 2
+ chk_add_nr 1 1
+ chk_rm_nr 1 1
++ chk_rst_nr 0 0
+ fi
+
+ # subflows and signal, remove
+@@ -2310,6 +2314,7 @@ remove_tests()
+ chk_join_nr 3 3 3
+ chk_add_nr 1 1
+ chk_rm_nr 2 2
++ chk_rst_nr 0 0
+ fi
+
+ # addresses remove
+@@ -2323,6 +2328,7 @@ remove_tests()
+ chk_join_nr 3 3 3
+ chk_add_nr 3 3
+ chk_rm_nr 3 3 invert
++ chk_rst_nr 0 0
+ fi
+
+ # invalid addresses remove
+@@ -2336,6 +2342,7 @@ remove_tests()
+ chk_join_nr 1 1 1
+ chk_add_nr 3 3
+ chk_rm_nr 3 1 invert
++ chk_rst_nr 0 0
+ fi
+
+ # subflows and signal, flush
+@@ -2349,6 +2356,7 @@ remove_tests()
+ chk_join_nr 3 3 3
+ chk_add_nr 1 1
+ chk_rm_nr 1 3 invert simult
++ chk_rst_nr 0 0
+ fi
+
+ # subflows flush
+@@ -2366,6 +2374,7 @@ remove_tests()
+ else
+ chk_rm_nr 3 3
+ fi
++ chk_rst_nr 0 0
+ fi
+
+ # addresses flush
+@@ -2379,6 +2388,7 @@ remove_tests()
+ chk_join_nr 3 3 3
+ chk_add_nr 3 3
+ chk_rm_nr 3 3 invert simult
++ chk_rst_nr 0 0
+ fi
+
+ # invalid addresses flush
+@@ -2392,6 +2402,7 @@ remove_tests()
+ chk_join_nr 1 1 1
+ chk_add_nr 3 3
+ chk_rm_nr 3 1 invert
++ chk_rst_nr 0 0
+ fi
+
+ # remove id 0 subflow
+@@ -2402,6 +2413,7 @@ remove_tests()
+ run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
+ chk_join_nr 1 1 1
+ chk_rm_nr 1 1
++ chk_rst_nr 0 0
+ fi
+
+ # remove id 0 address
+@@ -2413,6 +2425,7 @@ remove_tests()
+ chk_join_nr 1 1 1
+ chk_add_nr 1 1
+ chk_rm_nr 1 1 invert
++ chk_rst_nr 0 0 invert
+ fi
+ }
+
net-move-altnames-together-with-the-netdevice.patch
bluetooth-hci_sock-fix-slab-oob-read-in-create_monitor_event.patch
bluetooth-hci_sock-correctly-bounds-check-and-pad-hci_mon_new_index-name.patch
+mptcp-avoid-sending-rst-when-closing-the-initial-subflow.patch
+selftests-mptcp-join-correctly-check-for-no-rst.patch
+selftests-mptcp-join-no-rst-when-rm-subflow-addr.patch