[PATCH 1/2] Validate the DataOut length in WRITE_SAME_1*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



WRITE_SAME_1* takes either no data at all or exactly one block of data
as DataOut. Check for this and fail the cdb if the DataOut size differs.

(Some initiators use DataOut size == 0 (primarily together with unmap)
to mean "use a block all filled with 0" so that is why I think we
should be liberal and allow size==0 too here.)

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 usr/sbc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/usr/sbc.c b/usr/sbc.c
index 8dbcd78..e58a233 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -245,6 +245,7 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 	int ret;
 	uint64_t lba;
 	uint32_t tl;
+	size_t blocksize = 1 << cmd->dev->blk_shift;
 	unsigned char key = ILLEGAL_REQUEST;
 	uint16_t asc = ASC_LUN_NOT_SUPPORTED;
 	struct scsi_lu *lu = cmd->dev;
@@ -306,6 +307,13 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 			asc = ASC_INVALID_FIELD_IN_CDB;
 			goto sense;
 		}
+		/* Fail of DataOut is neither ==0 or ==blocksize */
+		if (scsi_get_out_length(cmd) &&
+		    blocksize != scsi_get_out_length(cmd)) {
+			key = ILLEGAL_REQUEST;
+			asc = ASC_PARAMETER_LIST_LENGTH_ERR;
+			goto sense;
+		}
 		break;
 	}
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux