From: sashiko-bot@kernel.org
To: "Bilal Hashim" <AeeSec@126.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: pr: fix use-after-free of per-controller ref during preempt-and-abort
Date: Tue, 01 Dec 2026 17:41:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-243873@kernel.org> (raw)
In-Reply-To: <179614571010.1268.3635657573115762278@126.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvmet: pr: missing rcu_barrier() on module exit for call_rcu()
callbacks
--
commit ebe935e60f135c9929e022f96b4706cc10465422
Author: Bilal Hashim <AeeSec@126.com>
nvmet: pr: fix use-after-free of per-controller ref during preempt-and-abort
This commit adds a kref and RCU-deferred teardown to struct
nvmet_pr_per_ctrl_ref so controller teardown cannot free pc_ref while
PREEMPT_AND_ABORT is iterating ns->pr_per_ctrl_refs.
> diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
> index 8c818f24815bd..e5eb83a3169d1 100644
> --- a/drivers/nvme/target/pr.c
> +++ b/drivers/nvme/target/pr.c
> @@ -474,19 +474,45 @@ static void nvmet_pr_confirm_ns_pc_ref(struct percpu_ref *ref)
> complete(&pc_ref->confirm_done);
> }
>
> +static void nvmet_pr_free_pc_ref_rcu(struct rcu_head *rcu)
> +{
> + struct nvmet_pr_per_ctrl_ref *pc_ref =
> + container_of(rcu, struct nvmet_pr_per_ctrl_ref, rcu);
> +
> + percpu_ref_exit(&pc_ref->ref);
> + kfree(pc_ref);
> +}
> +
> +static void nvmet_pr_free_pc_ref(struct kref *kref)
> +{
> + struct nvmet_pr_per_ctrl_ref *pc_ref =
> + container_of(kref, struct nvmet_pr_per_ctrl_ref, kref);
> +
> + call_rcu(&pc_ref->rcu, nvmet_pr_free_pc_ref_rcu);
> +}
[Severity: High]
Can nvmet_pr_free_pc_ref_rcu() run after the nvmet module is unloaded?
Neither nvmet_pr_exit_ns() nor nvmet_exit() calls rcu_barrier(), and
free_module() only calls synchronize_rcu(), which does not wait for
pending call_rcu() callbacks. If nvmet.ko is unloaded right after tearing
down a controller or namespace with reservations enabled, the deferred
nvmet_pr_free_pc_ref_rcu() callback can execute after the module text has
been unmapped. Adding rcu_barrier() to nvmet_exit() would ensure all
queued callbacks finish before the module is freed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179614571010.1268.3635657573115762278@126.com?part=1
prev parent reply other threads:[~2026-12-01 17:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:21 [PATCH] nvmet: pr: fix use-after-free of per-controller ref during preempt-and-abort Bilal Hashim
2026-12-01 17:41 ` sashiko-bot [this message]
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=sashiko-outbox-243873@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=AeeSec@126.com \
--cc=linux-nvme@lists.infradead.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.