Commit 81048fbc authored by Tony Battersby's avatar Tony Battersby Committed by Greg Kroah-Hartman

fix regression in SCSI_IOCTL_SEND_COMMAND

commit 2ba136da upstream.

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: f27b087b ("block: add blk_rq_set_block_pc()")
Signed-off-by: default avatarTony Battersby <tonyb@cybernetics.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8e9f1b75
......@@ -438,6 +438,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);
......@@ -491,7 +496,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);
......@@ -511,7 +515,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
error:
kfree(buffer);
blk_put_request(rq);
if (rq)
blk_put_request(rq);
return err;
}
EXPORT_SYMBOL_GPL(sg_scsi_ioctl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment