Skip to contentSkip to conversation

mptcp: fix endpoints with 'signal' and 'subflow' flags

PATCH Superseded Matthieu Baerts (NGI0) 4 participants 25 messages Jul 26, 2024 – Jul 31, 2024

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Matthieu Baerts (NGI0)

author maintainer
#0 lore raw

v5 cover mptcp: fix endpoints with 'signal' and 'subflow' flags

The first 11 patches have already been applied. Here are the remaining ones.

---
Changes in v5:
- Split patch 1 (previously 12): the renaming has been done in a
dedicated patch at the end (patch patch 12), for -next.
- Patch 10: fix typo and avoid memcpy.
- Patch 11: fix comment.
- Patch 13: fix build issue and use a new dedicated struct.
- Please see the individual changelog for more details.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Patch 19: check for msk->first != NULL
- New patches 21-22
- Imported patch 23: might be easier to review all of them, then this
single one alone, while it depends on the previous ones.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Small changes in patches 10 and 14, see individual changelog (Geliang)
- New patches 18-20: small fixes
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Do not split id_avail_bitmap per target in patch 5 (Paolo)
- Explicit deny (patch 2), reduce indentation (patch 3), stop earlier
(patch 4) (Paolo)
- New fixes and tests (patches 8-17).
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Matthieu Baerts (NGI0) (13):
mptcp: pm: re-using ID of unused flushed subflows
selftests: mptcp: join: test for flush/re-add endpoints
mptcp: pm: remove mptcp_pm_remove_subflow()
mptcp: pm: only mark 'subflow' endp as available
mptcp: pm: only decrement add_addr_accepted for MPJ req
mptcp: pm: check add_addr_accept_max before accepting new ADD_ADDR
mptcp: pm: only in-kernel cannot have entries with ID 0
mptcp: pm: fullmesh: select the right ID later
selftests: mptcp: join: validate fullmesh endp on 1st sf
mptcp: pm: avoid possible UaF when selecting endp
mptcp: pm: reuse ID 0 after delete and re-add
mptcp: pm: rename helpers linked to 'flush'
mptcp: pm: reduce entries iterations on connect

 net/mptcp/pm.c                                  |  24 ---
 net/mptcp/pm_netlink.c                          | 195 ++++++++++++++----------
 net/mptcp/pm_userspace.c                        |  40 ++---
 net/mptcp/protocol.h                            |  19 +--
 net/mptcp/subflow.c                             |  29 ++--
 tools/testing/selftests/net/mptcp/mptcp_join.sh |  31 ++++
 6 files changed, 180 insertions(+), 158 deletions(-)

---
base-commit: a9a9b3b154d187864b73eb0e86a0ff737d79a10a
change-id: 20240620-mptcp-pm-avail-f5e3957be441

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#1 lore raw

PATCH v5 1/13 mptcp: pm: re-using ID of unused flushed subflows

If no subflows are attached to the 'subflow' endpoints that are being flushed, the corresponding addr IDs will not be marked as available again.

Mark all ID as being available when flushing all the 'subflow' endpoints, and reset local_addr_used counter to cover these cases.

Note that mptcp_pm_remove_addrs_and_subflows() helper is only called for flushing operations, not to remove a specific set of addresses and subflows.

Fixes 06faa2271034 ("mptcp: remove multi addresses and subflows in PM")

---
Notes:
- v5: move the renaming of the helpers in a dedicated patch for -next

        (Mat)
---
 net/mptcp/pm_netlink.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/mptcp/pm_netlink.c +7 -0
index 44336ee22707..00b3184be45b 100644
@@ -1625,8 +1625,15 @@ static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 		mptcp_pm_remove_addr(msk, &alist);
 		spin_unlock_bh(&msk->pm.lock);
 	}
+
 	if (slist.nr)
 		mptcp_pm_remove_subflow(msk, &slist);
+
+	/* Reset counters: maybe some subflows have been removed before */
+	spin_lock_bh(&msk->pm.lock);
+	bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	msk->pm.local_addr_used = 0;
+	spin_unlock_bh(&msk->pm.lock);
 }
 
 static void mptcp_nl_remove_addrs_list(struct net *net,
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH v5 2/13 selftests: mptcp: join: test for flush/re-add endpoints

In reply to Matthieu Baerts (NGI0)

After having flushed endpoints that didn't cause the creation of new subflows, it is important to check endpoints can be re-created, re-using previously used IDs.

Before the previous commit, the client would not have been able to re-create the subflow that was previously rejected.

The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests, but it validates the previous fix for an issue introduced by this commit ID.

Fixes 06faa2271034 ("mptcp: remove multi addresses and subflows in PM")
---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 30 +++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +30 -0
index fbb0174145ad..f609c02c6123 100755
@@ -3651,6 +3651,36 @@ endpoint_tests()
 		chk_rm_nr 2 1 invert
 	fi
 
+	# flush and re-add
+	if reset_with_tcp_filter "flush re-add" ns2 10.0.3.2 REJECT OUTPUT &&
+	   mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 1 2
+		# broadcast IP: no packet for this address will be received on ns1
+		pm_nl_add_endpoint $ns1 224.0.0.1 id 2 flags signal
+		pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
+		test_linkfail=4 speed=20 \
+			run_tests $ns1 $ns2 10.0.1.1 &
+		local tests_pid=$!
+
+		wait_attempt_fail $ns2
+		chk_subflow_nr "before flush" 1
+		chk_mptcp_info subflows 0 subflows 0
+
+		pm_nl_flush_endpoint $ns2
+		pm_nl_flush_endpoint $ns1
+		wait_rm_addr $ns2 0
+		ip netns exec "${ns2}" ${iptables} -D OUTPUT -s "10.0.3.2" -p tcp -j REJECT
+		pm_nl_add_endpoint $ns2 10.0.3.2 id 3 flags subflow
+		wait_mpj $ns2
+		pm_nl_add_endpoint $ns1 10.0.3.1 id 2 flags signal
+		wait_mpj $ns2
+		mptcp_lib_kill_wait $tests_pid
+
+		chk_join_nr 2 2 2
+		chk_add_nr 2 2
+		chk_rm_nr 1 0 invert
+	fi
 }
 
 # [$1: error message]
Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH v5 3/13 mptcp: pm: remove mptcp_pm_remove_subflow()

In reply to Matthieu Baerts (NGI0)

This helper is confusing. It is in pm.c, but it is specific to the in-kernel PM and it cannot be used by the userspace one. Also, it simply calls one in-kernel specific function with the PM lock, while the similar mptcp_pm_remove_addr() helper requires the PM lock.

What's left is the pr_debug(), which is not that useful, because a similar one is present in the only function called by this helper:

mptcp_pm_nl_rm_subflow_received()

After these modifications, this helper can be marked as 'static', and the lock can be taken only once in mptcp_pm_flush_addrs_and_subflows().

Note that it is not a bug fix, but it will help backporting the following commits.

Fixes 0ee4261a3681 ("mptcp: implement mptcp_pm_remove_subflow")

---
Notes:
- v3:
- New line before 'if (remove_subflow) {' moved to patch 10 (Geliang)
- One PM spin lock to remove address and subflows (Geliang)

---
 net/mptcp/pm.c         | 10 ----------
 net/mptcp/pm_netlink.c | 16 +++++++---------
 net/mptcp/protocol.h   |  3 ---
 3 files changed, 7 insertions(+), 22 deletions(-)
net/mptcp/pm.c +0 -10
index 23bb89c94e90..925123e99889 100644
@@ -60,16 +60,6 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_
 	return 0;
 }
 
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list)
-{
-	pr_debug("msk=%p, rm_list_nr=%d", msk, rm_list->nr);
-
-	spin_lock_bh(&msk->pm.lock);
-	mptcp_pm_nl_rm_subflow_received(msk, rm_list);
-	spin_unlock_bh(&msk->pm.lock);
-	return 0;
-}
-
 /* path manager event handlers */
 
 void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side)
net/mptcp/pm_netlink.c +7 -9
index 00b3184be45b..8a28fdaf3bb6 100644
@@ -857,8 +857,8 @@ static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
 	mptcp_pm_nl_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR);
 }
 
