All of lore.kernel.org
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE
Date: Fri,  4 Dec 2026 22:32:29 -0800	[thread overview]
Message-ID: <20261205063229.2518424-10-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063229.2518424-1-praneethb2002@gmail.com>

__core_scsi3_add_registration() increments dev->t10_pr.pr_generation
with no lock held when it runs for a REGISTER AND MOVE. The old comment
says dev_reservation_lock is already held in that case. That is not
true. core_scsi3_emulate_pro_register_and_move() drops the lock before
calling core_scsi3_alloc_registration() because the allocation can
sleep. It only takes it back afterwards.

The unlocked increment can race with core_scsi3_pr_generation(), which
updates the same counter under dev_reservation_lock for a plain
REGISTER. Both updates can read the same value and one increment is
lost. READ KEYS then reports an incorrect PRgeneration. The effect is
functional only and it takes a remote initiator to trigger it.

Always take the generation from core_scsi3_pr_generation() and drop the
register_move special case along with the stale comment. No caller of
__core_scsi3_add_registration() holds dev_reservation_lock here. The
register_move=0 path in the same function already calls
core_scsi3_pr_generation() in this spot, so taking the lock cannot
deadlock.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3 and
    checked against the source with Claude Opus 5.5. I reviewed the patch
    and take responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I did not write a reproducer.

 drivers/target/target_core_pr.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 0f2ff9d42150..3283fa5ee298 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1095,15 +1095,8 @@ static void __core_scsi3_add_registration(
 	/*
 	 * Increment PRgeneration counter for struct se_device upon a successful
 	 * REGISTER, see spc4r17 section 6.3.2 READ_KEYS service action
-	 *
-	 * Also, when register_move = 1 for PROUT REGISTER_AND_MOVE service
-	 * action, the struct se_device->dev_reservation_lock will already be held,
-	 * so we do not call core_scsi3_pr_generation() which grabs the lock
-	 * for the REGISTER.
 	 */
-	pr_reg->pr_res_generation = (register_move) ?
-			dev->t10_pr.pr_generation++ :
-			core_scsi3_pr_generation(dev);
+	pr_reg->pr_res_generation = core_scsi3_pr_generation(dev);
 
 	spin_lock(&pr_tmpl->registration_lock);
 	list_add_tail(&pr_reg->pr_reg_list, &pr_tmpl->registration_list);
-- 
2.25.1


  parent reply	other threads:[~2026-12-05  6:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task() Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 2/9] scsi: mpt3sas: do not keep an enclosure pointer across a host reset Praneeth Balasubramanian
2026-12-05  6:46   ` sashiko-bot
2026-12-05  6:32 ` [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Praneeth Balasubramanian
2026-12-05  6:43   ` sashiko-bot
2026-12-05  8:20     ` Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 4/9] scsi: ipr: Skip dump entries whose length is not a 4 byte multiple Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 5/9] scsi: arm: Fix eh_abort race against the interrupt handler Praneeth Balasubramanian
2026-12-05  6:50   ` sashiko-bot
2026-12-05  8:20     ` Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command Praneeth Balasubramanian
2026-12-05  6:47   ` sashiko-bot
2026-12-05  8:20     ` Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 7/9] scsi: fnic: Hold fnic_lock for the oxid calls in the FIP timer work Praneeth Balasubramanian
2026-12-05  6:32 ` [PATCH 8/9] scsi: qla2xxx: Hold qp_lock when completing command in abort timeout Praneeth Balasubramanian
2026-12-05  6:58   ` sashiko-bot
2026-12-05  6:32 ` Praneeth Balasubramanian [this message]
2026-12-05  6:56   ` [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE 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=20261205063229.2518424-10-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.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 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.