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 2/8] scsi: target: keep REPORT REFERRALS stores inside the buffer
Date: Wed, 18 Nov 2026 12:13:05 +0800 [thread overview]
Message-ID: <20261118041311.19011-3-physicalmtea@gmail.com> (raw)
In-Reply-To: <20261118041311.19011-1-physicalmtea@gmail.com>
target_emulate_report_referrals() checks only that the start of an LBA
field is inside cmd->data_length before storing all eight bytes. A
short response buffer can therefore make the store run past its end.
For example, a nine-byte allocation reaches the LBA at buf[8].
The response builder must still visit the remaining LBA maps to compute
the reported length. Encode each LBA in a local array and copy only
the part that fits in the command buffer.
KASAN reports:
BUG: KASAN: use-after-free in target_emulate_report_referrals+0x100/0x380 [target_core_mod]
Write of size 8
target_emulate_report_referrals
__target_execute_cmd
target_execute_cmd
transport_generic_new_cmd
Fixes: 38edd7245771 ("target_core_alua: check for buffer overflow")
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
drivers/target/target_core_alua.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 140154d93c430..c110914b7b78b 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -49,6 +49,19 @@ static LIST_HEAD(lu_gps_list);
struct t10_alua_lu_gp *default_lu_gp;
+static void
+target_emulate_report_referrals_copy_lba(unsigned char *buf, u32 off,
+ u32 data_length, u64 lba)
+{
+ unsigned char lba_buf[sizeof(lba)];
+
+ if (off >= data_length)
+ return;
+ put_unaligned_be64(lba, lba_buf);
+ memcpy(&buf[off], lba_buf,
+ min_t(u32, sizeof(lba_buf), data_length - off));
+}
+
/*
* REPORT REFERRALS
*
@@ -88,11 +101,13 @@ target_emulate_report_referrals(struct se_cmd *cmd)
int pg_num;
off += 4;
- if (cmd->data_length > off)
- put_unaligned_be64(map->lba_map_first_lba, &buf[off]);
+ target_emulate_report_referrals_copy_lba(buf, off,
+ cmd->data_length,
+ map->lba_map_first_lba);
off += 8;
- if (cmd->data_length > off)
- put_unaligned_be64(map->lba_map_last_lba, &buf[off]);
+ target_emulate_report_referrals_copy_lba(buf, off,
+ cmd->data_length,
+ map->lba_map_last_lba);
off += 8;
rd_len += 20;
pg_num = 0;
next prev 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 ` Jia Jia [this message]
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 ` [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-3-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®