Commit 5676234f authored by Roman Bolshakov's avatar Roman Bolshakov Committed by Martin K. Petersen

scsi: target/iblock: Fix overrun in WRITE SAME emulation

WRITE SAME corrupts data on the block device behind iblock if the command
is emulated. The emulation code issues (M - 1) * N times more bios than
requested, where M is the number of 512 blocks per real block size and N is
the NUMBER OF LOGICAL BLOCKS specified in WRITE SAME command. So, for a
device with 4k blocks, 7 * N more LBAs gets written after the requested
range.

The issue happens because the number of 512 byte sectors to be written is
decreased one by one while the real bios are typically from 1 to 8 512 byte
sectors per bio.

Fixes: c66ac9db ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarRoman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 240b4cc8
...@@ -515,7 +515,7 @@ iblock_execute_write_same(struct se_cmd *cmd) ...@@ -515,7 +515,7 @@ iblock_execute_write_same(struct se_cmd *cmd)
/* Always in 512 byte units for Linux/Block */ /* Always in 512 byte units for Linux/Block */
block_lba += sg->length >> SECTOR_SHIFT; block_lba += sg->length >> SECTOR_SHIFT;
sectors -= 1; sectors -= sg->length >> SECTOR_SHIFT;
} }
iblock_submit_bios(&list); iblock_submit_bios(&list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment