From: Roland Dreier Date: Tue, 14 Oct 2014 21:16:24 +0000 (-0700) Subject: target: Don't call TFO->write_pending if data_length == 0 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5a6ca32c3dc134f20a9c99fd0ad5848ed3c0d718;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git target: Don't call TFO->write_pending if data_length == 0 commit 885e7b0e181c14e4d0ddd26c688bad2b84c1ada9 upstream. If an initiator sends a zero-length command (e.g. TEST UNIT READY) but sets the transfer direction in the transport layer to indicate a data-out phase, we still shouldn't try to transfer data. At best it's a NOP, and depending on the transport, we might crash on an uninitialized sg list. Reported-by: Craig Watson Signed-off-by: Roland Dreier Signed-off-by: Nicholas Bellinger Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 12342695ed7..dcc5daa0ff1 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2128,7 +2128,7 @@ transport_generic_new_cmd(struct se_cmd *cmd) * and let it call back once the write buffers are ready. */ target_add_to_state_list(cmd); - if (cmd->data_direction != DMA_TO_DEVICE) { + if (cmd->data_direction != DMA_TO_DEVICE || cmd->data_length == 0) { target_execute_cmd(cmd); return 0; }