Skip to content

Commit 32e18e7

Browse files
Oliver CrumrineMartin KaFai Lau
authored andcommitted
bpf: remove check in __cgroup_bpf_run_filter_skb
Originally, this patch removed a redundant check in BPF_CGROUP_RUN_PROG_INET_EGRESS, as the check was already being done in the function it called, __cgroup_bpf_run_filter_skb. For v2, it was reccomended that I remove the check from __cgroup_bpf_run_filter_skb, and add the checks to the other macro that calls that function, BPF_CGROUP_RUN_PROG_INET_INGRESS. To sum it up, checking that the socket exists and that it is a full socket is now part of both macros BPF_CGROUP_RUN_PROG_INET_EGRESS and BPF_CGROUP_RUN_PROG_INET_INGRESS, and it is no longer part of the function they call, __cgroup_bpf_run_filter_skb. v3->v4: Fixed weird merge conflict. v2->v3: Sent to bpf-next instead of generic patch v1->v2: Addressed feedback about where check should be removed. Signed-off-by: Oliver Crumrine <ozlinuxc@gmail.com> Acked-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/r/7lv62yiyvmj5a7eozv2iznglpkydkdfancgmbhiptrgvgan5sy@3fl3onchgdz3 Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 2c21a0f commit 32e18e7

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

include/linux/bpf-cgroup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
196196
({ \
197197
int __ret = 0; \
198198
if (cgroup_bpf_enabled(CGROUP_INET_INGRESS) && \
199-
cgroup_bpf_sock_enabled(sk, CGROUP_INET_INGRESS)) \
199+
cgroup_bpf_sock_enabled(sk, CGROUP_INET_INGRESS) && sk && \
200+
sk_fullsock(sk)) \
200201
__ret = __cgroup_bpf_run_filter_skb(sk, skb, \
201202
CGROUP_INET_INGRESS); \
202203
\

kernel/bpf/cgroup.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,9 +1364,6 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,
13641364
struct cgroup *cgrp;
13651365
int ret;
13661366

1367-
if (!sk || !sk_fullsock(sk))
1368-
return 0;
1369-
13701367
if (sk->sk_family != AF_INET && sk->sk_family != AF_INET6)
13711368
return 0;
13721369

0 commit comments

Comments
 (0)