bpf_skc_to_tcp6_sock() only checks if sk->sk_protocol is IPPROTO_TCP and sk->sk_family is AF_INET6, but RAW socket can bypass it: socket(AF_INET6, SOCK_RAW, IPPROTO_TCP) Let's check sk->sk_type too.
Unified · Split
| @@ -11947,7 +11947,7 @@ BPF_CALL_1(bpf_skc_to_tcp6_sock, struct sock *, sk) · 11946 unmodified lines | |||
| 11947 | */ | 11947 | */ |
| 11948 | BTF_TYPE_EMIT(struct tcp6_sock); | 11948 | BTF_TYPE_EMIT(struct tcp6_sock); |
| 11949 | if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && | 11949 | if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && |
| 11950 | sk->sk_family == AF_INET6) | 11950 | sk->sk_type == SOCK_STREAM && sk->sk_family == AF_INET6) |
| 11951 | return (unsigned long)sk; | 11951 | return (unsigned long)sk; |
| 11952 | 11952 | ||
| 11953 | return (unsigned long)NULL; | 11953 | return (unsigned long)NULL; |