Skip to content

Commit e181d3f

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
bpf: Disallow bpf_obj_new_impl call when bpf_mem_alloc_init fails
In the unlikely event that bpf_global_ma is not correctly initialized, instead of checking the boolean everytime bpf_obj_new_impl is called, simply check it while loading the program and return an error if bpf_global_ma_set is false. Suggested-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20221120212610.2361700-1-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent efc1970 commit e181d3f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

kernel/bpf/helpers.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,6 @@ void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign)
17601760
u64 size = local_type_id__k;
17611761
void *p;
17621762

1763-
if (unlikely(!bpf_global_ma_set))
1764-
return NULL;
17651763
p = bpf_mem_alloc(&bpf_global_ma, size);
17661764
if (!p)
17671765
return NULL;

kernel/bpf/verifier.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8878,6 +8878,9 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
88788878
struct btf *ret_btf;
88798879
u32 ret_btf_id;
88808880

8881+
if (unlikely(!bpf_global_ma_set))
8882+
return -ENOMEM;
8883+
88818884
if (((u64)(u32)meta.arg_constant.value) != meta.arg_constant.value) {
88828885
verbose(env, "local type ID argument must be in range [0, U32_MAX]\n");
88838886
return -EINVAL;

0 commit comments

Comments
 (0)