bpf: Misc changes around AF_UNIX.
Subsystems (4)
cover bpf: Misc changes around AF_UNIX.
Patch 1 adapts sk_is_XXX() helpers in __cgroup_bpf_run_filter_sock_addr(). Patch 2 removes an unnecessary sk_fullsock() in bpf_skc_to_unix_sock().
Kuniyuki Iwashima (2):
bpf: Use sk_is_inet() and sk_is_unix() in
__cgroup_bpf_run_filter_sock_addr().
bpf: Don't check sk_fullsock() in bpf_skc_to_unix_sock().
kernel/bpf/cgroup.c | 6 +----- net/core/filter.c | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
PATCH 1/2 bpf: Use sk_is_inet() and sk_is_unix() in __cgroup_bpf_run_filter_sock_addr().
sk->sk_family should be read with READ_ONCE() in __cgroup_bpf_run_filter_sock_addr() due to IPV6_ADDRFORM.
Also, the comment there is a bit stale since commit 859051dd165e ("bpf: Implement cgroup sockaddr hooks for unix sockets"), and the kdoc has the same comment.
Let's use sk_is_inet() and sk_is_unix() and remove the comment.
--- kernel/bpf/cgroup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/bpf/cgroup.c +1 -5
@@ -1680,11 +1680,7 @@ int __cgroup_bpf_run_filter_sock_addr(struct sock *sk,struct cgroup *cgrp;int ret; -/* Check socket family since not all sockets represent network -* endpoint (e.g. AF_UNIX). -*/ -if (sk->sk_family !=AF_INET && sk->sk_family !=AF_INET6 && - sk->sk_family !=AF_UNIX ) +if (!sk_is_inet (sk) && !sk_is_unix (sk))return 0 ;if (!ctx.uaddr) {
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
PATCH 2/2 bpf: Don't check sk_fullsock() in bpf_skc_to_unix_sock().
In reply to Kuniyuki IwashimaAF_UNIX does not use TCP_NEW_SYN_RECV nor TCP_TIME_WAIT and checking sk->sk_family is sufficient.
Let's remove sk_fullsock() and use sk_is_unix() in bpf_skc_to_unix_sock().
--- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
@@ -12021,7 +12021,7 @@ BPF_CALL_1(bpf_skc_to_unix_sock, struct sock *, sk)* trigger an explicit type generation here. */ BTF_TYPE_EMIT (struct unix_sock ); -if (sk &&sk_fullsock (sk) && sk->sk_family ==AF_UNIX ) +if (sk &&sk_is_unix (sk))return (unsigned long )sk;return (unsigned long )NULL ;
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Quoted 8 lines · Kuniyuki Iwashima
Patch 1 adapts
sk_is_XXX()helpers in__cgroup_bpf_run_filter_sock_addr(). Patch 2 removes an unnecessarysk_fullsock()inbpf_skc_to_unix_sock().Kuniyuki Iwashima (2):
bpf: Usesk_is_inet()andsk_is_unix()in__cgroup_bpf_run_filter_sock_addr().bpf: Don't check
sk_fullsock()inbpf_skc_to_unix_sock().
Martin KaFai Lau
reviewerQuoted 11 lines · Kuniyuki Iwashima
Patch 1 adapts
sk_is_XXX()helpers in__cgroup_bpf_run_filter_sock_addr(). Patch 2 removes an unnecessarysk_fullsock()inbpf_skc_to_unix_sock().Kuniyuki Iwashima (2):
bpf: Usesk_is_inet()andsk_is_unix()in__cgroup_bpf_run_filter_sock_addr().bpf: Don't check
sk_fullsock()inbpf_skc_to_unix_sock().kernel/bpf/cgroup.c | 6 +----- net/core/filter.c | 2 +-
The bot is slow. The change in filter.c is small and the cycle is closing, so I have landed them to the bpf_next/master.
I just noticed the netdev list is not in cc, so added it here also.