-void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
-				     const struct mptcp_rm_list *rm_list)
+static void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
+					    const struct mptcp_rm_list *rm_list)
 {
 	mptcp_pm_nl_rm_addr_or_subflow(msk, rm_list, MPTCP_MIB_RMSUBFLOW);
 }
@@ -1473,7 +1473,9 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
 					  !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT));
 
 		if (remove_subflow) {
-			mptcp_pm_remove_subflow(msk, &list);
+			spin_lock_bh(&msk->pm.lock);
+			mptcp_pm_nl_rm_subflow_received(msk, &list);
+			spin_unlock_bh(&msk->pm.lock);
 		} else if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
 			/* If the subflow has been used, but now closed */
 			spin_lock_bh(&msk->pm.lock);
@@ -1619,18 +1621,14 @@ static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 			alist.ids[alist.nr++] = entry->addr.id;
 	}
 
+	spin_lock_bh(&msk->pm.lock);
 	if (alist.nr) {
-		spin_lock_bh(&msk->pm.lock);
 		msk->pm.add_addr_signaled -= alist.nr;
 		mptcp_pm_remove_addr(msk, &alist);
-		spin_unlock_bh(&msk->pm.lock);
 	}
-
 	if (slist.nr)
-		mptcp_pm_remove_subflow(msk, &slist);
-
+		mptcp_pm_nl_rm_subflow_received(msk, &slist);
 	/* Reset counters: maybe some subflows have been removed before */
-	spin_lock_bh(&msk->pm.lock);
 	bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 	msk->pm.local_addr_used = 0;
 	spin_unlock_bh(&msk->pm.lock);
net/mptcp/protocol.h +0 -3
index 23dd0ecd5fbc..fcf6983ca555 100644
@@ -1031,7 +1031,6 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr,
 			   bool echo);
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);
-int mptcp_pm_remove_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);
 void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list);
 
 void mptcp_free_local_addr_list(struct mptcp_sock *msk);
@@ -1138,8 +1137,6 @@ static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflo
 
 void __init mptcp_pm_nl_init(void);
 void mptcp_pm_nl_work(struct mptcp_sock *msk);
-void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
-				     const struct mptcp_rm_list *rm_list);
 unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk);
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

PATCH v5 4/13 mptcp: pm: only mark 'subflow' endp as available

In reply to Matthieu Baerts (NGI0)

Adding the following warning ...

WARN_ON_ONCE(msk->pm.local_addr_used == 0)

... before decrementing the local_addr_used counter helped to find a bug when running the "remove single address" subtest from the mptcp_join.sh selftests.

Removing a 'signal' endpoint will trigger the removal of all subflows linked to this endpoint via mptcp_pm_nl_rm_addr_or_subflow() with rm_type == MPTCP_MIB_RMSUBFLOW. This will decrement the local_addr_used counter, which is wrong in this case because this counter is linked to 'subflow' endpoints, and here it is a 'signal' endpoint that is being removed.

Now, the counter is decremented, only if the ID is being used outside of mptcp_pm_nl_rm_addr_or_subflow(), only for 'subflow' endpoints, and if the ID is not 0 -- local_addr_used is not taking into account these ones. This marking of the ID as being available, and the decrement is done no matter if a subflow using this ID is currently available, because the subflow could have been closed before.

Fixes 06faa2271034 ("mptcp: remove multi addresses and subflows in PM")
---
 net/mptcp/pm_netlink.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +17 -9
index 8a28fdaf3bb6..3ea417b52ff4 100644
@@ -833,10 +833,10 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 			if (rm_type == MPTCP_MIB_RMSUBFLOW)
 				__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		}
-		if (rm_type == MPTCP_MIB_RMSUBFLOW)
-			__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap);
-		else if (rm_type == MPTCP_MIB_RMADDR)
+
+		if (rm_type == MPTCP_MIB_RMADDR)
 			__MPTCP_INC_STATS(sock_net(sk), rm_type);
+
 		if (!removed)
 			continue;
 
@@ -846,8 +846,6 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 		if (rm_type == MPTCP_MIB_RMADDR) {
 			msk->pm.add_addr_accepted--;
 			WRITE_ONCE(msk->pm.accept_addr, true);
-		} else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
-			msk->pm.local_addr_used--;
 		}
 	}
 }
@@ -1443,6 +1441,14 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
 	return ret;
 }
 
+static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id)
+{
+	/* If it was marked as used, and not ID 0, decrement local_addr_used */
+	if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap) &&
+	    id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0))
+		msk->pm.local_addr_used--;
+}
+
 static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
 						   const struct mptcp_pm_addr_entry *entry)
 {
@@ -1476,11 +1482,11 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
 			spin_lock_bh(&msk->pm.lock);
 			mptcp_pm_nl_rm_subflow_received(msk, &list);
 			spin_unlock_bh(&msk->pm.lock);
-		} else if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
-			/* If the subflow has been used, but now closed */
+		}
+
+		if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
 			spin_lock_bh(&msk->pm.lock);
-			if (!__test_and_set_bit(entry->addr.id, msk->pm.id_avail_bitmap))
-				msk->pm.local_addr_used--;
+			__mark_subflow_endp_available(msk, entry->addr.id);
 			spin_unlock_bh(&msk->pm.lock);
 		}
 
@@ -1518,6 +1524,7 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
 		spin_lock_bh(&msk->pm.lock);
 		mptcp_pm_remove_addr(msk, &list);
 		mptcp_pm_nl_rm_subflow_received(msk, &list);
+		__mark_subflow_endp_available(msk, 0);
 		spin_unlock_bh(&msk->pm.lock);
 		release_sock(sk);
 
@@ -1919,6 +1926,7 @@ static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk,
 
 	spin_lock_bh(&msk->pm.lock);
 	mptcp_pm_nl_rm_subflow_received(msk, &list);
+	__mark_subflow_endp_available(msk, addr->id);
 	mptcp_pm_create_subflow_or_signal_addr(msk);
 	spin_unlock_bh(&msk->pm.lock);
 }
Signature · 1 line
2.45.2
reviewer
#5 lore raw

Re: [PATCH mptcp-net v5 04/13] mptcp: pm: only mark 'subflow' endp as available

Hi Matt,

Quoted 57 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

Adding the following warning ...

  WARN_ON_ONCE(msk->pm.local_addr_used == 0)

... before decrementing the local_addr_used counter helped to find a bug
when running the "remove single address" subtest from the mptcp_join.sh
selftests.

Removing a 'signal' endpoint will trigger the removal of all subflows linked to this endpoint via mptcp_pm_nl_rm_addr_or_subflow() with rm_type == MPTCP_MIB_RMSUBFLOW. This will decrement the local_addr_used
counter, which is wrong in this case because this counter is linked to
'subflow' endpoints, and here it is a 'signal' endpoint that is being removed.

Now, the counter is decremented, only if the ID is being used outside of mptcp_pm_nl_rm_addr_or_subflow(), only for 'subflow' endpoints, and
if the ID is not 0 -- local_addr_used is not taking into account these
ones. This marking of the ID as being available, and the decrement is done no matter if a subflow using this ID is currently available, because the subflow could have been closed before.

Fixes 06faa2271034 ("mptcp: remove multi addresses and subflows in

PM")

---
 net/mptcp/pm_netlink.c | 26 +++++++++++++++++---------

 1 file changed, 17 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +3 -3
index 8a28fdaf3bb6..3ea417b52ff4 100644
@@ -833,10 +833,10 @@ static void
 mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
  			if (rm_type == MPTCP_MIB_RMSUBFLOW)
  				__MPTCP_INC_STATS(sock_net(sk),
 rm_type);
  		}
-		if (rm_type == MPTCP_MIB_RMSUBFLOW)
-			__set_bit(rm_id ? rm_id : msk-
 >mpc_endpoint_id, msk->pm.id_avail_bitmap);
-		else if (rm_type == MPTCP_MIB_RMADDR)
+
+		if (rm_type == MPTCP_MIB_RMADDR)
  			__MPTCP_INC_STATS(sock_net(sk), rm_type);
