From: Josef Bacik <jos…@toxicpanda.com>
There is room for one received list of address ids. An RM_ADDR that
arrives before the worker has taken the previous one is counted as
RmAddrDrop and forgotten, although the netlink events for its ids have
been sent already. Two options follow each other at once if, for
instance, the path manager in user space of the peer removes two of its
addresses. The subflows to the second address stay.
Add the new ids to the pending list. Only the ids that do not fit in
the list of MPTCP_RM_IDS_MAX ids are dropped, and the RM_ADDR is then
counted as RmAddrDrop. The netlink events are not sent for the
dropped ids, and they are sent before the worker can act on the others.
This issue has been found with the help of an LLM. It has not been
reproduced: the second RM_ADDR has to be processed before the PM worker
gets to the first one, a window that a Packetdrill script cannot
target. This fix is based on code inspection only, which is acceptable
here: the issue is clear from the code, and the fix is simple.
Fixes: d0876b2284cf ("mptcp: add the incoming RM_ADDR support")
Signed-off-by: Josef Bacik <jos…@toxicpanda.com>
[ Commit message: only the ids that do not fit are dropped + how the
issue was found, and why it is fine without a reproducer. No netlink
event for the dropped ids. ]
Signed-off-by: Matthieu Baerts (NGI0) <matt…@kernel.org>
---
net/mptcp/pm.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index fd8dc1132ad1..dacd3cf358f5 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -843,17 +843,30 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk,
const struct mptcp_rm_list *rm_list)
{
struct mptcp_pm_data *pm = &msk->pm;
+ bool drop = false;
u8 i;
pr_debug("msk=%p remote_ids_nr=%d\n", msk, rm_list->nr);
- for (i = 0; i < rm_list->nr; i++)
- mptcp_event_addr_removed(msk, rm_list->ids[i]);
-
spin_lock_bh(&pm->lock);
if (mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED))
- pm->rm_list_rx = *rm_list;
- else
+ pm->rm_list_rx.nr = 0;
+
+ /* the worker may not have got to the previous RM_ADDR yet */
+ for (i = 0; i < rm_list->nr; i++) {
+ u8 id = rm_list->ids[i];
+
+ if (!memchr(pm->rm_list_rx.ids, id, pm->rm_list_rx.nr)) {
+ if (pm->rm_list_rx.nr == MPTCP_RM_IDS_MAX) {
+ drop = true;
+ continue;
+ }
+ pm->rm_list_rx.ids[pm->rm_list_rx.nr++] = id;
+ }
+ /* not for the dropped ids, and before the worker acts */
+ mptcp_event_addr_removed(msk, id);
+ }
+ if (drop)
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_RMADDRDROP);
spin_unlock_bh(&pm->lock);
}
--
2.55.0