The in-kernel path manager can classify the endpoint linked to the initial
subflow as ID 0 even when that endpoint has a nonzero port. The resulting
port-bearing ID 0 ADD_ADDR is stored with that port, but ID 0 removal looks
for the required portless form. The stale announcement then makes a later
announcement hit the warning in mptcp_pm_announced_alloc().
Normalize MPC endpoint lookups to port zero, and only rewrite an endpoint's
ID to 0 when its port is zero. This prevents the invalid port-bearing ID 0
entry instead of making removal accept it.
Fixes: 2ac7d6e62076 ("mptcp: pm: kernel: drop pending ADD_ADDR when removing ID0")
Suggested-by: Matthieu Baerts <matt…@kernel.org>
Signed-off-by: Kyuwon Cho <kyuw…@skku.edu>
---
Changes in v2:
- Redesign the fix as suggested by Matthieu Baerts: a port-bearing endpoint
cannot become ID 0, and MPC endpoint lookups use the portless form.
- This also avoids accepting a port-specific ID 0 removal and leaves ID
allocation to existing endpoint registration, covering both Sashiko v1
findings.
- Rebase onto the current net tip.
v1: https://lore.kernel.org/all/1796…@skku.edu/
review reply: https://lore.kernel.org/all/1796…@skku.edu/
This issue was found by an LLM-guided test generator used in our research prototype.
A reproducer is available on request.
net/mptcp/pm_kernel.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
index f7396628490e..0c16812c4d36 100644
--- a/net/mptcp/pm_kernel.c
+++ b/net/mptcp/pm_kernel.c
@@ -314,6 +314,7 @@ static void mptcp_mpc_endpoint_setup(struct mptcp_sock *msk)
pernet = pm_nl_get_pernet_from_msk(msk);
mptcp_local_address((struct sock_common *)msk->first, &mpc_addr);
+ mpc_addr.port = 0; /* entries for ID0 don't have a specific port */
rcu_read_lock();
entry = __lookup_addr(pernet, &mpc_addr);
if (entry) {
@@ -368,7 +369,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
/* Special case for ID0: set the correct ID */
endp_id = local.addr.id;
- if (endp_id == msk->mpc_endpoint_id)
+ if (endp_id == msk->mpc_endpoint_id && local.addr.port == 0)
local.addr.id = 0;
/* If the alloc fails, we are on memory pressure, not worth
@@ -409,7 +410,7 @@ subflow:
__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
/* Special case for ID0: set the correct ID */
- if (local.addr.id == msk->mpc_endpoint_id)
+ if (local.addr.id == msk->mpc_endpoint_id && !local.addr.port)
local.addr.id = 0;
else /* local_addr_used is not decr for ID 0 */
msk->pm.local_addr_used++;
@@ -975,6 +976,7 @@ static int mptcp_nl_add_subflow_or_signal_addr(struct net *net,
/* if the endp linked to the init sf is re-added with a != ID */
mptcp_local_address((struct sock_common *)msk, &mpc_addr);
+ mpc_addr.port = 0; /* entries for ID0 don't have a port */
lock_sock(sk);
spin_lock_bh(&msk->pm.lock);
--
2.43.0