From: Yu Zhang <yuz08559@gmail.com>
To: Mike Christie <michael.christie@oracle.com>,
Dmitry Bogdanov <d.bogdanov@yadro.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org, Yu Zhang <yuz08559@gmail.com>
Subject: [BUG] scsi: target: use-after-free in PR REGISTER AND MOVE racing PR OUT CLEAR
Date: Fri, 16 Oct 2026 16:11:50 +1000 [thread overview]
Message-ID: <20261016061150.90624-1-yuz08559@gmail.com> (raw)
core_scsi3_emulate_pro_register_and_move() (drivers/target/target_core_pr.c)
drops dev_reservation_lock to allocate the destination registration, then
re-takes the lock and re-locates it:
spin_unlock(&dev->dev_reservation_lock);
if (core_scsi3_alloc_registration(... , 2, 1)) {
ret = TCM_INSUFFICIENT_REGISTRATION_RESOURCES;
goto out;
}
spin_lock(&dev->dev_reservation_lock);
dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl, iport_ptr);
new_reg = 1; /* result used unchecked */
...
__core_scsi3_complete_pro_release(dev, pr_res_nacl,
dev->dev_pr_res_holder, 0, 0);
dev->dev_pr_res_holder = dest_pr_reg;
dest_pr_reg->pr_res_holder = 1;
While the lock is dropped, a PR OUT command from another I_T nexus - most
easily CLEAR, which frees all registrations - runs
__core_scsi3_free_registration() and clears dev->dev_pr_res_holder. The move
path then uses the freed / NULL registration.
On a stock tree this is a NULL dereference (dest_pr_reg / dev_pr_res_holder
are NULL):
BUG: KASAN: null-ptr-deref in __core_scsi3_complete_pro_release+0x9d/0x3b0
Read of size 1 at addr 0000000000000228
Call Trace:
__core_scsi3_complete_pro_release+0x9d/0x3b0
? __core_scsi3_locate_pr_reg+0x13f/0x170
core_scsi3_emulate_pro_register_and_move+0xa95/...
target_scsi3_emulate_pr_out+0x3a4/...
__target_execute_cmd+0x56/0x140
A NULL check after the re-locate is not sufficient; a use-after-free of the
destination registration then shows up - allocated by one REGISTER AND MOVE,
freed by the concurrent CLEAR, still used by the move path (three tasks):
BUG: KASAN: slab-use-after-free in target_scsi3_emulate_pr_out+0xaf5/...
Read of size 8 at addr ffff8880058db670
Allocated by task 23:
__core_scsi3_alloc_registration+0x7c/...
core_scsi3_emulate_pro_register_and_move+0xed7/...
target_scsi3_emulate_pr_out+0x3a4/...
Freed by task 33:
__core_scsi3_free_registration+0x3d2/...
target_scsi3_emulate_pr_out+0xac0/... (PR OUT CLEAR)
Reproducer (KASAN build, panics in ~1 minute)
---------------------------------------------
- Two tcm_loop TPGs (SAS, distinct rtpi), a nexus each, both mapping one
iblock backstore -> two /dev/sdX = two I_T nexuses to the same LU.
- Thread A on nexus 1: loop { PR OUT REGISTER; RESERVE;
REGISTER AND MOVE to nexus 2 (unregistered destination) }.
- Thread B: loop { PR OUT CLEAR }.
C reproducer and full dmesg available on request.
Reported-by: Yu Zhang <yuz08559@gmail.com>
reply other threads:[~2026-10-16 6:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261016061150.90624-1-yuz08559@gmail.com \
--to=yuz08559@gmail.com \
--cc=d.bogdanov@yadro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--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
all inboxes | Powered by JetHome®