scsi: target/iblock: Fix overrun in WRITE SAME emulation
authorRoman Bolshakov <r.bolshakov@yadro.com>
Tue, 2 Jul 2019 19:16:38 +0000 (22:16 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Sep 2019 06:22:17 +0000 (08:22 +0200)
commit60b856dc174431561372d664c2c317dc4aa73fc8
treef465bccf8cd67da575cfc8a163018c091966ac36
parentba52842de1adfc46ee78d6e2fc6440b97508abc5
scsi: target/iblock: Fix overrun in WRITE SAME emulation

[ Upstream commit 5676234f20fef02f6ca9bd66c63a8860fce62645 ]

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: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Cc: <stable@vger.kernel.org>
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/target/target_core_iblock.c