| From 267e54468a68225a99ba740bf097f8102ed5804f Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Thu, 5 Feb 2026 07:38:07 +0100 |
| Subject: bpf: Limit bpf program signature size |
| |
| From: KP Singh <kpsingh@kernel.org> |
| |
| [ Upstream commit ea1535e28bb3773fc0b3cbd1f3842b808016990c ] |
| |
| 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: 349271568303 ("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> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| kernel/bpf/syscall.c | 7 +++++++ |
| 1 file changed, 7 insertions(+) |
| |
| diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c |
| index f39367765f0c4..2649e0472dfe0 100644 |
| --- a/kernel/bpf/syscall.c |
| +++ b/kernel/bpf/syscall.c |
| @@ -2825,6 +2825,13 @@ static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr |
| void *sig; |
| int err = 0; |
| |
| + /* |
| + * Don't attempt to use kmalloc_large or vmalloc for signatures. |
| + * Practical signature for BPF program should be below this limit. |
| + */ |
| + if (attr->signature_size > KMALLOC_MAX_CACHE_SIZE) |
| + return -EINVAL; |
| + |
| if (system_keyring_id_check(attr->keyring_id) == 0) |
| key = bpf_lookup_system_key(attr->keyring_id); |
| else |
| -- |
| 2.51.0 |
| |