Skip to content

Commit 322ea37

Browse files
matttbekuba-moo
authored andcommitted
mptcp: pm: only mark 'subflow' endp as available
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: 06faa22 ("mptcp: remove multi addresses and subflows in PM") Cc: [email protected] Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f448451 commit 322ea37

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

net/mptcp/pm_netlink.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,10 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
833833
if (rm_type == MPTCP_MIB_RMSUBFLOW)
834834
__MPTCP_INC_STATS(sock_net(sk), rm_type);
835835
}
836-
if (rm_type == MPTCP_MIB_RMSUBFLOW)
837-
__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap);
838-
else if (rm_type == MPTCP_MIB_RMADDR)
836+
837+
if (rm_type == MPTCP_MIB_RMADDR)
839838
__MPTCP_INC_STATS(sock_net(sk), rm_type);
839+
840840
if (!removed)
841841
continue;
842842

@@ -846,8 +846,6 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
846846
if (rm_type == MPTCP_MIB_RMADDR) {
847847
msk->pm.add_addr_accepted--;
848848
WRITE_ONCE(msk->pm.accept_addr, true);
849-
} else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
850-
msk->pm.local_addr_used--;
851849
}
852850
}
853851
}
@@ -1441,6 +1439,14 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
14411439
return ret;
14421440
}
14431441

1442+
static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id)
1443+
{
1444+
/* If it was marked as used, and not ID 0, decrement local_addr_used */
1445+
if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap) &&
1446+
id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0))
1447+
msk->pm.local_addr_used--;
1448+
}
1449+
14441450
static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
14451451
const struct mptcp_pm_addr_entry *entry)
14461452
{
@@ -1474,11 +1480,11 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net,
14741480
spin_lock_bh(&msk->pm.lock);
14751481
mptcp_pm_nl_rm_subflow_received(msk, &list);
14761482
spin_unlock_bh(&msk->pm.lock);
1477-
} else if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
1478-
/* If the subflow has been used, but now closed */
1483+
}
1484+
1485+
if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
14791486
spin_lock_bh(&msk->pm.lock);
1480-
if (!__test_and_set_bit(entry->addr.id, msk->pm.id_avail_bitmap))
1481-
msk->pm.local_addr_used--;
1487+
__mark_subflow_endp_available(msk, list.ids[0]);
14821488
spin_unlock_bh(&msk->pm.lock);
14831489
}
14841490

@@ -1516,6 +1522,7 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
15161522
spin_lock_bh(&msk->pm.lock);
15171523
mptcp_pm_remove_addr(msk, &list);
15181524
mptcp_pm_nl_rm_subflow_received(msk, &list);
1525+
__mark_subflow_endp_available(msk, 0);
15191526
spin_unlock_bh(&msk->pm.lock);
15201527
release_sock(sk);
15211528

@@ -1917,6 +1924,7 @@ static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk,
19171924

19181925
spin_lock_bh(&msk->pm.lock);
19191926
mptcp_pm_nl_rm_subflow_received(msk, &list);
1927+
__mark_subflow_endp_available(msk, list.ids[0]);
19201928
mptcp_pm_create_subflow_or_signal_addr(msk);
19211929
spin_unlock_bh(&msk->pm.lock);
19221930
}

0 commit comments

Comments
 (0)