bsg: Check queue type before attaching to a queue
authorBart Van Assche <bart.vanassche@sandisk.com>
Wed, 31 May 2017 21:43:47 +0000 (14:43 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 1 Jun 2017 19:10:41 +0000 (13:10 -0600)
Since BSG only supports request queues for which struct scsi_request
is the first member of their private request data, refuse to register
block layer queues for which struct scsi_request is not the first
member of their private data.

References: commit bd1599d931ca ("scsi_transport_sas: fix BSG ioctl memory corruption")
References: commit 82ed4db499b8 ("block: split scsi_request out of struct request")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/bsg.c

index 6fd08544d77eaaf94d6eeda990bd142936186e57..40db8ff4c618942396d808abc415512f9f372614 100644 (file)
@@ -750,6 +750,12 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
 #ifdef BSG_DEBUG
        unsigned char buf[32];
 #endif
+
+       if (!blk_queue_scsi_passthrough(rq)) {
+               WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
+               return ERR_PTR(-EINVAL);
+       }
+
        if (!blk_get_queue(rq))
                return ERR_PTR(-ENXIO);