From: Matthieu Baerts <matttbe@kernel.org>
To: Shardul Bankar <shardul.b@mpiricsoftware.com>, mptcp@lists.linux.dev
Cc: martineau@kernel.org, geliang@kernel.org, pabeni@redhat.com,
janak@mpiric.us, kalpan.jani@mpiricsoftware.com,
shardulsb08@gmail.com
Subject: Re: [PATCH net v2] mptcp: pm: fix memory leak from alloc-during-teardown race
Date: Wed, 27 May 2026 15:02:37 +1000 [thread overview]
Message-ID: <6046a321-9f73-46d9-93d5-5bfe62416cc8@kernel.org> (raw)
In-Reply-To: <20260523212930.2957096-1-shardul.b@mpiricsoftware.com>
Hi Shardul,
Thank you for the v2!
On 24/05/2026 07:29, Shardul Bankar wrote:
> mptcp_pm_destroy() drains msk->pm.anno_list via list_splice_init()
> under msk->pm.lock and then, for the userspace PM, drains
> msk->pm.userspace_pm_local_addr_list under the same lock. Between
> the two splices, msk->pm.lock is released.
>
> A concurrent userspace PM genl ANNOUNCE on the same msk holds a
> sock reference via mptcp_token_get_sock() and, in
> mptcp_pm_nl_announce_doit(), calls
> mptcp_userspace_pm_append_new_local_addr() and
> mptcp_pm_alloc_anno_list(). Both take msk->pm.lock briefly to
> add to their respective lists. Because the genl handler holds a
> sock reference, mptcp_pm_destroy() may run on the same msk via
> mptcp_disconnect(), which invokes mptcp_destroy_common() without
> dropping the sock refcount, before the handler completes.
>
> If the lock acquisitions interleave such that mptcp_pm_destroy()'s
> splice runs first, the subsequent alloc paths land on a list head
> pointing to itself. Nothing else iterates that list for this msk,
> and the added entry leaks. kmemleak reports both 192-byte
> mptcp_pm_add_entry objects (from mptcp_pm_alloc_anno_list()) and
> 64-byte mptcp_pm_addr_entry objects (from
> mptcp_userspace_pm_append_new_local_addr()) under sustained
> concurrent ANNOUNCE + close load against the userspace PM.
>
> Add an MPTCP_PM_DESTROYING bit in msk->pm.status, set by
> mptcp_pm_destroy() under pm.lock before the splice and checked
> under pm.lock by the alloc paths. Either the alloc takes pm.lock
> first, in which case its entry will be on the list when destroy's
> splice runs and will be freed normally; or destroy takes pm.lock
> first, in which case the subsequent alloc observes the bit and
> refuses. Either ordering is correct, and the race that orphans
> an entry is precluded. The bit lives in the pm data reset group,
> so mptcp_pm_data_reset() clears it on the disconnect/reuse path
> as well as on fresh socket init.
>
> Found by an MPTCP protocol-flow harness extending BRF
> (arXiv:2305.08782). Baseline ~0.3 kmemleak reports/minute on the
> userspace PM reduces to zero across multi-hour runs with this
> patch applied.
I guess you also validated the v2 against your reproducer, right?
I'm asking, because sashiko thinks there is still a way to hit the issue
if the userspace does a shutdown() (mptcp_disconnect()):
https://sashiko.dev/#/patchset/20260523212930.2957096-1-shardul.b@mpiricsoftware.com
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2026-05-27 5:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 21:29 [PATCH net v2] mptcp: pm: fix memory leak from alloc-during-teardown race Shardul Bankar
2026-05-23 22:31 ` MPTCP CI
2026-05-27 5:02 ` Matthieu Baerts [this message]
2026-06-10 15:24 ` Shardul Bankar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6046a321-9f73-46d9-93d5-5bfe62416cc8@kernel.org \
--to=matttbe@kernel.org \
--cc=geliang@kernel.org \
--cc=janak@mpiric.us \
--cc=kalpan.jani@mpiricsoftware.com \
--cc=martineau@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=shardul.b@mpiricsoftware.com \
--cc=shardulsb08@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox