bpf: Allow CGROUP_SKB eBPF program to access sk_buff
Subsystems (4)
PATCH 1/2 bpf: Allow CGROUP_SKB eBPF program to access sk_buff
From: Chenbo Feng <[email protected]>
This allows cgroup eBPF program to classify packet based on their protocol or other detail information. Currently program need CAP_NET_ADMIN privilege to attach a cgroup eBPF program, and A process with CAP_NET_ADMIN can already see all packets on the system, for example, by creating an iptables rules that causes the packet to be passed to userspace via NFLOG.
--- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+)
kernel/bpf/verifier.c +1 -0
@@ -2419,6 +2419,7 @@ static bool may_access_skb(enum bpf_prog_type type)case BPF_PROG_TYPE_SOCKET_FILTER :case BPF_PROG_TYPE_SCHED_CLS :case BPF_PROG_TYPE_SCHED_ACT : +case BPF_PROG_TYPE_CGROUP_SKB :return true;default :return false;
Signature · 1 line
2.7.4
PATCH 2/2 bpf: Remove the capability check for cgroup skb eBPF program
From: Chenbo Feng <[email protected]>
Currently loading a cgroup skb eBPF program require a CAP_SYS_ADMIN capability while attaching the program to a cgroup only requires the user have CAP_NET_ADMIN privilege. We can escape the capability check when load the program just like socket filter program to make the capability requirement consistent.
--- kernel/bpf/syscall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +3 -1
@@ -815,7 +815,9 @@ static int bpf_prog_load(union bpf_attr *attr) attr->kern_version != LINUX_VERSION_CODE)return -EINVAL ; -if (type !=BPF_PROG_TYPE_SOCKET_FILTER && !capable (CAP_SYS_ADMIN )) +if (type !=BPF_PROG_TYPE_SOCKET_FILTER + && type !=BPF_PROG_TYPE_CGROUP_SKB + && !capable (CAP_SYS_ADMIN ))return -EPERM ;/* plain bpf_prog allocation */
Signature · 1 line
2.7.4
RE: [PATCH net-next 2/2] bpf: Remove the capability check for cgroup skb eBPF program
hi
kernel/bpf/syscall.c static int bpf_prog_load(union bpf_attr *attr) · line 820
Quoted 13 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Chenbo Feng
Sent: Thursday, June 01, 2017 2:07 AM
To: [email protected]; David Miller
Cc: Lorenzo Colitti; Chenbo Feng
Subject: [PATCH net-next 2/2] bpf: Remove the capability check for cgroup skb eBPF program(quoted diff) +0
-1- if (type != BPF_PROG_TYPE_SOCKET_FILTER&& !capable(CAP_SYS_ADMIN))
kernel/bpf/syscall.c +3
-0+if (type !=BPF_PROG_TYPE_SOCKET_FILTER + && type !=BPF_PROG_TYPE_CGROUP_SKB + && !capable (CAP_SYS_ADMIN ))
checkpatch.pl prefer put && at end of line
Quoted 5 lines
kernel/bpf/syscall.c +0
-1return -EPERM ;/* plain bpf_prog allocation */ --2.7.4