All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Kalpan Jani <kalpan.jani@mpiricsoftware.com>,
	mptcp@lists.linux.dev, Geliang Tang <geliang@kernel.org>
Cc: matttbe@kernel.org, martineau@kernel.org,
	shardul.b@mpiricsoftware.com, janak@mpiric.us,
	kalpanjani009@gmail.com, shardulsb08@gmail.com,
	akshit@mpiricsoftware.com
Subject: Re: [PATCH mptcp-net v3] mptcp: bpf: fix NULL deref and UAF in bpf_mptcp_sock_from_subflow()
Date: Fri, 14 Aug 2026 10:02:39 +0200	[thread overview]
Message-ID: <e039e866-fe7e-41ef-ad41-92a76a123713@redhat.com> (raw)
In-Reply-To: <20260629105020.1670781-1-kalpan.jani@mpiricsoftware.com>

On 6/29/26 12:50 PM, Kalpan Jani wrote:
> bpf_mptcp_sock_from_subflow() is reachable from tracing BPF programs via
> bpf_skc_to_mptcp_sock() on an arbitrary socket, without the subflow
> socket lock held. It assumes sk_is_mptcp(sk) implies a valid subflow
> context whose ->conn points to a live parent mptcp_sock. That invariant
> does not hold in several windows:
> 
> - Fallback: subflow_ulp_fallback() clears icsk_ulp_data before clearing
>   tcp_sk(sk)->is_mptcp, so a reader can observe is_mptcp == 1 with a NULL
>   context and dereference mptcp_subflow_ctx(sk)->conn through NULL.
> 
> - Init: subflow_ulp_init() sets is_mptcp = 1 while ->conn is still NULL;
>   on CONFIG_DEBUG_NET, mptcp_sk() dereferences its argument in a
>   WARN_ON(), so mptcp_sk(NULL) faults.
> 
> - Publish: the passive MPC path in subflow_syn_recv_sock() stored the
>   freshly cloned parent into ->conn with a plain assignment, on a child
>   that is already hashed and globally visible. A lockless reader could
>   observe a non-NULL ->conn before the stores initialising the new
>   mptcp_sock were visible.
> 
> - Teardown: subflow_ulp_release() and mptcp_subflow_drop_ctx() dropped
>   the subflow-owned parent reference with sock_put() without clearing
>   ->conn, and the established parent msk was not SOCK_RCU_FREE, so a
>   lockless reader could dereference a freed parent: a use-after-free.

I think we should expose to tracing program arbitrary socket state
locklessly.

@Geliang: what about just removing such possibily? Something alike the 
following (completely untested).

If a tracing bpf program needs to access the msk, it should do just:

	mptcp_sk(sk)

on the main socket, via a new, to be defined/implemented helper, and
_non_ starting form a subflow.

AFAICS all the other accessors using from tracing are simple casts,
like the above, and do not traverse the rather risky ulp layer.

/P
---
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 75495a5c3507..ad4b8d04b190 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1745,8 +1745,6 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_skc_to_udp6_sock_proto;
 	case BPF_FUNC_skc_to_unix_sock:
 		return &bpf_skc_to_unix_sock_proto;
-	case BPF_FUNC_skc_to_mptcp_sock:
-		return &bpf_skc_to_mptcp_sock_proto;
 	case BPF_FUNC_sk_storage_get:
 		return &bpf_sk_storage_get_tracing_proto;
 	case BPF_FUNC_sk_storage_delete:



      parent reply	other threads:[~2026-08-14  8:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 10:50 [PATCH mptcp-net v3] mptcp: bpf: fix NULL deref and UAF in bpf_mptcp_sock_from_subflow() Kalpan Jani
2026-06-29 11:58 ` MPTCP CI
2026-08-14  8:02 ` Paolo Abeni [this message]

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=e039e866-fe7e-41ef-ad41-92a76a123713@redhat.com \
    --to=pabeni@redhat.com \
    --cc=akshit@mpiricsoftware.com \
    --cc=geliang@kernel.org \
    --cc=janak@mpiric.us \
    --cc=kalpan.jani@mpiricsoftware.com \
    --cc=kalpanjani009@gmail.com \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=shardul.b@mpiricsoftware.com \
    --cc=shardulsb08@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.