All of lore.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Martin KaFai Lau <kafai@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Network Development <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>
Subject: Re: Override default socket policy per cgroup
Date: Wed, 9 Feb 2022 14:38:15 -0800	[thread overview]
Message-ID: <YgRCVxaYirEDudjM@google.com> (raw)
In-Reply-To: <CAADnVQKVes3eKcDsFp=TZXRkteMU=WdmqWvXkW7RSMARbnoqxw@mail.gmail.com>

On 02/09, Alexei Starovoitov wrote:
> On Wed, Feb 9, 2022 at 1:51 PM <sdf@google.com> wrote:
> >
> > On 02/09, Martin KaFai Lau wrote:
> > > On Wed, Feb 09, 2022 at 09:03:45AM -0800, sdf@google.com wrote:
> > > > Let's say I want to set some default sk_priority for all sockets in  
> a
> > > > specific cgroup. I can do it right now using cgroup/sock_create,  
> but it
> > > > applies only to AF_INET{,6} sockets. I'd like to do the same for raw
> > > > (AF_PACKET) sockets and cgroup/sock_create doesn't trigger for  
> them :-(
> > > Other than AF_PACKET and INET[6], do you have use cases for other
> > > families?
> >
> > No, I only need AF_PACKET for now. But I feel like we should create
> > a more extensible hook point this time (if we go this route).
> >
> > > > (1) My naive approach would be to add another  
> cgroup/sock_post_create
> > > > which runs late from __sock_create and triggers on everything.
> > > >
> > > > (2) Another approach might be to move BPF_CGROUP_RUN_PROG_INET_SOCK  
> and
> > > > make it work with AF_PACKET. This might be not 100% backwards  
> compatible
> > > > but I'd assume that most users should look at the socket family  
> before
> > > > doing anything. (in this case it feels like we can extend
> > > > sock_bind/release for af_packets as well, just for accounting  
> purposes,
> > > > without any way to override the target ifindex).
> > > If adding a hook at __sock_create, I think having a new
> > > CGROUP_POST_SOCK_CREATE
> > > may be better instead of messing with the current inet assumption
> > > in CGROUP_'INET'_SOCK_CREATE.  Running all CGROUP_*_SOCK_CREATE at
> > > __sock_create could be a nice cleanup such that a few lines can be
> > > removed from inet[6]_create but an extra family check will be needed.
> >
> > SG. Hopefully I can at least reuse exiting progtype and just introduce
> > new hook point in __sock_create.

> Can you take a look at what it would take to add cgroup scope
> to bpf_lsm ?
> __sock_create() already has
> security_socket_create and security_socket_post_create
> in the right places.

> bpf_lsm cannot write directly into PTR_TO_BTF_ID like the 1st 'sock'  
> pointer.
> We can whitelist the write for certain cases.
> Maybe prototype it with bpf_lsm and use
> bpf_current_task_under_cgroup() helper to limit the scope
> before implementing cgroup-scoped bpf_lsm?

> There were cases in the past where bpf_lsm hook was in the ideal
> spot, but lack of cgroup scoping was a show stopper.
> This use case is another example and motivation to extend
> what bpf can do with lsm hooks. That's better than
> adding a new bpf_cgroup hook in the same location.

Cool, if you think we can whitelist some writes in lsm/fentry that
might be a perfect solution (especially if it gets per-cgroup scope).
I'll try to look in that, thanks!

  reply	other threads:[~2022-02-09 22:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 17:03 Override default socket policy per cgroup sdf
2022-02-09 21:02 ` Martin KaFai Lau
2022-02-09 21:51   ` sdf
2022-02-09 22:25     ` Alexei Starovoitov
2022-02-09 22:38       ` sdf [this message]
2022-02-09 23:40     ` Martin KaFai Lau

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=YgRCVxaYirEDudjM@google.com \
    --to=sdf@google.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.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.