From: Christian Brauner <brauner@kernel.org>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, paul@paul-moore.com,
linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org, keescook@chromium.org,
kernel-team@meta.com, sargun@sargun.me
Subject: Re: [PATCH v11 bpf-next 02/17] bpf: add BPF token delegation mount options to BPF FS
Date: Thu, 30 Nov 2023 15:18:33 +0100 [thread overview]
Message-ID: <20231130-zivildienst-weckt-4888b2689eea@brauner> (raw)
In-Reply-To: <20231127190409.2344550-3-andrii@kernel.org>
On Mon, Nov 27, 2023 at 11:03:54AM -0800, Andrii Nakryiko wrote:
> Add few new mount options to BPF FS that allow to specify that a given
> BPF FS instance allows creation of BPF token (added in the next patch),
> and what sort of operations are allowed under BPF token. As such, we get
> 4 new mount options, each is a bit mask
> - `delegate_cmds` allow to specify which bpf() syscall commands are
> allowed with BPF token derived from this BPF FS instance;
> - if BPF_MAP_CREATE command is allowed, `delegate_maps` specifies
> a set of allowable BPF map types that could be created with BPF token;
> - if BPF_PROG_LOAD command is allowed, `delegate_progs` specifies
> a set of allowable BPF program types that could be loaded with BPF token;
> - if BPF_PROG_LOAD command is allowed, `delegate_attachs` specifies
> a set of allowable BPF program attach types that could be loaded with
> BPF token; delegate_progs and delegate_attachs are meant to be used
> together, as full BPF program type is, in general, determined
> through both program type and program attach type.
>
> Currently, these mount options accept the following forms of values:
> - a special value "any", that enables all possible values of a given
> bit set;
> - numeric value (decimal or hexadecimal, determined by kernel
> automatically) that specifies a bit mask value directly;
> - all the values for a given mount option are combined, if specified
> multiple times. E.g., `mount -t bpf nodev /path/to/mount -o
> delegate_maps=0x1 -o delegate_maps=0x2` will result in a combined 0x3
> mask.
>
> Ideally, more convenient (for humans) symbolic form derived from
> corresponding UAPI enums would be accepted (e.g., `-o
> delegate_progs=kprobe|tracepoint`) and I intend to implement this, but
> it requires a bunch of UAPI header churn, so I postponed it until this
> feature lands upstream or at least there is a definite consensus that
> this feature is acceptable and is going to make it, just to minimize
> amount of wasted effort and not increase amount of non-essential code to
> be reviewed.
>
> Attentive reader will notice that BPF FS is now marked as
> FS_USERNS_MOUNT, which theoretically makes it mountable inside non-init
> user namespace as long as the process has sufficient *namespaced*
> capabilities within that user namespace. But in reality we still
> restrict BPF FS to be mountable only by processes with CAP_SYS_ADMIN *in
> init userns* (extra check in bpf_fill_super()). FS_USERNS_MOUNT is added
> to allow creating BPF FS context object (i.e., fsopen("bpf")) from
> inside unprivileged process inside non-init userns, to capture that
> userns as the owning userns. It will still be required to pass this
> context object back to privileged process to instantiate and mount it.
>
> This manipulation is important, because capturing non-init userns as the
> owning userns of BPF FS instance (super block) allows to use that userns
> to constraint BPF token to that userns later on (see next patch). So
> creating BPF FS with delegation inside unprivileged userns will restrict
> derived BPF token objects to only "work" inside that intended userns,
> making it scoped to a intended "container". Also, setting these
> delegation options requires capable(CAP_SYS_ADMIN), so unprivileged
> process cannot set this up without involvement of a privileged process.
>
> There is a set of selftests at the end of the patch set that simulates
> this sequence of steps and validates that everything works as intended.
> But careful review is requested to make sure there are no missed gaps in
> the implementation and testing.
>
> This somewhat subtle set of aspects is the result of previous
> discussions ([0]) about various user namespace implications and
> interactions with BPF token functionality and is necessary to contain
> BPF token inside intended user namespace.
>
> [0] https://lore.kernel.org/bpf/20230704-hochverdient-lehne-eeb9eeef785e@brauner/
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
I still think this is a little weird because this isn't really
unprivileged bpf and it isn't really safe bpf as well.
All this does is allow an administrator to punch a big fat hole into an
unprivileged container so workloads get to play with their favorite toy.
I think that having a way to have signed bpf programs in addition to
this would be much more interesting to generic workloads that don't know
who or what they can trust.
And there's a few things to remember:
* This absolutely isn't a safety mechanism.
* This absolutely isn't safe to enable generically in containers.
* This is a workaround and not a solution to unprivileged bpf.
And this is an ACK solely on the code of this patch, not the concept.
Acked-by: Christian Brauner <brauner@kernel.org> (reluctantly)
next prev parent reply other threads:[~2023-11-30 14:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 19:03 [PATCH v11 bpf-next 00/17] BPF token and BPF FS-based delegation Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 01/17] bpf: align CAP_NET_ADMIN checks with bpf_capable() approach Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 02/17] bpf: add BPF token delegation mount options to BPF FS Andrii Nakryiko
2023-11-30 14:18 ` Christian Brauner [this message]
2023-11-30 18:02 ` Andrii Nakryiko
2023-11-30 16:36 ` Simon Horman
2023-11-30 18:03 ` Andrii Nakryiko
2023-11-30 18:13 ` Andrii Nakryiko
2023-12-05 9:13 ` Simon Horman
2023-11-27 19:03 ` [PATCH v11 bpf-next 03/17] bpf: introduce BPF token object Andrii Nakryiko
2023-11-29 0:05 ` Andrii Nakryiko
2023-11-30 14:05 ` Christian Brauner
2023-11-30 14:27 ` Christian Brauner
2023-11-30 17:57 ` Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 04/17] bpf: add BPF token support to BPF_MAP_CREATE command Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 05/17] bpf: add BPF token support to BPF_BTF_LOAD command Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 06/17] bpf: add BPF token support to BPF_PROG_LOAD command Andrii Nakryiko
2023-11-27 19:03 ` [PATCH v11 bpf-next 07/17] bpf: take into account BPF token when fetching helper protos Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 08/17] bpf: consistently use BPF token throughout BPF verifier logic Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 09/17] bpf,lsm: refactor bpf_prog_alloc/bpf_prog_free LSM hooks Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 10/17] bpf,lsm: refactor bpf_map_alloc/bpf_map_free " Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 11/17] bpf,lsm: add BPF token " Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 12/17] libbpf: add bpf_token_create() API Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 13/17] libbpf: add BPF token support to bpf_map_create() API Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 14/17] libbpf: add BPF token support to bpf_btf_load() API Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 15/17] libbpf: add BPF token support to bpf_prog_load() API Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 16/17] selftests/bpf: add BPF token-enabled tests Andrii Nakryiko
2023-11-27 19:04 ` [PATCH v11 bpf-next 17/17] bpf,selinux: allocate bpf_security_struct per BPF token Andrii Nakryiko
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=20231130-zivildienst-weckt-4888b2689eea@brauner \
--to=brauner@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=keescook@chromium.org \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sargun@sargun.me \
/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