BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Blaise Boscaccy" <bboscaccy@linux.microsoft.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v7 04/10] lsm: framework for BPF integrity verification
Date: Fri, 08 May 2026 01:09:38 +0000	[thread overview]
Message-ID: <20260508010938.A9B4AC2BCB2@smtp.kernel.org> (raw)
In-Reply-To: <20260507191416.2984054-5-bboscaccy@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Double execution of `security_bpf_prog_free()` on error paths, leading to duplicate invocation of LSM cleanup hooks.
--

commit da3e568b0e83968c7e672f02d2dc4e5b4cb4a3e9
Author: Paul Moore <paul@paul-moore.com>

lsm: framework for BPF integrity verification

Add a new LSM hook and two new LSM hook callbacks to support LSMs that
perform integrity verification, e.g. digital signature verification,
of BPF programs.

> diff --git a/security/security.c b/security/security.c
> index a26c1474e2e49..bb78f7e45a98f 100644
> --- a/security/security.c
> +++ b/security/security.c
[ ... ]
> @@ -5255,9 +5315,18 @@ int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
>  	if (unlikely(rc))
>  		return rc;
>  
> +	rc = call_int_hook(bpf_prog_load_integrity, prog, attr, token, kernel);
> +	if (unlikely(rc))
> +		goto err;
> +
>  	rc = call_int_hook(bpf_prog_load, prog, attr, token, kernel);
>  	if (unlikely(rc))
> -		security_bpf_prog_free(prog);
> +		goto err;
> +
> +	return rc;
> +
> +err:
> +	security_bpf_prog_free(prog);
>  	return rc;
>  }

Does this introduce a regression by causing a double execution of
security_bpf_prog_free() on error paths?

If either the new bpf_prog_load_integrity hook or the existing
bpf_prog_load hook fails, the code jumps to the err label, calls
security_bpf_prog_free(), and returns the error code.

However, the caller bpf_prog_load() in kernel/bpf/syscall.c receives the
error code and jumps to the free_prog_sec label, which unconditionally calls
security_bpf_prog_free() again:

kernel/bpf/syscall.c:bpf_prog_load() {
    ...
    err = security_bpf_prog_load(prog, attr, token, bpf_prog_is_kernel(prog));
    if (err)
        goto free_prog_sec;
    ...
free_prog_sec:
    ...
    security_bpf_prog_free(prog);
    ...
}

This causes the bpf_prog_free LSM hook to execute twice for the same BPF
program. During the first call, prog->aux->security is freed and set to
NULL. The second call invokes the hook again with the NULL security blob.

Could this duplicate invocation violate lifecycle symmetry and potentially
cause reference count underflows, state corruption, or NULL pointer
dereferences in attached BPF LSM programs?

While this double-free behavior already existed for the bpf_prog_load hook,
this patch expands the flawed error handling to the newly introduced
bpf_prog_load_integrity hook. Should the internal cleanup in
security_bpf_prog_load() be removed to let the caller handle it?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260507191416.2984054-1-bboscaccy@linux.microsoft.com?part=4

  reply	other threads:[~2026-05-08  1:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 19:13 [PATCH v7 00/10] Reintroduce Hornet LSM Blaise Boscaccy
2026-05-07 19:13 ` [PATCH v7 01/10] crypto: pkcs7: add flag for validated trust on a signed info block Blaise Boscaccy
2026-05-07 23:51   ` sashiko-bot
2026-05-07 19:13 ` [PATCH v7 02/10] crypto: pkcs7: add ability to extract signed attributes by OID Blaise Boscaccy
2026-05-08  0:14   ` sashiko-bot
2026-05-07 19:13 ` [PATCH v7 03/10] crypto: pkcs7: add tests for pkcs7_get_authattr Blaise Boscaccy
2026-05-08  0:35   ` sashiko-bot
2026-05-07 19:13 ` [PATCH v7 04/10] lsm: framework for BPF integrity verification Blaise Boscaccy
2026-05-08  1:09   ` sashiko-bot [this message]
2026-05-07 19:13 ` [PATCH v7 05/10] lsm: security: Add additional enum values for bpf integrity checks Blaise Boscaccy
2026-05-07 19:14 ` [PATCH v7 06/10] security: Hornet LSM Blaise Boscaccy
2026-05-08  2:07   ` sashiko-bot
2026-05-07 19:14 ` [PATCH v7 07/10] hornet: Introduce gen_sig Blaise Boscaccy
2026-05-08  2:22   ` sashiko-bot
2026-05-07 19:14 ` [PATCH v7 08/10] hornet: Add a light skeleton data extractor scripts Blaise Boscaccy
2026-05-08  2:35   ` sashiko-bot
2026-05-07 19:14 ` [PATCH v7 09/10] selftests/hornet: Add a selftest for the Hornet LSM Blaise Boscaccy
2026-05-08  2:58   ` sashiko-bot
2026-05-07 19:14 ` [PATCH v7 10/10] ipe: Add BPF program load policy enforcement via Hornet integration Blaise Boscaccy
2026-05-08  4:21   ` sashiko-bot
2026-05-08 18:40   ` Fan Wu
2026-05-07 20:57 ` [PATCH v7 00/10] Reintroduce Hornet LSM Paul Moore
2026-05-07 21:58   ` Eric Biggers
2026-05-07 22:22     ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260508010938.A9B4AC2BCB2@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bboscaccy@linux.microsoft.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox