mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia Jia <physicalmtea@gmail.com>
To: "Martin K . Petersen" <mkp@kernel.org>,
	Jan Engelhardt <jengelh@inai.de>, Hannes Reinecke <hare@suse.de>,
	James Bottomley <James.Bottomley@suse.de>,
	Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Jia Jia <physicalmtea@gmail.com>
Subject: [PATCH v2 3/8] scsi: target: reject a short SET TARGET PORT GROUPS list
Date: Wed, 18 Nov 2026 12:13:06 +0800	[thread overview]
Message-ID: <20261118041311.19011-4-physicalmtea@gmail.com> (raw)
In-Reply-To: <20261118041311.19011-1-physicalmtea@gmail.com>

SET TARGET PORT GROUPS has a four-byte header followed by four-byte
descriptors. target_emulate_set_target_port_groups() accepts any list
at least four bytes long, then walks a descriptor whenever bytes remain.
A five-byte list can therefore make get_unaligned_be16() read past the
parameter data.

Reject lists whose lengths are not multiples of four before walking
them or changing port group state.

KASAN reports:

  BUG: KASAN: use-after-free in target_emulate_set_target_port_groups+0x1dc/0x540 [target_core_mod]
  Read of size 2

  target_emulate_set_target_port_groups
  __target_execute_cmd
  target_execute_cmd
  vhost_scsi_write_pending
  transport_generic_new_cmd

Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
 drivers/target/target_core_alua.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index c110914b7b78b..22b4c39748704 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -298,9 +298,9 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
 	int alua_access_state, primary = 0, valid_states;
 	u16 tg_pt_id, rtpi;
 
-	if (cmd->data_length < 4) {
-		pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
-			" small\n", cmd->data_length);
+	if (cmd->data_length < 4 || (cmd->data_length & 3)) {
+		pr_warn("SET TARGET PORT GROUPS invalid list length %u\n",
+			cmd->data_length);
 		return TCM_INVALID_PARAMETER_LIST;
 	}
 

  parent reply	other threads:[~2026-11-18  4:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  4:13 [PATCH v2 0/8] scsi: target: keep command bytes inside the sg Jia Jia
2026-11-18  4:13 ` [PATCH v2 1/8] scsi: target: take COMPARE AND WRITE data from the write half Jia Jia
2026-11-18  4:13 ` [PATCH v2 2/8] scsi: target: keep REPORT REFERRALS stores inside the buffer Jia Jia
2026-11-18  4:13 ` Jia Jia [this message]
2026-11-18  4:13 ` [PATCH v2 4/8] scsi: target: copy a DIF insert tuple across prot sgs Jia Jia
2026-11-18  4:13 ` [PATCH v2 5/8] scsi: target: copy a DIF verify " Jia Jia
2026-11-18  4:13 ` [PATCH v2 6/8] scsi: target: limit DIF block CRC to each data sg Jia Jia
2026-11-18  4:13 ` [PATCH v2 7/8] scsi: target: keep pscsi mode bytes inside the data sgs Jia Jia
2026-11-18  4:13 ` [PATCH v2 8/8] scsi: target: advance past escaped DIF blocks across " Jia Jia

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=20261118041311.19011-4-physicalmtea@gmail.com \
    --to=physicalmtea@gmail.com \
    --cc=James.Bottomley@suse.de \
    --cc=akinobu.mita@gmail.com \
    --cc=hare@suse.de \
    --cc=jengelh@inai.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@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®