From: Matthieu Baerts <matttbe@kernel.org>
To: Kuniyuki Iwashima <kuniyu@google.com>, sashiko@lists.linux.dev
Cc: bpf@vger.kernel.org, MPTCP Linux <mptcp@lists.linux.dev>
Subject: Re: [PATCH v2 bpf 3/6] mptcp: bpf: fix type confusion in bpf_mptcp_sock_from_subflow()
Date: Tue, 5 May 2026 17:14:08 +0200 [thread overview]
Message-ID: <64a691f2-4104-4538-9aa6-6feadc756c56@kernel.org> (raw)
In-Reply-To: <CAAVpQUB-K4YBE5Em4xg5wWsjtK=7xZwwXFynX2vUN4DQDx2tRw@mail.gmail.com>
Hi Kuniyuki,
(+cc MPTCP ML)
On 05/05/2026 07:43, Kuniyuki Iwashima wrote:
> Could you follow up on the comments by Sashiko ?
Thank you for having forwarded this!
> On Mon, May 4, 2026 at 9:14 PM <sashiko-bot@kernel.org> wrote:
(...)
>>> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
>>> index 8a16672b94e2..4cc16cbeb328 100644
>>> --- a/net/mptcp/bpf.c
>>> +++ b/net/mptcp/bpf.c
>>> @@ -14,7 +14,7 @@
>>>
>>> struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk)
>>> {
>>> - if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
>>> + if (sk && sk_fullsock(sk) && sk_is_tcp(sk) && sk_is_mptcp(sk))
>>> return mptcp_sk(mptcp_subflow_ctx(sk)->conn);
>>
>> Could this cause a regression by dereferencing a NULL pointer when accessed
>> concurrently?
>>
>> In subflow_ulp_fallback(), icsk->icsk_ulp_data is set to NULL prior to
>> clearing tcp_sk(sk)->is_mptcp. If a BPF program triggers in this window,
>> sk_is_mptcp() would return true but mptcp_subflow_ctx(sk) would return NULL,
>> leading to a NULL pointer dereference.
This would need to be confirmed, but from what I see, that's not a new
bug introduced by the patch here.
>> Additionally, could ctx->conn be NULL when read here?
>>
>> During subflow_ulp_init(), the context is allocated and is_mptcp is set to 1,
>> but ctx->conn is initially NULL. Passing NULL to mptcp_sk(ctx->conn) triggers
>> a kernel panic on CONFIG_DEBUG_NET builds. On non-debug builds, it returns a
>> non-NULL offset pointer, which bypasses BPF verifier NULL checks and causes
>> invalid memory accesses.
Same here: not a new bug.
>> Could this introduce a regression with a use-after-free of the mptcp_sock
>> during teardown?
>>
>> During subflow_ulp_release(), sock_put(ctx->conn) drops the reference to the
>> parent mptcp_sock and may free it. However, ctx->conn is not cleared, and the
>> subflow context remains valid until the RCU grace period ends.
>>
>> If a BPF tracing program triggers after sock_put(), could this retrieve
>> and return the dangling ctx->conn pointer, enabling the BPF program to read
>> from freed kernel slab memory?
Same here: not a new bug.
Sashiko is good at finding potential existing bugs that predate a patch,
which is good, but someone has to fix them :)
Because the issues raised here are not new, I suggest not blocking this
patch. I will check if someone can look at it quickly.
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2026-05-05 15:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 21:04 [PATCH v2 bpf 0/6] bpf: tcp: Fix type confusion in bpf helper functions Kuniyuki Iwashima
2026-05-04 21:04 ` [PATCH v2 bpf 1/6] bpf: tcp: Fix type confusion in bpf_tcp_sock() Kuniyuki Iwashima
2026-05-04 21:50 ` bot+bpf-ci
2026-05-04 21:53 ` Kuniyuki Iwashima
2026-05-05 4:14 ` sashiko-bot
2026-05-05 5:37 ` Kuniyuki Iwashima
2026-05-04 21:04 ` [PATCH v2 bpf 2/6] selftest: bpf: Add test for bpf_tcp_sock() and RAW socket Kuniyuki Iwashima
2026-05-05 4:14 ` sashiko-bot
2026-05-05 5:38 ` Kuniyuki Iwashima
2026-05-04 21:04 ` [PATCH v2 bpf 3/6] mptcp: bpf: fix type confusion in bpf_mptcp_sock_from_subflow() Kuniyuki Iwashima
2026-05-05 4:14 ` sashiko-bot
2026-05-05 5:43 ` Kuniyuki Iwashima
2026-05-05 15:14 ` Matthieu Baerts [this message]
2026-05-04 21:04 ` [PATCH v2 bpf 4/6] bpf: tcp: Fix type confusion in bpf_skc_to_tcp_sock() Kuniyuki Iwashima
2026-05-04 21:04 ` [PATCH v2 bpf 5/6] bpf: tcp: Fix type confusion in bpf_skc_to_tcp6_sock() Kuniyuki Iwashima
2026-05-04 21:04 ` [PATCH v2 bpf 6/6] bpf: tcp: Fix type confusion in sol_tcp_sockopt() Kuniyuki Iwashima
2026-05-08 19:10 ` [PATCH v2 bpf 0/6] bpf: tcp: Fix type confusion in bpf helper functions patchwork-bot+netdevbpf
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=64a691f2-4104-4538-9aa6-6feadc756c56@kernel.org \
--to=matttbe@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kuniyu@google.com \
--cc=mptcp@lists.linux.dev \
--cc=sashiko@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