Skip to content

Commit ea1535e

Browse files
sinkapAlexei Starovoitov
authored andcommitted
bpf: Limit bpf program signature size
Practical BPF signatures are significantly smaller than KMALLOC_MAX_CACHE_SIZE Allowing larger sizes opens the door for abuse by passing excessive size values and forcing the kernel into expensive allocation paths (via kmalloc_large or vmalloc). Fixes: 3492715 ("bpf: Implement signature verification for BPF programs") Reported-by: Chris Mason <clm@meta.com> Signed-off-by: KP Singh <kpsingh@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260205063807.690823-1-kpsingh@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 75cd3be commit ea1535e

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

kernel/bpf/syscall.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,13 @@ static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr
28132813
void *sig;
28142814
int err = 0;
28152815

2816+
/*
2817+
* Don't attempt to use kmalloc_large or vmalloc for signatures.
2818+
* Practical signature for BPF program should be below this limit.
2819+
*/
2820+
if (attr->signature_size > KMALLOC_MAX_CACHE_SIZE)
2821+
return -EINVAL;
2822+
28162823
if (system_keyring_id_check(attr->keyring_id) == 0)
28172824
key = bpf_lookup_system_key(attr->keyring_id);
28182825
else

0 commit comments

Comments
 (0)