From: Matthieu Baerts <matttbe@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH v3 mptcp-net 1/3] mptcp: fix grafting corner case
Date: Thu, 13 Nov 2025 09:47:54 +0100 [thread overview]
Message-ID: <49c300cc-e000-420d-82ad-aa59e5f1cd76@kernel.org> (raw)
In-Reply-To: <4696be966622c9d340e8bfa4728b219b7cac1d1b.1762992570.git.pabeni@redhat.com>
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?
> Address the issue always trying to graft the subflow in
> mptcp_finish_join(), regardless of the subflow itself being active or
> passive. To avoid races with accept(), access the msk->sk_socket under
> the callback lock.
Thank you for addressing this issue!
>
By chance, do you have a Fixes tag to add here? (if it is for -net)
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> net/mptcp/protocol.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 8965abb94b81..1b3c5fd01600 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -913,12 +913,6 @@ static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
> mptcp_subflow_joined(msk, ssk);
> spin_unlock_bh(&msk->fallback_lock);
>
> - /* attach to msk socket only after we are sure we will deal with it
> - * at close time
> - */
> - if (sk->sk_socket && !ssk->sk_socket)
> - mptcp_sock_graft(ssk, sk->sk_socket);
> -
> mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
> mptcp_sockopt_sync_locked(msk, ssk);
> mptcp_stop_tout_timer(sk);
> @@ -3734,6 +3728,20 @@ void mptcp_sock_graft(struct sock *sk, struct socket *parent)
> write_unlock_bh(&sk->sk_callback_lock);
> }
>
> +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).
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?
> +
> /* If we can't acquire msk socket lock here, let the release callback
> * handle it
> */
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2025-11-13 8:47 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 [this message]
2025-11-13 17:09 ` Paolo Abeni
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=49c300cc-e000-420d-82ad-aa59e5f1cd76@kernel.org \
--to=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