From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v5 10/16] bpf: export and generalize tcp_bpf_ioctl
Date: Sun, 13 Sep 2026 10:28:38 +0000 [thread overview]
Message-ID: <20260913102838.952271F000FF@smtp.kernel.org> (raw)
In-Reply-To: <2470bdd0b43b4b4530edd7d0448e0e92bd8e578f.1789294365.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Calling `sk->sk_prot->ioctl(sk, cmd, karg)` from within `tcp_bpf_ioctl` unconditionally causes an infinite recursive loop, leading to kernel stack exhaustion and a panic (DoS).
- [Critical] Dereferencing `sk->sk_socket->ops->peek_len` unconditionally crashes on MPTCP sockets because their protocol operations do not implement the `.peek_len` callback.
--
commit 2a70238c7c665c1d078c38019a80c54ba0029da5
Author: Geliang Tang <geliang@kernel.org>
bpf: export and generalize tcp_bpf_ioctl
This commit exports tcp_bpf_ioctl() and generalizes it to use
protocol-specific operations instead of hard-coded TCP functions. It also
wires this generalized ioctl handler into the MPTCP BPF protocol structures
so that SIOCINQ returns correct results accounting for data in the psock
ingress queue.
> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index e006131696e96..8aed3c309b0dc 100644
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
[ ... ]
> @@ -331,15 +331,15 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
> return copied;
> }
>
> -static int tcp_bpf_ioctl(struct sock *sk, int cmd, int *karg)
> +int tcp_bpf_ioctl(struct sock *sk, int cmd, int *karg)
> {
> struct sk_psock *psock;
> bool slow;
>
> if (cmd != SIOCINQ)
> - return tcp_ioctl(sk, cmd, karg);
> + return sk->sk_prot->ioctl(sk, cmd, karg);
[Severity: Critical]
Does this cause an infinite recursive loop regression?
When a socket is attached to a BPF sockmap, its protocol operations
structure is replaced by a BPF-specific protocol structure. Since this patch
assigns .ioctl = tcp_bpf_ioctl in those structures, sk->sk_prot->ioctl will
resolve right back to tcp_bpf_ioctl itself, exhausting the kernel stack and
leading to a system panic.
>
> - /* works similar as tcp_ioctl */
> + /* works similar as sk_prot->ioctl */
> if (sk->sk_state == TCP_LISTEN)
> return -EINVAL;
>
> @@ -347,7 +347,7 @@ static int tcp_bpf_ioctl(struct sock *sk, int cmd, int *karg)
> psock = sk_psock_get(sk);
> if (unlikely(!psock)) {
> unlock_sock_fast(sk, slow);
> - return tcp_ioctl(sk, cmd, karg);
> + return sk->sk_prot->ioctl(sk, cmd, karg);
[Severity: Critical]
Will this fallback path also trigger the same infinite recursion regression
as above?
> }
> *karg = sk_psock_get_msg_len_nolock(psock);
> /* Without a verdict program, ingress data is never diverted to
> @@ -357,7 +357,7 @@ static int tcp_bpf_ioctl(struct sock *sk, int cmd, int *karg)
> */
> if (!READ_ONCE(psock->progs.stream_verdict) &&
> !READ_ONCE(psock->progs.skb_verdict))
> - *karg += tcp_inq(sk);
> + *karg += sk->sk_socket->ops->peek_len(sk->sk_socket);
[Severity: Critical]
Will this cause a NULL pointer dereference regression for MPTCP sockets?
While TCP's socket operations define a .peek_len callback, MPTCP's socket
operations do not implement it, leaving the function pointer initialized to
NULL. Dereferencing it unconditionally here will crash when SIOCINQ is
invoked on an MPTCP socket attached to a BPF sockmap.
> sk_psock_put(sk, psock);
> unlock_sock_fast(sk, slow);
>
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index 7ecafbf51fa05..f6fd610f70778 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -398,6 +398,7 @@ static void mptcp_bpf_rebuild_protos(struct proto prot[MPTCP_BPF_NUM_CFGS],
> prot[MPTCP_BPF_BASE].close = sock_map_close;
> prot[MPTCP_BPF_BASE].recvmsg = mptcp_bpf_recvmsg;
> prot[MPTCP_BPF_BASE].sock_is_readable = sk_msg_is_readable;
> + prot[MPTCP_BPF_BASE].ioctl = tcp_bpf_ioctl;
[Severity: Critical]
Since tcp_bpf_ioctl is wired into the MPTCP BPF protocol structure here,
does this expose MPTCP sockets to the NULL pointer dereference mentioned
above?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1789294365.git.tanggeliang@kylinos.cn?part=10
next prev parent reply other threads:[~2026-09-13 10:28 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
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 [this message]
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=20260913102838.952271F000FF@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox