mptcp: pm: fix reachable extra_subflows guards
Subsystems (2)
cover mptcp: pm: fix reachable extra_subflows guards
From: Tao Cui <[email protected]>
Hi,
Following up on issue #629, here is a fix series for the two paths reported against e99c1ca871 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow").
Patch 1 bounds the userspace PM admission at U8_MAX, so the u8 can no longer be wrapped by a peer establishing more than 255 subflows.
Patch 2 addresses the disconnect() vs MP_JOIN race: as discussed, the decrement sites now check the msk state first and skip the accounting when the msk is already in TCP_CLOSE, as the state is set before mptcp_pm_data_reset() clears the counters, and once the msk is closed the accounting is not relevant anymore. No new lock is involved. The guards themselves are downgraded to a clamp with a rate-limited pr_warn(), as the warn was reachable and turned into a remotely triggerable panic on panic_on_warn kernels.
Both patches carry a Link: to the issue with the detailed analysis.
Validated with the virtme CI (mptcp selftests), and with a stress repro comparing the base kernel and the patched one: on the base kernel the server accepts 256 MP_JOINs and the counter wraps to 0, with the patches admission stops at 255 and the leftover imbalance only shows up as a rate-limited warning.
Tao Cui (2):
mptcp: pm: bound extra_subflows admission on userspace PM
mptcp: pm: skip extra_subflows accounting on disconnected msk
net/mptcp/pm.c | 22 +++++++++++++++++++--- net/mptcp/protocol.h | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-)
--
2.43.0
PATCH 1/2 mptcp: pm: bound extra_subflows admission on userspace PM
From: Tao Cui <[email protected]>
mptcp_pm_allow_new_subflow() increments the u8 extra_subflows counter for every accepted MP_JOIN on sockets using the userspace PM, without any limit. A peer establishing more than 255 live subflows wraps the counter back to 0, which then makes the underflow guards warn on the next subflow close, and permanently corrupts mptcpi_subflows_total reported to userspace.
Refuse new MP_JOINs once the counter has reached U8_MAX, so that it cannot wrap anymore.
--- net/mptcp/pm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/mptcp/pm.c +9 -2
@@ -562,10 +562,17 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)if (mptcp_pm_is_userspace (msk)) {if (mptcp_userspace_pm_active (msk)) { +bool allow; + +/* extra_subflows is a u8: don't let a peer wrap it +* with more than U8_MAX accepted MP_JOINs +*/ spin_lock_bh (&pm->lock); - pm->extra_subflows++; + allow = pm->extra_subflows <U8_MAX ; +if (allow) + pm->extra_subflows++;spin_unlock_bh (&pm->lock); -return true; +return allow; }return false; }
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 1/2] mptcp: pm: bound extra_subflows admission on userspace PM
Hi Tao,
+ cc Quanye
Quoted 9 lines · Tao Cui
From: Tao Cui <[email protected]>
mptcp_pm_allow_new_subflow()increments the u8extra_subflowscounter for every acceptedMP_JOINon sockets using the userspace PM, without any limit. A peer establishing more than 255 live subflows wraps the counter back to 0, which then makes the underflow guards warn on the next subflow close, and permanently corruptsmptcpi_subflows_totalreported to userspace.
Quoted 5 lines
Refuse new
MP_JOINsonce the counter has reachedU8_MAX, so that it cannot wrap anymore.Fixes e99c1ca89071 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow")
Do you have a GitHub account? Just to know if we can assign this task to you (or just leave a message in the comment section).
Quoted 10 lines
Signed-off-by Tao Cui <[email protected]>--- net/mptcp/pm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 565
Quoted 4 lines
net/mptcp/pm.c +1
-0@@ -562,10 +562,17 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)if (mptcp_pm_is_userspace (msk)) {if (mptcp_userspace_pm_active (msk)) { +bool allow;
"ret" could be re-used here.
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 569
Quoted 4 lines
net/mptcp/pm.c +4
-0+ +/* extra_subflows is a u8: don't let a peer wrap it +* with more than U8_MAX accepted MP_JOINs +*/
I don't think this comment is needed, "< U8_MAX" is probably clear enough.
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 578
Quoted 11 lines
net/mptcp/pm.c +4
-2spin_lock_bh (&pm->lock); - pm->extra_subflows++; + allow = pm->extra_subflows <U8_MAX ; +if (allow) + pm->extra_subflows++;spin_unlock_bh (&pm->lock); -return true; +return allow; }return false; }
So, at the end, we can re-used the same version as Quanye. Would it be OK for both of you to have a Co-developed-by tag here?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Re: [PATCH mptcp-next 1/2] mptcp: pm: bound extra_subflows admission on userspace PM
Hi Matt, Tao,
Quoted 2 lines · Matthieu Baerts
So, at the end, we can re-used the same version as Quanye. Would it be OK for both of you to have a Co-developed-by tag here?
Fine with me. Please reuse ret and drop the comment in v2, with Co-developed-by tags for both of us.
Quoted 5 lines · Matthieu Baerts
Maybe a goto could be used here ... to here, not to modify the rest of the code?
Would it be OK for both of you if this part of Quanye's patch is added to Tao's v2 series with Quanye as author?
Also fine. Please take the Netlink extra_subflows cap in v2 with me as author, using a goto to the existing error cleanup instead of the else-wrapping I sent.
I will not send a competing series.
Thanks,
Quanye
Re: [PATCH mptcp-next 1/2] mptcp: pm: bound extra_subflows admission on userspace PM
Hi Quanye,
Quoted 13 lines · quanyeyang
Hi Matt, Tao,
Quoted 2 lines · Matthieu Baerts
So, at the end, we can re-used the same version as Quanye. Would it be OK for both of you to have a Co-developed-by tag here?
Fine with me. Please reuse
retand drop the comment in v2, with Co-developed-by tags for both of us.Quoted 3 lines · Matthieu Baerts
Maybe a goto could be used here ... to here, not to modify the rest of the code?
Quoted 9 lines
Quoted 2 lines
Would it be OK for both of you if this part of Quanye's patch is added to Tao's v2 series with Quanye as author?
Also fine. Please take the Netlink
extra_subflowscap in v2 with me as author, using a goto to the existing error cleanup instead of the else-wrapping I sent.I will not send a competing series.
Thanks for having a look at this too, and for making the coordination easy.
You're right that the Netlink path was still open in my series, good catch. I'll take your patch into the v2 series as we just agreed, with you as author of that part.
Happy to share this one with you.
Thanks,
Tao
Quoted 2 lines
Thanks,
Quanye
Re: [PATCH mptcp-next 1/2] mptcp: pm: bound extra_subflows admission on userspace PM
In reply to Matthieu BaertsHi Matt,
Quoted 47 lines · Matthieu Baerts
Hi Tao,
+ cc Quanye
Quoted 9 lines · Tao Cui
From: Tao Cui <[email protected]>
mptcp_pm_allow_new_subflow()increments the u8extra_subflowscounter for every acceptedMP_JOINon sockets using the userspace PM, without any limit. A peer establishing more than 255 live subflows wraps the counter back to 0, which then makes the underflow guards warn on the next subflow close, and permanently corruptsmptcpi_subflows_totalreported to userspace.Quoted 5 lines
Refuse new
MP_JOINsonce the counter has reachedU8_MAX, so that it cannot wrap anymore.Fixes e99c1ca89071 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow")Do you have a GitHub account? Just to know if we can assign this task to you (or just leave a message in the comment section).
Quoted 10 lines
Signed-off-by Tao Cui <[email protected]>--- net/mptcp/pm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 565
Quoted 4 lines
net/mptcp/pm.c +1
-0@@ -562,10 +562,17 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)if (mptcp_pm_is_userspace (msk)) {if (mptcp_userspace_pm_active (msk)) { +bool allow;"ret" could be re-used here.
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 569
Quoted 4 lines
net/mptcp/pm.c +4
-0+ +/* extra_subflows is a u8: don't let a peer wrap it +* with more than U8_MAX accepted MP_JOINs +*/ I don't think this comment is needed, "<
U8_MAX" is probably clear enough.
Quoted 15 lines
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 578
Quoted 11 lines
net/mptcp/pm.c +4
-2spin_lock_bh (&pm->lock); - pm->extra_subflows++; + allow = pm->extra_subflows <U8_MAX ; +if (allow) + pm->extra_subflows++;spin_unlock_bh (&pm->lock); -return true; +return allow; }return false; }So, at the end, we can re-used the same version as Quanye. Would it be OK for both of you to have a Co-developed-by tag here?
Thanks for sorting this out with Quanye.
Sounds good to me. I'll send a v2 taking your two comments into account, reusing "ret" and dropping the comment, with Quanye's Netlink part as a separate patch with him as author, and Co-developed-by tags on the admission patch. I'll switch to "Closes:" for the issue as well.
About the GitHub account: I have one ([email protected]) but honestly I don't use it much because of the captcha checks, so sorry in advance if I'm slow to react there. I've left a comment on the issue, and I'll try to be better at watching it for this kind of thing.
Thanks,
Tao
Quoted 2 lines
Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 1/2] mptcp: pm: bound extra_subflows admission on userspace PM
Hi Tao,
Thank you for your reply!
Quoted 66 lines · Tao Cui
Hi Matt,
Quoted 47 lines · Matthieu Baerts
Hi Tao,
+ cc Quanye
Quoted 9 lines · Tao Cui
From: Tao Cui <[email protected]>
mptcp_pm_allow_new_subflow()increments the u8extra_subflowscounter for every acceptedMP_JOINon sockets using the userspace PM, without any limit. A peer establishing more than 255 live subflows wraps the counter back to 0, which then makes the underflow guards warn on the next subflow close, and permanently corruptsmptcpi_subflows_totalreported to userspace.Quoted 5 lines
Refuse new
MP_JOINsonce the counter has reachedU8_MAX, so that it cannot wrap anymore.Fixes e99c1ca89071 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow")Do you have a GitHub account? Just to know if we can assign this task to you (or just leave a message in the comment section).
Quoted 10 lines
Signed-off-by Tao Cui <[email protected]>--- net/mptcp/pm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 565
Quoted 4 lines
net/mptcp/pm.c +1
-0@@ -562,10 +562,17 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)if (mptcp_pm_is_userspace (msk)) {if (mptcp_userspace_pm_active (msk)) { +bool allow;"ret" could be re-used here.
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 569
Quoted 4 lines
net/mptcp/pm.c +4
-0+ +/* extra_subflows is a u8: don't let a peer wrap it +* with more than U8_MAX accepted MP_JOINs +*/ I don't think this comment is needed, "<
U8_MAX" is probably clear enough.Quoted 15 lines
net/mptcp/pm.c bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) · line 578
Quoted 11 lines
net/mptcp/pm.c +4
-2spin_lock_bh (&pm->lock); - pm->extra_subflows++; + allow = pm->extra_subflows <U8_MAX ; +if (allow) + pm->extra_subflows++;spin_unlock_bh (&pm->lock); -return true; +return allow; }return false; }So, at the end, we can re-used the same version as Quanye. Would it be OK for both of you to have a Co-developed-by tag here?
Quoted 7 lines
Thanks for sorting this out with Quanye.
Sounds good to me. I'll send a v2 taking your two comments into account, reusing "ret" and dropping the comment, with Quanye's Netlink part as a separate patch with him as author, and Co-developed-by tags on the admission patch. I'll switch to "Closes:" for the issue as well.
Thanks! Please use "Closes" only for the last patch of the series fixing the issue. You can use "Link" for the others.
Quoted 5 lines
About the GitHub account: I have one ([email protected]) but honestly I don't use it much because of the captcha checks, so sorry in advance if I'm slow to react there. I've left a comment on the issue, and I'll try to be better at watching it for this kind of thing.
Thanks! I guess there shouldn't be new comments over there, but we appreciate comments simply saying "I'm going to look at it".
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
PATCH 2/2 mptcp: pm: skip extra_subflows accounting on disconnected msk
In reply to Tao CuiFrom: Tao Cui <[email protected]>
The WARN_ON_ONCE() guards added to the extra_subflows decrement sites turn out to be reachable:
mptcp_pm_data_reset() zeroes the counter with only the msk socket lock held, while an MP_JOIN subflow can still sit in msk->join_list, its reference already accounted by mptcp_pm_allow_new_subflow() under pm->lock. If the socket gets disconnected(AF_UNSPEC) in that window, mptcp_pm_data_reset() zeroes the counter, and the join list is flushed later at release_sock() time: the leftover subflow then reaches mptcp_pm_subflow_check_next() (or __mptcp_pm_close_subflow() for kernel PM sockets) with the counter already at 0, firing the warning. On panic_on_warn kernels this is a remotely triggerable panic, which is worse than the silent wrap the guards replaced.
Skip the PM accounting when the msk is already in TCP_CLOSE: in the scenario above the state is set before the counters are cleared, and once the msk is closed the accounting is not relevant anymore. Keep a clamp and a rate-limited pr_warn() on the decrement sites instead, to leave a trace of any imbalance we would still not know about.
--- net/mptcp/pm.c | 11 ++++++++++- net/mptcp/protocol.h | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-)
net/mptcp/pm.c +10 -1
@@ -676,9 +676,18 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, update_subflows = subflow->request_join || subflow->mp_join;if (mptcp_pm_is_userspace (msk)) {if (update_subflows) { +/* The PM counters have already been cleared if the +* msk got disconnected while this subflow was still +* queued in the join list +*/ +if (inet_sk_state_load (sk) ==TCP_CLOSE ) +return ;spin_lock_bh (&pm->lock); -if (!WARN_ON_ONCE (pm->extra_subflows ==0 )) +if (likely (pm->extra_subflows)) pm->extra_subflows--; +else +pr_warn_ratelimited ("extra_subflows underflow, msk=%p\n" , + msk);spin_unlock_bh (&pm->lock); }return ;
net/mptcp/protocol.h +12 -2
@@ -1252,8 +1252,18 @@ u8 mptcp_pm_get_limit_extra_subflows(const struct mptcp_sock *msk);/* called under PM lock */ static inline void __mptcp_pm_close_subflow (struct mptcp_sock *msk) { -if (!WARN_ON_ONCE (msk->pm.extra_subflows ==0 ) && - --msk->pm.extra_subflows <mptcp_pm_get_limit_extra_subflows (msk)) +/* The PM counters have already been cleared if the msk got +* disconnected while this subflow was still queued in the +* join list +*/ +if (inet_sk_state_load ((struct sock *)msk) ==TCP_CLOSE ) +return ; + +if (unlikely (msk->pm.extra_subflows ==0 )) { +pr_warn_ratelimited ("extra_subflows underflow, msk=%p\n" , msk); +return ; + } +if (--msk->pm.extra_subflows <mptcp_pm_get_limit_extra_subflows (msk))WRITE_ONCE (msk->pm.accept_subflow, true); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH mptcp-next 2/2] mptcp: pm: skip extra_subflows accounting on disconnected msk
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Subflows in join_list can be leaked due to unsynchronized zeroing of cb_flags in mptcp_disconnect.
- [High] Data race on pm->reset and pm->rm_list_* fields due to missing pm->lock in mptcp_pm_data_reset(). --
commit 179deded54d27540d6b26de1228c24065e1fa9d4
Author: Tao Cui <[email protected]>
mptcp: pm: skip extra_subflows accounting on disconnected msk
This commit addresses a WARN_ON_ONCE crash related to extra_subflows underflow by skipping the PM accounting when the mptcp socket is in the TCP_CLOSE state. It replaces the warnings with rate-limited prints and avoids modifying the counters for disconnected sockets.
Quoted 5 lines
net/mptcp/pm.c +0
-0
net/mptcp/pm.c void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, · line 684
Quoted 9 lines
net/mptcp/pm.c +6
-0@@ -676,9 +676,18 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, update_subflows = subflow->request_join || subflow->mp_join;if (mptcp_pm_is_userspace (msk)) {if (update_subflows) { +/* The PM counters have already been cleared if the +* msk got disconnected while this subflow was still +* queued in the join list +*/ +if (inet_sk_state_load (sk) ==TCP_CLOSE ) +return ;
[Severity: High]
This is a pre-existing issue, but does mptcp_disconnect() leak subflows when zeroing cb_flags non-atomically?
If a concurrent mptcp_finish_join() receives an MP_JOIN ACK for a subflow while the parent socket is being disconnected, it can hit the sock_owned_by_user(parent) branch. The subflow is added to msk->join_list and MPTCP_FLUSH_JOIN_LIST is set in msk->cb_flags while holding the parent's data lock.
Simultaneously, mptcp_disconnect() executes msk->cb_flags = 0 without holding the mptcp_data_lock, erasing the MPTCP_FLUSH_JOIN_LIST flag:
net/mptcp/protocol.c:mptcp_disconnect() {
...
msk->cb_flags = 0;
...
}When the lock is released, release_sock() invokes mptcp_release_cb(), but since the flag was erased, it skips the flush:
net/mptcp/protocol.c:mptcp_release_cb() {
...
if (flags & BIT(MPTCP_FLUSH_JOIN_LIST))
__mptcp_flush_join_list(sk, &join_list);
...
}Can this lead to the sockets in join_list being completely leaked when mptcp_destroy_common() later iterates only over conn_list?
[Severity: High]
This is a pre-existing issue, but is there a data race on pm->reset and pm->rm_list_* fields when mptcp_pm_data_reset() is called during disconnect?
When mptcp_disconnect() sets sk->sk_state to TCP_CLOSE, it calls mptcp_pm_data_reset(msk), which modifies PM structures without acquiring pm->lock:
net/mptcp/pm.c:mptcp_pm_data_reset() {
...
memset(&pm->reset, 0, sizeof(pm->reset));
pm->rm_list_tx.nr = 0;
pm->rm_list_rx.nr = 0;
...
}At the same time, subflow receive paths can process incoming MP_JOIN or RM_ADDR packets in BH context, holding only pm->lock and lock_sock(ssk) rather than lock_sock(msk). For example:
net/mptcp/pm.c:mptcp_pm_allow_new_subflow() {
...
spin_lock_bh(&pm->lock);
if (READ_ONCE(pm->accept_subflow)) {
ret = pm->extra_subflows < limit_extra_subflows;
...
}Could this unprotected memset in mptcp_pm_data_reset() cause torn writes and corrupted PM state when racing with readers and writers that only hold pm->lock?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH mptcp-next 2/2] mptcp: pm: skip extra_subflows accounting on disconnected msk
Hi,
Thanks for the review.
Quoted 5 lines · 在 2026/8/31 18:11, [email protected] 写道:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Subflows injoin_listcan be leaked due to unsynchronized zeroing ofcb_flagsinmptcp_disconnect.
- [High] Data race onpm->resetandpm->rm_list_*fields due to missingpm->lockinmptcp_pm_data_reset().
Both findings are pre-existing issues rather
than regressions from this series, but I had a look at them:
For the join_list leak, I agree it is real. When an MP_JOIN is processed while the parent socket is being disconnected, the subflow is queued in msk->join_list and MPTCP_FLUSH_JOIN_LIST is set under the data lock, but mptcp_disconnect() then clears msk->cb_flags with a plain write. The flag is lost, mptcp_release_cb() never flushes the list, and since mptcp_destroy_common() only iterates conn_list, those subflow sockets are leaked. The plain write also drops flags that were already pending before the disconnect, so taking the data lock around it is not enough. What I have in mind is to keep the flush-related bits across the disconnect and let release_sock() process the join list as originally intended, or to drain it explicitly in the disconnect path, checking the lock nesting commented in mptcp_destroy_common().
For the pm->reset data race, the lasting effect is the counter imbalance this series now clamps and traces, and the other fields are discarded on a closed socket anyway. The direct fix is to take pm->lock around the reset in mptcp_pm_data_reset(), after checking the lock ordering on all callers.
These are two separate bugs with separate Fixes: targets, so I plan to submit them as their own series rather than folding them into this one.
Tao
Quoted 95 lines
--
commit
179deded54d27540d6b26de1228c24065e1fa9d4
Author: Tao Cui <[email protected]>mptcp: pm: skip
extra_subflowsaccounting on disconnected mskThis commit addresses a
WARN_ON_ONCEcrash related toextra_subflowsunderflow by skipping the PM accounting when the mptcp socket is in theTCP_CLOSEstate. It replaces the warnings with rate-limited prints and avoids modifying the counters for disconnected sockets.Quoted 5 lines
net/mptcp/pm.c +0
-0net/mptcp/pm.c void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, · line 684
Quoted 9 lines
net/mptcp/pm.c +6
-0@@ -676,9 +676,18 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, update_subflows = subflow->request_join || subflow->mp_join;if (mptcp_pm_is_userspace (msk)) {if (update_subflows) { +/* The PM counters have already been cleared if the +* msk got disconnected while this subflow was still +* queued in the join list +*/ +if (inet_sk_state_load (sk) ==TCP_CLOSE ) +return ;[Severity: High]
This is a pre-existing issue, but doesmptcp_disconnect()leak subflows when zeroingcb_flagsnon-atomically?If a concurrent
mptcp_finish_join()receives anMP_JOINACK for a subflow while the parent socket is being disconnected, it can hit thesock_owned_by_user(parent)branch. The subflow is added tomsk->join_listandMPTCP_FLUSH_JOIN_LISTis set inmsk->cb_flagswhile holding the parent's data lock.Simultaneously,
mptcp_disconnect()executesmsk->cb_flags= 0 without holding themptcp_data_lock, erasing theMPTCP_FLUSH_JOIN_LISTflag:net/mptcp/protocol.c:mptcp_disconnect() { ... msk->cb_flags = 0; ... }When the lock is released,
release_sock()invokesmptcp_release_cb(), but since the flag was erased, it skips the flush:net/mptcp/protocol.c:mptcp_release_cb() { ... if (flags & BIT(MPTCP_FLUSH_JOIN_LIST)) __mptcp_flush_join_list(sk, &join_list); ... }Can this lead to the sockets in
join_listbeing completely leaked whenmptcp_destroy_common()later iterates only overconn_list?[Severity: High]
This is a pre-existing issue, but is there a data race onpm->resetand pm->rm_list_* fields whenmptcp_pm_data_reset()is called during disconnect?When
mptcp_disconnect()setssk->sk_statetoTCP_CLOSE, it callsmptcp_pm_data_reset(msk), which modifies PM structures without acquiringpm->lock:net/mptcp/pm.c:mptcp_pm_data_reset() { ... memset(&pm->reset, 0, sizeof(pm->reset)); pm->rm_list_tx.nr = 0; pm->rm_list_rx.nr = 0; ... }At the same time, subflow receive paths can process incoming
MP_JOINorRM_ADDRpackets in BH context, holding onlypm->lockandlock_sock(ssk)rather thanlock_sock(msk). For example:net/mptcp/pm.c:mptcp_pm_allow_new_subflow() { ... spin_lock_bh(&pm->lock); if (READ_ONCE(pm->accept_subflow)) { ret = pm->extra_subflows < limit_extra_subflows; ... }Could this unprotected memset in
mptcp_pm_data_reset()cause torn writes and corrupted PM state when racing with readers and writers that only holdpm->lock?[ ... ]
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 2/2] mptcp: pm: skip extra_subflows accounting on disconnected msk
Hi Tao,
Quoted 34 lines · Tao Cui
Hi,
Thanks for the review.
Quoted 5 lines · 在 2026/8/31 18:11, [email protected] 写道:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Subflows injoin_listcan be leaked due to unsynchronized zeroing ofcb_flagsinmptcp_disconnect.
- [High] Data race onpm->resetandpm->rm_list_*fields due to missingpm->lockinmptcp_pm_data_reset().Both findings are pre-existing issues rather
than regressions from this series, but I had a look at them:For the
join_listleak, I agree it is real. When anMP_JOINis processed while the parent socket is being disconnected, the subflow is queued inmsk->join_listandMPTCP_FLUSH_JOIN_LISTis set under the data lock, butmptcp_disconnect()then clearsmsk->cb_flagswith a plain write. The flag is lost,mptcp_release_cb()never flushes the list, and sincemptcp_destroy_common()only iteratesconn_list, those subflow sockets are leaked. The plain write also drops flags that were already pending before the disconnect, so taking the data lock around it is not enough. What I have in mind is to keep the flush-related bits across the disconnect and letrelease_sock()process the join list as originally intended, or to drain it explicitly in the disconnect path, checking the lock nesting commented inmptcp_destroy_common().For the
pm->resetdata race, the lasting effect is the counter imbalance this series now clamps and traces, and the other fields are discarded on a closed socket anyway. The direct fix is to takepm->lockaround the reset inmptcp_pm_data_reset(), after checking the lock ordering on all callers.
Quoted 3 lines
These are two separate bugs with separate Fixes: targets, so I plan to submit them as their own series rather than folding them into this one.
Thank you! Yes a different series is better.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 2/2] mptcp: pm: skip extra_subflows accounting on disconnected msk
In reply to Tao CuiHi Tao Cui,
Quoted 16 lines · Tao Cui
From: Tao Cui <[email protected]>
The
WARN_ON_ONCE()guards added to theextra_subflowsdecrement sites turn out to be reachable:
mptcp_pm_data_reset()zeroes the counter with only the msk socket lock held, while anMP_JOINsubflow can still sit inmsk->join_list, its reference already accounted bymptcp_pm_allow_new_subflow()underpm->lock. If the socket getsdisconnected(AF_UNSPEC)in that window,mptcp_pm_data_reset()zeroes the counter, and the join list is flushed later atrelease_sock()time: the leftover subflow then reachesmptcp_pm_subflow_check_next()(or__mptcp_pm_close_subflow()for kernel PM sockets) with the counter already at 0, firing the warning. Onpanic_on_warnkernels this is a remotely triggerable panic, which is worse than the silent wrap the guards replaced.
Quoted 8 lines
Skip the PM accounting when the msk is already in
TCP_CLOSE: in the scenario above the state is set before the counters are cleared, and once the msk is closed the accounting is not relevant anymore. Keep a clamp and a rate-limitedpr_warn()on the decrement sites instead, to leave a trace of any imbalance we would still not know about.Fixes e99c1ca89071 ("mptcp: pm: add WARN_ON_ONCE guards on extra_subflows underflow")
This patch looks good to me, but could you please use the "Closes" tag for the last patch of the series closing this ticket, please?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
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): Notice: Call Traces at boot time, rebooted and continued ⚠️
- KVM Validation: debug (only selftest_mptcp_join): Notice: Call Traces at boot time, rebooted and continued ⚠️
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Notice: Call Traces at boot time, rebooted and continued - Notice: Call Traces at shutdown time, ignored and continued ⚠️
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/33379349810
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/190a5d9ad47e
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1154350
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-normalFor 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)