BPF List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Check size of the signature buffer
@ 2025-11-02 11:37 KP Singh
  2025-11-03 12:36 ` James Bottomley
  0 siblings, 1 reply; 3+ messages in thread
From: KP Singh @ 2025-11-02 11:37 UTC (permalink / raw)
  To: bpf; +Cc: ast, daniel, clm, KP Singh

Accept only a SHA256 sized buffer.

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 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 8a129746bd6c..cc5bce20ec86 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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
-- 
2.43.0


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

* Re: [PATCH bpf] bpf: Check size of the signature buffer
  2025-11-02 11:37 [PATCH bpf] bpf: Check size of the signature buffer KP Singh
@ 2025-11-03 12:36 ` James Bottomley
  2025-11-04 10:17   ` KP Singh
  0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2025-11-03 12:36 UTC (permalink / raw)
  To: KP Singh, bpf; +Cc: ast, daniel, clm

On Sun, 2025-11-02 at 12:37 +0100, KP Singh wrote:
> Accept only a SHA256 sized buffer.
> 
> 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 | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 8a129746bd6c..cc5bce20ec86 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -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;
> +

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




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

* Re: [PATCH bpf] bpf: Check size of the signature buffer
  2025-11-03 12:36 ` James Bottomley
@ 2025-11-04 10:17   ` KP Singh
  0 siblings, 0 replies; 3+ messages in thread
From: KP Singh @ 2025-11-04 10:17 UTC (permalink / raw)
  To: James Bottomley; +Cc: bpf, ast, daniel, clm

On Mon, Nov 3, 2025 at 1:36 PM James Bottomley
<James.Bottomley@hansenpartnership.com> wrote:
>
> On Sun, 2025-11-02 at 12:37 +0100, KP Singh wrote:
> > Accept only a SHA256 sized buffer.
> >
> > 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 | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index 8a129746bd6c..cc5bce20ec86 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -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;
> > +
>
> 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

>
> Regards,
>
> James
>
>
>

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

end of thread, other threads:[~2025-11-04 10:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-02 11:37 [PATCH bpf] bpf: Check size of the signature buffer KP Singh
2025-11-03 12:36 ` James Bottomley
2025-11-04 10:17   ` KP Singh

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