From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
<paul@paul-moore.com>, <brauner@kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>,
<linux-security-module@vger.kernel.org>, <keescook@chromium.org>,
<kernel-team@meta.com>, <sargun@sargun.me>
Subject: [PATCH RFC bpf-next 3/3] selftests/bpf: utilize string values for delegate_xxx mount options
Date: Thu, 7 Dec 2023 14:27:55 -0800 [thread overview]
Message-ID: <20231207222755.3920286-4-andrii@kernel.org> (raw)
In-Reply-To: <20231207222755.3920286-1-andrii@kernel.org>
Use both hex-based and string-based way to specify delegate mount
options for BPF FS.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
.../testing/selftests/bpf/prog_tests/token.c | 43 +++++++++++--------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c
index dc03790c6272..ec59c81c54b5 100644
--- a/tools/testing/selftests/bpf/prog_tests/token.c
+++ b/tools/testing/selftests/bpf/prog_tests/token.c
@@ -55,14 +55,22 @@ static int restore_priv_caps(__u64 old_caps)
return cap_enable_effective(old_caps, NULL);
}
-static int set_delegate_mask(int fs_fd, const char *key, __u64 mask)
+static int set_delegate_mask(int fs_fd, const char *key, __u64 mask, const char *mask_str)
{
char buf[32];
int err;
- snprintf(buf, sizeof(buf), "0x%llx", (unsigned long long)mask);
+ if (!mask_str) {
+ if (mask == ~0ULL) {
+ mask_str = "any";
+ } else {
+ snprintf(buf, sizeof(buf), "0x%llx", (unsigned long long)mask);
+ mask_str = buf;
+ }
+ }
+
err = sys_fsconfig(fs_fd, FSCONFIG_SET_STRING, key,
- mask == ~0ULL ? "any" : buf, 0);
+ mask_str, 0);
if (err < 0)
err = -errno;
return err;
@@ -72,6 +80,7 @@ static int set_delegate_mask(int fs_fd, const char *key, __u64 mask)
struct bpffs_opts {
__u64 cmds;
+ const char *cmds_str;
__u64 maps;
__u64 progs;
__u64 attachs;
@@ -93,16 +102,16 @@ static int materialize_bpffs_fd(int fs_fd, struct bpffs_opts *opts)
int mnt_fd, err;
/* set up token delegation mount options */
- err = set_delegate_mask(fs_fd, "delegate_cmds", opts->cmds);
+ err = set_delegate_mask(fs_fd, "delegate_cmds", opts->cmds, opts->cmds_str);
if (!ASSERT_OK(err, "fs_cfg_cmds"))
return err;
- err = set_delegate_mask(fs_fd, "delegate_maps", opts->maps);
+ err = set_delegate_mask(fs_fd, "delegate_maps", opts->maps, NULL);
if (!ASSERT_OK(err, "fs_cfg_maps"))
return err;
- err = set_delegate_mask(fs_fd, "delegate_progs", opts->progs);
+ err = set_delegate_mask(fs_fd, "delegate_progs", opts->progs, NULL);
if (!ASSERT_OK(err, "fs_cfg_progs"))
return err;
- err = set_delegate_mask(fs_fd, "delegate_attachs", opts->attachs);
+ err = set_delegate_mask(fs_fd, "delegate_attachs", opts->attachs, NULL);
if (!ASSERT_OK(err, "fs_cfg_attachs"))
return err;
@@ -284,13 +293,13 @@ static void child(int sock_fd, struct bpffs_opts *opts, child_callback_fn callba
}
/* ensure unprivileged child cannot set delegation options */
- err = set_delegate_mask(fs_fd, "delegate_cmds", 0x1);
+ err = set_delegate_mask(fs_fd, "delegate_cmds", 0x1, NULL);
ASSERT_EQ(err, -EPERM, "delegate_cmd_eperm");
- err = set_delegate_mask(fs_fd, "delegate_maps", 0x1);
+ err = set_delegate_mask(fs_fd, "delegate_maps", 0x1, NULL);
ASSERT_EQ(err, -EPERM, "delegate_maps_eperm");
- err = set_delegate_mask(fs_fd, "delegate_progs", 0x1);
+ err = set_delegate_mask(fs_fd, "delegate_progs", 0x1, NULL);
ASSERT_EQ(err, -EPERM, "delegate_progs_eperm");
- err = set_delegate_mask(fs_fd, "delegate_attachs", 0x1);
+ err = set_delegate_mask(fs_fd, "delegate_attachs", 0x1, NULL);
ASSERT_EQ(err, -EPERM, "delegate_attachs_eperm");
/* pass BPF FS context object to parent */
@@ -314,22 +323,22 @@ static void child(int sock_fd, struct bpffs_opts *opts, child_callback_fn callba
}
/* ensure unprivileged child cannot reconfigure to set delegation options */
- err = set_delegate_mask(fs_fd, "delegate_cmds", ~0ULL);
+ err = set_delegate_mask(fs_fd, "delegate_cmds", 0, "any");
if (!ASSERT_EQ(err, -EPERM, "delegate_cmd_eperm_reconfig")) {
err = -EINVAL;
goto cleanup;
}
- err = set_delegate_mask(fs_fd, "delegate_maps", ~0ULL);
+ err = set_delegate_mask(fs_fd, "delegate_maps", 0, "any");
if (!ASSERT_EQ(err, -EPERM, "delegate_maps_eperm_reconfig")) {
err = -EINVAL;
goto cleanup;
}
- err = set_delegate_mask(fs_fd, "delegate_progs", ~0ULL);
+ err = set_delegate_mask(fs_fd, "delegate_progs", 0, "any");
if (!ASSERT_EQ(err, -EPERM, "delegate_progs_eperm_reconfig")) {
err = -EINVAL;
goto cleanup;
}
- err = set_delegate_mask(fs_fd, "delegate_attachs", ~0ULL);
+ err = set_delegate_mask(fs_fd, "delegate_attachs", 0, "any");
if (!ASSERT_EQ(err, -EPERM, "delegate_attachs_eperm_reconfig")) {
err = -EINVAL;
goto cleanup;
@@ -647,7 +656,7 @@ void test_token(void)
{
if (test__start_subtest("map_token")) {
struct bpffs_opts opts = {
- .cmds = 1ULL << BPF_MAP_CREATE,
+ .cmds_str = "BPF_MAP_CREATE",
.maps = 1ULL << BPF_MAP_TYPE_STACK,
};
@@ -662,7 +671,7 @@ void test_token(void)
}
if (test__start_subtest("prog_token")) {
struct bpffs_opts opts = {
- .cmds = 1ULL << BPF_PROG_LOAD,
+ .cmds_str = "BPF_PROG_LOAD",
.progs = 1ULL << BPF_PROG_TYPE_XDP,
.attachs = 1ULL << BPF_XDP,
};
--
2.34.1
prev parent reply other threads:[~2023-12-07 22:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 22:27 [PATCH RFC bpf-next 0/3] BPF FS mount options parsing follow ups Andrii Nakryiko
2023-12-07 22:27 ` [PATCH RFC bpf-next 1/3] bpf: add mapper macro for bpf_cmd enum Andrii Nakryiko
2023-12-12 2:40 ` Alexei Starovoitov
2023-12-12 4:01 ` Andrii Nakryiko
2023-12-12 4:06 ` Alexei Starovoitov
2023-12-13 1:37 ` Martin KaFai Lau
2023-12-13 17:26 ` Andrii Nakryiko
2023-12-07 22:27 ` [PATCH RFC bpf-next 2/3] bpf: extend parsing logic for BPF FS delegate_cmds mount option Andrii Nakryiko
2023-12-07 22:27 ` Andrii Nakryiko [this message]
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=20231207222755.3920286-4-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@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;
as well as URLs for NNTP newsgroup(s).