* [PATCH mptcp-next v3 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM connect failure
2026-05-14 13:29 [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
@ 2026-05-14 13:29 ` Tao Cui
2026-05-14 13:29 ` [PATCH mptcp-next v3 2/2] mptcp: pm: fix extra_subflows leak on userspace PM subflow close race Tao Cui
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Tao Cui @ 2026-05-14 13:29 UTC (permalink / raw)
To: matttbe, martineau, geliang, davem, edumazet, kuba, pabeni
Cc: horms, mptcp, Tao Cui
__mptcp_subflow_connect() calls mptcp_pm_close_subflow() on failure
to roll back the pre-increment done by kernel PM's fill_*() helpers.
The userspace PM does not pre-increment — it only increments after
__mptcp_subflow_connect() succeeds — so this decrement is spurious.
Fix it by gating mptcp_pm_close_subflow() on the PM type.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
net/mptcp/subflow.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index d562e149606f..c45ad67cb650 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1716,7 +1716,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
/* we account subflows before the creation, and this failures will not
* be caught by sk_state_change()
*/
- mptcp_pm_close_subflow(msk);
+ if (!mptcp_pm_is_userspace(msk))
+ mptcp_pm_close_subflow(msk);
return err;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH mptcp-next v3 2/2] mptcp: pm: fix extra_subflows leak on userspace PM subflow close race
2026-05-14 13:29 [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
2026-05-14 13:29 ` [PATCH mptcp-next v3 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM connect failure Tao Cui
@ 2026-05-14 13:29 ` Tao Cui
2026-05-14 14:02 ` [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Jakub Kicinski
2026-05-14 14:44 ` MPTCP CI
3 siblings, 0 replies; 6+ messages in thread
From: Tao Cui @ 2026-05-14 13:29 UTC (permalink / raw)
To: matttbe, martineau, geliang, davem, edumazet, kuba, pabeni
Cc: horms, mptcp, Tao Cui
In the userspace PM subflow creation path, extra_subflows is incremented
after release_sock(sk). If a TCP RST arrives for the newly created
subflow, mptcp_worker can acquire the socket lock during the gap between
release_sock(sk) and the subsequent spin_lock_bh(&msk->pm.lock), close
the subflow via mptcp_pm_subflow_check_next(), and decrement the counter
before it was incremented -- causing a u8 underflow from 0 to 255.
Move extra_subflows++ into the lock_sock(sk) section, before
release_sock(sk), so that the worker always sees a non-zero counter and
decrements correctly. This also eliminates the transient underflow window
visible to lockless readers (e.g. sosockopt READ_ONCE).
Additionally, add an underflow guard in mptcp_pm_subflow_check_next() as
a safety net for other edge cases.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
net/mptcp/pm.c | 3 ++-
net/mptcp/pm_userspace.c | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 3c152bf66cd5..a83a56b467f9 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -655,7 +655,8 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk,
if (mptcp_pm_is_userspace(msk)) {
if (update_subflows) {
spin_lock_bh(&pm->lock);
- pm->extra_subflows--;
+ if (pm->extra_subflows)
+ pm->extra_subflows--;
spin_unlock_bh(&pm->lock);
}
return;
diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 8cbc1920afb4..61c10ec00be0 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -410,6 +410,11 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
lock_sock(sk);
err = __mptcp_subflow_connect(sk, &local, &addr_r);
+ if (!err) {
+ spin_lock_bh(&msk->pm.lock);
+ msk->pm.extra_subflows++;
+ spin_unlock_bh(&msk->pm.lock);
+ }
release_sock(sk);
if (err)
@@ -418,8 +423,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
spin_lock_bh(&msk->pm.lock);
if (err)
mptcp_userspace_pm_delete_local_addr(msk, &entry);
- else
- msk->pm.extra_subflows++;
spin_unlock_bh(&msk->pm.lock);
create_err:
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
2026-05-14 13:29 [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
2026-05-14 13:29 ` [PATCH mptcp-next v3 1/2] mptcp: pm: fix extra_subflows underflow on userspace PM connect failure Tao Cui
2026-05-14 13:29 ` [PATCH mptcp-next v3 2/2] mptcp: pm: fix extra_subflows leak on userspace PM subflow close race Tao Cui
@ 2026-05-14 14:02 ` Jakub Kicinski
2026-05-14 16:00 ` Matthieu Baerts
2026-05-14 14:44 ` MPTCP CI
3 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2026-05-14 14:02 UTC (permalink / raw)
To: Tao Cui; +Cc: matttbe, martineau, geliang, davem, edumazet, pabeni, horms,
mptcp
On Thu, 14 May 2026 21:29:23 +0800 Tao Cui wrote:
> To: matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Please don't CC maintainers without CCing the mailing list associated
with their area. If you're CCing core networking maintainers you should
also CC netdev@
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
2026-05-14 14:02 ` [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Jakub Kicinski
@ 2026-05-14 16:00 ` Matthieu Baerts
0 siblings, 0 replies; 6+ messages in thread
From: Matthieu Baerts @ 2026-05-14 16:00 UTC (permalink / raw)
To: Tao Cui
Cc: martineau, geliang, davem, edumazet, pabeni, horms, mptcp,
Jakub Kicinski
Hi Tao,
14 May 2026 17:02:20 Jakub Kicinski <kuba@kernel.org>:
> On Thu, 14 May 2026 21:29:23 +0800 Tao Cui wrote:
>> To: matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
>
> Please don't CC maintainers without CCing the mailing list associated
> with their area. If you're CCing core networking maintainers you should
> also CC netdev@
Indeed, thank you. And if you are using the mptcp-next prefix, please
don't cc the netdev mailing list.
Cheers,
Matt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM
2026-05-14 13:29 [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Tao Cui
` (2 preceding siblings ...)
2026-05-14 14:02 ` [PATCH mptcp-next v3 0/2] mptcp: pm: fix extra_subflows underflow for userspace PM Jakub Kicinski
@ 2026-05-14 14:44 ` MPTCP CI
3 siblings, 0 replies; 6+ messages in thread
From: MPTCP CI @ 2026-05-14 14:44 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: 2 failed test(s): packetdrill_dss packetdrill_sockopts ⚠️
- 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/25863948276
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/dec78c185606
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1094801
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