bpf: fail BPF_TOKEN_CREATE if no delegation option was set on BPF FS
authorAndrii Nakryiko <andrii@kernel.org>
Wed, 13 Dec 2023 19:08:33 +0000 (11:08 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 Dec 2023 23:47:04 +0000 (15:47 -0800)
commitf5fdb51fb980077a4c6c78f3f775821f611fb38b
treefa1e7a72820564b8bab55f1c448f446d68b0c41f
parentf04f2ce6018f3cb33ac96270b9153c2920ead190
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@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20231213190842.3844987-2-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/token.c