Skip to contentSkip to conversation

pvSCSI : Add white list to SCSI command emulation

PATCH In review Jun Kamada 2 participants 4 messages Jul 3, 2008 – Jul 7, 2008 Xen hypervisor interface

lore
Share & tools
lore

Jun Kamada

author
#0 lore raw

PATCH 1/4 pvSCSI : Add white list to SCSI command emulation

Add "white list" control to SCSI command emulation. Current setting allows following mandatory and safe commands.

TEST UNIT READY
REZERO UNIT
REQUEST SENSE
FORMAT UNIT
READ BLOCK LIMITS
READ(06)
WRITE(06)
WRITE FILEMARKS
SPACE
INQUIRY
ERASE
MODE SENSE(06)
SEND DIAGNOSTIC
READ CAPACITY
READ(10)
WRITE(10)
REPORT LUN

-----
Jun Kamada

# HG changeset patch
# User [email protected]
# Date 1215043545 -32400
# Node ID 3132ef07eecf3f7d57bd6659d8f9ecf6f13421f5 # Parent b5ca56b48581e3e8ffc659d78f4aa725082c974c
pvscsi: Fix whitelist emulation.

drivers/xen/scsiback/emulate.c +76 -7
diff -r b5ca56b48581 -r 3132ef07eecf drivers/xen/scsiback/emulate.c
@@ -93,7 +93,7 @@ static void scsiback_mk_sense_buffer(uin
 	data[13] = asq;
 }
 
