scsi: target: core: Add cmd length set before cmd complete
authorAleksandr Miloserdov <a.miloserdov@yadro.com>
Tue, 9 Feb 2021 07:22:01 +0000 (10:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Mar 2021 16:06:25 +0000 (17:06 +0100)
commit17c2c52051c4e0c42c8e54ee087f89fb6c78b86b
treee002875e9464463351d6324d69e6939a1f0b2043
parent79b4fdd8b4cfd88e0314b368bd911a732161c944
scsi: target: core: Add cmd length set before cmd complete

[ Upstream commit 1c73e0c5e54d5f7d77f422a10b03ebe61eaed5ad ]

TCM doesn't properly handle underflow case for service actions. One way to
prevent it is to always complete command with
target_complete_cmd_with_length(), however it requires access to data_sg,
which is not always available.

This change introduces target_set_cmd_data_length() function which allows
to set command data length before completing it.

Link: https://lore.kernel.org/r/20210209072202.41154-2-a.miloserdov@yadro.com
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>
Signed-off-by: Aleksandr Miloserdov <a.miloserdov@yadro.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/target/target_core_transport.c
include/target/target_core_backend.h