+

  if (!removed)
  continue;

net/mptcp/pm_netlink.c static void mptcp_pm_nl_rm_addr_or_subflow(struct · line 851

Quoted 6 lines
net/mptcp/pm_netlink.c +0 -2
@@ -846,8 +846,6 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct
 mptcp_sock *msk,
  		if (rm_type == MPTCP_MIB_RMADDR) {
  			msk->pm.add_addr_accepted--;
  			WRITE_ONCE(msk->pm.accept_addr, true);
-		} else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
-			msk->pm.local_addr_used--;

Is it necessary to call __mark_subflow_endp_available() here? I'm not sure.

Quoted 63 lines
net/mptcp/pm_netlink.c +0 -0
  		}
  	}

 }

net/mptcp/pm_netlink.c +0 -0
@@ -1443,6 +1441,14 @@ static bool mptcp_pm_remove_anno_addr(struct
 mptcp_sock *msk,
  	return ret;
  }


+static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id)

net/mptcp/pm_netlink.c +2 -0
+{
+	/* If it was marked as used, and not ID 0, decrement

local_addr_used */

net/mptcp/pm_netlink.c +1 -0
+	if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk-
Quoted 1 line

pm.id_avail_bitmap) &&

net/mptcp/pm_netlink.c +4 -0
+	    id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0))
+		msk->pm.local_addr_used--;
+}
+

 static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, const struct mptcp_pm_addr_entry *entry)
 {

net/mptcp/pm_netlink.c +0 -2
@@ -1476,11 +1482,11 @@ static int
 mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
  			spin_lock_bh(&msk->pm.lock);
  			mptcp_pm_nl_rm_subflow_received(msk, &list);
  			spin_unlock_bh(&msk->pm.lock);
-		} else if (entry->flags &
 MPTCP_PM_ADDR_FLAG_SUBFLOW) {
-			/* If the subflow has been used, but now

closed */

net/mptcp/pm_netlink.c +3 -0
+		}
+
+		if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {

  spin_lock_bh(&msk->pm.lock);

net/mptcp/pm_netlink.c +0 -1
-			if (!__test_and_set_bit(entry->addr.id, msk-
Quoted 1 line

pm.id_avail_bitmap))

net/mptcp/pm_netlink.c +1 -1
-				msk->pm.local_addr_used--;
+			__mark_subflow_endp_available(msk, entry-
Quoted 1 line

addr.id);

  spin_unlock_bh(&msk->pm.lock); }

net/mptcp/pm_netlink.c +1 -0
@@ -1518,6 +1524,7 @@ static int
 mptcp_nl_remove_id_zero_address(struct net *net,
  		spin_lock_bh(&msk->pm.lock);
  		mptcp_pm_remove_addr(msk, &list);
  		mptcp_pm_nl_rm_subflow_received(msk, &list);
+		__mark_subflow_endp_available(msk, 0);
  		spin_unlock_bh(&msk->pm.lock);
  		release_sock(sk);

net/mptcp/pm_netlink.c +0 -0
@@ -1919,6 +1926,7 @@ static void mptcp_pm_nl_fullmesh(struct
 mptcp_sock *msk,


  spin_lock_bh(&msk->pm.lock); mptcp_pm_nl_rm_subflow_received(msk, &list);

net/mptcp/pm_netlink.c +1 -0
+	__mark_subflow_endp_available(msk, addr->id);

  mptcp_pm_create_subflow_or_signal_addr(msk); spin_unlock_bh(&msk->pm.lock);
 }

author maintainer
#6 lore raw

Re: [PATCH mptcp-net v5 04/13] mptcp: pm: only mark 'subflow' endp as available

Hi Geliang,

Thank you for the review.

Quoted 62 lines · Geliang Tang

Hi Matt,

Quoted 59 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

Adding the following warning ...

  WARN_ON_ONCE(msk->pm.local_addr_used == 0)

... before decrementing the local_addr_used counter helped to find a bug
when running the "remove single address" subtest from the mptcp_join.sh
selftests.

Removing a 'signal' endpoint will trigger the removal of all subflows linked to this endpoint via mptcp_pm_nl_rm_addr_or_subflow() with rm_type == MPTCP_MIB_RMSUBFLOW. This will decrement the local_addr_used
counter, which is wrong in this case because this counter is linked to
'subflow' endpoints, and here it is a 'signal' endpoint that is being removed.

Now, the counter is decremented, only if the ID is being used outside of mptcp_pm_nl_rm_addr_or_subflow(), only for 'subflow' endpoints, and
if the ID is not 0 -- local_addr_used is not taking into account these
ones. This marking of the ID as being available, and the decrement is done no matter if a subflow using this ID is currently available, because the subflow could have been closed before.

Fixes 06faa2271034 ("mptcp: remove multi addresses and subflows in

PM")

---
 net/mptcp/pm_netlink.c | 26 +++++++++++++++++---------

 1 file changed, 17 insertions(+), 9 deletions(-)
net/mptcp/pm_netlink.c +3 -3
index 8a28fdaf3bb6..3ea417b52ff4 100644
@@ -833,10 +833,10 @@ static void
 mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
  			if (rm_type == MPTCP_MIB_RMSUBFLOW)
  				__MPTCP_INC_STATS(sock_net(sk),
 rm_type);
  		}
-		if (rm_type == MPTCP_MIB_RMSUBFLOW)
-			__set_bit(rm_id ? rm_id : msk-
 > mpc_endpoint_id, msk->pm.id_avail_bitmap);
-		else if (rm_type == MPTCP_MIB_RMADDR)
+
+		if (rm_type == MPTCP_MIB_RMADDR)
  			__MPTCP_INC_STATS(sock_net(sk), rm_type);
+

  if (!removed)
  continue;

net/mptcp/pm_netlink.c +0 -0
@@ -846,8 +846,6 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct
 mptcp_sock *msk,
  		if (rm_type == MPTCP_MIB_RMADDR) {
Quoted 8 lines

net/mptcp/pm_netlink.c static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, · line 850

Quoted 4 lines
net/mptcp/pm_netlink.c +0 -2
  			msk->pm.add_addr_accepted--;
  			WRITE_ONCE(msk->pm.accept_addr, true);
-		} else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
-			msk->pm.local_addr_used--;

Is it necessary to call __mark_subflow_endp_available() here? I'm not sure.

No, because mptcp_pm_nl_rm_addr_or_subflow(MPTCP_MIB_RMSUBFLOW) will be called when removing an endpoint, to delete all linked subflows. That can be a 'signal' endpoint as well, while 'local_addr_used' is only linked to 'subflow' endpoint. There are more details about that in the commit message, but in short, that why I moved this to functions calling this helper, where there are more info about the endpoint type.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#7 lore raw

PATCH v5 5/13 mptcp: pm: only decrement add_addr_accepted for MPJ req

In reply to Matthieu Baerts (NGI0)

Adding the following warning ...

WARN_ON_ONCE(msk->pm.add_addr_accepted == 0)

... before decrementing the add_addr_accepted counter helped to find a bug when running the "remove single subflow" subtest from the mptcp_join.sh selftest.

Removing a 'subflow' endpoint will first trigger a RM_ADDR, then the subflow closure. Before this patch, and upon the reception of the RM_ADDR, the other peer will then try to decrement this add_addr_accepted. That's not correct because the attached subflows have not been created upon the reception of an ADD_ADDR.

A way to solve that is to decrement the counter only if the attached subflow was an MP_JOIN to a remote id that was not 0, and initiated by the host receiving the RM_ADDR.

Fixes d0876b2284cf ("mptcp: add the incoming RM_ADDR support")
---
 net/mptcp/pm_netlink.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +6 -2
index 3ea417b52ff4..061fa3183eca 100644
@@ -829,7 +829,7 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 			mptcp_close_ssk(sk, ssk, subflow);
 			spin_lock_bh(&msk->pm.lock);
 
-			removed = true;
+			removed |= subflow->request_join;
 			if (rm_type == MPTCP_MIB_RMSUBFLOW)
 				__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		}
@@ -843,7 +843,11 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 		if (!mptcp_pm_is_kernel(msk))
 			continue;
 
-		if (rm_type == MPTCP_MIB_RMADDR) {
+		if (rm_type == MPTCP_MIB_RMADDR && rm_id &&
+		    !WARN_ON_ONCE(msk->pm.add_addr_accepted == 0)) {
+			/* Note: if the subflow has been closed before, this
+			 * add_addr_accepted counter will not be decremented.
+			 */
 			msk->pm.add_addr_accepted--;
 			WRITE_ONCE(msk->pm.accept_addr, true);
 		}
Signature · 1 line
2.45.2
author maintainer
#8 lore raw

PATCH v5 6/13 mptcp: pm: check add_addr_accept_max before accepting new ADD_ADDR

In reply to Matthieu Baerts (NGI0)

The limits might have changed in between, it is best to check them before accepting new ADD_ADDR.

Fixes d0876b2284cf ("mptcp: add the incoming RM_ADDR support")
---
 net/mptcp/pm_netlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +2 -2
index 061fa3183eca..3cb02fe359c0 100644
@@ -848,8 +848,8 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 			/* Note: if the subflow has been closed before, this
 			 * add_addr_accepted counter will not be decremented.
 			 */
-			msk->pm.add_addr_accepted--;
-			WRITE_ONCE(msk->pm.accept_addr, true);
+			if (--msk->pm.add_addr_accepted < mptcp_pm_get_add_addr_accept_max(msk))
+				WRITE_ONCE(msk->pm.accept_addr, true);
 		}
 	}
 }
Signature · 1 line
2.45.2
author maintainer
#9 lore raw

PATCH v5 7/13 mptcp: pm: only in-kernel cannot have entries with ID 0

In reply to Matthieu Baerts (NGI0)

The ID 0 is specific per MPTCP connections. The per netns entries cannot have this special ID 0 then.

But that's different for the userspace PM where the entries are per connection, they can then use this special ID 0.

Fixes f40be0db0b76 ("mptcp: unify pm get_flags_and_ifindex_by_id")
---
 net/mptcp/pm.c         | 3 ---
 net/mptcp/pm_netlink.c | 4 ++++
 2 files changed, 4 insertions(+), 3 deletions(-)
net/mptcp/pm.c +0 -3
index 925123e99889..3e6e0f5510bb 100644
@@ -434,9 +434,6 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id
 	*flags = 0;
 	*ifindex = 0;
 
-	if (!id)
-		return 0;
-
 	if (mptcp_pm_is_userspace(msk))
 		return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
 	return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
net/mptcp/pm_netlink.c +4 -0
index 3cb02fe359c0..6a1495fec7ae 100644
@@ -1395,6 +1395,10 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int
 	struct sock *sk = (struct sock *)msk;
 	struct net *net = sock_net(sk);
 
+	/* No entries with ID 0 */
+	if (id == 0)
+		return 0;
+
 	rcu_read_lock();
 	entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id);
 	if (entry) {
Signature · 1 line
2.45.2
reviewer
#10 lore raw

Re: [PATCH mptcp-net v5 07/13] mptcp: pm: only in-kernel cannot have entries with ID 0

Quoted 42 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

The ID 0 is specific per MPTCP connections. The per netns entries cannot
have this special ID 0 then.

But that's different for the userspace PM where the entries are per connection, they can then use this special ID 0.

Fixes f40be0db0b76 ("mptcp: unify pm get_flags_and_ifindex_by_id")

---
 net/mptcp/pm.c         | 3 ---
 net/mptcp/pm_netlink.c | 4 ++++

 2 files changed, 4 insertions(+), 3 deletions(-)
net/mptcp/pm.c +0 -0
index 925123e99889..3e6e0f5510bb 100644
@@ -434,9 +434,6 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct

mptcp_sock *msk, unsigned int id
  *flags = 0;
  *ifindex = 0;

net/mptcp/pm.c +0 -3
-	if (!id)
-		return 0;
-

  if (mptcp_pm_is_userspace(msk))
  return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
  return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);

net/mptcp/pm_netlink.c +0 -0
index 3cb02fe359c0..6a1495fec7ae 100644
@@ -1395,6 +1395,10 @@ int
 mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,

unsigned int
  struct sock *sk = (struct sock *)msk;
  struct net *net = sock_net(sk);

net/mptcp/pm_netlink.c int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int · line 1401

Quoted 4 lines
net/mptcp/pm_netlink.c +4 -0
+	/* No entries with ID 0 */
+	if (id == 0)
+		return 0;
+

I think this check needs to be added in mptcp_userspace_pm_get_flags_and_ifindex_by_id() too.

Quoted 4 lines

  rcu_read_lock();
  entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id); if (entry) {

author maintainer
#11 lore raw

Re: [PATCH mptcp-net v5 07/13] mptcp: pm: only in-kernel cannot have entries with ID 0

Hi Geliang,

Quoted 42 lines · Geliang Tang
Quoted 41 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

The ID 0 is specific per MPTCP connections. The per netns entries cannot
have this special ID 0 then.

But that's different for the userspace PM where the entries are per connection, they can then use this special ID 0.

Fixes f40be0db0b76 ("mptcp: unify pm get_flags_and_ifindex_by_id")

---
 net/mptcp/pm.c         | 3 ---
 net/mptcp/pm_netlink.c | 4 ++++

 2 files changed, 4 insertions(+), 3 deletions(-)
net/mptcp/pm.c +0 -0
index 925123e99889..3e6e0f5510bb 100644
@@ -434,9 +434,6 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct

mptcp_sock *msk, unsigned int id
  *flags = 0;
  *ifindex = 0;

net/mptcp/pm.c +0 -3
-	if (!id)
-		return 0;
-

  if (mptcp_pm_is_userspace(msk))
  return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
  return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);

net/mptcp/pm_netlink.c +0 -0
index 3cb02fe359c0..6a1495fec7ae 100644
@@ -1395,6 +1395,10 @@ int
 mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,

unsigned int
  struct sock *sk = (struct sock *)msk;
  struct net *net = sock_net(sk);

Quoted 8 lines

net/mptcp/pm_netlink.c int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int · line 1401

Quoted 5 lines

net/mptcp/pm_netlink.c +4 -0
+	/* No entries with ID 0 */
+	if (id == 0)
+		return 0;
+

I think this check needs to be added in mptcp_userspace_pm_get_flags_and_ifindex_by_id() too.

We don't need it for the userspace PM, because the endpoints are managed per MPTCP connection, they can have an ID 0. On the other hand, the in-kernel PM manages the endpoints globally, they cannot have the ID 0 because it is reserved to the address used by the initial subflow, which can be different per MPTCP connection.

Please see the commit message for more details.

