From: Hou Tao <houtao@huaweicloud.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org, keescook@chromium.org,
brauner@kernel.org, lennart@poettering.net, kernel-team@meta.com,
sargun@sargun.me
Subject: Re: [PATCH v6 bpf-next 02/13] bpf: add BPF token delegation mount options to BPF FS
Date: Tue, 10 Oct 2023 15:08:57 +0800 [thread overview]
Message-ID: <02a63a35-7a0c-503b-eb24-774300e86841@huaweicloud.com> (raw)
In-Reply-To: <20230927225809.2049655-3-andrii@kernel.org>
On 9/28/2023 6:57 AM, 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.
>
SNIP
> return 0;
> @@ -740,10 +786,14 @@ static int populate_bpffs(struct dentry *parent)
> static int bpf_fill_super(struct super_block *sb, struct fs_context *fc)
> {
> static const struct tree_descr bpf_rfiles[] = { { "" } };
> - struct bpf_mount_opts *opts = fc->fs_private;
> + struct bpf_mount_opts *opts = sb->s_fs_info;
> struct inode *inode;
> int ret;
>
> + /* Mounting an instance of BPF FS requires privileges */
> + if (fc->user_ns != &init_user_ns && !capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> ret = simple_fill_super(sb, BPF_FS_MAGIC, bpf_rfiles);
> if (ret)
> return ret;
> @@ -765,7 +815,10 @@ static int bpf_get_tree(struct fs_context *fc)
>
> static void bpf_free_fc(struct fs_context *fc)
> {
> - kfree(fc->fs_private);
> + struct bpf_mount_opts *opts = fc->s_fs_info;
> +
> + if (opts)
> + kfree(opts);
> }
>
The NULL check is not needed here, use kfree(fc->s_fs_info) will be enough.
> static const struct fs_context_operations bpf_context_ops = {
> @@ -787,17 +840,32 @@ static int bpf_init_fs_context(struct fs_context *fc)
>
> opts->mode = S_IRWXUGO;
>
> - fc->fs_private = opts;
> + /* start out with no BPF token delegation enabled */
> + opts->delegate_cmds = 0;
> + opts->delegate_maps = 0;
> + opts->delegate_progs = 0;
> + opts->delegate_attachs = 0;
> +
> + fc->s_fs_info = opts;
> fc->ops = &bpf_context_ops;
> return 0;
> }
>
> +static void bpf_kill_super(struct super_block *sb)
> +{
> + struct bpf_mount_opts *opts = sb->s_fs_info;
> +
> + kill_litter_super(sb);
> + kfree(opts);
> +}
> +
> static struct file_system_type bpf_fs_type = {
> .owner = THIS_MODULE,
> .name = "bpf",
> .init_fs_context = bpf_init_fs_context,
> .parameters = bpf_fs_parameters,
> - .kill_sb = kill_litter_super,
> + .kill_sb = bpf_kill_super,
> + .fs_flags = FS_USERNS_MOUNT,
> };
>
> static int __init bpf_init(void)
next prev parent reply other threads:[~2023-10-10 7:09 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 22:57 [PATCH v6 bpf-next 00/13] BPF token and BPF FS-based delegation Andrii Nakryiko
2023-09-27 22:57 ` [PATCH v6 bpf-next 01/13] bpf: align CAP_NET_ADMIN checks with bpf_capable() approach Andrii Nakryiko
2023-09-27 22:57 ` [PATCH v6 bpf-next 02/13] bpf: add BPF token delegation mount options to BPF FS Andrii Nakryiko
2023-10-10 7:08 ` Hou Tao [this message]
2023-10-12 0:30 ` Andrii Nakryiko
2023-09-27 22:57 ` [PATCH v6 bpf-next 03/13] bpf: introduce BPF token object Andrii Nakryiko
2023-10-11 1:17 ` [PATCH v6 3/13] " Paul Moore
2023-10-12 0:31 ` Andrii Nakryiko
2023-10-12 21:48 ` Andrii Nakryiko
2023-10-12 23:43 ` Paul Moore
2023-10-12 23:51 ` Andrii Nakryiko
2023-10-12 23:18 ` Paul Moore
2023-10-12 23:45 ` Andrii Nakryiko
2023-10-11 2:35 ` [PATCH v6 bpf-next 03/13] " Hou Tao
2023-10-12 0:31 ` Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 04/13] bpf: add BPF token support to BPF_MAP_CREATE command Andrii Nakryiko
2023-10-10 8:35 ` Jiri Olsa
2023-10-12 0:30 ` Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 05/13] bpf: add BPF token support to BPF_BTF_LOAD command Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 06/13] bpf: add BPF token support to BPF_PROG_LOAD command Andrii Nakryiko
2023-10-11 1:17 ` [PATCH v6 6/13] " Paul Moore
2023-10-12 0:31 ` Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 07/13] bpf: take into account BPF token when fetching helper protos Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 08/13] bpf: consistenly use BPF token throughout BPF verifier logic Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 09/13] libbpf: add bpf_token_create() API Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 10/13] libbpf: add BPF token support to bpf_map_create() API Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 11/13] libbpf: add BPF token support to bpf_btf_load() API Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 12/13] libbpf: add BPF token support to bpf_prog_load() API Andrii Nakryiko
2023-09-27 22:58 ` [PATCH v6 bpf-next 13/13] selftests/bpf: add BPF token-enabled tests 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=02a63a35-7a0c-503b-eb24-774300e86841@huaweicloud.com \
--to=houtao@huaweicloud.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=keescook@chromium.org \
--cc=kernel-team@meta.com \
--cc=lennart@poettering.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).