From f27af1b46e73839dff4eccbed62698c606c9d0da Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Wed, 2 Oct 2013 05:10:56 +0000 Subject: [PATCH] Fix incorrect NUMBER OF LOGICAL BLOCKS handling in WRITE SAME command git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5015 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 6 ++++++ scst/src/scst_lib.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index dfc41304b..66ceb4359 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -2245,6 +2245,11 @@ static enum compl_status_e vdisk_exec_write_same(struct vdisk_cmd_params *p) goto out; } + if (unlikely(cmd->data_len <= 0)) { + scst_set_invalid_field_in_cdb(cmd, cmd->len_off, 0); + goto out; + } + if (cmd->cdb[1] & 0x8) { vdisk_exec_write_same_unmap(p); goto out; @@ -2507,6 +2512,7 @@ static enum compl_status_e vdisk_exec_inquiry(struct vdisk_cmd_params *p) int max_transfer; buf[1] = 0xB0; buf[3] = 0x3C; + buf[4] = 1; /* WSNZ set */ /* Optimal transfer granuality is PAGE_SIZE */ put_unaligned_be16(max_t(int, PAGE_SIZE/dev->block_size, 1), &buf[6]); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 459ff99b7..ffb59c35b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4859,6 +4859,11 @@ void scst_write_same(struct scst_cmd *cmd) TRACE_ENTRY(); + if (unlikely(cmd->data_len <= 0)) { + scst_set_invalid_field_in_cdb(cmd, cmd->len_off, 0); + goto out_done; + } + if (cmd->sg_cnt != 1) { PRINT_ERROR("WRITE SAME must contain only single block of data " "in a single SG (cmd %p)", cmd);