Skip to contentSkip to conversation

fix regression in SCSI_IOCTL_SEND_COMMAND

PATCH In review Tony Battersby 3 participants 3 messages Aug 22, 2014 – Aug 23, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix regression in SCSI_IOCTL_SEND_COMMAND

blk_rq_set_block_pc() memsets rq->cmd to 0, so it should come immediately after blk_get_request() to avoid overwriting the user-supplied CDB. Also check for failure to allocate rq.

Fixes f27b087b81b7 ("block: add blk_rq_set_block_pc()")
Cc <[email protected]> # 3.16.x

---

For inclusion in 3.17 and 3.16.x.

Note: I don't have any programs that use this ioctl, so this patch is compile-tested only.

block/scsi_ioctl.c +7 -2
@@ -448,6 +448,11 @@ int sg_scsi_ioctl(struct request_queue *
 	}
 
 	rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
+	if (!rq) {
+		err = -ENOMEM;
+		goto error;
+	}
+	blk_rq_set_block_pc(rq);
 
 	cmdlen = COMMAND_SIZE(opcode);
 
@@ -501,7 +506,6 @@ int sg_scsi_ioctl(struct request_queue *
 	memset(sense, 0, sizeof(sense));
 	rq->sense = sense;
 	rq->sense_len = 0;
-	blk_rq_set_block_pc(rq);
 
 	blk_execute_rq(q, disk, rq, 0);
 
@@ -521,7 +525,8 @@ out:
 	
 error:
 	kfree(buffer);
-	blk_put_request(rq);
+	if (rq)
+		blk_put_request(rq);
 	return err;
 }
 EXPORT_SYMBOL_GPL(sg_scsi_ioctl);
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Tony Battersby

blk_rq_set_block_pc() memsets rq->cmd to 0, so it should come immediately after blk_get_request() to avoid overwriting the user-supplied CDB. Also check for failure to allocate rq.

Fixes f27b087b81b7 ("block: add blk_rq_set_block_pc()")
Cc <[email protected]> # 3.16.x
Quoted 4 lines

For inclusion in 3.17 and 3.16.x.

Note: I don't have any programs that use this ioctl, so this patch is compile-tested only.

To test this ioctl one option is to get the sg3_utils package and build scsi_ioctl.c in the examples directory with 'make scsi_ioctl'.

In lk 3.17-rc1, scsi_ioctl indicates that SCSI_IOCTL_SEND_COMMAND is not working. In my test applying this patch fixes the regression.

Quoted 34 lines
block/scsi_ioctl.c +7 -3
@@ -448,6 +448,11 @@ int sg_scsi_ioctl(struct request_queue *
  	}
 
  	rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
+	if (!rq) {
+		err = -ENOMEM;
+		goto error;
+	}
+	blk_rq_set_block_pc(rq);
 
  	cmdlen = COMMAND_SIZE(opcode);
 
@@ -501,7 +506,6 @@ int sg_scsi_ioctl(struct request_queue *
  	memset(sense, 0, sizeof(sense));
  	rq->sense = sense;
  	rq->sense_len = 0;
-	blk_rq_set_block_pc(rq);
 
  	blk_execute_rq(q, disk, rq, 0);
 
@@ -521,7 +525,8 @@ out:
 
  error:
  	kfree(buffer);
-	blk_put_request(rq);
+	if (rq)
+		blk_put_request(rq);
  	return err;
  }
  EXPORT_SYMBOL_GPL(sg_scsi_ioctl);
 
--
#2 lore raw
Quoted 7 lines · Douglas Gilbert

To test this ioctl one option is to get the sg3_utils package and build scsi_ioctl.c in the examples directory with 'make scsi_ioctl'.

In lk 3.17-rc1, scsi_ioctl indicates that SCSI_IOCTL_SEND_COMMAND is not working. In my test applying this patch fixes the regression.

Is there any amount of chocolate or beer that could trick you into adding an automated regression test suite to sg3_utils that could be used to automatically check for regressions like this?