Quoted 6 lines
Quoted 5 lines

  rcu_read_lock();
  entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id); if (entry) {

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer Acked-by
#12 lore raw

Re: [PATCH mptcp-net v5 07/13] mptcp: pm: only in-kernel cannot have entries with ID 0

Quoted 66 lines · Matthieu Baerts

Hi Geliang,

Quoted 45 lines · Geliang Tang
Quoted 44 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

The ID 0 is specific per MPTCP connections. The per netns entries cannot
have this special ID 0 then.

But that's different for the userspace PM where the entries are per
connection, they can then use this special ID 0.

Fixes f40be0db0b76 ("mptcp: unify pm

get_flags_and_ifindex_by_id")

---
 net/mptcp/pm.c         | 3 ---
 net/mptcp/pm_netlink.c | 4 ++++

 2 files changed, 4 insertions(+), 3 deletions(-)
net/mptcp/pm.c +0 -0
index 925123e99889..3e6e0f5510bb 100644
@@ -434,9 +434,6 @@ int

mptcp_pm_get_flags_and_ifindex_by_id(struct
mptcp_sock *msk, unsigned int id
  *flags = 0;
  *ifindex = 0;

net/mptcp/pm.c +0 -3
-	if (!id)
-		return 0;
-

  if (mptcp_pm_is_userspace(msk))
  return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
  return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);

net/mptcp/pm_netlink.c +0 -0
index 3cb02fe359c0..6a1495fec7ae 100644
@@ -1395,6 +1395,10 @@ int
 mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,

unsigned int
  struct sock *sk = (struct sock *)msk;
  struct net *net = sock_net(sk);

Quoted 8 lines

net/mptcp/pm_netlink.c int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int · line 1401

Quoted 5 lines

net/mptcp/pm_netlink.c +4 -0
+	/* No entries with ID 0 */
+	if (id == 0)
+		return 0;
+

I think this check needs to be added in mptcp_userspace_pm_get_flags_and_ifindex_by_id() too.

We don't need it for the userspace PM, because the endpoints are managed
per MPTCP connection, they can have an ID 0. On the other hand, the in-kernel PM manages the endpoints globally, they cannot have the ID 0
because it is reserved to the address used by the initial subflow, which
can be different per MPTCP connection.

Quoted 1 line

Please see the commit message for more details.

Thanks for your explanation.

Quoted 10 lines
Quoted 7 lines
Quoted 6 lines

  rcu_read_lock();
  entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id); if (entry) {

Cheers,
Matt

author maintainer
#13 lore raw

PATCH v5 8/13 mptcp: pm: fullmesh: select the right ID later

In reply to Matthieu Baerts (NGI0)

When reacting upon the reception of an ADD_ADDR, the in-kernel PM first looks for fullmesh endpoints. If there are some, it will pick them, using their entry ID.

It should set the ID 0 when using the endpoint corresponding to the initial subflow, it is a special case imposed by the MPTCP specs.

Note that msk->mpc_endpoint_id might not be set when receiving the first ADD_ADDR from the server. So better to compare the addresses.

Fixes 1a0d6136c5f0 ("mptcp: local addresses fullmesh")

---
Notes:
- v4:
- Check that msk->first is not NULL.

---
 net/mptcp/pm_netlink.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/mptcp/pm_netlink.c +12 -1
index 6a1495fec7ae..bc9c2e40881e 100644
@@ -636,6 +636,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
 {
 	struct sock *sk = (struct sock *)msk;
 	struct mptcp_pm_addr_entry *entry;
+	struct mptcp_addr_info mpc_addr;
 	struct pm_nl_pernet *pernet;
 	unsigned int subflows_max;
 	int i = 0;
@@ -643,6 +644,9 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
 	pernet = pm_nl_get_pernet_from_msk(msk);
 	subflows_max = mptcp_pm_get_subflows_max(msk);
 
+	if (msk->first)
+		mptcp_local_address((struct sock_common *)msk->first, &mpc_addr);
+
 	rcu_read_lock();
 	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
 		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_FULLMESH))
@@ -653,7 +657,14 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
 
 		if (msk->pm.subflows < subflows_max) {
 			msk->pm.subflows++;
-			addrs[i++] = entry->addr;
+			addrs[i] = entry->addr;
+
+			/* Special case for ID0: set the correct ID */
+			if (msk->first &&
+			    mptcp_addresses_equal(&entry->addr, &mpc_addr, entry->addr.port))
+				addrs[i].id = 0;
+
+			i++;
 		}
 	}
 	rcu_read_unlock();
Signature · 1 line
2.45.2
author maintainer
#14 lore raw

PATCH v5 9/13 selftests: mptcp: join: validate fullmesh endp on 1st sf

In reply to Matthieu Baerts (NGI0)

This case was not covered, and the wrong ID was set before the previous commit.

The rest is not modified, it is just that it will increase the code coverage.

The right address ID can be verified by looking at the packet traces. We could automate that using Netfilter with some cBPF code for example, but that's always a bit cryptic. Packetdrill seems better fitted for that.

Fixes 4f49d63352da ("selftests: mptcp: add fullmesh testcases")
---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -0
index f609c02c6123..e4ac275366ce 100755
@@ -3058,6 +3058,7 @@ fullmesh_tests()
 	if reset "fullmesh test 1x1"; then
 		pm_nl_set_limits $ns1 1 3
 		pm_nl_set_limits $ns2 1 3
+		pm_nl_add_endpoint $ns2 10.0.1.2 flags subflow,fullmesh
 		pm_nl_add_endpoint $ns1 10.0.2.1 flags signal
 		fullmesh=1 speed=slow \
 			run_tests $ns1 $ns2 10.0.1.1
Signature · 1 line
2.45.2
reviewer
#15 lore raw

Re: [PATCH mptcp-net v5 09/13] selftests: mptcp: join: validate fullmesh endp on 1st sf

Quoted 30 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

This case was not covered, and the wrong ID was set before the previous
commit.

The rest is not modified, it is just that it will increase the code coverage.

The right address ID can be verified by looking at the packet traces. We
could automate that using Netfilter with some cBPF code for example, but
that's always a bit cryptic. Packetdrill seems better fitted for that.

Fixes 4f49d63352da ("selftests: mptcp: add fullmesh testcases")

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 1 +

 1 file changed, 1 insertion(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index f609c02c6123..e4ac275366ce 100755
@@ -3058,6 +3058,7 @@ fullmesh_tests()

  if reset "fullmesh test 1x1"; then
  pm_nl_set_limits $ns1 1 3
  pm_nl_set_limits $ns2 1 3

tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -0
+		pm_nl_add_endpoint $ns2 10.0.1.2 flags
Quoted 1 line

subflow,fullmesh

nit: add this line behind "pm_nl_add_endpoint $ns1 10.0.2.1 flags signal". Usually, set n1 first and then n2.

Quoted 4 lines

  pm_nl_add_endpoint $ns1 10.0.2.1 flags signal fullmesh=1 speed=slow \
  run_tests $ns1 $ns2 10.0.1.1

author maintainer
#16 lore raw

Re: [PATCH mptcp-net v5 09/13] selftests: mptcp: join: validate fullmesh endp on 1st sf

Hi Geliang,

Quoted 21 lines · Geliang Tang
Quoted 20 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

This case was not covered, and the wrong ID was set before the previous
commit.

The rest is not modified, it is just that it will increase the code coverage.

The right address ID can be verified by looking at the packet traces. We
could automate that using Netfilter with some cBPF code for example, but
that's always a bit cryptic. Packetdrill seems better fitted for that.

Fixes 4f49d63352da ("selftests: mptcp: add fullmesh testcases")

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 1 +

 1 file changed, 1 insertion(+)
Quoted 14 lines
Quoted 11 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index f609c02c6123..e4ac275366ce 100755
@@ -3058,6 +3058,7 @@ fullmesh_tests()

  if reset "fullmesh test 1x1"; then
  pm_nl_set_limits $ns1 1 3
  pm_nl_set_limits $ns2 1 3

tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -0
+		pm_nl_add_endpoint $ns2 10.0.1.2 flags

subflow,fullmesh

nit: add this line behind "pm_nl_add_endpoint $ns1 10.0.2.1 flags signal". Usually, set n1 first and then n2.

It looks like we have a mix, but yes, most of the time we set the endpoints for the ns1, then the ns2. I can fix that when applying the patches if there are no other big changes needed here.

Quoted 6 lines
Quoted 4 lines

  pm_nl_add_endpoint $ns1 10.0.2.1 flags signal fullmesh=1 speed=slow \
  run_tests $ns1 $ns2 10.0.1.1

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer
#17 lore raw

Re: [PATCH mptcp-net v5 09/13] selftests: mptcp: join: validate fullmesh endp on 1st sf

Quoted 42 lines · Matthieu Baerts

Hi Geliang,

Quoted 24 lines · Geliang Tang
Quoted 23 lines · On Fri, 2024-07-26 at 16:28 +0200, Matthieu Baerts (NGI0) wrote:

This case was not covered, and the wrong ID was set before the previous
commit.

The rest is not modified, it is just that it will increase the code
coverage.

The right address ID can be verified by looking at the packet traces.
We
could automate that using Netfilter with some cBPF code for example,
but
that's always a bit cryptic. Packetdrill seems better fitted for that.

Fixes 4f49d63352da ("selftests: mptcp: add fullmesh testcases")

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 1 +

 1 file changed, 1 insertion(+)
Quoted 14 lines
Quoted 11 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index f609c02c6123..e4ac275366ce 100755
@@ -3058,6 +3058,7 @@ fullmesh_tests()

  if reset "fullmesh test 1x1"; then
  pm_nl_set_limits $ns1 1 3
  pm_nl_set_limits $ns2 1 3

tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -0
+		pm_nl_add_endpoint $ns2 10.0.1.2 flags

subflow,fullmesh

nit: add this line behind "pm_nl_add_endpoint $ns1 10.0.2.1 flags signal". Usually, set n1 first and then n2.

Quoted 3 lines

It looks like we have a mix, but yes, most of the time we set the endpoints for the ns1, then the ns2. I can fix that when applying the patches if there are no other big changes needed here.

Sure, please update this when merging it.

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

  pm_nl_add_endpoint $ns1 10.0.2.1 flags signal fullmesh=1 speed=slow \
  run_tests $ns1 $ns2 10.0.1.1

Cheers,
Matt

author maintainer
#18 lore raw

PATCH v5 10/13 mptcp: pm: avoid possible UaF when selecting endp

In reply to Matthieu Baerts (NGI0)

select_local_address() and select_signal_address() both select an endpoint entry from the list inside an RCU protected section, but return a reference to it, to be read later on. If the entry is dereferenced after the RCU unlock, reading info could cause a Use-after-Free.

A simple solution is to copy the required info while inside the RCU protected section to avoid any risk of UaF later. The address ID might need to be modified later to handle the ID0 case later, so a copy seems OK to deal with.

Fixes 01cacb00b35c ("mptcp: add netlink-based PM")

---
Notes:
- v5:
- fix typo in title: s/whend/when/ (Mat)
- avoid using memcpy() when not needed (Paolo)

---
 net/mptcp/pm_netlink.c | 64 +++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 30 deletions(-)
net/mptcp/pm_netlink.c +34 -30
index bc9c2e40881e..0dacf16a4b53 100644
@@ -143,11 +143,13 @@ static bool lookup_subflow_by_daddr(const struct list_head *list,
 	return false;
 }
 
-static struct mptcp_pm_addr_entry *
+static bool
 select_local_address(const struct pm_nl_pernet *pernet,
-		     const struct mptcp_sock *msk)
+		     const struct mptcp_sock *msk,
+		     struct mptcp_pm_addr_entry *new_entry)
 {
-	struct mptcp_pm_addr_entry *entry, *ret = NULL;
+	struct mptcp_pm_addr_entry *entry;
+	bool found = false;
 
 	msk_owned_by_me(msk);
 
@@ -159,17 +161,21 @@ select_local_address(const struct pm_nl_pernet *pernet,
 		if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
 			continue;
 
-		ret = entry;
+		*new_entry = *entry;
+		found = true;
 		break;
 	}
 	rcu_read_unlock();
-	return ret;
+
+	return found;
 }
 
-static struct mptcp_pm_addr_entry *
-select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
+static bool
+select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,
+		      struct mptcp_pm_addr_entry *new_entry)
 {
-	struct mptcp_pm_addr_entry *entry, *ret = NULL;
+	struct mptcp_pm_addr_entry *entry;
+	bool found = false;
 
 	rcu_read_lock();
 	/* do not keep any additional per socket state, just signal
@@ -184,11 +190,13 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
 		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
 			continue;
 
-		ret = entry;
+		*new_entry = *entry;
+		found = true;
 		break;
 	}
 	rcu_read_unlock();
-	return ret;
+
+	return found;
 }
 
 unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk)
@@ -512,9 +520,10 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
 
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
-	struct mptcp_pm_addr_entry *local, *signal_and_subflow = NULL;
 	struct sock *sk = (struct sock *)msk;
+	struct mptcp_pm_addr_entry local;
 	unsigned int add_addr_signal_max;
+	bool signal_and_subflow = false;
 	unsigned int local_addr_max;
 	struct pm_nl_pernet *pernet;
 	unsigned int subflows_max;
@@ -565,23 +574,22 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
 			return;
 
-		local = select_signal_address(pernet, msk);
-		if (!local)
+		if (!select_signal_address(pernet, msk, &local))
 			goto subflow;
 
 		/* If the alloc fails, we are on memory pressure, not worth
 		 * continuing, and trying to create subflows.
 		 */
-		if (!mptcp_pm_alloc_anno_list(msk, &local->addr))
+		if (!mptcp_pm_alloc_anno_list(msk, &local.addr))
 			return;
 
-		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+		__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
 		msk->pm.add_addr_signaled++;
-		mptcp_pm_announce_addr(msk, &local->addr, false);
+		mptcp_pm_announce_addr(msk, &local.addr, false);
 		mptcp_pm_nl_addr_send_ack(msk);
 
-		if (local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
-			signal_and_subflow = local;
+		if (local.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+			signal_and_subflow = true;
 	}
 
 subflow:
@@ -592,26 +600,22 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		bool fullmesh;
 		int i, nr;
 
-		if (signal_and_subflow) {
-			local = signal_and_subflow;
-			signal_and_subflow = NULL;
-		} else {
-			local = select_local_address(pernet, msk);
-			if (!local)
-				break;
-		}
+		if (signal_and_subflow)
+			signal_and_subflow = false;
+		else if (!select_local_address(pernet, msk, &local))
+			break;
 
-		fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
+		fullmesh = !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
 
 		msk->pm.local_addr_used++;
-		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
-		nr = fill_remote_addresses_vec(msk, &local->addr, fullmesh, addrs);
+		__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
+		nr = fill_remote_addresses_vec(msk, &local.addr, fullmesh, addrs);
 		if (nr == 0)
 			continue;
 
 		spin_unlock_bh(&msk->pm.lock);
 		for (i = 0; i < nr; i++)
-			__mptcp_subflow_connect(sk, &local->addr, &addrs[i]);
+			__mptcp_subflow_connect(sk, &local.addr, &addrs[i]);
 		spin_lock_bh(&msk->pm.lock);
 	}
 	mptcp_pm_nl_check_work_pending(msk);
Signature · 1 line
2.45.2
author maintainer
#19 lore raw

PATCH v5 11/13 mptcp: pm: reuse ID 0 after delete and re-add

In reply to Matthieu Baerts (NGI0)

When the endpoint used by the initial subflow is removed and re-added later, the PM has to force the ID 0, it is a special case imposed by the MPTCP specs.

Note that the endpoint should then need to be re-added reusing the same ID.

Fixes 3ad14f54bd74 ("mptcp: more accurate MPC endpoint tracking")

---
Notes:
- v5:
- Add missing 'ID' in comment (Mat)

---
 net/mptcp/pm_netlink.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/mptcp/pm_netlink.c +9 -0
index 0dacf16a4b53..36e179f1f888 100644
@@ -585,6 +585,11 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 
 		__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
 		msk->pm.add_addr_signaled++;
+
+		/* Special case for ID0: set the correct ID */
+		if (local.addr.id == msk->mpc_endpoint_id)
+			local.addr.id = 0;
+
 		mptcp_pm_announce_addr(msk, &local.addr, false);
 		mptcp_pm_nl_addr_send_ack(msk);
 
@@ -613,6 +618,10 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (nr == 0)
 			continue;
 
+		/* Special case for ID0: set the correct ID */
+		if (local.addr.id == msk->mpc_endpoint_id)
+			local.addr.id = 0;
+
 		spin_unlock_bh(&msk->pm.lock);
 		for (i = 0; i < nr; i++)
 			__mptcp_subflow_connect(sk, &local.addr, &addrs[i]);
Signature · 1 line
2.45.2
author maintainer
#20 lore raw

PATCH v5 12/13 mptcp: pm: rename helpers linked to 'flush'

In reply to Matthieu Baerts (NGI0)

Rename all the helpers specific to the flushing operations to make it clear that the intention is to flush all created subflows, and remove all announced addresses, not just a specific selection.

That way, it is easier to understand why the id_avail_bitmap and local_addr_used are reset at the end.

---
Notes:
- This patch is for net-next
- v5:
- This patch has been extracted from "mptcp: pm: re-using ID of unused flushed subflows", without any other modifications.

---
 net/mptcp/pm_netlink.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/mptcp/pm_netlink.c +6 -6
index 36e179f1f888..53355f629846 100644
@@ -1644,8 +1644,8 @@ void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list)
 	}
 }
 
