MPTCP Linux Development
 help / color / mirror / Atom feed
* [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
@ 2026-05-22  8:46 Tao Cui
  2026-05-22  8:46 ` [PATCH mptcp-net v4 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM subflow creation Tao Cui
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tao Cui @ 2026-05-22  8:46 UTC (permalink / raw)
  To: matttbe, geliang; +Cc: mptcp, Tao Cui

This is v4 of the series that fixes extra_subflows u8 underflow bugs
in the MPTCP userspace path manager.

extra_subflows is a u8 field in struct mptcp_pm_data. The userspace PM
increments it after __mptcp_subflow_connect() succeeds, but
__mptcp_subflow_connect() calls mptcp_pm_close_subflow() on failure to
roll back the pre-increment done by the kernel PM. Because the userspace
PM hasn't incremented yet at that point, this decrement is spurious and
causes extra_subflows to underflow from 0 to 255.

Patch 1 fixes the underflow by aligning the userspace PM with the kernel
PM: increment extra_subflows before calling __mptcp_subflow_connect(),
so the existing error path in subflow.c correctly rolls it back on
failure. This also eliminates the race window described in v3 patch 2
where the worker could decrement before the user thread increments.

Patch 2 adds a selftest to validate that subflow creation failure with
an unreachable address does not corrupt the extra_subflows counter.

Tao Cui (2):
  mptcp: pm: fix extra_subflows underflow on userspace PM subflow
    creation
  selftests: mptcp: add test for extra_subflows underflow on userspace
    PM

 net/mptcp/pm_userspace.c                        | 14 ++++++++------
 tools/testing/selftests/net/mptcp/mptcp_join.sh |  4 ++++
 2 files changed, 12 insertions(+), 6 deletions(-)

---
Changes in v4:
  - Rework patch 1 per Mat's review: instead of gating
    mptcp_pm_close_subflow() on the PM type in subflow.c, move
    extra_subflows++ before __mptcp_subflow_connect() in the userspace
    PM to align with the kernel PM behavior. No changes to subflow.c.
  - Simplify error handling in userspace PM: take pm.lock only on
    failure for cleanup.
  - Add selftest (patch 2) as suggested by Mat.
  - Drop the previous race fix (v3 patch 2), as it is no longer needed
    once the increment is moved before the call.

Changes in v3:
  - Patch 2: move extra_subflows++ before release_sock(sk) to close
    the race window, instead of relying solely on the underflow guard.

Changes in v2:
  - Dropped the use-after-free fix.
  - Split the underflow fix into two patches, one per code path.

v1:
  https://lore.kernel.org/all/20260509075629.217791-2-cuitao@kylinos.cn/
v3:
  https://lore.kernel.org/all/20260514132925.410184-1-cuitao@kylinos.cn/

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH mptcp-net v4 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM subflow creation
  2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
@ 2026-05-22  8:46 ` Tao Cui
  2026-05-22  8:46 ` [PATCH mptcp-net v4 2/2] selftests: mptcp: add test for extra_subflows underflow on userspace PM Tao Cui
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Cui @ 2026-05-22  8:46 UTC (permalink / raw)
  To: matttbe, geliang; +Cc: mptcp, Tao Cui

The userspace PM increments extra_subflows after __mptcp_subflow_connect()
succeeds, but __mptcp_subflow_connect() calls mptcp_pm_close_subflow()
on failure to roll back the pre-increment done by the kernel PM's fill_*()
helpers. Because the userspace PM hasn't incremented yet at that point,
this decrement is spurious and causes extra_subflows to underflow.

Fix it by aligning the userspace PM with the kernel PM: increment
extra_subflows before calling __mptcp_subflow_connect(), so the existing
error path in subflow.c correctly rolls it back on failure. Also simplify
the error handling by taking pm.lock only when needed for cleanup.

Fixes: 77e4b94a3de6 ("mptcp: update userspace pm infos")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
 net/mptcp/pm_userspace.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 8cbc1920afb4..0d3a95e676f1 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -408,19 +408,21 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
 	local.flags = entry.flags;
 	local.ifindex = entry.ifindex;
 
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.extra_subflows++;
+	spin_unlock_bh(&msk->pm.lock);
+
 	lock_sock(sk);
 	err = __mptcp_subflow_connect(sk, &local, &addr_r);
 	release_sock(sk);
 
-	if (err)
+	if (err) {
 		GENL_SET_ERR_MSG_FMT(info, "connect error: %d", err);
 
-	spin_lock_bh(&msk->pm.lock);
-	if (err)
+		spin_lock_bh(&msk->pm.lock);
 		mptcp_userspace_pm_delete_local_addr(msk, &entry);
-	else
-		msk->pm.extra_subflows++;
-	spin_unlock_bh(&msk->pm.lock);
+		spin_unlock_bh(&msk->pm.lock);
+	}
 
  create_err:
 	sock_put(sk);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH mptcp-net v4 2/2] selftests: mptcp: add test for extra_subflows underflow on userspace PM
  2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
  2026-05-22  8:46 ` [PATCH mptcp-net v4 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM subflow creation Tao Cui
@ 2026-05-22  8:46 ` Tao Cui
  2026-05-22 10:26 ` [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for " MPTCP CI
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tao Cui @ 2026-05-22  8:46 UTC (permalink / raw)
  To: matttbe, geliang; +Cc: mptcp, Tao Cui

Add a test to verify that when userspace PM fails to create a subflow
(e.g. using an unreachable address), the extra_subflows counter is not
decremented below zero.

Fixes: 77e4b94a3de6 ("mptcp: update userspace pm infos")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index c6bb345d056b..3a8d6c665055 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -4098,6 +4098,10 @@ userspace_tests()
 		chk_rm_nr 0 1
 		chk_mptcp_info subflows 0 subflows 0
 		chk_subflows_total 1 1
+		# check counters are not affected by errors at creation time
+		userspace_pm_add_sf $ns2 10.0.12.2 10 2>/dev/null
+		chk_mptcp_info subflows 0 subflows 0
+		chk_subflows_total 1 1
 		kill_events_pids
 		mptcp_lib_kill_group_wait $tests_pid
 	fi
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
  2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
  2026-05-22  8:46 ` [PATCH mptcp-net v4 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM subflow creation Tao Cui
  2026-05-22  8:46 ` [PATCH mptcp-net v4 2/2] selftests: mptcp: add test for extra_subflows underflow on userspace PM Tao Cui
@ 2026-05-22 10:26 ` MPTCP CI
  2026-05-27 11:20 ` Matthieu Baerts
  2026-05-27 11:34 ` Matthieu Baerts
  4 siblings, 0 replies; 6+ messages in thread
From: MPTCP CI @ 2026-05-22 10:26 UTC (permalink / raw)
  To: Tao Cui; +Cc: mptcp

Hi Tao,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_mp_capable ⚠️ 
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/26278624724

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


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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
  2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
                   ` (2 preceding siblings ...)
  2026-05-22 10:26 ` [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for " MPTCP CI
@ 2026-05-27 11:20 ` Matthieu Baerts
  2026-05-27 11:34 ` Matthieu Baerts
  4 siblings, 0 replies; 6+ messages in thread
From: Matthieu Baerts @ 2026-05-27 11:20 UTC (permalink / raw)
  To: Tao Cui, geliang; +Cc: mptcp

Hi Tao,

On 22/05/2026 18:46, Tao Cui wrote:
> This is v4 of the series that fixes extra_subflows u8 underflow bugs
> in the MPTCP userspace path manager.
> 
> extra_subflows is a u8 field in struct mptcp_pm_data. The userspace PM
> increments it after __mptcp_subflow_connect() succeeds, but
> __mptcp_subflow_connect() calls mptcp_pm_close_subflow() on failure to
> roll back the pre-increment done by the kernel PM. Because the userspace
> PM hasn't incremented yet at that point, this decrement is spurious and
> causes extra_subflows to underflow from 0 to 255.
> 
> Patch 1 fixes the underflow by aligning the userspace PM with the kernel
> PM: increment extra_subflows before calling __mptcp_subflow_connect(),
> so the existing error path in subflow.c correctly rolls it back on
> failure. This also eliminates the race window described in v3 patch 2
> where the worker could decrement before the user thread increments.
> 
> Patch 2 adds a selftest to validate that subflow creation failure with
> an unreachable address does not corrupt the extra_subflows counter.
Thank you for the v4, the series looks good to me:

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
  2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
                   ` (3 preceding siblings ...)
  2026-05-27 11:20 ` Matthieu Baerts
@ 2026-05-27 11:34 ` Matthieu Baerts
  4 siblings, 0 replies; 6+ messages in thread
From: Matthieu Baerts @ 2026-05-27 11:34 UTC (permalink / raw)
  To: Tao Cui, geliang; +Cc: mptcp

Hi Tao,

On 22/05/2026 18:46, Tao Cui wrote:
> This is v4 of the series that fixes extra_subflows u8 underflow bugs
> in the MPTCP userspace path manager.
> 
> extra_subflows is a u8 field in struct mptcp_pm_data. The userspace PM
> increments it after __mptcp_subflow_connect() succeeds, but
> __mptcp_subflow_connect() calls mptcp_pm_close_subflow() on failure to
> roll back the pre-increment done by the kernel PM. Because the userspace
> PM hasn't incremented yet at that point, this decrement is spurious and
> causes extra_subflows to underflow from 0 to 255.
> 
> Patch 1 fixes the underflow by aligning the userspace PM with the kernel
> PM: increment extra_subflows before calling __mptcp_subflow_connect(),
> so the existing error path in subflow.c correctly rolls it back on
> failure. This also eliminates the race window described in v3 patch 2
> where the worker could decrement before the user thread increments.
> 
> Patch 2 adds a selftest to validate that subflow creation failure with
> an unreachable address does not corrupt the extra_subflows counter.
Now in our tree:

New patches for t/upstream-net and t/upstream:
- 39532fa9ab3a: mptcp: pm: fix extra_subflows underflow on userspace PM
subflow creation
- f4c28694fcb2: selftests: mptcp: add test for extra_subflows underflow
on userspace PM
- Results: e4d7ed773e9a..a6fc1cc14ba0 (export-net)
- Results: e10477e57c2f..c40ac68d9bc2 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/a5802653c80bed89b89dfb2bcf7a1d27a9ccbb05/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/c556587fb705370c99b07b8eae2f23e16e6bb145/checks

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-27 11:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22  8:46 [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
2026-05-22  8:46 ` [PATCH mptcp-net v4 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM subflow creation Tao Cui
2026-05-22  8:46 ` [PATCH mptcp-net v4 2/2] selftests: mptcp: add test for extra_subflows underflow on userspace PM Tao Cui
2026-05-22 10:26 ` [PATCH mptcp-net v4 0/2] mptcp: pm: fix extra_subflows underflow for " MPTCP CI
2026-05-27 11:20 ` Matthieu Baerts
2026-05-27 11:34 ` Matthieu Baerts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox