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 8/8] scsi: target: advance past escaped DIF blocks across data sgs
Date: Wed, 18 Nov 2026 12:13:11 +0800	[thread overview]
Message-ID: <20261118041311.19011-9-physicalmtea@gmail.com> (raw)
In-Reply-To: <20261118041311.19011-1-physicalmtea@gmail.com>

An escaped protection tuple advances dsg_off by one logical block.
sbc_dif_verify() adjusts the cursor across only one data sg on the next
iteration. When the skipped block spans several short entries, the
offset can still exceed the next sg's length and the following CRC
reads beyond that entry.

Advance through data sgs until the offset is within the current entry
before checking the next block.

KASAN reports:

  BUG: KASAN: use-after-free in crc_t10dif_update+0x91/0xf0
  Read of size 1

  crc_t10dif_update
  sbc_dif_verify
  target_execute_cmd
  vhost_scsi_write_pending
  transport_generic_new_cmd

Fixes: 18213afbd8ce ("target: handle odd SG mapping for data transfer memory")
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
 drivers/target/target_core_sbc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index e752b23b1bef7..671427d9ae74a 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -1553,7 +1553,7 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors,
 			return TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED;
 		}
 
-		if (dsg_off >= dsg->length) {
+		while (dsg_off >= dsg->length) {
 			dsg_off -= dsg->length;
 			kunmap_atomic(daddr - dsg->offset);
 			dsg = sg_next(dsg);

      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 ` [PATCH v2 3/8] scsi: target: reject a short SET TARGET PORT GROUPS list Jia Jia
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 ` Jia Jia [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=20261118041311.19011-9-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®