Skip to content

Commit 8e575c5

Browse files
author
Nicholas Bellinger
committed
target: Add missing WRITE_SAME end-of-device sanity check
This patch adds a check to sbc_setup_write_same() to verify the incoming WRITE_SAME LBA + number of blocks does not exceed past the end-of-device. Also check for potential LBA wrap-around as well. Reported-by: Bart Van Assche <bart.vanassche@sandisk.com> Cc: Martin Petersen <martin.petersen@oracle.com> Cc: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.org # 3.8+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 72859d9 commit 8e575c5

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎drivers/target/target_core_sbc.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb)
251251
static sense_reason_t
252252
sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops)
253253
{
254+
struct se_device *dev = cmd->se_dev;
255+
sector_t end_lba = dev->transport->get_blocks(dev) + 1;
254256
unsigned int sectors = sbc_get_write_same_sectors(cmd);
255257

256258
if ((flags[0] & 0x04) || (flags[0] & 0x02)) {
@@ -264,6 +266,16 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o
264266
sectors, cmd->se_dev->dev_attrib.max_write_same_len);
265267
return TCM_INVALID_CDB_FIELD;
266268
}
269+
/*
270+
* Sanity check for LBA wrap and request past end of device.
271+
*/
272+
if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) ||
273+
((cmd->t_task_lba + sectors) > end_lba)) {
274+
pr_err("WRITE_SAME exceeds last lba %llu (lba %llu, sectors %u)\n",
275+
(unsigned long long)end_lba, cmd->t_task_lba, sectors);
276+
return TCM_ADDRESS_OUT_OF_RANGE;
277+
}
278+
267279
/* We always have ANC_SUP == 0 so setting ANCHOR is always an error */
268280
if (flags[0] & 0x10) {
269281
pr_warn("WRITE SAME with ANCHOR not supported\n");

0 commit comments

Comments
 (0)