]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: tcp: Fix type confusion in sol_tcp_sockopt().
authorKuniyuki Iwashima <kuniyu@google.com>
Mon, 4 May 2026 21:04:53 +0000 (21:04 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 8 May 2026 18:38:10 +0000 (11:38 -0700)
sol_tcp_sockopt() only checks if sk->sk_protocol is IPPROTO_TCP,
but RAW socket can bypass it:

  socket(AF_INET, SOCK_RAW, IPPROTO_TCP)

Let's use sk_is_tcp().

Note that initially sol_tcp_sockopt() checked sk->sk_prot->setsockopt.

Fixes: 2ab42c7b871f ("bpf: Check the protocol of a sock to agree the calls to bpf_setsockopt().")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260504210610.180150-7-kuniyu@google.com
net/core/filter.c

index 684922efd48106fbba681093a31b50422b506fed..ef0877eefaa7cfab152912f084ad4102374675d4 100644 (file)
@@ -5481,7 +5481,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
                           char *optval, int *optlen,
                           bool getopt)
 {
-       if (sk->sk_protocol != IPPROTO_TCP)
+       if (!sk_is_tcp(sk))
                return -EINVAL;
 
        switch (optname) {