diff options
author | Tony Battersby <tonyb@cybernetics.com> | 2014-08-22 15:53:35 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-08-22 16:04:33 -0400 |
commit | 2ba136daa3ae1e881c9f586f283fcaa164767dce (patch) | |
tree | e10d432b6e8fe38d768aa3f9ba3c136ff9756ad7 /block/scsi_ioctl.c | |
parent | 6f4a16266fb3e58cd3e200eab51d2220ef92d604 (diff) |
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: <stable@vger.kernel.org> # 3.16.x
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/scsi_ioctl.c')
-rw-r--r-- | block/scsi_ioctl.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 1d78e6cf9d61..5dd477bfb4bc 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c | |||
@@ -456,6 +456,11 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, | |||
456 | } | 456 | } |
457 | 457 | ||
458 | rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); | 458 | rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); |
459 | if (!rq) { | ||
460 | err = -ENOMEM; | ||
461 | goto error; | ||
462 | } | ||
463 | blk_rq_set_block_pc(rq); | ||
459 | 464 | ||
460 | cmdlen = COMMAND_SIZE(opcode); | 465 | cmdlen = COMMAND_SIZE(opcode); |
461 | 466 | ||
@@ -509,7 +514,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, | |||
509 | memset(sense, 0, sizeof(sense)); | 514 | memset(sense, 0, sizeof(sense)); |
510 | rq->sense = sense; | 515 | rq->sense = sense; |
511 | rq->sense_len = 0; | 516 | rq->sense_len = 0; |
512 | blk_rq_set_block_pc(rq); | ||
513 | 517 | ||
514 | blk_execute_rq(q, disk, rq, 0); | 518 | blk_execute_rq(q, disk, rq, 0); |
515 | 519 | ||
@@ -529,7 +533,8 @@ out: | |||
529 | 533 | ||
530 | error: | 534 | error: |
531 | kfree(buffer); | 535 | kfree(buffer); |
532 | blk_put_request(rq); | 536 | if (rq) |
537 | blk_put_request(rq); | ||
533 | return err; | 538 | return err; |
534 | } | 539 | } |
535 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); | 540 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); |