Skip to content

Commit

Permalink
scst: Reject inconsistent COMPARE AND WRITE commands
Browse files Browse the repository at this point in the history
Reject COMPARE AND WRITE commands if the size of the data buffer does not
match the number of logical blocks specified in the CDB. This patch makes
two more libiscsi conformance tests pass.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8927 d57e44dd-8a1f-0410-8b47-8ef2f437770f
  • Loading branch information
bvanassche committed May 16, 2020
1 parent d5e13d6 commit 4525b04
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scst/src/scst_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -6870,6 +6870,19 @@ static void scst_cwr_read_cmd_finished(struct scst_cmd *cmd)
goto out;
}

/*
* The Data-Out Buffer contains two instances of logical block data:
* 1) the compare instance, in which:
* A) the user data is used for the compare operation; and
* B) the protection information, if any, is not used;
* and
* 2) the write instance, in which:
* A) the user data is used for the write operations; and
* B) the protection information, if any, is used for the write operations.
*
* Note: cmd->data_len is half of the DataOut buffer size while cmd->bufflen
* and cmd->expected_transfer_len refer to the entire DataOut buffer.
*/
enum scst_exec_res scst_cmp_wr_local(struct scst_cmd *cmd)
{
enum scst_exec_res res = SCST_EXEC_COMPLETED;
Expand Down Expand Up @@ -6913,6 +6926,14 @@ enum scst_exec_res scst_cmp_wr_local(struct scst_cmd *cmd)
cwrp->cwr_orig_cmd = cmd;
cwrp->cwr_finish_fn = scst_cwr_read_cmd_finished;

if (cmd->bufflen != scst_cmd_get_expected_transfer_len_data(cmd)) {
PRINT_ERROR("COMPARE AND WRITE: data buffer length mismatch (CDB %u <> ini %u)",
cmd->bufflen,
scst_cmd_get_expected_transfer_len_data(cmd));
scst_set_invalid_field_in_cdb(cmd, 13/*NLB*/, 0);
goto out_done;
}

/*
* As required by SBC, DIF PI, if any, is not checked for the read part
*/
Expand Down

0 comments on commit 4525b04

Please sign in to comment.