Skip to content

Commit 4342476

Browse files
rikvanrielAlexei Starovoitov
authored andcommitted
bpf: use kvzmalloc to allocate BPF verifier environment
The kzmalloc call in bpf_check can fail when memory is very fragmented, which in turn can lead to an OOM kill. Use kvzmalloc to fall back to vmalloc when memory is too fragmented to allocate an order 3 sized bpf verifier environment. Admittedly this is not a very common case, and only happens on systems where memory has already been squeezed close to the limit, but this does not seem like much of a hot path, and it's a simple enough fix. Signed-off-by: Rik van Riel <riel@surriel.com> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev> Link: https://lore.kernel.org/r/20241008170735.16766766@imladris.surriel.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 830b8e4 commit 4342476

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22315,7 +22315,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
2231522315
/* 'struct bpf_verifier_env' can be global, but since it's not small,
2231622316
* allocate/free it every time bpf_check() is called
2231722317
*/
22318-
env = kzalloc(sizeof(struct bpf_verifier_env), GFP_KERNEL);
22318+
env = kvzalloc(sizeof(struct bpf_verifier_env), GFP_KERNEL);
2231922319
if (!env)
2232022320
return -ENOMEM;
2232122321

@@ -22551,6 +22551,6 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
2255122551
mutex_unlock(&bpf_verifier_lock);
2255222552
vfree(env->insn_aux_data);
2255322553
err_free_env:
22554-
kfree(env);
22554+
kvfree(env);
2255522555
return ret;
2255622556
}

0 commit comments

Comments
 (0)