diff mbox

[12/31] bsg: Check queue type before attaching to a queue

Message ID 20170524003420.5381-13-bart.vanassche@sandisk.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bart Van Assche May 24, 2017, 12:34 a.m. UTC
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>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: linux-block@vger.kernel.org
---
 block/bsg.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Hannes Reinecke May 24, 2017, 6:01 a.m. UTC | #1
On 05/24/2017 02:34 AM, Bart Van Assche wrote:
> 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>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Omar Sandoval <osandov@fb.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: linux-block@vger.kernel.org
> ---
>  block/bsg.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/block/bsg.c b/block/bsg.c
> index 6fd08544d77e..f7695bb141d9 100644
> --- a/block/bsg.c
> +++ b/block/bsg.c
> @@ -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_sup(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);
>  
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
Martin K. Petersen May 25, 2017, 2:01 a.m. UTC | #2
Bart,

> 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.

> +
> +	if (!blk_queue_scsi_sup(rq)) {

If you are renaming the flag, how about blk_queue_scsi_pdu()?

> +		WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>  	if (!blk_get_queue(rq))
>  		return ERR_PTR(-ENXIO);
diff mbox

Patch

diff --git a/block/bsg.c b/block/bsg.c
index 6fd08544d77e..f7695bb141d9 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -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_sup(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);