Skip to content

Commit

Permalink
scsi: target/iblock: Fix overrun in WRITE SAME emulation
Browse files Browse the repository at this point in the history
commit 5676234 upstream.

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: c66ac9d ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
[bwh: Backported to 3.16: use IBLOCK_LBA_SHIFT instead of SECTOR_SHIFT]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
Roman Bolshakov authored and Ben Hutchings committed Oct 5, 2019
1 parent 0cc44ac commit b172516
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/target/target_core_iblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ iblock_execute_write_same(struct se_cmd *cmd)

/* Always in 512 byte units for Linux/Block */
block_lba += sg->length >> IBLOCK_LBA_SHIFT;
sectors -= 1;
sectors -= sg->length >> IBLOCK_LBA_SHIFT;
}

iblock_submit_bios(&list, WRITE);
Expand Down

0 comments on commit b172516

Please sign in to comment.