diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2024-07-30 07:16:04 +0200 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2024-08-14 00:58:17 +0200 |
commit | 55f325958ccc41eaea43eb4546d4dc77c1b5ef8a (patch) | |
tree | 3a67490e9e4a0ce16ffc6c7c92d36cb5c87c834a /kernel/bpf/verifier.c | |
parent | bpf: factor out fetching bpf_map from FD and adding it to used_maps list (diff) | |
download | linux-55f325958ccc41eaea43eb4546d4dc77c1b5ef8a.tar.xz linux-55f325958ccc41eaea43eb4546d4dc77c1b5ef8a.zip |
bpf: switch maps to CLASS(fd, ...)
Calling conventions for __bpf_map_get() would be more convenient
if it left fpdut() on failure to callers. Makes for simpler logics
in the callers.
Among other things, the proof of memory safety no longer has to
rely upon file->private_data never being ERR_PTR(...) for bpffs files.
Original calling conventions made it impossible for the caller to tell
whether __bpf_map_get() has returned ERR_PTR(-EINVAL) because it has found
the file not be a bpf map one (in which case it would've done fdput())
or because it found that ERR_PTR(-EINVAL) in file->private_data of a
bpf map file (in which case fdput() would _not_ have been done).
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'kernel/bpf/verifier.c')
-rw-r--r-- | kernel/bpf/verifier.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 14e4ef687a59..e3932f8ce10a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -18872,7 +18872,7 @@ static bool bpf_map_is_cgroup_storage(struct bpf_map *map) */ static int add_used_map_from_fd(struct bpf_verifier_env *env, int fd, bool *reused) { - struct fd f = fdget(fd); + CLASS(fd, f)(fd); struct bpf_map *map; int i; @@ -18886,7 +18886,6 @@ static int add_used_map_from_fd(struct bpf_verifier_env *env, int fd, bool *reus for (i = 0; i < env->used_map_cnt; i++) { if (env->used_maps[i] == map) { *reused = true; - fdput(f); return i; } } @@ -18894,7 +18893,6 @@ static int add_used_map_from_fd(struct bpf_verifier_env *env, int fd, bool *reus if (env->used_map_cnt >= MAX_USED_MAPS) { verbose(env, "The total number of maps per program has reached the limit of %u\n", MAX_USED_MAPS); - fdput(f); return -E2BIG; } @@ -18911,10 +18909,7 @@ static int add_used_map_from_fd(struct bpf_verifier_env *env, int fd, bool *reus *reused = false; env->used_maps[env->used_map_cnt++] = map; - fdput(f); - return env->used_map_cnt - 1; - } /* find and rewrite pseudo imm in ld_imm64 instructions: |