aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/bloom_filter.c
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2024-03-27 09:32:25 -0700
committerAlexei Starovoitov <ast@kernel.org>2024-03-27 09:56:43 -0700
commita4e02d6b91c5e57f820032ec6ad794694c86f327 (patch)
treebf6977a9ab0b8a0c54accee088371e52c6d6d08d /kernel/bpf/bloom_filter.c
parent96b98a6552a90690d7bc18dd71b66312c9ded1fb (diff)
parentecc6a2101840177e57c925c102d2d29f260d37c8 (diff)
downloadlinux-a4e02d6b91c5e57f820032ec6ad794694c86f327.tar.gz
Merge branch 'check-bloom-filter-map-value-size'
Andrei Matei says: ==================== Check bloom filter map value size v1->v2: - prepend a patch addressing the bloom map specifically - change low-level rejection error to EFAULT, to indicate a bug ==================== Link: https://lore.kernel.org/r/20240327024245.318299-1-andreimatei1@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/bloom_filter.c')
-rw-r--r--kernel/bpf/bloom_filter.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/kernel/bpf/bloom_filter.c b/kernel/bpf/bloom_filter.c
index addf3dd57b59b5..35e1ddca74d210 100644
--- a/kernel/bpf/bloom_filter.c
+++ b/kernel/bpf/bloom_filter.c
@@ -80,6 +80,18 @@ static int bloom_map_get_next_key(struct bpf_map *map, void *key, void *next_key
return -EOPNOTSUPP;
}
+/* Called from syscall */
+static int bloom_map_alloc_check(union bpf_attr *attr)
+{
+ if (attr->value_size > KMALLOC_MAX_SIZE)
+ /* if value_size is bigger, the user space won't be able to
+ * access the elements.
+ */
+ return -E2BIG;
+
+ return 0;
+}
+
static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
{
u32 bitset_bytes, bitset_mask, nr_hash_funcs, nr_bits;
@@ -191,6 +203,7 @@ static u64 bloom_map_mem_usage(const struct bpf_map *map)
BTF_ID_LIST_SINGLE(bpf_bloom_map_btf_ids, struct, bpf_bloom_filter)
const struct bpf_map_ops bloom_filter_map_ops = {
.map_meta_equal = bpf_map_meta_equal,
+ .map_alloc_check = bloom_map_alloc_check,
.map_alloc = bloom_map_alloc,
.map_free = bloom_map_free,
.map_get_next_key = bloom_map_get_next_key,