-static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
-					       struct list_head *rm_list)
+static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk,
+					      struct list_head *rm_list)
 {
 	struct mptcp_rm_list alist = { .nr = 0 }, slist = { .nr = 0 };
 	struct mptcp_pm_addr_entry *entry;
@@ -1673,8 +1673,8 @@ static void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 	spin_unlock_bh(&msk->pm.lock);
 }
 
-static void mptcp_nl_remove_addrs_list(struct net *net,
-				       struct list_head *rm_list)
+static void mptcp_nl_flush_addrs_list(struct net *net,
+				      struct list_head *rm_list)
 {
 	long s_slot = 0, s_num = 0;
 	struct mptcp_sock *msk;
@@ -1687,7 +1687,7 @@ static void mptcp_nl_remove_addrs_list(struct net *net,
 
 		if (!mptcp_pm_is_userspace(msk)) {
 			lock_sock(sk);
-			mptcp_pm_remove_addrs_and_subflows(msk, rm_list);
+			mptcp_pm_flush_addrs_and_subflows(msk, rm_list);
 			release_sock(sk);
 		}
 
@@ -1728,7 +1728,7 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info)
 	pernet->next_id = 1;
 	bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 	spin_unlock_bh(&pernet->lock);
-	mptcp_nl_remove_addrs_list(sock_net(skb->sk), &free_list);
+	mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list);
 	synchronize_rcu();
 	__flush_addrs(&free_list);
 	return 0;
Signature · 1 line
2.45.2
author maintainer
#21 lore raw

PATCH v5 13/13 mptcp: pm: reduce entries iterations on connect

In reply to Matthieu Baerts (NGI0)

__mptcp_subflow_connect() is currently called from the path-managers, which have all the required information to create subflows. No need to call the PM again to re-iterate over the list of entries with RCU lock to get more info.

Instead, it is possible to pass a mptcp_pm_addr_entry structure, instead of a mptcp_addr_info one. The former contains the ifindex and the flags that are required when creating the new subflow.

This is a partial revert of commit ee285257a9c1 ("mptcp: drop flags and ifindex arguments").

While at it, the local ID can also be set if it is known and 0, to avoid having to set it in the 'rebuild_header' hook, which will cause a new iteration of the endpoint entries.

---
Notes:
- This patch is for net-next
- v4:
- Avoid multiple copies of an addr entry in fill_local_addresses_vec().
- Rebased on top of "mptcp: fix endpoints with 'signal' and 'subflow'

     flags", v4.
 - v5:
   - Use CONFIG_MPTCP_IPV6 instead of CONFIG_IPV6 (Intel's Kernel robot)
   - Use new mptcp_pm_local struct, not to use mptcp_pm_addr_entry with
     only half of the info we need to reduce the memory reserved on the
     stack needed for the fill_*_addresses_vec() helpers to handle the
     fullmesh case. (Paolo)
     Note that we could also embed 'struct mptcp_pm_local' in 'struct
     mptcp_pm_addr_entry', but that means adapting that in quite a few
     places (171).
---
 net/mptcp/pm.c           | 11 --------
 net/mptcp/pm_netlink.c   | 66 ++++++++++++++++++------------------------------
 net/mptcp/pm_userspace.c | 40 ++++++++++-------------------
 net/mptcp/protocol.h     | 16 +++++-------
 net/mptcp/subflow.c      | 29 +++++++++++++--------
 5 files changed, 62 insertions(+), 100 deletions(-)
net/mptcp/pm.c +0 -11
index 3e6e0f5510bb..56c0a318e5df 100644
@@ -428,17 +428,6 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc)
 	return mptcp_pm_nl_is_backup(msk, &skc_local);
 }
 
-int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
-					 u8 *flags, int *ifindex)
-{
-	*flags = 0;
-	*ifindex = 0;
-
-	if (mptcp_pm_is_userspace(msk))
-		return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
-	return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex);
-}
-
 int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info)
 {
 	if (info->attrs[MPTCP_PM_ATTR_TOKEN])
net/mptcp/pm_netlink.c +24 -42

160 lines not on this page · raw message

net/mptcp/pm_userspace.c +13 -27
index 8eaa9fbe3e34..2cceded3a83a 100644
@@ -119,23 +119,6 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id)
 	return NULL;
 }
 
-int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
-						   unsigned int id,
-						   u8 *flags, int *ifindex)
-{
-	struct mptcp_pm_addr_entry *match;
-
-	spin_lock_bh(&msk->pm.lock);
-	match = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
-	spin_unlock_bh(&msk->pm.lock);
-	if (match) {
-		*flags = match->flags;
-		*ifindex = match->ifindex;
-	}
-
-	return 0;
-}
-
 int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
 				    struct mptcp_addr_info *skc)
 {
@@ -352,8 +335,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 	struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE];
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR];
-	struct mptcp_pm_addr_entry local = { 0 };
+	struct mptcp_pm_addr_entry entry = { 0 };
 	struct mptcp_addr_info addr_r;
+	struct mptcp_pm_local local;
 	struct mptcp_sock *msk;
 	int err = -EINVAL;
 	struct sock *sk;
@@ -379,18 +363,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 		goto create_err;
 	}
 
-	err = mptcp_pm_parse_entry(laddr, info, true, &local);
+	err = mptcp_pm_parse_entry(laddr, info, true, &entry);
 	if (err < 0) {
 		NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr");
 		goto create_err;
 	}
 
-	if (local.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
+	if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
 		GENL_SET_ERR_MSG(info, "invalid addr flags");
 		err = -EINVAL;
 		goto create_err;
 	}
-	local.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;
+	entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW;
 
 	err = mptcp_pm_parse_addr(raddr, info, &addr_r);
 	if (err < 0) {
@@ -398,27 +382,29 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 		goto create_err;
 	}
 
-	if (!mptcp_pm_addr_families_match(sk, &local.addr, &addr_r)) {
+	if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) {
 		GENL_SET_ERR_MSG(info, "families mismatch");
 		err = -EINVAL;
 		goto create_err;
 	}
 
-	err = mptcp_userspace_pm_append_new_local_addr(msk, &local, false);
+	err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false);
 	if (err < 0) {
 		GENL_SET_ERR_MSG(info, "did not match address and id");
 		goto create_err;
 	}
 
+	local.addr = entry.addr;
+	local.flags = entry.flags;
+	local.ifindex = entry.ifindex;
+
 	lock_sock(sk);
-
-	err = __mptcp_subflow_connect(sk, &local.addr, &addr_r);
-
+	err = __mptcp_subflow_connect(sk, &local, &addr_r);
 	release_sock(sk);
 
 	spin_lock_bh(&msk->pm.lock);
 	if (err)
-		mptcp_userspace_pm_delete_local_addr(msk, &local);
+		mptcp_userspace_pm_delete_local_addr(msk, &entry);
 	else
 		msk->pm.subflows++;
 	spin_unlock_bh(&msk->pm.lock);
net/mptcp/protocol.h +7 -9
index fcf6983ca555..22b7eff311f5 100644
@@ -236,6 +236,12 @@ struct mptcp_pm_data {
 	struct mptcp_rm_list rm_list_rx;
 };
 
+struct mptcp_pm_local {
+	struct mptcp_addr_info	addr;
+	u8			flags;
+	int			ifindex;
+};
+
 struct mptcp_pm_addr_entry {
 	struct list_head	list;
 	struct mptcp_addr_info	addr;
@@ -723,7 +729,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
 void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr);
 
 /* called with sk socket lock held */
-int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
+int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
 			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
 				struct socket **new_sock);
@@ -1016,14 +1022,6 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 struct mptcp_pm_add_entry *
 mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk,
 				const struct mptcp_addr_info *addr);
