From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
Stanislav Fomichev <sdf@google.com>,
kafai@fb.com, kpsingh@kernel.org
Subject: [RFC bpf-next 0/4] bpf: cgroup_sock lsm flavor
Date: Tue, 15 Feb 2022 16:12:37 -0800 [thread overview]
Message-ID: <20220216001241.2239703-1-sdf@google.com> (raw)
This is an RFC proposal for a recent discussion about default socket
policy [0]. The series implements new lsm flavor for attaching
lsm-like programs to existing lsm hooks that operate on 'struct socket'
The actual requirement is that the first argument is of type 'struct
socket'. Later on we can add support 'struct sock' based hooks without
any user-visible changes.
For demonstration purposes only two hooks are included (can be extended
to more later). Also, for demonstration purposes, writes to sock->sk_priority
are exposed to lsm hooks (can cover more bpf_sock fields later).
The intended workflow is:
The users load lsm_cgroup_sock tracepoint into the system. This installs
generic fmod_ret trampoline that runs __cgroup_bpf_run_lsm_sock.
After that, bpf_prog_attach should be called to activate this program
for the particular cgroup. This interface uses exiting cgroup_bpf
functionality and should support all existing inheritance flags.
I'd like to get a generic feedback whether I'm going into the right
direction or not. The thing I'm not sure about is the way I'm
abusing jit generation (maybe fmod_ret should be automagically
installed instead?).
For non-socket specific hooks, we can add a similar BPF_LSM_CGROUP
attach point that looks at current->cgroup instead of socket->cgroup.
[0] https://lore.kernel.org/bpf/YgPz8akQ4+qBz7nf@google.com/
Cc: ast@kernel.org
Cc: daniel@iogearbox.net
Cc: kafai@fb.com
Cc: kpsingh@kernel.org
Stanislav Fomichev (4):
bpf: cgroup_sock lsm flavor
bpf: allow writing to sock->sk_priority from lsm progtype
libbpf: add lsm_cgoup_sock type
selftest: lsm_cgroup_sock sample usage
arch/x86/net/bpf_jit_comp.c | 27 +++++--
include/linux/bpf-cgroup-defs.h | 4 +
include/linux/bpf.h | 2 +
include/uapi/linux/bpf.h | 1 +
kernel/bpf/bpf_lsm.c | 49 +++++++++++
kernel/bpf/btf.c | 10 +++
kernel/bpf/cgroup.c | 43 +++++++++-
kernel/bpf/syscall.c | 6 +-
kernel/bpf/trampoline.c | 1 +
kernel/bpf/verifier.c | 4 +-
tools/include/uapi/linux/bpf.h | 1 +
tools/lib/bpf/libbpf.c | 2 +
.../bpf/prog_tests/lsm_cgroup_sock.c | 81 +++++++++++++++++++
.../selftests/bpf/progs/lsm_cgroup_sock.c | 55 +++++++++++++
14 files changed, 273 insertions(+), 13 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/lsm_cgroup_sock.c
create mode 100644 tools/testing/selftests/bpf/progs/lsm_cgroup_sock.c
--
2.35.1.265.g69c8d7142f-goog
next reply other threads:[~2022-02-16 0:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 0:12 Stanislav Fomichev [this message]
2022-02-16 0:12 ` [RFC bpf-next 1/4] bpf: cgroup_sock lsm flavor Stanislav Fomichev
2022-02-17 2:38 ` Alexei Starovoitov
2022-02-17 16:21 ` sdf
2022-02-17 16:58 ` Alexei Starovoitov
2022-02-16 0:12 ` [RFC bpf-next 2/4] bpf: allow writing to sock->sk_priority from lsm progtype Stanislav Fomichev
2022-02-16 0:12 ` [RFC bpf-next 3/4] libbpf: add lsm_cgoup_sock type Stanislav Fomichev
2022-02-16 0:12 ` [RFC bpf-next 4/4] selftest: lsm_cgroup_sock sample usage Stanislav Fomichev
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=20220216001241.2239703-1-sdf@google.com \
--to=sdf@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).