From: Paolo Abeni <pabeni@redhat.com>
To: Matthieu Baerts <matttbe@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH v3 mptcp-net 1/3] mptcp: fix grafting corner case
Date: Thu, 13 Nov 2025 18:09:03 +0100 [thread overview]
Message-ID: <2102ad3b-4f22-4da7-ac2f-7da0eba0ba46@redhat.com> (raw)
In-Reply-To: <49c300cc-e000-420d-82ad-aa59e5f1cd76@kernel.org>
On 11/13/25 9:47 AM, Matthieu Baerts wrote:
> Hi Paolo,
>
> On 13/11/2025 01:10, Paolo Abeni wrote:
>> If a passive MPTCP socket creates active subflows while still unaccepted,
>> __mptcp_subflow_connect() will try to graft such subflows to the msk,
>> but the msk struct socket is not yet initialized at that point:
>> the subflows will misbehave.
>
> What kind of errors were visible?
Found by code inspection, never replicated in practice; thinking again
about it. I'm no more sure this is actually needed: the subflow
mentioned above should be catched and fixed at accept time.
/me needs more coffee and thinking...
>> +static void mptcp_check_graft(struct sock *sk, struct sock *ssk)
>> +{
>> + struct socket *sock;
>> +
>> + if (ssk->sk_socket)
>> + return;
>> +
>> + write_lock_bh(&sk->sk_callback_lock);
>> + sock = sk->sk_socket;
>> + write_lock_bh(&sk->sk_callback_lock);
>
> The build job failed because here it should be the unlock version
> (write_unlock_bh()).
> (and probably an empty line just after).
Oh, it looks like I shared an older revision, sorry.
> If there is only that, I can fix that when applying the patches.
>
>> + if (sock)
>> + mptcp_sock_graft(ssk, sock);
>> +}
>> +
>> bool mptcp_finish_join(struct sock *ssk)
>> {
>> struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
>> @@ -3758,6 +3766,7 @@ bool mptcp_finish_join(struct sock *ssk)
>> }
>> mptcp_subflow_joined(msk, ssk);
>> spin_unlock_bh(&msk->fallback_lock);
>> + mptcp_check_graft(parent, ssk);
>> mptcp_propagate_sndbuf(parent, ssk);
>> return true;
>> }
>> @@ -3767,6 +3776,8 @@ bool mptcp_finish_join(struct sock *ssk)
>> goto err_prohibited;
>> }
>>
>> + mptcp_check_graft(parent, ssk);
>
> Is it OK to graft it even in case of errors in __mptcp_finish_join()?
> i.e. not in an established state or !msk->allow_subflows.
>
> Should it not be done after the block below, if there was no error?
My understanding/hope is that grafting early don't cause issues:
- no UaF access to ssk->sk_socket, because ssk either do finish
successfully the join or is reset/delete very soon.
- no ref leak, because ssk does not acquire any actual reference on
msk/socket.
It's needed to do it in mptcp_finish_join(), to ensure that in patch 3/3
all the subflows will always push accounted data after that
mptcp_graft_subflows() completes - or more specifically the
`backlog_unaccounted` counter is flushed.
Let me see if I can rework 3/3 without this patch
/P
next prev parent reply other threads:[~2025-11-13 17:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 0:10 [PATCH v3 mptcp-net 0/3] mptcp: cg and backlog follow-up Paolo Abeni
2025-11-13 0:10 ` [PATCH v3 mptcp-net 1/3] mptcp: fix grafting corner case Paolo Abeni
2025-11-13 8:47 ` Matthieu Baerts
2025-11-13 17:09 ` Paolo Abeni [this message]
2025-11-13 17:14 ` Matthieu Baerts
2025-11-13 0:10 ` [PATCH v3 mptcp-net 2/3] Squash-to: "mptcp: fix memcg accounting for passive sockets" Paolo Abeni
2025-11-13 0:10 ` [PATCH v3 mptcp-net 3/3] Squash-to: "mptcp: leverage the backlog for RX packet processing" Paolo Abeni
2025-11-13 9:00 ` Matthieu Baerts
2025-11-13 11:30 ` kernel test robot
2025-11-13 17:16 ` Matthieu Baerts
2025-11-13 11:52 ` kernel test robot
2025-11-13 0:35 ` [PATCH v3 mptcp-net 0/3] mptcp: cg and backlog follow-up MPTCP CI
2025-11-13 1:21 ` MPTCP CI
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=2102ad3b-4f22-4da7-ac2f-7da0eba0ba46@redhat.com \
--to=pabeni@redhat.com \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
/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