diff options
author | Martin KaFai Lau <kafai@fb.com> | 2016-06-30 13:28:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-07-01 16:32:13 -0400 |
commit | 4a482f34afcc162d8456f449b137ec2a95be60d8 (patch) | |
tree | 0eb3ace759a7df82f868dc4d999fb65f120cabb2 /kernel/bpf/verifier.c | |
parent | 4ed8ec521ed57c4e207ad464ca0388776de74d4b (diff) |
cgroup: bpf: Add bpf_skb_in_cgroup_proto
Adds a bpf helper, bpf_skb_in_cgroup, to decide if a skb->sk
belongs to a descendant of a cgroup2. It is similar to the
feature added in netfilter:
commit c38c4597e4bf ("netfilter: implement xt_cgroup cgroup2 path match")
The user is expected to populate a BPF_MAP_TYPE_CGROUP_ARRAY
which will be used by the bpf_skb_in_cgroup.
Modifications to the bpf verifier is to ensure BPF_MAP_TYPE_CGROUP_ARRAY
and bpf_skb_in_cgroup() are always used together.
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/verifier.c')
-rw-r--r-- | kernel/bpf/verifier.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 69ba2251a22b..e206c2181412 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c | |||
@@ -1036,7 +1036,9 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id) | |||
1036 | goto error; | 1036 | goto error; |
1037 | break; | 1037 | break; |
1038 | case BPF_MAP_TYPE_CGROUP_ARRAY: | 1038 | case BPF_MAP_TYPE_CGROUP_ARRAY: |
1039 | goto error; | 1039 | if (func_id != BPF_FUNC_skb_in_cgroup) |
1040 | goto error; | ||
1041 | break; | ||
1040 | default: | 1042 | default: |
1041 | break; | 1043 | break; |
1042 | } | 1044 | } |
@@ -1056,6 +1058,10 @@ static int check_map_func_compatibility(struct bpf_map *map, int func_id) | |||
1056 | if (map->map_type != BPF_MAP_TYPE_STACK_TRACE) | 1058 | if (map->map_type != BPF_MAP_TYPE_STACK_TRACE) |
1057 | goto error; | 1059 | goto error; |
1058 | break; | 1060 | break; |
1061 | case BPF_FUNC_skb_in_cgroup: | ||
1062 | if (map->map_type != BPF_MAP_TYPE_CGROUP_ARRAY) | ||
1063 | goto error; | ||
1064 | break; | ||
1059 | default: | 1065 | default: |
1060 | break; | 1066 | break; |
1061 | } | 1067 | } |