[PATCH] nvmet: pr: fix use-after-free of per-controller ref during preempt-and-abort
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Dec 1 09:41:56 PST 2026
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 at 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
More information about the Linux-nvme
mailing list