[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240124022127.2379740-19-andrii@kernel.org>
Date: Tue, 23 Jan 2024 18:21:15 -0800
From: Andrii Nakryiko <andrii@...nel.org>
To: bpf@...r.kernel.org,
netdev@...r.kernel.org,
paul@...l-moore.com,
brauner@...nel.org
Cc: torvalds@...ux-foundation.org,
linux-fsdevel@...r.kernel.org,
linux-security-module@...r.kernel.org,
kernel-team@...a.com
Subject: [PATCH v2 bpf-next 18/30] bpf: fail BPF_TOKEN_CREATE if no delegation option was set on BPF FS
It's quite confusing in practice when it's possible to successfully
create a BPF token from BPF FS that didn't have any of delegate_xxx
mount options set up. While it's not wrong, it's actually more
meaningful to reject BPF_TOKEN_CREATE with specific error code (-ENOENT)
to let user-space know that no token delegation is setup up.
So, instead of creating empty BPF token that will be always ignored
because it doesn't have any of the allow_xxx bits set, reject it with
-ENOENT. If we ever need empty BPF token to be possible, we can support
that with extra flag passed into BPF_TOKEN_CREATE.
Acked-by: Christian Brauner <brauner@...nel.org>
Acked-by: John Fastabend <john.fastabend@...il.com>
Signed-off-by: Andrii Nakryiko <andrii@...nel.org>
---
kernel/bpf/token.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/token.c b/kernel/bpf/token.c
index 64c568f47f69..0bca93b60c43 100644
--- a/kernel/bpf/token.c
+++ b/kernel/bpf/token.c
@@ -162,6 +162,15 @@ int bpf_token_create(union bpf_attr *attr)
goto out_path;
}
+ mnt_opts = path.dentry->d_sb->s_fs_info;
+ if (mnt_opts->delegate_cmds == 0 &&
+ mnt_opts->delegate_maps == 0 &&
+ mnt_opts->delegate_progs == 0 &&
+ mnt_opts->delegate_attachs == 0) {
+ err = -ENOENT; /* no BPF token delegation is set up */
+ goto out_path;
+ }
+
mode = S_IFREG | ((S_IRUSR | S_IWUSR) & ~current_umask());
inode = bpf_get_inode(path.mnt->mnt_sb, NULL, mode);
if (IS_ERR(inode)) {
@@ -191,7 +200,6 @@ int bpf_token_create(union bpf_attr *attr)
/* remember bpffs owning userns for future ns_capable() checks */
token->userns = get_user_ns(userns);
- mnt_opts = path.dentry->d_sb->s_fs_info;
token->allowed_cmds = mnt_opts->delegate_cmds;
token->allowed_maps = mnt_opts->delegate_maps;
token->allowed_progs = mnt_opts->delegate_progs;
--
2.34.1
Powered by blists - more mailing lists