From: Shardul Bankar <shardul.b@mpiricsoftware.com>
To: Matthieu Baerts <matttbe@kernel.org>, mptcp@lists.linux.dev
Cc: Mat Martineau <martineau@kernel.org>,
Geliang Tang <geliang@kernel.org>,
pabeni@redhat.com, kalpan.jani@mpiricsoftware.com,
janak@mpiric.us, akshit@mpiricsoftware.com
Subject: Re: [PATCH mptcp-next 2/2] mptcp: pm: fix memory leak from alloc-during-teardown race
Date: Wed, 24 Jun 2026 18:16:14 +0530 [thread overview]
Message-ID: <fe240744590015e557feccbbdf0c5c0a06546eff.camel@mpiricsoftware.com> (raw)
In-Reply-To: <b0dccb83-b9de-4207-9132-f3944bc3d5e6@kernel.org>
Hi Matt,
Thanks for the review, and for flagging Sashiko's note.
On Mon, 2026-06-22 at 19:37 +0200, Matthieu Baerts wrote:
> Hi Shardul,
>
> Thank you for the v4!
>
> (Note: please make sure to keep the version in the prefix -- b4 does
> that for you automatically ;) -- to help with the patch tracking)
>
Yes I'll be more careful, thanks for pointing it out.
> On 20/06/2026 10:44, Shardul Bankar wrote:
> > mptcp_pm_destroy() empties msk->pm.anno_list and
> > msk->pm.userspace_pm_local_addr_list under msk->pm.lock during
> > socket
> > teardown, dropping the lock between the two.
> >
> > 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_announced_alloc(). 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.
>
> Sashiko seems to say [1] that the mptcp_disconnect() path is not
> covered
> (when 'shutdown()' then 'connect()' is called from the userspace),
> but
> it looks like that's what you are covering it. Just to be sure: is it
> a
> false positive? (I didn't check the different code path to see if
> that's
> possible)
>
> [1]
> https://sashiko.dev/#/patchset/20260620084424.3072634-1-shardul.b%40mpiricsoftware.com?part=2
>
> Cheers,
> Matt
It's a false positive for the leak, and your reading is right.
The factual part of the note is true: mptcp_pm_destroy() sets
MPTCP_PM_DESTROYING, but mptcp_disconnect() then calls
mptcp_pm_data_reset(), whose memset(&pm->reset, ...) clears the bit
(status lives in the reset struct_group). So the bit deliberately does
not survive a disconnect(). It just doesn't cause a leak, because the
two teardown paths are covered by two different mechanisms:
- Final teardown: __mptcp_destroy_sock() sets pm.status = 0 and then
calls sk_prot->destroy() -> mptcp_destroy_common() ->
mptcp_pm_destroy(), which sets DESTROYING under pm.lock right around
the list free. There is no pm_data_reset() afterwards, so the bit
persists. A concurrent ANNOUNCE
(mptcp_userspace_pm_append_new_local_addr() runs under pm.lock only,
before announce_doit() takes lock_sock()) either runs before the free
and gets reclaimed, or sees DESTROYING and aborts. This is the race the
fence exists for.
- disconnect()/reuse: the userspace list free in mptcp_pm_destroy() is
unconditional (patch 1/2) and runs on every teardown. An entry appended
after the disconnect-time reset lands on the reused, still-live socket
and is reclaimed by the unconditional free at that socket's next
teardown. So it is never orphaned. The fence bit being reset here is
harmless by design.
Thanks,
Shardul
next prev parent reply other threads:[~2026-06-24 12:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-20 8:44 [PATCH mptcp-next 0/2] mptcp: pm: net-next port of the alloc-during-teardown leak fix Shardul Bankar
2026-06-20 8:44 ` [PATCH mptcp-next 1/2] Squash to "mptcp: pm: init and release mptcp_pm_ops" Shardul Bankar
2026-06-20 8:44 ` [PATCH mptcp-next 2/2] mptcp: pm: fix memory leak from alloc-during-teardown race Shardul Bankar
2026-06-22 17:37 ` Matthieu Baerts
2026-06-24 12:46 ` Shardul Bankar [this message]
2026-06-20 9:37 ` [PATCH mptcp-next 0/2] mptcp: pm: net-next port of the alloc-during-teardown leak fix MPTCP CI
2026-07-31 15:49 ` Matthieu Baerts
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=fe240744590015e557feccbbdf0c5c0a06546eff.camel@mpiricsoftware.com \
--to=shardul.b@mpiricsoftware.com \
--cc=akshit@mpiricsoftware.com \
--cc=geliang@kernel.org \
--cc=janak@mpiric.us \
--cc=kalpan.jani@mpiricsoftware.com \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).