Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread David Ahern
On 10/26/16 2:31 PM, Mahesh Bandewar (महेश बंडेवार) wrote: > The hook insertion in sk_alloc() may not solve all control-path checks as not > much can be done (probably apart for changing sk_bound_dev_if) during > allocation but hooks in bind(), listen(), setsockopt() etc. (not a complete > list)

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread Thomas Graf
On 10/26/16 at 10:08am, David Ahern wrote: > On 10/26/16 2:41 AM, Thomas Graf wrote: > > On 10/25/16 at 03:30pm, David Ahern wrote: > >> @@ -171,6 +177,9 @@ int __cgroup_bpf_run_filter(struct sock *sk, > >>case BPF_CGROUP_INET_EGRESS: > >>ret = __cgroup_bpf_run_filte

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread David Ahern
On 10/26/16 2:41 AM, Thomas Graf wrote: > On 10/25/16 at 03:30pm, David Ahern wrote: >> @@ -171,6 +177,9 @@ int __cgroup_bpf_run_filter(struct sock *sk, >> case BPF_CGROUP_INET_EGRESS: >> ret = __cgroup_bpf_run_filter_skb(skb, prog); >> break;

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread David Ahern
On 10/26/16 2:33 AM, Daniel Borkmann wrote: > Sure, I understand that, and I know it was brought up at netconf, I'm > just still wondering in general if BPF is a good fit here in the sense > that what the program can do is just really really limited (at least > right now). Hmm, just trying to under

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread Thomas Graf
On 10/25/16 at 03:30pm, David Ahern wrote: > @@ -171,6 +177,9 @@ int __cgroup_bpf_run_filter(struct sock *sk, > case BPF_CGROUP_INET_EGRESS: > ret = __cgroup_bpf_run_filter_skb(skb, prog); > break; > + case BPF_CGROUP_INET_SOCK_C

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-26 Thread Daniel Borkmann
On 10/26/2016 04:05 AM, David Ahern wrote: On 10/25/16 5:28 PM, Daniel Borkmann wrote: +BPF_CALL_3(bpf_sock_store_u32, struct sock *, sk, u32, offset, u32, val) +{ +u8 *ptr = (u8 *)sk; + +if (unlikely(offset > sizeof(*sk))) +return -EFAULT; + +*((u32 *)ptr) = val; + +retu

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread David Ahern
On 10/25/16 8:48 PM, Eric Dumazet wrote: > Maybe I do not understand how you plan to use this. > > Let say you want a filter to force a BIND_TO_DEVICE xxx because a task > runs in a cgroup yyy > > Then a program doing a socket() + connect (127.0.0.1) will fail ? maybe. VRF devices can have 127.

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread Eric Dumazet
On Tue, 2016-10-25 at 20:21 -0600, David Ahern wrote: > On 10/25/16 5:39 PM, Eric Dumazet wrote: > > On Tue, 2016-10-25 at 15:30 -0700, David Ahern wrote: > >> Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to > >> BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread David Ahern
On 10/25/16 7:55 PM, Alexei Starovoitov wrote: > Same question as Daniel... why extra helper? It can be dropped. wrong path while learning this code. > If program overwrites bpf_sock->sk_bound_dev_if can we use that > after program returns? > Also do you think it's possible to extend this patch t

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread David Ahern
On 10/25/16 5:39 PM, Eric Dumazet wrote: > On Tue, 2016-10-25 at 15:30 -0700, David Ahern wrote: >> Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to >> BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup and run >> any time a process in the cgroup opens an AF_INET

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread David Ahern
On 10/25/16 5:28 PM, Daniel Borkmann wrote: >> +BPF_CALL_3(bpf_sock_store_u32, struct sock *, sk, u32, offset, u32, val) >> +{ >> +u8 *ptr = (u8 *)sk; >> + >> +if (unlikely(offset > sizeof(*sk))) >> +return -EFAULT; >> + >> +*((u32 *)ptr) = val; >> + >> +return 0; >> +} > >

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread Alexei Starovoitov
On Wed, Oct 26, 2016 at 01:28:24AM +0200, Daniel Borkmann wrote: > On 10/26/2016 12:30 AM, David Ahern wrote: > >Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to > >BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup and run > >any time a process in the cgroup open

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread Eric Dumazet
On Tue, 2016-10-25 at 15:30 -0700, David Ahern wrote: > Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to > BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup and run > any time a process in the cgroup opens an AF_INET or AF_INET6 socket. > Currently only sk_bound_

Re: [PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread Daniel Borkmann
On 10/26/2016 12:30 AM, David Ahern wrote: Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup and run any time a process in the cgroup opens an AF_INET or AF_INET6 socket. Currently only sk_bound_dev_if is exporte

[PATCH net-next 2/3] bpf: Add new cgroups prog type to enable sock modifications

2016-10-25 Thread David Ahern
Add new cgroup based program type, BPF_PROG_TYPE_CGROUP_SOCK. Similar to BPF_PROG_TYPE_CGROUP_SKB programs can be attached to a cgroup and run any time a process in the cgroup opens an AF_INET or AF_INET6 socket. Currently only sk_bound_dev_if is exported to userspace for modification by a bpf prog