-int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
-					 unsigned int id,
-					 u8 *flags, int *ifindex);
-int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
-					    u8 *flags, int *ifindex);
-int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
-						   unsigned int id,
-						   u8 *flags, int *ifindex);
 int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
 int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info);
 int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info);
net/mptcp/subflow.c +18 -11
index a21c712350c3..a7fb4d46e024 100644
@@ -1561,26 +1561,24 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
 #endif
 }
 
-int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
+int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
 			    const struct mptcp_addr_info *remote)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct mptcp_subflow_context *subflow;
+	int local_id = local->addr.id;
 	struct sockaddr_storage addr;
 	int remote_id = remote->id;
-	int local_id = loc->id;
 	int err = -ENOTCONN;
 	struct socket *sf;
 	struct sock *ssk;
 	u32 remote_token;
 	int addrlen;
-	int ifindex;
-	u8 flags;
 
 	if (!mptcp_is_fully_established(sk))
 		goto err_out;
 
-	err = mptcp_subflow_create_socket(sk, loc->family, &sf);
+	err = mptcp_subflow_create_socket(sk, local->addr.family, &sf);
 	if (err)
 		goto err_out;
 
@@ -1590,23 +1588,32 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 		get_random_bytes(&subflow->local_nonce, sizeof(u32));
 	} while (!subflow->local_nonce);
 
-	if (local_id)
+	/* if 'IPADDRANY', the ID will be set later, after the routing */
+	if (local->addr.family == AF_INET) {
+		if (!local->addr.addr.s_addr)
+			local_id = -1;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	} else if (sk->sk_family == AF_INET6) {
+		if (ipv6_addr_any(&local->addr.addr6))
+			local_id = -1;
+#endif
+	}
+
+	if (local_id >= 0)
 		subflow_set_local_id(subflow, local_id);
 
-	mptcp_pm_get_flags_and_ifindex_by_id(msk, local_id,
-					     &flags, &ifindex);
 	subflow->remote_key_valid = 1;
 	subflow->remote_key = READ_ONCE(msk->remote_key);
 	subflow->local_key = READ_ONCE(msk->local_key);
 	subflow->token = msk->token;
-	mptcp_info2sockaddr(loc, &addr, ssk->sk_family);
+	mptcp_info2sockaddr(&local->addr, &addr, ssk->sk_family);
 
 	addrlen = sizeof(struct sockaddr_in);
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 	if (addr.ss_family == AF_INET6)
 		addrlen = sizeof(struct sockaddr_in6);
 #endif
-	ssk->sk_bound_dev_if = ifindex;
+	ssk->sk_bound_dev_if = local->ifindex;
 	err = kernel_bind(sf, (struct sockaddr *)&addr, addrlen);
 	if (err)
 		goto failed;
@@ -1617,7 +1624,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	subflow->remote_token = remote_token;
 	WRITE_ONCE(subflow->remote_id, remote_id);
 	subflow->request_join = 1;
-	subflow->request_bkup = !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP);
+	subflow->request_bkup = !!(local->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
 	subflow->subflow_id = msk->subflow_id++;
 	mptcp_info2sockaddr(remote, &addr, ssk->sk_family);
 
Signature · 1 line
2.45.2
#22 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10113181188

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/7fbdf5eb8c37
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=874103

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v5 series
#23 lore raw
In reply to Matthieu Baerts (NGI0)
Quoted 4 lines · On Fri, 26 Jul 2024, Matthieu Baerts (NGI0) wrote:

The first 11 patches have already been applied. Here are the remaining ones.

Quoted 10 lines

---
Changes in v5:
- Split patch 1 (previously 12): the renaming has been done in a
dedicated patch at the end (patch patch 12), for -next.
- Patch 10: fix typo and avoid memcpy.
- Patch 11: fix comment.
- Patch 13: fix build issue and use a new dedicated struct.
- Please see the individual changelog for more details.
- Link to v4: https://lore.kernel.org/r/[email protected]

Hi Matthieu -

v5 LGTM, with the "fix when applying" changes already discussed in this thread.

Quoted 52 lines

Changes in v4:
- Patch 19: check for msk->first != NULL
- New patches 21-22
- Imported patch 23: might be easier to review all of them, then this
single one alone, while it depends on the previous ones.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Small changes in patches 10 and 14, see individual changelog (Geliang)
- New patches 18-20: small fixes
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Do not split id_avail_bitmap per target in patch 5 (Paolo)
- Explicit deny (patch 2), reduce indentation (patch 3), stop earlier
(patch 4) (Paolo)
- New fixes and tests (patches 8-17).
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Matthieu Baerts (NGI0) (13):
mptcp: pm: re-using ID of unused flushed subflows
selftests: mptcp: join: test for flush/re-add endpoints
mptcp: pm: remove mptcp_pm_remove_subflow()
mptcp: pm: only mark 'subflow' endp as available
mptcp: pm: only decrement add_addr_accepted for MPJ req
mptcp: pm: check add_addr_accept_max before accepting new ADD_ADDR
mptcp: pm: only in-kernel cannot have entries with ID 0
mptcp: pm: fullmesh: select the right ID later
selftests: mptcp: join: validate fullmesh endp on 1st sf
mptcp: pm: avoid possible UaF when selecting endp
mptcp: pm: reuse ID 0 after delete and re-add
mptcp: pm: rename helpers linked to 'flush'
mptcp: pm: reduce entries iterations on connect

net/mptcp/pm.c                                  |  24 ---
net/mptcp/pm_netlink.c                          | 195 ++++++++++++++----------
net/mptcp/pm_userspace.c                        |  40 ++---
net/mptcp/protocol.h                            |  19 +--
net/mptcp/subflow.c                             |  29 ++--
tools/testing/selftests/net/mptcp/mptcp_join.sh |  31 ++++
6 files changed, 180 insertions(+), 158 deletions(-)

---
base-commit: a9a9b3b154d187864b73eb0e86a0ff737d79a10a
change-id: 20240620-mptcp-pm-avail-f5e3957be441

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#24 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Mat, Geliang,

Quoted 4 lines · On 26/07/2024 16:28, Matthieu Baerts (NGI0) wrote:

The first 11 patches have already been applied. Here are the remaining ones.

Quoted 9 lines

---
Changes in v5:
- Split patch 1 (previously 12): the renaming has been done in a
dedicated patch at the end (patch patch 12), for -next.
- Patch 10: fix typo and avoid memcpy.
- Patch 11: fix comment.
- Patch 13: fix build issue and use a new dedicated struct.
- Please see the individual changelog for more details.
- Link to v4: https://lore.kernel.org/r/[email protected]

Thank you for the reviews!

These patches are now in our tree (with the requested modification in patch 9/13)

New patches for t/upstream-net and t/upstream:
- 4fdf3e16474d: mptcp: pm: re-using ID of unused flushed subflows
- f4dcf600f081: selftests: mptcp: join: test for flush/re-add endpoints
- 54cd819d5f1f: mptcp: pm: remove mptcp_pm_remove_subflow()
- 5be0e90ef7d3: mptcp: pm: only mark 'subflow' endp as available
- fdf749c7585a: mptcp: pm: only decrement add_addr_accepted for MPJ req
- 6eb489c794e8: mptcp: pm: check add_addr_accept_max before accepting new ADD_ADDR
- 91dc97dedafa: mptcp: pm: only in-kernel cannot have entries with ID 0
- 3cc3d86a170e: mptcp: pm: fullmesh: select the right ID later
- 19c879bdde12: selftests: mptcp: join: validate fullmesh endp on 1st sf
- b84992e37697: mptcp: pm: avoid possible UaF when selecting endp
- ba96900cae7a: mptcp: pm: reuse ID 0 after delete and re-add
- Results: 36737d2814d6..6cd1e6d73592 (export-net)
- Results: dec783f2e72a..2f4228f46030 (export)

New patches for t/upstream:
- 1d3e4f41c9fc: mptcp: pm: rename helpers linked to 'flush'
- 54792ce59a08: mptcp: pm: reduce entries iterations on connect
- Results: 2f4228f46030..6197303cc231 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/af4eff14c4262c736783183997c94795ccff10d0/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/2ec038c21e3561ad3df17324253524d53d6ff97b/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.