]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mptcp: bpf: Fix type confusion in bpf_mptcp_sock_from_subflow()
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Mon, 4 May 2026 21:04:50 +0000 (21:04 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 8 May 2026 18:38:10 +0000 (11:38 -0700)
bpf_mptcp_sock_from_subflow() only checks if sk->sk_protocol is
IPPROTO_TCP, but RAW socket can bypass it:

  socket(AF_INET, SOCK_RAW, IPPROTO_TCP)

In this case, it would NOT be valid to call sk_is_mptcp() which will
assume sk is a pointer to a struct tcp_sock, and wrongly checks for:
tcp_sk(sk)->is_mptcp.

Fixes: 3bc253c2e652 ("bpf: Add bpf_skc_to_mptcp_sock_proto")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260504210610.180150-4-kuniyu@google.com
net/mptcp/bpf.c

index 8a16672b94e2384f5263e1432296cbca1236bb30..4cc16cbeb328174bcf40e27bbc15dd479296651b 100644 (file)
@@ -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);
 
        return NULL;