From: Geliang Tang <geliang@kernel.org>
To: Shardul Bankar <shardul.b@mpiricsoftware.com>, mptcp@lists.linux.dev
Cc: Matthieu Baerts <matttbe@kernel.org>,
Mat Martineau <martineau@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
kalpan.jani@mpiricsoftware.com, janak@mpiric.us,
shardulsb08@gmail.com
Subject: Re: [PATCH mptcp-next v2 2/5] Squash to "bpf: Export mptcp packet scheduler helpers"
Date: Mon, 06 Jul 2026 14:34:14 +0800 [thread overview]
Message-ID: <0dc8e723ee2af76224d2fe23eca6c4891207fbe0.camel@kernel.org> (raw)
In-Reply-To: <20260703-mptcp_bpf_kfunc_fixes-v2-2-87ae3c64dc7e@mpiricsoftware.com>
Hi Shardul,
Thanks for this v2. It's much better now.
On Fri, 2026-07-03 at 22:27 +0530, Shardul Bankar wrote:
> mptcp_pm_subflow_chk_stale() is exposed to BPF MPTCP packet
> schedulers as
> a kfunc taking a generic "struct sock *ssk", but it treats ssk as a
> subflow TCP socket: it derives the subflow context with
> mptcp_subflow_ctx(), an unchecked cast of inet_csk(ssk)-
> >icsk_ulp_data,
> then reads and writes through it. The verifier only proves ssk is a
> trusted struct sock, not that it is one of msk's subflows, so a
> mistyped
> or foreign socket would make the helper operate on a bogus context.
>
> Register a bpf_mptcp_pm_subflow_chk_stale() wrapper that validates
> ssk is
> a full MPTCP subflow TCP socket belonging to the passed msk before
> calling
> the helper, which assumes both but checks neither. This mirrors
> bpf_mptcp_subflow_ctx(). A scheduler passing one of its own subflows
> is
> unaffected; the in-tree burst scheduler selftest is updated to the
> wrapper
> name in a separate squash-to.
>
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com>
> ---
> net/mptcp/bpf.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index 9355fb53e89d5..e2d2c3394ad71 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -306,6 +306,18 @@ __bpf_kfunc static void
> bpf_mptcp_set_timeout(struct mptcp_sock *msk)
> mptcp_set_timeout((struct sock *)msk);
> }
>
> +__bpf_kfunc static void
> +bpf_mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct
> sock *ssk)
> +{
> + if (ssk && sk_fullsock(ssk) && ssk->sk_type == SOCK_STREAM
> &&
> + ssk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(ssk)) {
> + struct mptcp_subflow_context *subflow =
> mptcp_subflow_ctx(ssk);
> +
> + if (subflow && subflow->conn == (const struct sock
> *)msk)
Sashiko complained that the rcu lock is not held here [1]. It seems we
can add the lock, something like:
rcu_read_lock();
subflow = mptcp_subflow_ctx(ssk);
if (subflow && subflow->conn == (const struct sock *)msk)
mptcp_pm_subflow_chk_stale(msk, ssk);
rcu_read_unlock();
WDYT?
Thanks,
-Geliang
[1]
https://sashiko.dev/#/patchset/20260703-mptcp_bpf_kfunc_fixes-v2-0-87ae3c64dc7e@mpiricsoftware.com?part=2
> + mptcp_pm_subflow_chk_stale(msk, ssk);
> + }
> +}
> +
> __bpf_kfunc_end_defs();
>
> BTF_KFUNCS_START(bpf_mptcp_iter_kfunc_ids)
> @@ -327,7 +339,7 @@ BTF_ID_FLAGS(func, mptcp_subflow_active)
> BTF_ID_FLAGS(func, bpf_mptcp_set_timeout)
> BTF_ID_FLAGS(func, mptcp_wnd_end)
> BTF_ID_FLAGS(func, bpf_sk_stream_memory_free)
> -BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
> +BTF_ID_FLAGS(func, bpf_mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
> BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)
>
> static int bpf_mptcp_common_kfunc_filter(const struct bpf_prog
> *prog, u32 kfunc_id)
next prev parent reply other threads:[~2026-07-06 6:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 16:57 [PATCH mptcp-next v2 0/5] mptcp: bpf: fix scheduler kfunc socket type confusion Shardul Bankar
2026-07-03 16:57 ` [PATCH mptcp-next v2 1/5] Squash to "bpf: Export mptcp packet scheduler helpers" Shardul Bankar
2026-07-03 16:57 ` [PATCH mptcp-next v2 2/5] " Shardul Bankar
2026-07-06 6:34 ` Geliang Tang [this message]
2026-07-06 11:03 ` Shardul Bankar
2026-07-22 10:47 ` Geliang Tang
2026-07-03 16:57 ` [PATCH mptcp-next v2 3/5] Squash to "selftests/bpf: Add bpf_burst scheduler & test" Shardul Bankar
2026-07-03 16:57 ` [PATCH mptcp-next v2 4/5] DO-NOT-MERGE: selftests/bpf: mptcp: verify scheduler rejects non-msk socket to set_timeout Shardul Bankar
2026-07-03 16:57 ` [PATCH mptcp-next v2 5/5] DO-NOT-MERGE: selftests/bpf: mptcp: extend bad scheduler test to the kfunc type contract Shardul Bankar
2026-07-03 18:18 ` [PATCH mptcp-next v2 0/5] mptcp: bpf: fix scheduler kfunc socket type confusion 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=0dc8e723ee2af76224d2fe23eca6c4891207fbe0.camel@kernel.org \
--to=geliang@kernel.org \
--cc=janak@mpiric.us \
--cc=kalpan.jani@mpiricsoftware.com \
--cc=martineau@kernel.org \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox