mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: Mike Christie <michael.christie@oracle.com>,
	linux-scsi@vger.kernel.org,  target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org,  stable@vger.kernel.org,
	Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH] scsi: target: alua: Hold tg_pt_gp_lock across the RTPG size check
Date: Wed, 11 Nov 2026 09:27:19 -0500	[thread overview]
Message-ID: <20261111-bug-target-rtpg-oob-v1-1-1c6b9cfb6831@linux.dev> (raw)

target_emulate_report_target_port_groups() checks that each target port
group, with one descriptor per member port, fits in the allocation
length, and then writes a descriptor for every LUN on the group's list.

The size check reads tg_pt_gp_members without tg_pt_gp_lock, which is
only taken for the list walk. A LUN attached to the group in between,
e.g. by a LUN created through configfs, adds a port the check did not
account for, and its descriptor can be written past cmd->data_length.

Take tg_pt_gp_lock before the size check, so that the member count and
the list walked stay in sync.

Fixes: 6b20fa9aaf0c2 ("target: Fix REPORT TARGET PORT GROUPS handling with small allocation length")
Cc: stable@vger.kernel.org
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 drivers/target/target_core_alua.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 140154d93c430..c9413e67b7f3f 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -166,9 +166,17 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd)
 	spin_lock(&dev->t10_alua.tg_pt_gps_lock);
 	list_for_each_entry(tg_pt_gp, &dev->t10_alua.tg_pt_gps_list,
 			tg_pt_gp_list) {
+		/*
+		 * Hold tg_pt_gp_lock from the size check to the end of the
+		 * descriptor list, so that LUNs joining the group cannot make
+		 * the list longer than the space checked for.
+		 */
+		spin_lock(&tg_pt_gp->tg_pt_gp_lock);
 		/* Skip empty port groups */
-		if (!tg_pt_gp->tg_pt_gp_members)
+		if (!tg_pt_gp->tg_pt_gp_members) {
+			spin_unlock(&tg_pt_gp->tg_pt_gp_lock);
 			continue;
+		}
 		/*
 		 * Check if the Target port group and Target port descriptor list
 		 * based on tg_pt_gp_members count will fit into the response payload.
@@ -178,6 +186,7 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd)
 		if ((off + 8 + (tg_pt_gp->tg_pt_gp_members * 4)) >
 		     cmd->data_length) {
 			rd_len += 8 + (tg_pt_gp->tg_pt_gp_members * 4);
+			spin_unlock(&tg_pt_gp->tg_pt_gp_lock);
 			continue;
 		}
 		/*
@@ -215,7 +224,6 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd)
 		buf[off++] = (tg_pt_gp->tg_pt_gp_members & 0xff);
 		rd_len += 8;
 
-		spin_lock(&tg_pt_gp->tg_pt_gp_lock);
 		list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list,
 				lun_tg_pt_gp_link) {
 			/*

---
base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
change-id: 20261110-bug-target-rtpg-oob-66d1ab0272c9

Best regards,
-- 
Qiliang Yuan <qiliang.yuan@linux.dev>


                 reply	other threads:[~2026-11-11 14:27 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=20261111-bug-target-rtpg-oob-v1-1-1c6b9cfb6831@linux.dev \
    --to=qiliang.yuan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=michael.christie@oracle.com \
    --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 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®