Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: matttbe@kernel.org
Cc: edumazet@kernel.org, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, willemb@google.com, horms@kernel.org,
	martineau@kernel.org, geliang@kernel.org, cpaasch@openai.com,
	fw@strlen.de, netdev@vger.kernel.org, mptcp@lists.linux.dev,
	dcaratti@redhat.com, mason@kernel.org, stable@vger.kernel.org,
	ncardwell@google.com, kuniyu@google.com, kafai@fb.com,
	daniel@iogearbox.net, ast@kernel.org, martin.lau@kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list
Date: Tue, 24 Nov 2026 14:26:51 +0000	[thread overview]
Message-ID: <179553041150.3135.10012593386905502123@kernel.org> (raw)
In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-4-278042217e8d@kernel.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment in the sock_owned_by_user() branch of
  mptcp_napi_poll() (net/mptcp/protocol.c) is now wrong for the case…

--

mptcp: fix use-after-free of the subflow context on the delegated list

This fixes a use-after-free. subflow_ulp_release() frees the subflow
context with kfree_rcu() while the context is still linked on the per-CPU
delegated napi list. A new MPTCP_DELEGATE_DEAD bit hands the free to
mptcp_napi_poll() when the subflow is scheduled, skips delegated actions
for dead contexts, and moves delegated_status out of struct_group(reset).

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 50c294d925b0c..23d35f43b566e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -4803,10 +4803,13 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)
>  	delegated = container_of(napi, struct mptcp_delegated_action, napi);
>  	while ((subflow = mptcp_subflow_delegated_next(delegated)) != NULL) {
>  		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
> +		long status;
>  
>  		bh_lock_sock_nested(ssk);
>  		if (!sock_owned_by_user(ssk)) {
> -			mptcp_subflow_process_delegated(ssk, xchg(&subflow->delegated_status, 0));
> +			status = xchg(&subflow->delegated_status, 0);
> +			if (!(status & BIT(MPTCP_DELEGATE_DEAD)))
> +				mptcp_subflow_process_delegated(ssk, status);
>  		} else {
>  			/* tcp_release_cb_override already processed
>  			 * the action or will do at next release_sock().
> @@ -4814,11 +4817,15 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)
>  			 * CPU that scheduled it.
>  			 */
>  			smp_wmb();
> -			clear_bit(MPTCP_DELEGATE_SCHEDULED, &subflow->delegated_status);
> +			status = set_mask_bits(&subflow->delegated_status,
> +					       BIT(MPTCP_DELEGATE_SCHEDULED), 0);

[Severity: Low]
This isn't a bug, but is the comment above this branch still accurate
once MPTCP_DELEGATE_DEAD is set?

The comment says tcp_release_cb_override "already processed the action or
will do at next release_sock()". However, every path that reaches
mptcp_subflow_free_ctx() runs after mptcp_subflow_ops_undo_override() has
restored ssk->sk_prot to plain tcp_prot/tcpv6_prot:

net/mptcp/subflow.c:subflow_ulp_release() {
    ...
	mptcp_subflow_ops_undo_override(ssk);
	if (release)
		mptcp_subflow_free_ctx(ctx);
}

mptcp_subflow_drop_ctx() reaches the same undo through
subflow_ulp_fallback(). __mptcp_close_ssk() only calls
mptcp_subflow_free_ctx() when icsk_ulp_ops is already NULL.

So for a dead context, the next release_sock() calls tcp_release_cb()
rather than tcp_release_cb_override(). Any pending action bits are dropped,
and the commit message says that is intended ("the pending actions must not
run").

A dead context can reach this branch. __mptcp_close_ssk() holds
lock_sock_nested(ssk) across this chain:

__tcp_close()->inet_csk_destroy_sock()->tcp_cleanup_ulp()->
    subflow_ulp_release()->mptcp_subflow_free_ctx()

That means a concurrent mptcp_napi_poll() can see sock_owned_by_user(ssk)
after DEAD has been set.

Could the comment be updated to say that dead contexts have their pending
actions discarded here? It could also mention that status is captured so
the context can be freed with kfree_rcu() after bh_unlock_sock() and
sock_put().

>  		}
>  		bh_unlock_sock(ssk);
>  		sock_put(ssk);
>  
> +		if (status & BIT(MPTCP_DELEGATE_DEAD))
> +			kfree_rcu(subflow, rcu);
> +
>  		if (++work_done == budget)
>  			return budget;
>  	}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d%40kernel.org

  reply	other threads:[~2026-11-24 14:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 01/10] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 02/10] mptcp: " Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list Matthieu Baerts (NGI0)
2026-11-24 14:26   ` netdev-bot+sashiko [this message]
2026-11-23 13:24 ` [PATCH net 05/10] mptcp: leave an orphan's DATA_FIN to the worker Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 06/10] mptcp: don't leak an orphan when the PM closes its last subflow Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 07/10] net: add __sk_net_refcnt_upgrade() with a GFP mask Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
2026-11-23 19:00   ` Matthieu Baerts
2026-11-24 14:26   ` netdev-bot+sashiko
2026-11-23 13:24 ` [PATCH net 09/10] mptcp: initialize drop_req in subflow_init_req() Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener Matthieu Baerts (NGI0)

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=179553041150.3135.10012593386905502123@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cpaasch@openai.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=martin.lau@kernel.org \
    --cc=martineau@kernel.org \
    --cc=mason@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.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