-static void resp_not_supported_cmd(pending_req_t *pending_req)
+static void resp_not_supported_cmd(pending_req_t *pending_req, void *data)
 {
 	scsiback_mk_sense_buffer(pending_req->sense_buffer, ILLEGAL_REQUEST,
 		INVALID_OPCODE, 0);
@@ -270,7 +270,7 @@ int __pre_do_emulation(pending_req_t *pe
 	    1: non emulation or should call native driver 
 	       after modifing the request buffer.
 	*/
-	return (bitmap[op_code] & VSCSIIF_NEED_CMD_EXEC);
+	return !!(bitmap[op_code] & VSCSIIF_NEED_CMD_EXEC);
 }
 
 void scsiback_rsp_emulation(pending_req_t *pending_req)
@@ -308,16 +308,14 @@ void scsiback_emulation_init(void)
 
 	/* Initialize to default state */
 	for (i = 0; i < VSCSI_MAX_SCSI_OP_CODE; i++) {
-		bitmap[i]        = VSCSIIF_NEED_CMD_EXEC;
-		pre_function[i]  = NULL;
+		bitmap[i]        = (VSCSIIF_NEED_EMULATE_REQBUF | 
+					VSCSIIF_NEED_EMULATE_RSPBUF);
+		pre_function[i]  = resp_not_supported_cmd;
 		post_function[i] = NULL;
 		/* means,
 		   - no need for pre-emulation
 		   - no need for post-emulation
 		   - call native driver
-
-		   (Current setting is black-list bases, white-list
-		   bases may be appropriate for security.)
 		*/
 	}
 
@@ -325,6 +323,77 @@ void scsiback_emulation_init(void)
 	  Register appropriate functions below as you need.
 	  (See scsi/scsi.h for definition of SCSI op_code.)
 	*/
+
+	/*
+	  This command is Non emulation.
+	*/
+	bitmap[TEST_UNIT_READY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[TEST_UNIT_READY] = NULL;
+	post_function[TEST_UNIT_READY] = NULL;
+
+	bitmap[REZERO_UNIT] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[REZERO_UNIT] = NULL;
+	post_function[REZERO_UNIT] = NULL;
+
+	bitmap[REQUEST_SENSE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[REQUEST_SENSE] = NULL;
+	post_function[REQUEST_SENSE] = NULL;
+
+	bitmap[FORMAT_UNIT] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[FORMAT_UNIT] = NULL;
+	post_function[FORMAT_UNIT] = NULL;
+
+	bitmap[READ_BLOCK_LIMITS] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_BLOCK_LIMITS] = NULL;
+	post_function[READ_BLOCK_LIMITS] = NULL;
+
+	bitmap[READ_6] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_6] = NULL;
+	post_function[READ_6] = NULL;
+
+	bitmap[WRITE_6] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_6] = NULL;
+	post_function[WRITE_6] = NULL;
+
+	bitmap[WRITE_FILEMARKS] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_FILEMARKS] = NULL;
+	post_function[WRITE_FILEMARKS] = NULL;
+
+	bitmap[SPACE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[SPACE] = NULL;
+	post_function[SPACE] = NULL;
+
+	bitmap[INQUIRY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[INQUIRY] = NULL;
+	post_function[INQUIRY] = NULL;
+
+	bitmap[ERASE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[ERASE] = NULL;
+	post_function[ERASE] = NULL;
+
+	bitmap[MODE_SENSE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[MODE_SENSE] = NULL;
+	post_function[MODE_SENSE] = NULL;
+
+	bitmap[SEND_DIAGNOSTIC] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[SEND_DIAGNOSTIC] = NULL;
+	post_function[SEND_DIAGNOSTIC] = NULL;
+
+	bitmap[READ_CAPACITY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_CAPACITY] = NULL;
+	post_function[READ_CAPACITY] = NULL;
+
+	bitmap[READ_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_10] = NULL;
+	post_function[READ_10] = NULL;
+
+	bitmap[WRITE_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_10] = NULL;
+	post_function[WRITE_10] = NULL;
+
+	/*
+	  This command is Full emulation.
+	*/
 	pre_function[REPORT_LUNS] = __report_luns;
 	bitmap[REPORT_LUNS] = (VSCSIIF_NEED_EMULATE_REQBUF | 
 					VSCSIIF_NEED_EMULATE_RSPBUF);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

drivers/xen/scsiback/emulate.c void scsiback_emulation_init(void) · line 380

Quoted 11 lines
drivers/xen/scsiback/emulate.c +11 -0
+	bitmap[ERASE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[ERASE] = NULL;
+	post_function[ERASE] = NULL;
+
+	bitmap[MODE_SENSE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[MODE_SENSE] = NULL;
+	post_function[MODE_SENSE] = NULL;
+
+	bitmap[SEND_DIAGNOSTIC] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[SEND_DIAGNOSTIC] = NULL;
+	post_function[SEND_DIAGNOSTIC] = NULL;

Hmm, careful here. If the DevOffL bit is set on a SEND DIAGNOSTIC command then it can cause interference in other LUNs on the target, which would be unfortunate if they're exposed to different VMs.

drivers/xen/scsiback/emulate.c void scsiback_emulation_init(void) · line 392

Quoted 12 lines
drivers/xen/scsiback/emulate.c +12 -0
+
+	bitmap[READ_CAPACITY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_CAPACITY] = NULL;
+	post_function[READ_CAPACITY] = NULL;
+
+	bitmap[READ_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_10] = NULL;
+	post_function[READ_10] = NULL;
+
+	bitmap[WRITE_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_10] = NULL;
+	post_function[WRITE_10] = NULL;

Do you know what happens if the SCSI CDB is inconsistent with the scatter list? For instance, if the CDB says to read 16 sectors but the frontend-supplied buffer is only big enough for 8, are we going to end up DMAing over random memory?

Steven.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw

Steven-san,

Quoted 15 lines · On Fri, 4 Jul 2008 17:21:54 +0100 Steven Smith <[email protected]> wrote:

drivers/xen/scsiback/emulate.c void scsiback_emulation_init(void) · line 380

Quoted 11 lines
drivers/xen/scsiback/emulate.c +11 -0
+	bitmap[ERASE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[ERASE] = NULL;
+	post_function[ERASE] = NULL;
+
+	bitmap[MODE_SENSE] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[MODE_SENSE] = NULL;
+	post_function[MODE_SENSE] = NULL;
+
+	bitmap[SEND_DIAGNOSTIC] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[SEND_DIAGNOSTIC] = NULL;
+	post_function[SEND_DIAGNOSTIC] = NULL;

Hmm, careful here. If the DevOffL bit is set on a SEND DIAGNOSTIC command then it can cause interference in other LUNs on the target, which would be unfortunate if they're exposed to different VMs.

Quoted 16 lines

drivers/xen/scsiback/emulate.c void scsiback_emulation_init(void) · line 392

Quoted 12 lines
drivers/xen/scsiback/emulate.c +12 -0
+
+	bitmap[READ_CAPACITY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_CAPACITY] = NULL;
+	post_function[READ_CAPACITY] = NULL;
+
+	bitmap[READ_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_10] = NULL;
+	post_function[READ_10] = NULL;
+
+	bitmap[WRITE_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_10] = NULL;
+	post_function[WRITE_10] = NULL;

Do you know what happens if the SCSI CDB is inconsistent with the scatter list? For instance, if the CDB says to read 16 sectors but the frontend-supplied buffer is only big enough for 8, are we going to end up DMAing over random memory?

I consider that native SCSI driver, which generates DMA request, will reject such the inconsistent request. The native driver generates multiple CDB requests according to the number of scatter/gather segments. At the same time, doesn't the native driver check such the inconsistency?
So, if there are any inconsistency, pvSCSI backend driver will just get an error from native driver.

Perhaps, do you warry about inconsitency between size of some segment frontend driver says, and size of the segment the frontend driver actually allocated?

# Sorry, if I misundastood your question.

Best regards,

-----
Jun Kamada

#3 lore raw
Quoted 23 lines
Quoted 7 lines
Quoted 7 lines
drivers/xen/scsiback/emulate.c +7 -0
+	bitmap[READ_CAPACITY] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_CAPACITY] = NULL;
+	post_function[READ_CAPACITY] = NULL;
+
+	bitmap[READ_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[READ_10] = NULL;
+	post_function[READ_10] = NULL;
Quoted 8 lines

drivers/xen/scsiback/emulate.c void scsiback_emulation_init(void) · line 392

Quoted 4 lines
drivers/xen/scsiback/emulate.c +4 -0
+
+	bitmap[WRITE_10] = VSCSIIF_NEED_CMD_EXEC;
+	pre_function[WRITE_10] = NULL;
+	post_function[WRITE_10] = NULL;

Do you know what happens if the SCSI CDB is inconsistent with the scatter list? For instance, if the CDB says to read 16 sectors but the frontend-supplied buffer is only big enough for 8, are we going to end up DMAing over random memory?

I consider that native SCSI driver, which generates DMA request, will reject such the inconsistent request. The native driver generates multiple CDB requests according to the number of scatter/gather segments. At the same time, doesn't the native driver check such the inconsistency?
So, if there are any inconsistency, pvSCSI backend driver will just get an error from native driver.

Quoted 3 lines

Perhaps, do you warry about inconsitency between size of some segment frontend driver says, and size of the segment the frontend driver actually allocated?

Suppose the frontend generates a READ command with the CDB TransferLength field set to 128 sectors, but the nr_segments field of the vscsiif_request_t set to 1. scsiback will then a scsi_cmnd whose CDB says to read 128 sectors, but whose associated scatter-gather list only has room for 8, and pass that off to blk_execute_rq_nowait(). What happens to the other 120 sectors? Hopefully, something will detect the inconsistency and make the request fail, but I can't really see what. It would be very bad if the request made it down to the physical card, which tried to satisfy it by DMAing the 120 sectors into some random bit of memory. I've had a quick look around drivers/scsi and I can't immediately see anything which tries to do the required kind of consistency checking. On the other hand, I'd have expected sg.c to need something, at least, and it doesn't, so perhaps it's safe to rely on the hardware to do the checks.

Actually doing the checking could prove tricky, as well, because of commands like READ6 where you need to know the type of device which is being addressed. For block devices, the command has the logical block address in bytes 2 and 3, with the transfer length in byte 4, but streaming devices use all three bytes to encode the length (because block address is meaningless on stream devices). That's going to make it tricky to design a generic validation routine. Hmm.

Steven.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel