From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v5 07/16] mptcp: add sock_map_update BPF helper
Date: Sun, 13 Sep 2026 10:30:55 +0000 [thread overview]
Message-ID: <20260913103056.3886D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <393478c81ea50e72c49041752385e9b4fc82d469.1789294365.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The verifier incorrectly allows bpf_mptcp_sock_map_update to be used with BPF_MAP_TYPE_SOCKHASH and other arbitrary map types, but its implementation treats the map strictly as an array-based BPF_MAP_TYPE_SOCKMAP. This causes type confusion and severe out-of-bounds memory corruption.
- [High] bpf_mptcp_sock_map_update modifies the parent MPTCP socket (msk) state without holding its socket lock, leading to data races with userspace and MPTCP stack operations.
- [High] bpf_mptcp_sock_map_update bypasses necessary socket state and operation context validation (sock_map_op_okay), allowing transient state MPTCP sockets or ANY standard TCP socket to be unsafely inserted into a sockmap.
--
commit d25c16225b28c5b937139f3df217e21f3cd9bb7b
Author: Geliang Tang <geliang@kernel.org>
mptcp: add sock_map_update BPF helper
Add a BPF helper bpf_mptcp_sock_map_update() that allows sockops programs
running on MPTCP subflows to insert the parent MPTCP socket into a sockmap
or sockhash. When called from a sockops callback on a subflow, it resolves
the parent MPTCP socket via bpf_mptcp_sock_from_subflow() and validates
that the subflow is the first subflow (msk->first) before inserting the
MPTCP socket into the map via sock_map_update_common().
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 72a3f5998dd27..c58c2ba87d264 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -9075,6 +9076,7 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
> func_id != BPF_FUNC_msg_redirect_hash &&
> func_id != BPF_FUNC_sk_select_reuseport &&
> func_id != BPF_FUNC_map_lookup_elem &&
> + func_id != BPF_FUNC_mptcp_sock_map_update &&
> !may_update_sockmap(env, func_id))
> goto error;
> break;
[Severity: Critical]
Does allowing BPF_FUNC_mptcp_sock_map_update for BPF_MAP_TYPE_SOCKHASH maps
cause type confusion?
Because mptcp_sock_map_update() calls sock_map_update_common() which casts
the map to struct bpf_stab, passing a SOCKHASH (backed by struct bpf_shtab)
will write the socket pointer into what it thinks is the stab->sks array.
Couldn't this overlap with hash bucket lists or spinlocks and corrupt memory?
Additionally, because BPF_FUNC_mptcp_sock_map_update is omitted from the
subsequent switch (func_id) statement in check_map_func_compatibility(),
could this helper be incorrectly allowed for other unrestricted map types
like ARRAY or HASH?
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index 662b80ce2cf63..7ecafbf51fa05 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
[ ... ]
> +BPF_CALL_4(mptcp_sock_map_update, struct bpf_sock_ops_kern *, sops,
> + struct bpf_map *, map, void *, key, u64, flags)
> +{
> + struct sock *sk = sops->sk;
> + struct mptcp_sock *msk;
> +
> + WARN_ON_ONCE(!rcu_read_lock_held());
> +
> + msk = bpf_mptcp_sock_from_subflow(sk);
> + if (msk) {
[Severity: High]
Does this bypass the socket state and operation validation checks normally
performed before inserting a socket into a sockmap?
If a BPF program calls this helper from an early hook (e.g.,
BPF_SOCK_OPS_TCP_CONNECT_CB) to insert a TCP_SYN_SENT socket, it appears
unprepared or closing sockets could be inserted, violating subsystem
invariants.
Furthermore, if the socket is a standard TCP socket rather than an MPTCP
subflow, bpf_mptcp_sock_from_subflow() returns NULL. Would this cause the
helper to silently fall through and insert the standard TCP socket into the
map, completely bypassing checks like sock_map_op_okay() and
sock_map_sk_is_suitable()?
> + if (sk != READ_ONCE(msk->first))
> + return -EINVAL;
> +
> + sk = (struct sock *)msk;
[Severity: High]
Does modifying the parent MPTCP socket (msk) state without holding its socket
lock lead to data races with userspace and MPTCP stack operations?
When called from a sockops hook running on a subflow socket, the network stack
only holds the subflow socket lock, not the parent MPTCP socket lock.
Because sock_map_update_common() modifies the socket's protocol operations
(sk->sk_prot) and sets sk_user_data, could modifying sk_prot concurrently
while another CPU executes userspace system calls (e.g., recvmsg or sendmsg)
on the parent socket cause use-after-free crashes or data corruption?
> + }
> +
> + return sock_map_update_common(map, *(u32 *)key, sk, flags);
[Severity: Critical]
Does unconditionally calling the array-based sockmap update logic here cause
type confusion when a hash map is supplied?
Also, doesn't this truncate variable-length hash keys to u32?
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1789294365.git.tanggeliang@kylinos.cn?part=7
next prev parent reply other threads:[~2026-09-13 10:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 10:14 [PATCH mptcp-next v5 00/16] MPTCP sockmap support Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 01/16] mptcp: defer read_sock cleanup to mptcp_worker Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 02/16] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 03/16] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 04/16] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 05/16] bpf: drop duplicate check_app_limited in tcp_bpf_push Geliang Tang
2026-09-13 18:18 ` Matthieu Baerts
2026-09-13 10:14 ` [PATCH mptcp-next v5 06/16] mptcp: implement psock_update_sk_prot for sockmap Geliang Tang
2026-09-13 10:46 ` sashiko-bot
2026-09-13 18:22 ` Matthieu Baerts
2026-09-13 10:14 ` [PATCH mptcp-next v5 07/16] mptcp: add sock_map_update BPF helper Geliang Tang
2026-09-13 10:30 ` sashiko-bot [this message]
2026-09-13 10:14 ` [PATCH mptcp-next v5 08/16] selftests/bpf: enable MPTCP support in sockmap tests Geliang Tang
2026-09-13 10:33 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 09/16] mptcp: implement read_skb for sockmap stream verdict Geliang Tang
2026-09-13 10:40 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 10/16] bpf: export and generalize tcp_bpf_ioctl Geliang Tang
2026-09-13 10:28 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 11/16] mptcp: add TCP_REPAIR sockopt support Geliang Tang
2026-09-13 10:38 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 12/16] selftests/bpf: add MPTCP coverage to sockmap_basic Geliang Tang
2026-09-13 10:30 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 13/16] mptcp: add sk_is_msk() helper and use it in sockmap Geliang Tang
2026-09-13 10:48 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 14/16] mptcp: add SO_ATTACH_REUSEPORT_EBPF support Geliang Tang
2026-09-13 10:14 ` [PATCH mptcp-next v5 15/16] mptcp: add sk_select_reuseport BPF helper Geliang Tang
2026-09-13 10:48 ` sashiko-bot
2026-09-13 10:14 ` [PATCH mptcp-next v5 16/16] selftests/bpf: add MPTCP coverage to sockmap_listen Geliang Tang
2026-09-13 10:45 ` sashiko-bot
2026-09-13 11:24 ` [PATCH mptcp-next v5 00/16] MPTCP sockmap support MPTCP CI
2026-09-13 11:43 ` 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=20260913103056.3886D1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=geliang@kernel.org \
--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 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.