From: sashiko-bot@kernel.org
To: "Justin Suess" <utilityemal77@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/4] bpf: Use rcu_work in BTF teardown
Date: Wed, 29 Apr 2026 01:49:48 +0000 [thread overview]
Message-ID: <20260429014949.7C1A0C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260428201422.1518903-3-utilityemal77@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free in `btf_module_notify()` when flushing RCU work after `btf_put()`.
--
commit dc547d68e9d5193df746bf0203a1b6ef30ad4a58
Author: Justin Suess <utilityemal77@gmail.com>
bpf: Use rcu_work in BTF teardown
This commit queues the final BTF teardown from an RCU callback onto
an rcu_work. This ensures all RCU grace periods cease before proceeding
with the free work, allowing synchronous teardown for subsequent patches.
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 77af44d8a3ad..2b0511663319 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
[ ... ]
> @@ -8446,6 +8451,7 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
> sysfs_remove_bin_file(btf_kobj, btf_mod->sysfs_attr);
> purge_cand_cache(btf_mod->btf);
> btf_put(btf_mod->btf);
> + flush_rcu_work(&btf_mod->btf->free_work);
Can this result in a use-after-free regression of the btf object?
When btf_put() drops the module's reference to the BTF object, the current
thread no longer owns a reference. If this was the last reference,
queue_rcu_work() is invoked to asynchronously free the btf object after
an RCU grace period.
Because the thread is no longer inside an RCU read-side critical section,
it can be preempted before flush_rcu_work() runs. During this preemption
window, the RCU grace period could expire, allowing the background workqueue
to execute btf_free_work() and free the btf object via kfree().
When the thread resumes, flush_rcu_work() evaluates &btf_mod->btf->free_work
and checks its internal state. Does this directly dereference the
potentially freed btf memory?
> kfree(btf_mod->sysfs_attr);
> kfree(btf_mod);
> break;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260428201422.1518903-1-utilityemal77@gmail.com?part=2
next prev parent reply other threads:[~2026-04-29 1:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 20:14 [PATCH bpf-next 0/4] bpf: Fix NMI deadlock in referenced kptr destructors Justin Suess
2026-04-28 20:14 ` [PATCH bpf-next 1/4] bpf: Limit fields used in btf_record_equal comparisons Justin Suess
2026-04-28 20:14 ` [PATCH bpf-next 2/4] bpf: Use rcu_work in BTF teardown Justin Suess
2026-04-29 1:49 ` sashiko-bot [this message]
2026-04-28 20:14 ` [PATCH bpf-next 3/4] bpf: Fix deadlock in kptr dtor in nmi Justin Suess
2026-04-29 2:29 ` sashiko-bot
2026-04-29 9:37 ` Alexei Starovoitov
2026-04-29 16:21 ` Justin Suess
2026-05-02 14:33 ` Justin Suess
2026-04-28 20:14 ` [PATCH bpf-next 4/4] selftests/bpf: Add kptr nmi deadlock reproducer Justin Suess
2026-04-29 3:39 ` sashiko-bot
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=20260429014949.7C1A0C2BCB7@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=utilityemal77@gmail.com \
/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