Skip to contentSkip to conversation

bpf: Check size of the signature buffer

PATCH In review KP Singh 2 participants 3 messages Nov 2, 2025 – Nov 4, 2025

Subsystems (2)
lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 1/1 bpf: Check size of the signature buffer

Accept only a SHA256 sized buffer.

Fixes 349271568303 ("bpf: Implement signature verification for BPF programs")
---
 kernel/bpf/syscall.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/bpf/syscall.c +3 -0
index 8a129746bd6c..cc5bce20ec86 100644
@@ -2826,6 +2826,9 @@ static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr
 	void *sig;
 	int err = 0;
 
+	if (attr->signature_size != SHA256_DIGEST_SIZE)
+		return -EINVAL;
+
 	if (system_keyring_id_check(attr->keyring_id) == 0)
 		key = bpf_lookup_system_key(attr->keyring_id);
 	else
Signature · 1 line
2.43.0
#1 lore raw
Quoted 19 lines · KP Singh

Accept only a SHA256 sized buffer.

Fixes 349271568303 ("bpf: Implement signature verification for BPF

programs")

---
 kernel/bpf/syscall.c | 3 +++

 1 file changed, 3 insertions(+)
kernel/bpf/syscall.c +0 -0
index 8a129746bd6c..cc5bce20ec86 100644
@@ -2826,6 +2826,9 @@ static int bpf_prog_verify_signature(struct

bpf_prog *prog, union bpf_attr *attr
  void *sig;
  int err = 0;

kernel/bpf/syscall.c static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr · line 2831

Quoted 3 lines
kernel/bpf/syscall.c +3 -0
+	if (attr->signature_size != SHA256_DIGEST_SIZE)
+		return -EINVAL;
+

That's not going to work unless something really strange is going on: a pkcs7 signature is way bigger than a simple hash. I believe Chris was thinking we should do something like modules do: check to see that the signature is not bigger than the total size of the passed in file data size less the program data before doing the vmalloc.

Regards,

James

author
#2 lore raw
Quoted 21 lines · James Bottomley
Quoted 19 lines · KP Singh

Accept only a SHA256 sized buffer.

Fixes 349271568303 ("bpf: Implement signature verification for BPF

programs")

---
 kernel/bpf/syscall.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/bpf/syscall.c +0 -0
index 8a129746bd6c..cc5bce20ec86 100644
@@ -2826,6 +2826,9 @@ static int bpf_prog_verify_signature(struct

bpf_prog *prog, union bpf_attr *attr

      void *sig;
      int err = 0;
Quoted 9 lines

kernel/bpf/syscall.c static int bpf_prog_verify_signature(struct bpf_prog *prog, union bpf_attr *attr · line 2831

Quoted 3 lines
kernel/bpf/syscall.c +3 -0
+     if (attr->signature_size != SHA256_DIGEST_SIZE)
+             return -EINVAL;
+

That's not going to work unless something really strange is going on: a pkcs7 signature is way bigger than a simple hash. I believe Chris was thinking we should do something like modules do: check to see that the signature is not bigger than the total size of the passed in file data size less the program data before doing the vmalloc.

Ah, duh, yes. Apologies.

Will respin.

- KP

Quoted 7 lines

Regards,

James