Skip to content

Commit

Permalink
target: Fix parameter list length checking in MODE SELECT
Browse files Browse the repository at this point in the history
An empty parameter list (length == 0) is not an error, so succeed MODE
SELECT in this case.  If the parameter list length is too small,
return the correct sense code of PARAMETER LIST LENGTH ERROR.

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Roland Dreier authored and Nicholas Bellinger committed Feb 13, 2013
1 parent bb992e7 commit 71f41fe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drivers/target/target_core_spc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,14 @@ static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd)
int ret = 0;
int i;

if (!cmd->data_length) {
target_complete_cmd(cmd, GOOD);
return 0;
}

if (cmd->data_length < off + 2)
return TCM_PARAMETER_LIST_LENGTH_ERROR;

buf = transport_kmap_data_sg(cmd);
if (!buf)
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
Expand All @@ -1024,6 +1032,11 @@ static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd)
goto out;

check_contents:
if (cmd->data_length < off + length) {
ret = TCM_PARAMETER_LIST_LENGTH_ERROR;
goto out;
}

if (memcmp(buf + off, tbuf, length))
ret = TCM_INVALID_PARAMETER_LIST;

Expand Down

0 comments on commit 71f41fe

Please sign in to comment.