From: sashiko-bot@kernel.org
To: "Kalpan Jani" <kalpan.jani@mpiricsoftware.com>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v8] mptcp: bpf: fix NULL deref and UAF in bpf_mptcp_sock_from_subflow()
Date: Wed, 02 Dec 2026 12:37:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-245731@kernel.org> (raw)
In-Reply-To: <20261202120552.1973095-1-kalpan.jani@mpiricsoftware.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mptcp: NULL deref in listener RCU callbacks on close clearing
icsk_ulp_data
- [Medium] mptcp: race in mptcp_subflow_free_ctx() retires ctx before
clearing ulp_data
--
commit 2920297291ae75033b2c3766c517dafe93d8a3a6
Author: Kalpan Jani <kalpan.jani@mpiricsoftware.com>
mptcp: bpf: fix NULL deref and UAF in bpf_mptcp_sock_from_subflow()
This commit fixes race conditions in bpf_mptcp_sock_from_subflow() by
loading the subflow context under RCU, pairing smp_store_release() and
smp_load_acquire() on ctx->conn, setting SOCK_RCU_FREE on parent MPTCP
sockets, and deferring the parent socket reference release to an RCU
callback.
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 7cdd0a7e8296b..5d93ea6e88987 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
[ ... ]
> @@ -822,14 +822,23 @@ mptcp_subflow_delegated_next(struct mptcp_delegated_action *delegated)
> return ret;
> }
>
> +void mptcp_subflow_free_ctx_rcu(struct rcu_head *head);
> +
> static inline void mptcp_subflow_free_ctx(struct mptcp_subflow_context *subflow)
> {
> + struct sock *ssk = subflow->tcp_sock;
> + struct inet_connection_sock *icsk = inet_csk(ssk);
> long old = set_mask_bits(&subflow->delegated_status, 0,
> BIT(MPTCP_DELEGATE_DEAD));
>
> - /* a scheduled subflow is owned by mptcp_napi_poll(), which will free it */
> + if (rcu_access_pointer(icsk->icsk_ulp_data) == subflow) {
> + rcu_assign_pointer(icsk->icsk_ulp_data, NULL);
> + WRITE_ONCE(tcp_sk(ssk)->is_mptcp, 0);
> + }
> +
> + /* A scheduled subflow is retired by mptcp_napi_poll(). */
> if (!(old & BIT(MPTCP_DELEGATE_SCHEDULED)))
> - kfree_rcu(subflow, rcu);
> + call_rcu(&subflow->rcu, mptcp_subflow_free_ctx_rcu);
> }
[Severity: Medium]
Can setting BIT(MPTCP_DELEGATE_DEAD) before clearing icsk->icsk_ulp_data
allow mptcp_napi_poll() to start the RCU grace period while subflow is
still published in icsk->icsk_ulp_data?
__mptcp_close_ssk() calls mptcp_subflow_free_ctx() in preemptible process
context holding lock_sock_nested(ssk), which sets ssk->sk_lock.owned but
does not hold ssk->sk_lock.slock. If the subflow was previously queued on
the delegated list, mptcp_napi_poll() on another CPU sees
sock_owned_by_user(ssk) and retires the context as soon as it sees
BIT(MPTCP_DELEGATE_DEAD):
CPU0 CPU1
__mptcp_close_ssk()
lock_sock_nested(ssk, ...)
mptcp_subflow_free_ctx(subflow)
set_mask_bits(...,
BIT(MPTCP_DELEGATE_DEAD))
<preempted>
mptcp_napi_poll()
bh_lock_sock_nested(ssk)
/* sock_owned_by_user(ssk) is true */
status = set_mask_bits(...,
BIT(MPTCP_DELEGATE_SCHEDULED), 0)
bh_unlock_sock(ssk)
call_rcu(&subflow->rcu,
mptcp_subflow_free_ctx_rcu)
/* RCU grace period elapses */
mptcp_subflow_free_ctx_rcu()
sock_put(conn)
kfree(subflow)
bpf_mptcp_sock_from_subflow(ssk)
ctx = rcu_dereference(
icsk->icsk_ulp_data)
smp_load_acquire(&ctx->conn)
<-- use-after-free
rcu_assign_pointer(
icsk->icsk_ulp_data, NULL)
Clearing icsk->icsk_ulp_data and tcp_sk(ssk)->is_mptcp before setting
BIT(MPTCP_DELEGATE_DEAD) would ensure the context is unpublished before
either path can queue call_rcu().
> diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
> index 85695fe00cc38..2402fc87fd091 100644
> --- a/net/mptcp/subflow.c
> +++ b/net/mptcp/subflow.c
[ ... ]
> @@ -2145,9 +2160,10 @@ static void subflow_ulp_release(struct sock *ssk)
> if (!release && !test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW,
> &mptcp_sk(sk)->flags))
> mptcp_schedule_work(sk);
> - sock_put(sk);
> +
> }
>
> + mptcp_subflow_tcp_fallback(ssk, ctx);
> mptcp_subflow_ops_undo_override(ssk);
> if (release)
> mptcp_subflow_free_ctx(ctx);
[Severity: High]
Does clearing icsk->icsk_ulp_data in mptcp_subflow_free_ctx() during
subflow_ulp_release() cause a NULL pointer dereference when a listening
MPTCP socket is closed concurrently with incoming TCP traffic?
On TCP ingress, listener callbacks such as subflow_syn_recv_sock(),
subflow_check_req(), and subflow_data_ready() run under rcu_read_lock()
without holding the listener socket lock, which is why 5e20087d1b67
("mptcp: handle mptcp listener destruction via rcu") kept icsk_ulp_data
and the listener context valid across an RCU grace period. Because
inet_csk_destroy_sock() runs synchronously inside __tcp_close(),
subflow_ulp_release() now resets the listener's callbacks and clears
icsk->icsk_ulp_data to NULL while an in-flight RCU reader is already
inside a subflow callback:
CPU0 (softirq, RCU read lock) CPU1 (process context)
tcp_v4_rcv()
tcp_check_req()
/* loads icsk_af_ops->syn_recv_sock
* (subflow_syn_recv_sock)
*/
__mptcp_close_ssk(listener_ssk)
__tcp_close(listener_ssk, 0)
inet_csk_destroy_sock()
tcp_cleanup_ulp()
subflow_ulp_release()
mptcp_subflow_free_ctx()
rcu_assign_pointer(
icsk->icsk_ulp_data,
NULL)
subflow_syn_recv_sock(sk, ...)
listener = mptcp_subflow_ctx(sk)
/* listener is NULL */
listener->icsk_af_ops->syn_recv_sock(...)
<-- NULL pointer dereference
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202120552.1973095-1-kalpan.jani@mpiricsoftware.com?part=1
next prev parent reply other threads:[~2026-12-02 12:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:05 [PATCH mptcp-next v8] mptcp: bpf: fix NULL deref and UAF in bpf_mptcp_sock_from_subflow() Kalpan Jani
2026-12-02 12:37 ` sashiko-bot [this message]
2026-12-02 13:13 ` 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=sashiko-outbox-245731@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kalpan.jani@mpiricsoftware.com \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@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