BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v3] bpf: Limit signature size to KMALLOC_MAX_CACHE_SIZE
@ 2026-02-05  6:38 KP Singh
  2026-02-05 10:29 ` Daniel Borkmann
  2026-02-05 16:35 ` Alexei Starovoitov
  0 siblings, 2 replies; 3+ messages in thread
From: KP Singh @ 2026-02-05  6:38 UTC (permalink / raw)
  To: bpf; +Cc: ast, daniel, clm, KP Singh

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>
---
 kernel/bpf/syscall.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 4ff82144f885..15e87f507991 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2820,6 +2820,12 @@ 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.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-05 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05  6:38 [PATCH bpf v3] bpf: Limit signature size to KMALLOC_MAX_CACHE_SIZE KP Singh
2026-02-05 10:29 ` Daniel Borkmann
2026-02-05 16:35 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox