mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-10 14:19:09 -04:00
UPSTREAM: bpf: Bpf_skc_to_* casting helpers require a NULL check on sk
The bpf_skc_to_* type casting helpers are available to
BPF_PROG_TYPE_TRACING. The traced PTR_TO_BTF_ID may be NULL.
For example, the skb->sk may be NULL. Thus, these casting helpers
need to check "!sk" also and this patch fixes them.
Fixes: 0d4fad3e57df ("bpf: Add bpf_skc_to_udp6_sock() helper")
Fixes: 478cfbdf5f13 ("bpf: Add bpf_skc_to_{tcp, tcp_timewait, tcp_request}_sock() helpers")
Fixes: af7ec1383361 ("bpf: Add bpf_skc_to_tcp6_sock() helper")
Change-Id: Ia3705bf63acedaa26eff72b0889e99ff44e63e2d
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200915182959.241101-1-kafai@fb.com
This commit is contained in:
parent
796d3586f3
commit
d0a0ab7359
1 changed files with 7 additions and 7 deletions
|
|
@ -10028,7 +10028,7 @@ BPF_CALL_1(bpf_skc_to_tcp6_sock, struct sock *, sk)
|
|||
* trigger an explicit type generation here.
|
||||
*/
|
||||
BTF_TYPE_EMIT(struct tcp6_sock);
|
||||
if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP &&
|
||||
if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP &&
|
||||
sk->sk_family == AF_INET6)
|
||||
return (unsigned long)sk;
|
||||
|
||||
|
|
@ -10046,7 +10046,7 @@ const struct bpf_func_proto bpf_skc_to_tcp6_sock_proto = {
|
|||
|
||||
BPF_CALL_1(bpf_skc_to_tcp_sock, struct sock *, sk)
|
||||
{
|
||||
if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP)
|
||||
if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP)
|
||||
return (unsigned long)sk;
|
||||
|
||||
return (unsigned long)NULL;
|
||||
|
|
@ -10064,12 +10064,12 @@ const struct bpf_func_proto bpf_skc_to_tcp_sock_proto = {
|
|||
BPF_CALL_1(bpf_skc_to_tcp_timewait_sock, struct sock *, sk)
|
||||
{
|
||||
#ifdef CONFIG_INET
|
||||
if (sk->sk_prot == &tcp_prot && sk->sk_state == TCP_TIME_WAIT)
|
||||
if (sk && sk->sk_prot == &tcp_prot && sk->sk_state == TCP_TIME_WAIT)
|
||||
return (unsigned long)sk;
|
||||
#endif
|
||||
|
||||
#if IS_BUILTIN(CONFIG_IPV6)
|
||||
if (sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_TIME_WAIT)
|
||||
if (sk && sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_TIME_WAIT)
|
||||
return (unsigned long)sk;
|
||||
#endif
|
||||
|
||||
|
|
@ -10088,12 +10088,12 @@ const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = {
|
|||
BPF_CALL_1(bpf_skc_to_tcp_request_sock, struct sock *, sk)
|
||||
{
|
||||
#ifdef CONFIG_INET
|
||||
if (sk->sk_prot == &tcp_prot && sk->sk_state == TCP_NEW_SYN_RECV)
|
||||
if (sk && sk->sk_prot == &tcp_prot && sk->sk_state == TCP_NEW_SYN_RECV)
|
||||
return (unsigned long)sk;
|
||||
#endif
|
||||
|
||||
#if IS_BUILTIN(CONFIG_IPV6)
|
||||
if (sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_NEW_SYN_RECV)
|
||||
if (sk && sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_NEW_SYN_RECV)
|
||||
return (unsigned long)sk;
|
||||
#endif
|
||||
|
||||
|
|
@ -10115,7 +10115,7 @@ BPF_CALL_1(bpf_skc_to_udp6_sock, struct sock *, sk)
|
|||
* trigger an explicit type generation here.
|
||||
*/
|
||||
BTF_TYPE_EMIT(struct udp6_sock);
|
||||
if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_UDP &&
|
||||
if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_UDP &&
|
||||
sk->sk_type == SOCK_DGRAM && sk->sk_family == AF_INET6)
|
||||
return (unsigned long)sk;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue