mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liuyong <pkfxxxing@gmail.com>
To: "Martin K. Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org, security@kernel.org
Subject: [PATCH 1/1] scsi: target: Skip zero-length protection SG allocation
Date: Mon,  9 Nov 2026 17:27:36 +0800	[thread overview]
Message-ID: <20261109092744.822646-2-pkfxxxing@gmail.com> (raw)
In-Reply-To: <20261109092744.822646-1-pkfxxxing@gmail.com>

A READ(10) command with its TRANSFER LENGTH field set to zero, sent to a
LUN with protection information enabled, can select TARGET_PROT_DIN_STRIP
while leaving cmd->prot_length at zero. transport_generic_new_cmd() then
passes that zero length to target_alloc_sgl(). This reaches
sg_init_table() with no entries, so sg_init_marker() accesses an invalid
last entry and causes a target-side Oops, which can also lead to
use-after-free during subsequent iSCSI connection cleanup. A logged-in
iSCSI initiator can trigger this on a FILEIO LUN with protection
information enabled.

Require a nonzero protection length before allocating its SG list,
allowing commands with no protection payload to proceed without an
empty allocation.

These issues were discovered and fixed by Qihoo 360's Tulongfeng
multi-agent system.

Fixes: 5835812f13e5 ("target: ensure se_cmd->t_prot_sg is allocated when required")
Cc: stable@vger.kernel.org
Signed-off-by: liuyong <pkfxxxing@gmail.com>
---
 drivers/target/target_core_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 927861c30..4cda1e610 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2841,7 +2841,7 @@ transport_generic_new_cmd(struct se_cmd *cmd)
 	int ret = 0;
 	bool zero_flag = !(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB);
 
-	if (cmd->prot_op != TARGET_PROT_NORMAL &&
+	if (cmd->prot_length && cmd->prot_op != TARGET_PROT_NORMAL &&
 	    !(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) {
 		ret = target_alloc_sgl(&cmd->t_prot_sg, &cmd->t_prot_nents,
 				       cmd->prot_length, true, false);

base-commit: f66469d9905b39d2c260a15d7d6db450f4db67c1

      reply	other threads:[~2026-11-09  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  9:27 [PATCH 0/1] scsi: target: Fix " liuyong
2026-11-09  9:27 ` liuyong [this message]

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=20261109092744.822646-2-pkfxxxing@gmail.com \
    --to=pkfxxxing@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=security@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®