From: Yifei Gao <gyf161023@gmail.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Cc: Nicholas Bellinger <nab@linux-iscsi.org>,
Hannes Reinecke <hare@suse.de>,
Mike Christie <michael.christie@oracle.com>,
linux-kernel@vger.kernel.org, Yifei Gao <gyf161023@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] scsi: target: use kref_get_unless_zero() in core_get_se_deve_from_rtpi()
Date: Tue, 4 Aug 2026 21:37:25 +0000 [thread overview]
Message-ID: <20260804213726.3411698-1-gyf161023@gmail.com> (raw)
core_get_se_deve_from_rtpi() iterates nacl->lun_entry_hlist under
rcu_read_lock() and takes a plain kref_get() on deve->pr_kref for the
matching entry. The disable path, core_disable_device_list_for_node(),
unhashes the entry, drops the final reference, waits for pr_comp and
frees it via call_rcu() while holding lun_entry_mutex, which the reader
does not hold. A reader racing that path can revive the kref after it has
reached zero, defeating the pr_comp completion barrier and leading to a
use-after-free.
Use kref_get_unless_zero() and skip entries whose refcount has already
dropped to zero.
Fixes: 29a05deebf6c ("target: Convert se_node_acl->device_list[] to RCU hlist")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Yifei Gao <gyf161023@gmail.com>
---
drivers/target/target_core_device.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 9db2201aa553..bff97c6efffb 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -220,7 +220,8 @@ struct se_dev_entry *core_get_se_deve_from_rtpi(
if (lun->lun_tpg->tpg_rtpi != rtpi)
continue;
- kref_get(&deve->pr_kref);
+ if (!kref_get_unless_zero(&deve->pr_kref))
+ continue;
rcu_read_unlock();
return deve;
--
2.43.0
next reply other threads:[~2026-08-04 21:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 21:37 Yifei Gao [this message]
2026-08-04 21:50 ` [PATCH] scsi: target: use kref_get_unless_zero() in core_get_se_deve_from_rtpi() 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=20260804213726.3411698-1-gyf161023@gmail.com \
--to=gyf161023@gmail.com \
--cc=hare@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=nab@linux-iscsi.org \
--cc=stable@vger.kernel.org \
--cc=target-devel@vger.kernel.org \
/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