From: Daniel Borkmann <daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
To: Daniel Mack <daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>,
htejun-b10kYP2dOMg@public.gmane.org,
ast-b10kYP2dOMg@public.gmane.org
Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
kafai-b10kYP2dOMg@public.gmane.org,
fw-HFFVJYpyMKqzQB+pC5nmwQ@public.gmane.org,
pablo-Cap9r6Oaw4JrovVCs/uTlw@public.gmane.org,
harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
sargun-GaZTRHToo+CzQB+pC5nmwQ@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v4 2/6] cgroup: add support for eBPF programs
Date: Tue, 06 Sep 2016 19:18:00 +0200 [thread overview]
Message-ID: <57CEFA48.6010101@iogearbox.net> (raw)
In-Reply-To: <1473169568-30525-3-git-send-email-daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>
On 09/06/2016 03:46 PM, Daniel Mack wrote:
> This patch adds two sets of eBPF program pointers to struct cgroup.
> One for such that are directly pinned to a cgroup, and one for such
> that are effective for it.
>
> To illustrate the logic behind that, assume the following example
> cgroup hierarchy.
>
> A - B - C
> \ D - E
>
> If only B has a program attached, it will be effective for B, C, D
> and E. If D then attaches a program itself, that will be effective for
> both D and E, and the program in B will only affect B and C. Only one
> program of a given type is effective for a cgroup.
>
> Attaching and detaching programs will be done through the bpf(2)
> syscall. For now, ingress and egress inet socket filtering are the
> only supported use-cases.
>
> Signed-off-by: Daniel Mack <daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>
[...]
> +/**
> + * __cgroup_bpf_run_filter() - Run a program for packet filtering
> + * @sk: The socken sending or receiving traffic
> + * @skb: The skb that is being sent or received
> + * @type: The type of program to be exectuted
> + *
> + * If no socket is passed, or the socket is not of type INET or INET6,
> + * this function does nothing and returns 0.
> + *
> + * The program type passed in via @type must be suitable for network
> + * filtering. No further check is performed to assert that.
> + *
> + * This function will return %-EPERM if any if an attached program was found
> + * and if it returned != 1 during execution. In all other cases, 0 is returned.
> + */
> +int __cgroup_bpf_run_filter(struct sock *sk,
> + struct sk_buff *skb,
> + enum bpf_attach_type type)
> +{
> + struct bpf_prog *prog;
> + struct cgroup *cgrp;
> + int ret = 0;
> +
> + if (!sk)
> + return 0;
Doesn't this also need to check || !sk_fullsock(sk)?
> +
> + if (sk->sk_family != AF_INET &&
> + sk->sk_family != AF_INET6)
> + return 0;
> +
> + cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data);
> +
> + rcu_read_lock();
> +
> + prog = rcu_dereference(cgrp->bpf.effective[type]);
> + if (prog) {
> + unsigned int offset = skb->data - skb_mac_header(skb);
> +
> + __skb_push(skb, offset);
> + ret = bpf_prog_run_clear_cb(prog, skb) == 1 ? 0 : -EPERM;
> + __skb_pull(skb, offset);
> + }
> +
> + rcu_read_unlock();
> +
> + return ret;
> +}
next prev parent reply other threads:[~2016-09-06 17:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 13:46 [PATCH v4 0/6] Add eBPF hooks for cgroups Daniel Mack
2016-09-06 13:46 ` [PATCH v4 1/6] bpf: add new prog type for cgroup socket filtering Daniel Mack
2016-09-06 13:46 ` [PATCH v4 2/6] cgroup: add support for eBPF programs Daniel Mack
[not found] ` <1473169568-30525-3-git-send-email-daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org>
2016-09-06 17:18 ` Daniel Borkmann [this message]
[not found] ` <57CEFA48.6010101-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
2016-09-07 8:04 ` Daniel Mack
2016-09-07 4:58 ` Rami Rosen
2016-09-07 5:00 ` kbuild test robot
2016-09-06 13:46 ` [PATCH v4 3/6] bpf: add BPF_PROG_ATTACH and BPF_PROG_DETACH commands Daniel Mack
2016-09-06 13:46 ` [PATCH v4 4/6] net: filter: run cgroup eBPF ingress programs Daniel Mack
2016-09-06 13:46 ` [PATCH v4 5/6] net: core: run cgroup eBPF egress programs Daniel Mack
2016-09-06 13:46 ` [PATCH v4 6/6] samples: bpf: add userspace example for attaching eBPF programs to cgroups Daniel Mack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57CEFA48.6010101@iogearbox.net \
--to=daniel-fec+5ew28dpmcu3hniyyjq@public.gmane.org \
--cc=ast-b10kYP2dOMg@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=daniel-cYrQPVfZoowdnm+yROfE0A@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=fw-HFFVJYpyMKqzQB+pC5nmwQ@public.gmane.org \
--cc=harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=htejun-b10kYP2dOMg@public.gmane.org \
--cc=kafai-b10kYP2dOMg@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=pablo-Cap9r6Oaw4JrovVCs/uTlw@public.gmane.org \
--cc=sargun-GaZTRHToo+CzQB+pC5nmwQ@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.