Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/19/2016 11:53 PM, Sargun Dhillon wrote: > On Mon, Sep 19, 2016 at 06:34:28PM +0200, Daniel Mack wrote: >> On 09/16/2016 09:57 PM, Sargun Dhillon wrote: >>> Now, with this patch, we don't have that, but I think we can reasonably add >>> some >>> flag like "no override" when applying policies, or alternatively something >>> like >>> "no new privileges", to prevent children from applying policies that >>> override >>> top-level policy. >> >> Yes, but the API is already guarded by CAP_NET_ADMIN. Take that >> capability away from your children, and they can't tamper with the >> policy. Does that work for you? > > No. This can be addressed in a follow-on patch, but the use-case is that I > have > a container orchestrator (Docker, or Mesos), and systemd. The sysadmin > controls > systemd, and Docker is controlled by devs. Typically, the system owner wants > some system level statistics, and filtering, and then we want to do > per-container filtering. > > We really want to be able to do nesting with userspace tools that are > oblivious, > and we want to delegate a level of the cgroup hierarchy to the tool that > created > it. I do not see Docker integrating with systemd any time soon, and that's > really the only other alternative. Then we'd need to find out whether you want to block other users from installing (thus overriding) an existing eBPF program, or if you want to allow that but execute them all. Both is possible. [...] >>> It would be nice to be able to see whether or not a filter is attached to a >>> cgroup, but given this is going through syscalls, at least introspection >>> is possible as opposed to something like netlink. >> >> Sure, there are many ways. I implemented the bpf cgroup logic using an >> own cgroup controller once, which made it possible to read out the >> status. But as we agreed on attaching programs through the bpf(2) system >> call, I moved back to the implementation that directly stores the >> pointers in the cgroup. >> >> First enabling the controller through the fs-backed cgroup interface, >> then come back through the bpf(2) syscall and then go back to the fs >> interface to read out status values is a bit weird. >> > Hrm, that makes sense. with the BPF syscall, would there be a way to get > file descriptor of the currently attached BPF program? A file descriptor is local to a task, so we would need to install a new fd and return its number. But I'm not sure what we'd gain from that. Thanks, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Mon, Sep 19, 2016 at 06:34:28PM +0200, Daniel Mack wrote: > Hi, > > On 09/16/2016 09:57 PM, Sargun Dhillon wrote: > > On Wed, Sep 14, 2016 at 01:13:16PM +0200, Daniel Mack wrote: > > >> I have no idea what makes you think this is limited to systemd. As I > >> said, I provided an example for userspace that works from the command > >> line. The same limitation apply as for all other users of cgroups. > >> > > So, at least in my work, we have Mesos, but on nearly every machine that > > Mesos > > runs, people also have systemd. Now, there's recently become a bit of a > > battle > > of ownership of things like cgroups on these machines. We can usually solve > > it > > by nesting under systemd cgroups, and thus so far we've avoided making too > > many > > systemd-specific concessions. > > > > The reason this works (mostly), is because everything we touch has a sense > > of > > nesting, where we can apply policy at a place lower in the hierarchy, and > > yet > > systemd's monitoring and policy still stays in place. > > > > Now, with this patch, we don't have that, but I think we can reasonably add > > some > > flag like "no override" when applying policies, or alternatively something > > like > > "no new privileges", to prevent children from applying policies that > > override > > top-level policy. > > Yes, but the API is already guarded by CAP_NET_ADMIN. Take that > capability away from your children, and they can't tamper with the > policy. Does that work for you? > No. This can be addressed in a follow-on patch, but the use-case is that I have a container orchestrator (Docker, or Mesos), and systemd. The sysadmin controls systemd, and Docker is controlled by devs. Typically, the system owner wants some system level statistics, and filtering, and then we want to do per-container filtering. We really want to be able to do nesting with userspace tools that are oblivious, and we want to delegate a level of the cgroup hierarchy to the tool that created it. I do not see Docker integrating with systemd any time soon, and that's really the only other alternative. > > I realize there is a speed concern as well, but I think for > > people who want nested policy, we're willing to make the tradeoff. The cost > > of traversing a few extra pointers still outweighs the overhead of network > > namespaces, iptables, etc.. for many of us. > > Not sure. Have you tried it? > Tried nested policies? Yes. I tried nested policy execution with syscalls, and I tested with bind and connect. The performance overhead was pretty minimal, but latency increased by 100 microseconds+ once the number of BPF hooks increased beyond 30. The BPF programs were trivial, and essentially did a map lookup, and returned 0. I don't think that it's just raw cycles / execution time, but I didn't spend enough time digging into it to determine the performance hit. I'm waiting for your patchset to land, and then I plan to work off of it. > > What do you think Daniel? > > I think we should look at an implementation once we really need it, and > then revisit the performance impact. In any case, this can be changed > under the hood, without touching the userspace API (except for adding > flags if we need them). > +1 > >> Not necessarily. You can as well do it the inetd way, and pass the > >> socket to a process that is launched on demand, but do SO_ATTACH_FILTER > >> + SO_LOCK_FILTER in the middle. What happens with payload on the socket > >> is not transparent to the launched binary at all. The proposed cgroup > >> eBPF solution implements a very similar behavior in that regard. > > > > It would be nice to be able to see whether or not a filter is attached to a > > cgroup, but given this is going through syscalls, at least introspection > > is possible as opposed to something like netlink. > > Sure, there are many ways. I implemented the bpf cgroup logic using an > own cgroup controller once, which made it possible to read out the > status. But as we agreed on attaching programs through the bpf(2) system > call, I moved back to the implementation that directly stores the > pointers in the cgroup. > > First enabling the controller through the fs-backed cgroup interface, > then come back through the bpf(2) syscall and then go back to the fs > interface to read out status values is a bit weird. > Hrm, that makes sense. with the BPF syscall, would there be a way to get file descriptor of the currently attached BPF program? > >> And FWIW, I agree with Thomas - there is nothing wrong with having > >> multiple options to use for such use-cases. > > > > Right now, for containers, we have netfilter and network namespaces. > > There's a lot of performance overhead that comes with this. > > Out of curiosity: Could you express that in numbers? And how exactly are > you testing? > Sure. Our workload that we use as a baseline is Redis with redis-benchmark. We reconnect after every connection, and we're running
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
Hi, On 09/16/2016 09:57 PM, Sargun Dhillon wrote: > On Wed, Sep 14, 2016 at 01:13:16PM +0200, Daniel Mack wrote: >> I have no idea what makes you think this is limited to systemd. As I >> said, I provided an example for userspace that works from the command >> line. The same limitation apply as for all other users of cgroups. >> > So, at least in my work, we have Mesos, but on nearly every machine that > Mesos > runs, people also have systemd. Now, there's recently become a bit of a > battle > of ownership of things like cgroups on these machines. We can usually solve > it > by nesting under systemd cgroups, and thus so far we've avoided making too > many > systemd-specific concessions. > > The reason this works (mostly), is because everything we touch has a sense of > nesting, where we can apply policy at a place lower in the hierarchy, and yet > systemd's monitoring and policy still stays in place. > > Now, with this patch, we don't have that, but I think we can reasonably add > some > flag like "no override" when applying policies, or alternatively something > like > "no new privileges", to prevent children from applying policies that override > top-level policy. Yes, but the API is already guarded by CAP_NET_ADMIN. Take that capability away from your children, and they can't tamper with the policy. Does that work for you? > I realize there is a speed concern as well, but I think for > people who want nested policy, we're willing to make the tradeoff. The cost > of traversing a few extra pointers still outweighs the overhead of network > namespaces, iptables, etc.. for many of us. Not sure. Have you tried it? > What do you think Daniel? I think we should look at an implementation once we really need it, and then revisit the performance impact. In any case, this can be changed under the hood, without touching the userspace API (except for adding flags if we need them). >> Not necessarily. You can as well do it the inetd way, and pass the >> socket to a process that is launched on demand, but do SO_ATTACH_FILTER >> + SO_LOCK_FILTER in the middle. What happens with payload on the socket >> is not transparent to the launched binary at all. The proposed cgroup >> eBPF solution implements a very similar behavior in that regard. > > It would be nice to be able to see whether or not a filter is attached to a > cgroup, but given this is going through syscalls, at least introspection > is possible as opposed to something like netlink. Sure, there are many ways. I implemented the bpf cgroup logic using an own cgroup controller once, which made it possible to read out the status. But as we agreed on attaching programs through the bpf(2) system call, I moved back to the implementation that directly stores the pointers in the cgroup. First enabling the controller through the fs-backed cgroup interface, then come back through the bpf(2) syscall and then go back to the fs interface to read out status values is a bit weird. >> And FWIW, I agree with Thomas - there is nothing wrong with having >> multiple options to use for such use-cases. > > Right now, for containers, we have netfilter and network namespaces. > There's a lot of performance overhead that comes with this. Out of curiosity: Could you express that in numbers? And how exactly are you testing? > Not only > that, but iptables doesn't really have a simple way of usage by > automated infrastructure. We (firewalld, systemd, dockerd, mesos) > end up fighting with one another for ownership over firewall rules. Yes, that's a common problem. > Although, I have problems with this approach, I think that it's > a good baseline where we can have top level owned by systemd, > docker underneath that, and Mesos underneath that. We can add > additional hooks for things like Checmate and Landlock, and > with a little more work, we can do compositition, solving > all of our problems. It is supposed to be just a baseline, yes. Thanks for your feedback, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Fri, Sep 16, 2016 at 12:57:29PM -0700, Sargun Dhillon wrote: > On Wed, Sep 14, 2016 at 01:13:16PM +0200, Daniel Mack wrote: > > Hi Pablo, > > > > On 09/13/2016 07:24 PM, Pablo Neira Ayuso wrote: > > > On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: > > >> On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: > > >>> On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: > > This is v5 of the patch set to allow eBPF programs for network > > filtering and accounting to be attached to cgroups, so that they apply > > to all sockets of all tasks placed in that cgroup. The logic also > > allows to be extendeded for other cgroup based eBPF logic. > > >>> > > >>> 1) This infrastructure can only be useful to systemd, or any similar > > >>>orchestration daemon. Look, you can only apply filtering policies > > >>>to processes that are launched by systemd, so this only works > > >>>for server processes. > > >> > > >> Sorry, but both statements aren't true. The eBPF policies apply to every > > >> process that is placed in a cgroup, and my example program in 6/6 shows > > >> how that can be done from the command line. > > > > > > Then you have to explain me how can anyone else than systemd use this > > > infrastructure? > > > > I have no idea what makes you think this is limited to systemd. As I > > said, I provided an example for userspace that works from the command > > line. The same limitation apply as for all other users of cgroups. > > > So, at least in my work, we have Mesos, but on nearly every machine that > Mesos > runs, people also have systemd. Now, there's recently become a bit of a > battle > of ownership of things like cgroups on these machines. We can usually solve > it > by nesting under systemd cgroups, and thus so far we've avoided making too > many > systemd-specific concessions. > > The reason this works (mostly), is because everything we touch has a sense of > nesting, where we can apply policy at a place lower in the hierarchy, and yet > systemd's monitoring and policy still stays in place. > > Now, with this patch, we don't have that, but I think we can reasonably add > some > flag like "no override" when applying policies, or alternatively something > like > "no new privileges", to prevent children from applying policies that override > top-level policy. I realize there is a speed concern as well, but I think for > people who want nested policy, we're willing to make the tradeoff. The cost > of traversing a few extra pointers still outweighs the overhead of network > namespaces, iptables, etc.. for many of us. > > What do you think Daniel? > > > > My main point is that those processes *need* to be launched by the > > > orchestrator, which is was refering as 'server processes'. > > > > Yes, that's right. But as I said, this rule applies to many other kernel > > concepts, so I don't see any real issue. > > > Also, cgroups have become such a big part of how applications are managed > that many of us have solved this problem. > > > >> That's a limitation that applies to many more control mechanisms in the > > >> kernel, and it's something that can easily be solved with fork+exec. > > > > > > As long as you have control to launch the processes yes, but this > > > will not work in other scenarios. Just like cgroup net_cls and friends > > > are broken for filtering for things that you have no control to > > > fork+exec. > > > > Probably, but that's only solvable with rules that store the full cgroup > > path then, and do a string comparison (!) for each packet flying by. > > > > >> That's just as transparent as SO_ATTACH_FILTER. What kind of > > >> introspection mechanism do you have in mind? > > > > > > SO_ATTACH_FILTER is called from the process itself, so this is a local > > > filtering policy that you apply to your own process. > > > > Not necessarily. You can as well do it the inetd way, and pass the > > socket to a process that is launched on demand, but do SO_ATTACH_FILTER > > + SO_LOCK_FILTER in the middle. What happens with payload on the socket > > is not transparent to the launched binary at all. The proposed cgroup > > eBPF solution implements a very similar behavior in that regard. > > > It would be nice to be able to see whether or not a filter is attached to a > cgroup, but given this is going through syscalls, at least introspection > is possible as opposed to something like netlink. > > > >> It's about filtering outgoing network packets of applications, and > > >> providing them with L2 information for filtering purposes. I don't think > > >> that's a very specific use-case. > > >> > > >> When the feature is not used at all, the added costs on the output path > > >> are close to zero, due to the use of static branches. > > > > > > *You're proposing a socket filtering facility that hooks layer 2 > > > output path*! > > > > As I said, I'm open to discussing that. In order to make it work for L3, > >
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Wed, Sep 14, 2016 at 01:13:16PM +0200, Daniel Mack wrote: > Hi Pablo, > > On 09/13/2016 07:24 PM, Pablo Neira Ayuso wrote: > > On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: > >> On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: > >>> On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: > This is v5 of the patch set to allow eBPF programs for network > filtering and accounting to be attached to cgroups, so that they apply > to all sockets of all tasks placed in that cgroup. The logic also > allows to be extendeded for other cgroup based eBPF logic. > >>> > >>> 1) This infrastructure can only be useful to systemd, or any similar > >>>orchestration daemon. Look, you can only apply filtering policies > >>>to processes that are launched by systemd, so this only works > >>>for server processes. > >> > >> Sorry, but both statements aren't true. The eBPF policies apply to every > >> process that is placed in a cgroup, and my example program in 6/6 shows > >> how that can be done from the command line. > > > > Then you have to explain me how can anyone else than systemd use this > > infrastructure? > > I have no idea what makes you think this is limited to systemd. As I > said, I provided an example for userspace that works from the command > line. The same limitation apply as for all other users of cgroups. > So, at least in my work, we have Mesos, but on nearly every machine that Mesos runs, people also have systemd. Now, there's recently become a bit of a battle of ownership of things like cgroups on these machines. We can usually solve it by nesting under systemd cgroups, and thus so far we've avoided making too many systemd-specific concessions. The reason this works (mostly), is because everything we touch has a sense of nesting, where we can apply policy at a place lower in the hierarchy, and yet systemd's monitoring and policy still stays in place. Now, with this patch, we don't have that, but I think we can reasonably add some flag like "no override" when applying policies, or alternatively something like "no new privileges", to prevent children from applying policies that override top-level policy. I realize there is a speed concern as well, but I think for people who want nested policy, we're willing to make the tradeoff. The cost of traversing a few extra pointers still outweighs the overhead of network namespaces, iptables, etc.. for many of us. What do you think Daniel? > > My main point is that those processes *need* to be launched by the > > orchestrator, which is was refering as 'server processes'. > > Yes, that's right. But as I said, this rule applies to many other kernel > concepts, so I don't see any real issue. > Also, cgroups have become such a big part of how applications are managed that many of us have solved this problem. > >> That's a limitation that applies to many more control mechanisms in the > >> kernel, and it's something that can easily be solved with fork+exec. > > > > As long as you have control to launch the processes yes, but this > > will not work in other scenarios. Just like cgroup net_cls and friends > > are broken for filtering for things that you have no control to > > fork+exec. > > Probably, but that's only solvable with rules that store the full cgroup > path then, and do a string comparison (!) for each packet flying by. > > >> That's just as transparent as SO_ATTACH_FILTER. What kind of > >> introspection mechanism do you have in mind? > > > > SO_ATTACH_FILTER is called from the process itself, so this is a local > > filtering policy that you apply to your own process. > > Not necessarily. You can as well do it the inetd way, and pass the > socket to a process that is launched on demand, but do SO_ATTACH_FILTER > + SO_LOCK_FILTER in the middle. What happens with payload on the socket > is not transparent to the launched binary at all. The proposed cgroup > eBPF solution implements a very similar behavior in that regard. > It would be nice to be able to see whether or not a filter is attached to a cgroup, but given this is going through syscalls, at least introspection is possible as opposed to something like netlink. > >> It's about filtering outgoing network packets of applications, and > >> providing them with L2 information for filtering purposes. I don't think > >> that's a very specific use-case. > >> > >> When the feature is not used at all, the added costs on the output path > >> are close to zero, due to the use of static branches. > > > > *You're proposing a socket filtering facility that hooks layer 2 > > output path*! > > As I said, I'm open to discussing that. In order to make it work for L3, > the LL_OFF issues need to be solved, as Daniel explained. Daniel, > Alexei, any idea how much work that would be? > > > That is only a rough ~30 lines kernel patchset to support this in > > netfilter and only one extra input hook, with potential access to > > conntrack and
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/15/2016 08:36 AM, Vincent Bernat wrote: > ❦ 12 septembre 2016 18:12 CEST, Daniel Mack: > >> * The sample program learned to support both ingress and egress, and >> can now optionally make the eBPF program drop packets by making it >> return 0. > > Ability to lock the eBPF program to avoid modification from a later > program or in a subcgroup would be pretty interesting from a security > perspective. For now, you can achieve that by dropping CAP_NET_ADMIN after installing a program between fork and exec. I think that should suffice for a first version. Flags to further limit that could be be added later. Thanks, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
❦ 12 septembre 2016 18:12 CEST, Daniel Mack: > * The sample program learned to support both ingress and egress, and > can now optionally make the eBPF program drop packets by making it > return 0. Ability to lock the eBPF program to avoid modification from a later program or in a subcgroup would be pretty interesting from a security perspective. -- Use recursive procedures for recursively-defined data structures. - The Elements of Programming Style (Kernighan & Plauger)
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Wed, Sep 14, 2016 at 01:42:49PM +0200, Daniel Borkmann wrote: > >As I said, I'm open to discussing that. In order to make it work for L3, > >the LL_OFF issues need to be solved, as Daniel explained. Daniel, > >Alexei, any idea how much work that would be? > > Not much. You simply need to declare your own struct bpf_verifier_ops > with a get_func_proto() handler that handles BPF_FUNC_skb_load_bytes, > and verifier in do_check() loop would need to handle that these ld_abs/ > ld_ind are rejected for BPF_PROG_TYPE_CGROUP_SOCKET. yep. that part is solvable. I'm still torn between l2 and l3. On one side it sux to lose l2 information. yet we don't have a use case to look into l2 for our container monitoring, so the only thing lack of l2 will do is confuse byte accounting, since instead of skb->len, we'd need to do skb->len + ETH_HLEN... but I guess vlan handling messes it up as well. On the other side doing it at socket level we can drop these checks: + if (!sk || !sk_fullsock(sk)) + return 0; + + if (sk->sk_family != AF_INET && + sk->sk_family != AF_INET6) + return 0; which will make it even faster when it's on. So I don't mind either l2 and l3. I guess if l3 approach will prove to be limiting, we can add l2 later?
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/14/2016 01:13 PM, Daniel Mack wrote: On 09/13/2016 07:24 PM, Pablo Neira Ayuso wrote: On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: This is v5 of the patch set to allow eBPF programs for network filtering and accounting to be attached to cgroups, so that they apply to all sockets of all tasks placed in that cgroup. The logic also allows to be extendeded for other cgroup based eBPF logic. 1) This infrastructure can only be useful to systemd, or any similar orchestration daemon. Look, you can only apply filtering policies to processes that are launched by systemd, so this only works for server processes. Sorry, but both statements aren't true. The eBPF policies apply to every process that is placed in a cgroup, and my example program in 6/6 shows how that can be done from the command line. Then you have to explain me how can anyone else than systemd use this infrastructure? I have no idea what makes you think this is limited to systemd. As I said, I provided an example for userspace that works from the command line. The same limitation apply as for all other users of cgroups. My main point is that those processes *need* to be launched by the orchestrator, which is was refering as 'server processes'. Yes, that's right. But as I said, this rule applies to many other kernel concepts, so I don't see any real issue. That's a limitation that applies to many more control mechanisms in the kernel, and it's something that can easily be solved with fork+exec. As long as you have control to launch the processes yes, but this will not work in other scenarios. Just like cgroup net_cls and friends are broken for filtering for things that you have no control to fork+exec. Probably, but that's only solvable with rules that store the full cgroup path then, and do a string comparison (!) for each packet flying by. That's just as transparent as SO_ATTACH_FILTER. What kind of introspection mechanism do you have in mind? SO_ATTACH_FILTER is called from the process itself, so this is a local filtering policy that you apply to your own process. Not necessarily. You can as well do it the inetd way, and pass the socket to a process that is launched on demand, but do SO_ATTACH_FILTER + SO_LOCK_FILTER in the middle. What happens with payload on the socket is not transparent to the launched binary at all. The proposed cgroup eBPF solution implements a very similar behavior in that regard. It's about filtering outgoing network packets of applications, and providing them with L2 information for filtering purposes. I don't think that's a very specific use-case. When the feature is not used at all, the added costs on the output path are close to zero, due to the use of static branches. *You're proposing a socket filtering facility that hooks layer 2 output path*! As I said, I'm open to discussing that. In order to make it work for L3, the LL_OFF issues need to be solved, as Daniel explained. Daniel, Alexei, any idea how much work that would be? Not much. You simply need to declare your own struct bpf_verifier_ops with a get_func_proto() handler that handles BPF_FUNC_skb_load_bytes, and verifier in do_check() loop would need to handle that these ld_abs/ ld_ind are rejected for BPF_PROG_TYPE_CGROUP_SOCKET. That is only a rough ~30 lines kernel patchset to support this in netfilter and only one extra input hook, with potential access to conntrack and better integration with other existing subsystems. Care to share the patches for that? I'd really like to have a look. And FWIW, I agree with Thomas - there is nothing wrong with having multiple options to use for such use-cases. Thanks, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/14/2016 12:30 PM, Pablo Neira Ayuso wrote: On Tue, Sep 13, 2016 at 09:42:19PM -0700, Alexei Starovoitov wrote: [...] For us this cgroup+bpf is _not_ for filterting and _not_ for security. If your goal is monitoring, then convert these hooks not to allow to issue a verdict on the packet, so this becomes inoquous in the same fashion as the tracing infrastructure. [...] I'd really love to have an alternative to bpf for such tasks, but you seem to spend all the energy arguing against bpf whereas nft still has a lot to be desired. Please Alexei, stop that FUD. Anyone that has spent just one day using the bpf tooling and infrastructure knows you have problems to resolve... Not quite sure on the spreading of FUD, but sounds like we should all get back to technical things to resolve. ;)
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
Hi Pablo, On 09/13/2016 07:24 PM, Pablo Neira Ayuso wrote: > On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: >> On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: >>> On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: This is v5 of the patch set to allow eBPF programs for network filtering and accounting to be attached to cgroups, so that they apply to all sockets of all tasks placed in that cgroup. The logic also allows to be extendeded for other cgroup based eBPF logic. >>> >>> 1) This infrastructure can only be useful to systemd, or any similar >>>orchestration daemon. Look, you can only apply filtering policies >>>to processes that are launched by systemd, so this only works >>>for server processes. >> >> Sorry, but both statements aren't true. The eBPF policies apply to every >> process that is placed in a cgroup, and my example program in 6/6 shows >> how that can be done from the command line. > > Then you have to explain me how can anyone else than systemd use this > infrastructure? I have no idea what makes you think this is limited to systemd. As I said, I provided an example for userspace that works from the command line. The same limitation apply as for all other users of cgroups. > My main point is that those processes *need* to be launched by the > orchestrator, which is was refering as 'server processes'. Yes, that's right. But as I said, this rule applies to many other kernel concepts, so I don't see any real issue. >> That's a limitation that applies to many more control mechanisms in the >> kernel, and it's something that can easily be solved with fork+exec. > > As long as you have control to launch the processes yes, but this > will not work in other scenarios. Just like cgroup net_cls and friends > are broken for filtering for things that you have no control to > fork+exec. Probably, but that's only solvable with rules that store the full cgroup path then, and do a string comparison (!) for each packet flying by. >> That's just as transparent as SO_ATTACH_FILTER. What kind of >> introspection mechanism do you have in mind? > > SO_ATTACH_FILTER is called from the process itself, so this is a local > filtering policy that you apply to your own process. Not necessarily. You can as well do it the inetd way, and pass the socket to a process that is launched on demand, but do SO_ATTACH_FILTER + SO_LOCK_FILTER in the middle. What happens with payload on the socket is not transparent to the launched binary at all. The proposed cgroup eBPF solution implements a very similar behavior in that regard. >> It's about filtering outgoing network packets of applications, and >> providing them with L2 information for filtering purposes. I don't think >> that's a very specific use-case. >> >> When the feature is not used at all, the added costs on the output path >> are close to zero, due to the use of static branches. > > *You're proposing a socket filtering facility that hooks layer 2 > output path*! As I said, I'm open to discussing that. In order to make it work for L3, the LL_OFF issues need to be solved, as Daniel explained. Daniel, Alexei, any idea how much work that would be? > That is only a rough ~30 lines kernel patchset to support this in > netfilter and only one extra input hook, with potential access to > conntrack and better integration with other existing subsystems. Care to share the patches for that? I'd really like to have a look. And FWIW, I agree with Thomas - there is nothing wrong with having multiple options to use for such use-cases. Thanks, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/14/16 at 12:30pm, Pablo Neira Ayuso wrote: > On Tue, Sep 13, 2016 at 09:42:19PM -0700, Alexei Starovoitov wrote: > [...] > > For us this cgroup+bpf is _not_ for filterting and _not_ for security. > > If your goal is monitoring, then convert these hooks not to allow to > issue a verdict on the packet, so this becomes inoquous in the same > fashion as the tracing infrastructure. Why? How is this at all offensive? We have three parties voicing interest in this work for both monitoring and security. At least two specific use cases have been described. It builds on top of existing infrastructure and nicely complements other ongoing work. Why not both?
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Tue, Sep 13, 2016 at 09:42:19PM -0700, Alexei Starovoitov wrote: [...] > For us this cgroup+bpf is _not_ for filterting and _not_ for security. If your goal is monitoring, then convert these hooks not to allow to issue a verdict on the packet, so this becomes inoquous in the same fashion as the tracing infrastructure. [...] > I'd really love to have an alternative to bpf for such tasks, > but you seem to spend all the energy arguing against bpf whereas > nft still has a lot to be desired. Please Alexei, stop that FUD. Anyone that has spent just one day using the bpf tooling and infrastructure knows you have problems to resolve...
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
[Sorry for the repost, gmail decided to start sending HTML crap along overnight for some reason] On 09/13/16 at 09:42pm, Alexei Starovoitov wrote: > On Tue, Sep 13, 2016 at 07:24:08PM +0200, Pablo Neira Ayuso wrote: > > Then you have to explain me how can anyone else than systemd use this > > infrastructure? > > Jokes aside. I'm puzzled why systemd is even being mentioned here. > Here we use tupperware (our internal container management system) that > is heavily using cgroups and has nothing to do with systemd. Just confirming that we are planning to use this decoupled from systemd as well. I fail to see how this is at all systemd specific. > For us this cgroup+bpf is _not_ for filterting and _not_ for security. > We run a ton of tasks in cgroups that launch all sorts of > things on their own. We need to monitor what they do from networking > point of view. Therefore bpf programs need to monitor the traffic in > particular part of cgroup hierarchy. Not globally and no pass/drop decisions. +10, although filtering/drop is a valid use case, the really strong use case is definitely introspection at networking level. Statistics, monitoring, verification of application correctness, etc. I don't see why this is at all an either or discussion. If nft wants cgroups integration similar to this effort, I see no reason why that should stop this effort.
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Tue, Sep 13, 2016 at 07:24:08PM +0200, Pablo Neira Ayuso wrote: > On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: > > Hi, > > > > On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: > > > On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: > > >> This is v5 of the patch set to allow eBPF programs for network > > >> filtering and accounting to be attached to cgroups, so that they apply > > >> to all sockets of all tasks placed in that cgroup. The logic also > > >> allows to be extendeded for other cgroup based eBPF logic. > > > > > > 1) This infrastructure can only be useful to systemd, or any similar > > >orchestration daemon. Look, you can only apply filtering policies > > >to processes that are launched by systemd, so this only works > > >for server processes. > > > > Sorry, but both statements aren't true. The eBPF policies apply to every > > process that is placed in a cgroup, and my example program in 6/6 shows > > how that can be done from the command line. > > Then you have to explain me how can anyone else than systemd use this > infrastructure? Sounds like systemd and bpf phobia combined :) Jokes aside. I'm puzzled why systemd is even being mentioned here. Here we use tupperware (our internal container management system) that is heavily using cgroups and has nothing to do with systemd. we're working as part of open container initiative, so hopefully soon all container management systems will benefit from what we're building. cgroups and bpf are crucial part of this process. > > Also, systemd is able to control userspace processes just fine, and > > it not limited to 'server processes'. > > My main point is that those processes *need* to be launched by the > orchestrator, which is was refering as 'server processes'. No experience in systemd, so cannot comment about it, but that statement is not true for our stuff. > > > For client processes this infrastructure is > > >*racy*, you have to add new processes in runtime to the cgroup, > > >thus there will be time some little time where no filtering policy > > >will be applied. For quality of service, this may be an acceptable > > >race, but this is aiming to deploy a filtering policy. > > > > That's a limitation that applies to many more control mechanisms in the > > kernel, and it's something that can easily be solved with fork+exec. > > As long as you have control to launch the processes yes, but this > will not work in other scenarios. Just like cgroup net_cls and friends > are broken for filtering for things that you have no control to > fork+exec. not true > To use this infrastructure from a non-launcher process, you'll have to > rely on the proc connection to subscribe to new process events, then > echo that pid to the cgroup, and that interface is asynchronous so > *adding new processes to the cgroup is subject to races*. in general not true either. have you worked with cgroups or just speculating? > *You're proposing a socket filtering facility that hooks layer 2 > output path*! flashback. Not too long ago you were beating drums about netfilter ingress hook operating at layer 2... sounds like nobody used it and that was a bad call? Should we remove that netfilter hook then? Our use case is different from Daniel's. For us this cgroup+bpf is _not_ for filterting and _not_ for security. We run a ton of tasks in cgroups that launch all sorts of things on their own. We need to monitor what they do from networking point of view. Therefore bpf programs need to monitor the traffic in particular part of cgroup hierarchy. Not globally and no pass/drop decisions. The monitoring itself is complicated. Like we need to group and aggregate within bpf program based on certain bits of ipv6 address and so on. bpf is only programmable engine that can do this job. nft is simply not flexible enough to do that. I'd really love to have an alternative to bpf for such tasks, but you seem to spend all the energy arguing against bpf whereas nft still has a lot to be desired.
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On Tue, Sep 13, 2016 at 03:31:20PM +0200, Daniel Mack wrote: > Hi, > > On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: > > On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: > >> This is v5 of the patch set to allow eBPF programs for network > >> filtering and accounting to be attached to cgroups, so that they apply > >> to all sockets of all tasks placed in that cgroup. The logic also > >> allows to be extendeded for other cgroup based eBPF logic. > > > > 1) This infrastructure can only be useful to systemd, or any similar > >orchestration daemon. Look, you can only apply filtering policies > >to processes that are launched by systemd, so this only works > >for server processes. > > Sorry, but both statements aren't true. The eBPF policies apply to every > process that is placed in a cgroup, and my example program in 6/6 shows > how that can be done from the command line. Then you have to explain me how can anyone else than systemd use this infrastructure? > Also, systemd is able to control userspace processes just fine, and > it not limited to 'server processes'. My main point is that those processes *need* to be launched by the orchestrator, which is was refering as 'server processes'. > > For client processes this infrastructure is > >*racy*, you have to add new processes in runtime to the cgroup, > >thus there will be time some little time where no filtering policy > >will be applied. For quality of service, this may be an acceptable > >race, but this is aiming to deploy a filtering policy. > > That's a limitation that applies to many more control mechanisms in the > kernel, and it's something that can easily be solved with fork+exec. As long as you have control to launch the processes yes, but this will not work in other scenarios. Just like cgroup net_cls and friends are broken for filtering for things that you have no control to fork+exec. To use this infrastructure from a non-launcher process, you'll have to rely on the proc connection to subscribe to new process events, then echo that pid to the cgroup, and that interface is asynchronous so *adding new processes to the cgroup is subject to races*. > > 2) This aproach looks uninfrastructured to me. This provides a hook > >to push a bpf blob at a place in the stack that deploys a filtering > >policy that is not visible to others. > > That's just as transparent as SO_ATTACH_FILTER. What kind of > introspection mechanism do you have in mind? SO_ATTACH_FILTER is called from the process itself, so this is a local filtering policy that you apply to your own process. In this case, this filtering policy is *global*, other processes with similar capabilities can get just a bpf blob at best... [...] > >> After chatting with Daniel Borkmann and Alexei off-list, we concluded > >> that __dev_queue_xmit() is the place where the egress hooks should live > >> when eBPF programs need access to the L2 bits of the skb. > > > > 3) This egress hook is coming very late, the only reason I find to > >place it at __dev_queue_xmit() is that bpf naturally works with > >layer 2 information in place. But this new hook is placed in > >_everyone's output ath_ that only works for the very specific > >usecase I exposed above. > > It's about filtering outgoing network packets of applications, and > providing them with L2 information for filtering purposes. I don't think > that's a very specific use-case. > > When the feature is not used at all, the added costs on the output path > are close to zero, due to the use of static branches. *You're proposing a socket filtering facility that hooks layer 2 output path*! [...] > > I have nothing against systemd or the needs for more > > programmability/flexibility in the stack, but I think this needs to > > fulfill some requirements to fit into the infrastructure that we have > > in the right way. > > Well, as I explained already, this patch set results from endless > discussions that went nowhere, about how such a thing can be achieved > with netfilter. That is only a rough ~30 lines kernel patchset to support this in netfilter and only one extra input hook, with potential access to conntrack and better integration with other existing subsystems.
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
On 09/13/2016 03:31 PM, Daniel Mack wrote: On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: This is v5 of the patch set to allow eBPF programs for network filtering and accounting to be attached to cgroups, so that they apply to all sockets of all tasks placed in that cgroup. The logic also allows to be extendeded for other cgroup based eBPF logic. 1) This infrastructure can only be useful to systemd, or any similar orchestration daemon. Look, you can only apply filtering policies to processes that are launched by systemd, so this only works for server processes. Sorry, but both statements aren't true. The eBPF policies apply to every process that is placed in a cgroup, and my example program in 6/6 shows how that can be done from the command line. Also, systemd is able to control userspace processes just fine, and it not limited to 'server processes'. For client processes this infrastructure is *racy*, you have to add new processes in runtime to the cgroup, thus there will be time some little time where no filtering policy will be applied. For quality of service, this may be an acceptable race, but this is aiming to deploy a filtering policy. That's a limitation that applies to many more control mechanisms in the kernel, and it's something that can easily be solved with fork+exec. 2) This aproach looks uninfrastructured to me. This provides a hook to push a bpf blob at a place in the stack that deploys a filtering policy that is not visible to others. That's just as transparent as SO_ATTACH_FILTER. What kind of introspection mechanism do you have in mind? We have interfaces that allows us to dump the filtering policy that is being applied, report events to enable cooperation between several processes with similar capabilities and so on. Well, in practice, for netfilter, there can only be one instance in the system that acts as central authoritative, otherwise you'll end up with orphaned entries or with situation where some client deletes rules behind the back of the one that originally installed it. So I really think there is nothing wrong with demanding a single, privileged controller to manage things. After chatting with Daniel Borkmann and Alexei off-list, we concluded that __dev_queue_xmit() is the place where the egress hooks should live when eBPF programs need access to the L2 bits of the skb. 3) This egress hook is coming very late, the only reason I find to place it at __dev_queue_xmit() is that bpf naturally works with layer 2 information in place. But this new hook is placed in _everyone's output ath_ that only works for the very specific usecase I exposed above. It's about filtering outgoing network packets of applications, and providing them with L2 information for filtering purposes. I don't think that's a very specific use-case. When the feature is not used at all, the added costs on the output path are close to zero, due to the use of static branches. If used somewhere in the system but not for the packet in flight, costs are slightly higher but acceptable. In fact, it's not even measurable in my tests here. How is that different from the netfilter OUTPUT hook, btw? That said, limiting it to L3 is still an option. It's just that we need ingress and egress to be in sync, so both would be L3 then. So far, the possible advantages for future use-cases having access to L2 outweighed the concerns of putting the hook to dev_queue_xmit(), but I'm open to discussing that. While I fully disagree with Pablo's point 1) and 2), in the last set I raised a similar concern as in point 3) wrt __dev_queue_xmit(). The set as-is would indeed need the L2 info, since a filter could do a load via LLVM built-ins such as asm("llvm.bpf.load.byte") et al, with BPF_LL_OFF, where we're forced to do a load relative to skb_mac_header(). As stated by Daniel already, it would be nice to see the full frame, so it comes down to a trade-off, but the option of L3 onwards also exists and BPF can work just fine with it, too. This just means it's placed in the local output path and the verifier would need to disallow these built-ins during bpf(2) load time. They are a rather cumbersome legacy anyway, so bpf_skb_load_bytes() helper can be used instead, which is also easier to use. The main concern during the workshop was that a hook only for cgroups is too specific, but this is actually even more specific than this. This patch set merely implements an infrastructure that can accommodate many more things as well in the future. We could, in theory, even add hooks for forwarded packets specifically, or other eBPF programs, not even for network filtering etc. I have nothing against systemd or the needs for more programmability/flexibility in the stack, but I think this needs to fulfill some requirements to fit into the infrastructure that we have in the right way. Well, as
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
Hi, On 09/13/2016 01:56 PM, Pablo Neira Ayuso wrote: > On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: >> This is v5 of the patch set to allow eBPF programs for network >> filtering and accounting to be attached to cgroups, so that they apply >> to all sockets of all tasks placed in that cgroup. The logic also >> allows to be extendeded for other cgroup based eBPF logic. > > 1) This infrastructure can only be useful to systemd, or any similar >orchestration daemon. Look, you can only apply filtering policies >to processes that are launched by systemd, so this only works >for server processes. Sorry, but both statements aren't true. The eBPF policies apply to every process that is placed in a cgroup, and my example program in 6/6 shows how that can be done from the command line. Also, systemd is able to control userspace processes just fine, and it not limited to 'server processes'. > For client processes this infrastructure is >*racy*, you have to add new processes in runtime to the cgroup, >thus there will be time some little time where no filtering policy >will be applied. For quality of service, this may be an acceptable >race, but this is aiming to deploy a filtering policy. That's a limitation that applies to many more control mechanisms in the kernel, and it's something that can easily be solved with fork+exec. > 2) This aproach looks uninfrastructured to me. This provides a hook >to push a bpf blob at a place in the stack that deploys a filtering >policy that is not visible to others. That's just as transparent as SO_ATTACH_FILTER. What kind of introspection mechanism do you have in mind? > We have interfaces that allows >us to dump the filtering policy that is being applied, report events >to enable cooperation between several processes with similar >capabilities and so on. Well, in practice, for netfilter, there can only be one instance in the system that acts as central authoritative, otherwise you'll end up with orphaned entries or with situation where some client deletes rules behind the back of the one that originally installed it. So I really think there is nothing wrong with demanding a single, privileged controller to manage things. >> After chatting with Daniel Borkmann and Alexei off-list, we concluded >> that __dev_queue_xmit() is the place where the egress hooks should live >> when eBPF programs need access to the L2 bits of the skb. > > 3) This egress hook is coming very late, the only reason I find to >place it at __dev_queue_xmit() is that bpf naturally works with >layer 2 information in place. But this new hook is placed in >_everyone's output ath_ that only works for the very specific >usecase I exposed above. It's about filtering outgoing network packets of applications, and providing them with L2 information for filtering purposes. I don't think that's a very specific use-case. When the feature is not used at all, the added costs on the output path are close to zero, due to the use of static branches. If used somewhere in the system but not for the packet in flight, costs are slightly higher but acceptable. In fact, it's not even measurable in my tests here. How is that different from the netfilter OUTPUT hook, btw? That said, limiting it to L3 is still an option. It's just that we need ingress and egress to be in sync, so both would be L3 then. So far, the possible advantages for future use-cases having access to L2 outweighed the concerns of putting the hook to dev_queue_xmit(), but I'm open to discussing that. > The main concern during the workshop was that a hook only for cgroups > is too specific, but this is actually even more specific than this. This patch set merely implements an infrastructure that can accommodate many more things as well in the future. We could, in theory, even add hooks for forwarded packets specifically, or other eBPF programs, not even for network filtering etc. > I have nothing against systemd or the needs for more > programmability/flexibility in the stack, but I think this needs to > fulfill some requirements to fit into the infrastructure that we have > in the right way. Well, as I explained already, this patch set results from endless discussions that went nowhere, about how such a thing can be achieved with netfilter. Thanks, Daniel
Re: [PATCH v5 0/6] Add eBPF hooks for cgroups
Hi, On Mon, Sep 12, 2016 at 06:12:09PM +0200, Daniel Mack wrote: > This is v5 of the patch set to allow eBPF programs for network > filtering and accounting to be attached to cgroups, so that they apply > to all sockets of all tasks placed in that cgroup. The logic also > allows to be extendeded for other cgroup based eBPF logic. 1) This infrastructure can only be useful to systemd, or any similar orchestration daemon. Look, you can only apply filtering policies to processes that are launched by systemd, so this only works for server processes. For client processes this infrastructure is *racy*, you have to add new processes in runtime to the cgroup, thus there will be time some little time where no filtering policy will be applied. For quality of service, this may be an acceptable race, but this is aiming to deploy a filtering policy. 2) This aproach looks uninfrastructured to me. This provides a hook to push a bpf blob at a place in the stack that deploys a filtering policy that is not visible to others. We have interfaces that allows us to dump the filtering policy that is being applied, report events to enable cooperation between several processes with similar capabilities and so on. For the XDP thing, this ability to push blobs may be fine as long as it will not interfer with the stack so we can provide an alternative to DPDK in Linux. For tracing, that's fine too since it is innocuous. And likely for other applications is a good fit. But I don't think this is the case. > After chatting with Daniel Borkmann and Alexei off-list, we concluded > that __dev_queue_xmit() is the place where the egress hooks should live > when eBPF programs need access to the L2 bits of the skb. 3) This egress hook is coming very late, the only reason I find to place it at __dev_queue_xmit() is that bpf naturally works with layer 2 information in place. But this new hook is placed in _everyone's output ath_ that only works for the very specific usecase I exposed above. The main concern during the workshop was that a hook only for cgroups is too specific, but this is actually even more specific than this. I have nothing against systemd or the needs for more programmability/flexibility in the stack, but I think this needs to fulfill some requirements to fit into the infrastructure that we have in the right way.
[PATCH v5 0/6] Add eBPF hooks for cgroups
This is v5 of the patch set to allow eBPF programs for network filtering and accounting to be attached to cgroups, so that they apply to all sockets of all tasks placed in that cgroup. The logic also allows to be extendeded for other cgroup based eBPF logic. After chatting with Daniel Borkmann and Alexei off-list, we concluded that __dev_queue_xmit() is the place where the egress hooks should live when eBPF programs need access to the L2 bits of the skb. Changes from v4: * Plug an skb leak when dropping packets due to eBPF verdicts in __dev_queue_xmit(). Spotted by Daniel Borkmann. * Check for sk_fullsock(sk) in __cgroup_bpf_run_filter() so we don't operate on timewait or request sockets. Suggested by Daniel Borkmann. * Add missing @parent parameter in kerneldoc of __cgroup_bpf_update(). Spotted by Rami Rosen. * Include linux/jump_label.h from bpf-cgroup.h to fix a kbuild error. Changes from v3: * Dropped the _FILTER suffix from BPF_PROG_TYPE_CGROUP_SOCKET_FILTER, renamed BPF_ATTACH_TYPE_CGROUP_INET_{E,IN}GRESS to BPF_CGROUP_INET_{IN,E}GRESS and alias BPF_MAX_ATTACH_TYPE to __BPF_MAX_ATTACH_TYPE, as suggested by Daniel Borkmann. * Dropped the attach_flags member from the anonymous struct for BPF attach operations in union bpf_attr. They can be added later on via CHECK_ATTR. Requested by Daniel Borkmann and Alexei. * Release old_prog at the end of __cgroup_bpf_update rather that at the beginning to fix a race gap between program updates and their users. Spotted by Daniel Borkmann. * Plugged an skb leak when dropping packets on the egress path. Spotted by Daniel Borkmann. * Add cgro...@vger.kernel.org to the loop, as suggested by Rami Rosen. * Some minor coding style adoptions not worth mentioning in particular. Changes from v2: * Fixed the RCU locking details Tejun pointed out. * Assert bpf_attr.flags == 0 in BPF_PROG_DETACH syscall handler. Changes from v1: * Moved all bpf specific cgroup code into its own file, and stub out related functions for !CONFIG_CGROUP_BPF as static inline nops. This way, the call sites are not cluttered with #ifdef guards while the feature remains compile-time configurable. * Implemented the new scheme proposed by Tejun. Per cgroup, store one set of pointers that are pinned to the cgroup, and one for the programs that are effective. When a program is attached or detached, the change is propagated to all the cgroup's descendants. If a subcgroup has its own pinned program, skip the whole subbranch in order to allow delegation models. * The hookup for egress packets is now done from __dev_queue_xmit(). * A static key is now used in both the ingress and egress fast paths to keep performance penalties close to zero if the feature is not in use. * Overall cleanup to make the accessors use the program arrays. This should make it much easier to add new program types, which will then automatically follow the pinned vs. effective logic. * Fixed locking issues, as pointed out by Eric Dumazet and Alexei Starovoitov. Changes to the program array are now done with xchg() and are protected by cgroup_mutex. * eBPF programs are now expected to return 1 to let the packet pass, not >= 0. Pointed out by Alexei. * Operation is now limited to INET sockets, so local AF_UNIX sockets are not affected. The enum members are renamed accordingly. In case other socket families should be supported, this can be extended in the future. * The sample program learned to support both ingress and egress, and can now optionally make the eBPF program drop packets by making it return 0. As always, feedback is much appreciated. Thanks, Daniel Daniel Mack (6): bpf: add new prog type for cgroup socket filtering cgroup: add support for eBPF programs bpf: add BPF_PROG_ATTACH and BPF_PROG_DETACH commands net: filter: run cgroup eBPF ingress programs net: core: run cgroup eBPF egress programs samples: bpf: add userspace example for attaching eBPF programs to cgroups include/linux/bpf-cgroup.h | 71 + include/linux/cgroup-defs.h | 4 + include/uapi/linux/bpf.h| 17 init/Kconfig| 12 +++ kernel/bpf/Makefile | 1 + kernel/bpf/cgroup.c | 166 kernel/bpf/syscall.c| 81 kernel/bpf/verifier.c | 1 + kernel/cgroup.c | 18 + net/core/dev.c | 6 ++ net/core/filter.c | 10 +++ samples/bpf/Makefile| 2 + samples/bpf/libbpf.c| 21 + samples/bpf/libbpf.h| 3 + samples/bpf/test_cgrp2_attach.c | 147 +++ 15 files changed, 560 insertions(+) create mode 100644 include/linux/bpf-cgroup.h create mode 100644 kernel/bpf/cgroup.c create mode 100644 samples/bpf/test_cgrp2_attach.c -- 2.5.5