Skip to content

Commit 7e6f4b2

Browse files
author
Paolo Abeni
committed
Alexei Starovoitov says: ==================== pull-request: bpf 2024-03-27 The following pull-request contains BPF updates for your *net* tree. We've added 4 non-merge commits during the last 1 day(s) which contain a total of 5 files changed, 26 insertions(+), 3 deletions(-). The main changes are: 1) Fix bloom filter value size validation and protect the verifier against such mistakes, from Andrei. 2) Fix build due to CONFIG_KEXEC_CORE/CRASH_DUMP split, from Hari. 3) Update bpf_lsm maintainers entry, from Matt. * tag 'for-net' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: bpf: update BPF LSM designated reviewer list bpf: Protect against int overflow for stack access size bpf: Check bloom filter map value size bpf: fix warning for crash_kexec ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 56d2f48 + 4dd6510 commit 7e6f4b2

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

MAINTAINERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,8 +3941,7 @@ F: kernel/bpf/ringbuf.c
39413941

39423942
BPF [SECURITY & LSM] (Security Audit and Enforcement using BPF)
39433943
M: KP Singh <[email protected]>
3944-
R: Florent Revest <[email protected]>
3945-
R: Brendan Jackman <[email protected]>
3944+
R: Matt Bobrowski <[email protected]>
39463945
39473946
S: Maintained
39483947
F: Documentation/bpf/prog_lsm.rst

kernel/bpf/bloom_filter.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ static int bloom_map_get_next_key(struct bpf_map *map, void *key, void *next_key
8080
return -EOPNOTSUPP;
8181
}
8282

83+
/* Called from syscall */
84+
static int bloom_map_alloc_check(union bpf_attr *attr)
85+
{
86+
if (attr->value_size > KMALLOC_MAX_SIZE)
87+
/* if value_size is bigger, the user space won't be able to
88+
* access the elements.
89+
*/
90+
return -E2BIG;
91+
92+
return 0;
93+
}
94+
8395
static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
8496
{
8597
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)
191203
BTF_ID_LIST_SINGLE(bpf_bloom_map_btf_ids, struct, bpf_bloom_filter)
192204
const struct bpf_map_ops bloom_filter_map_ops = {
193205
.map_meta_equal = bpf_map_meta_equal,
206+
.map_alloc_check = bloom_map_alloc_check,
194207
.map_alloc = bloom_map_alloc,
195208
.map_free = bloom_map_free,
196209
.map_get_next_key = bloom_map_get_next_key,

kernel/bpf/helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ __bpf_kfunc void bpf_throw(u64 cookie)
25482548
__bpf_kfunc_end_defs();
25492549

25502550
BTF_KFUNCS_START(generic_btf_ids)
2551-
#ifdef CONFIG_KEXEC_CORE
2551+
#ifdef CONFIG_CRASH_DUMP
25522552
BTF_ID_FLAGS(func, crash_kexec, KF_DESTRUCTIVE)
25532553
#endif
25542554
BTF_ID_FLAGS(func, bpf_obj_new_impl, KF_ACQUIRE | KF_RET_NULL)

kernel/bpf/verifier.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6701,6 +6701,11 @@ static int check_stack_access_within_bounds(
67016701
err = check_stack_slot_within_bounds(env, min_off, state, type);
67026702
if (!err && max_off > 0)
67036703
err = -EINVAL; /* out of stack access into non-negative offsets */
6704+
if (!err && access_size < 0)
6705+
/* access_size should not be negative (or overflow an int); others checks
6706+
* along the way should have prevented such an access.
6707+
*/
6708+
err = -EFAULT; /* invalid negative access size; integer overflow? */
67046709

67056710
if (err) {
67066711
if (tnum_is_const(reg->var_off)) {

tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (c) 2021 Facebook */
33

44
#include <sys/syscall.h>
5+
#include <limits.h>
56
#include <test_progs.h>
67
#include "bloom_filter_map.skel.h"
78

@@ -21,6 +22,11 @@ static void test_fail_cases(void)
2122
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid value size 0"))
2223
close(fd);
2324

25+
/* Invalid value size: too big */
26+
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, INT32_MAX, 100, NULL);
27+
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid value too large"))
28+
close(fd);
29+
2430
/* Invalid max entries size */
2531
fd = bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, NULL, 0, sizeof(value), 0, NULL);
2632
if (!ASSERT_LT(fd, 0, "bpf_map_create bloom filter invalid max entries size"))

0 commit comments

Comments
 (0)