summaryrefslogtreecommitdiffstats
path: root/block/scsi_ioctl.c
diff options
context:
space:
mode:
authorTony Battersby <tonyb@cybernetics.com>2014-08-22 15:53:35 -0400
committerJens Axboe <axboe@fb.com>2014-08-22 15:04:33 -0500
commit2ba136daa3ae1e881c9f586f283fcaa164767dce (patch)
treee10d432b6e8fe38d768aa3f9ba3c136ff9756ad7 /block/scsi_ioctl.c
parent6f4a16266fb3e58cd3e200eab51d2220ef92d604 (diff)
downloadlinux-stable-2ba136daa3ae1e881c9f586f283fcaa164767dce.tar.gz
linux-stable-2ba136daa3ae1e881c9f586f283fcaa164767dce.tar.bz2
linux-stable-2ba136daa3ae1e881c9f586f283fcaa164767dce.zip
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.c9
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,
}
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);
@@ -509,7 +514,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
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);
@@ -529,7 +533,8 @@ out:
error:
kfree(buffer);
- blk_put_request(rq);
+ if (rq)
+ blk_put_request(rq);
return err;
}
EXPORT_SYMBOL_GPL(sg_scsi_ioctl);