]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Drop redundant hash_buf from map_get_hash operation
authorDaniel Borkmann <daniel@iogearbox.net>
Mon, 1 Jun 2026 15:02:43 +0000 (17:02 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 2 Jun 2026 01:36:40 +0000 (18:36 -0700)
bpf_map_get_info_by_fd() is the only caller of the ->map_get_hash
and always invokes it with hash_buf == map->sha and hash_buf_size
of SHA256_DIGEST_SIZE. array_map_get_hash() in turn lets sha256()
write the digest directly into that buffer (map->sha) and then
performs a trailing memcpy(), which evaluates to memcpy(map->sha,
map->sha, 32): a redundant self-copy. The hash_buf_size argument
was never used at all. Simplify this a bit, no functional change.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20260601150248.394863-3-daniel@iogearbox.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/arraymap.c
kernel/bpf/syscall.c

index d1a17c1183161ee6eac24b587ff881d396106299..c0510d2236854edc6655b010941f701de96d7226 100644 (file)
@@ -111,7 +111,7 @@ struct bpf_map_ops {
        long (*map_pop_elem)(struct bpf_map *map, void *value);
        long (*map_peek_elem)(struct bpf_map *map, void *value);
        void *(*map_lookup_percpu_elem)(struct bpf_map *map, void *key, u32 cpu);
-       int (*map_get_hash)(struct bpf_map *map, u32 hash_buf_size, void *hash_buf);
+       int (*map_get_hash)(struct bpf_map *map);
 
        /* funcs called by prog_array and perf_event_array map */
        void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file,
index dfb2110ab733571b448446b6233c084a60941ab0..e6271a2bf6d64b2df04ab33b93ce8360daed559d 100644 (file)
@@ -175,14 +175,12 @@ static void *array_map_lookup_elem(struct bpf_map *map, void *key)
        return array->value + (u64)array->elem_size * (index & array->index_mask);
 }
 
-static int array_map_get_hash(struct bpf_map *map, u32 hash_buf_size,
-                              void *hash_buf)
+static int array_map_get_hash(struct bpf_map *map)
 {
        struct bpf_array *array = container_of(map, struct bpf_array, map);
 
        sha256(array->value, (u64)array->elem_size * array->map.max_entries,
-              hash_buf);
-       memcpy(array->map.sha, hash_buf, sizeof(array->map.sha));
+              array->map.sha);
        return 0;
 }
 
index 2aafd21319831ab731b371b67f65249b58c12015..a27fa2b9b40562b3e402c8fa0b0c20585d86a1ee 100644 (file)
@@ -5434,18 +5434,16 @@ static int bpf_map_get_info_by_fd(struct file *file,
 
                if (!map->ops->map_get_hash)
                        return -EINVAL;
-
-               if (info.hash_size != SHA256_DIGEST_SIZE)
+               if (info.hash_size != sizeof(map->sha))
                        return -EINVAL;
-
                if (!READ_ONCE(map->frozen))
                        return -EPERM;
 
-               err = map->ops->map_get_hash(map, SHA256_DIGEST_SIZE, map->sha);
+               err = map->ops->map_get_hash(map);
                if (err != 0)
                        return err;
 
-               if (copy_to_user(uhash, map->sha, SHA256_DIGEST_SIZE) != 0)
+               if (copy_to_user(uhash, map->sha, sizeof(map->sha)) != 0)
                        return -EFAULT;
        } else if (info.hash_size) {
                return -EINVAL;