From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: move security_bpf_prog_free() out of RCU callback
Date: Fri, 26 Jun 2026 09:59:49 +0000 [thread overview]
Message-ID: <20260626095949.C88281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260626093711.2969648-1-rhkrqnwk98@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch fails to fix the `BUG: sleeping function called from invalid context` because `security_bpf_prog_free()` can still execute synchronously in softirq contexts.
- [High] Use-After-Free on `prog->aux` fields when traversing the `bpf_prog` structure in the `bpf_prog_free` LSM hook.
--
commit ce00646a70b27dcf100e6bb9652d3943185fcac5
Author: Sechang Lim <rhkrqnwk98@gmail.com>
bpf: move security_bpf_prog_free() out of RCU callback
This commit moves security_bpf_prog_free() from __bpf_prog_put_rcu() to
__bpf_prog_put_noref() before the RCU deferral. This change is intended
to prevent a BUG caused by sleeping LSM BPF programs executing in atomic
context when attached to the bpf_prog_free hook.
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 6db306d23b479..6d9a662241159 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
[ ... ]
> @@ -2457,6 +2456,7 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
> if (prog->aux->attach_btf)
> btf_put(prog->aux->attach_btf);
>
> + security_bpf_prog_free(prog);
[Severity: High]
This is a pre-existing issue, but does moving this hook here expose a
use-after-free read if an attached LSM BPF program traverses the
bpf_prog structure?
The hook is invoked after several dynamically allocated fields in prog->aux
(such as linfo, jited_linfo, and kfunc_tab) have been freed earlier in
__bpf_prog_put_noref() via kvfree() and kfree(). An LSM BPF
program attached to bpf_prog_free could read these dangling pointers.
[Severity: High]
This isn't a bug introduced by this patch, but will this placement actually
resolve the "sleeping function called from invalid context" BUG?
If a program refcount is dropped from an RCU softirq path, such as in
__dev_map_entry_free() in kernel/bpf/devmap.c, it appears we still reach this
hook synchronously in atomic context:
kernel/bpf/syscall.c:__bpf_prog_put() {
...
if (in_hardirq() || irqs_disabled()) {
INIT_WORK(&aux->work, bpf_prog_put_deferred);
schedule_work(&aux->work);
} else {
bpf_prog_put_deferred(&aux->work);
}
}
Because in_hardirq() and irqs_disabled() are both false in softirq context,
bpf_prog_put_deferred() and consequently __bpf_prog_put_noref() will execute
synchronously, firing the LSM hook and hitting the same BUG.
> if (deferred) {
> if (prog->sleepable)
> call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260626093711.2969648-1-rhkrqnwk98@gmail.com?part=1
next prev parent reply other threads:[~2026-06-26 9:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 9:37 [PATCH bpf] bpf: move security_bpf_prog_free() out of RCU callback Sechang Lim
2026-06-26 9:59 ` sashiko-bot [this message]
2026-06-30 23:17 ` Alexei Starovoitov
2026-07-01 8:05 ` Sechang Lim
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=20260626095949.C88281F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=rhkrqnwk98@gmail.com \
--cc=sashiko-reviews@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