diff mbox

[05/19] cdrom: Check private request size before attaching to a queue

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

Commit Message

Bart Van Assche May 25, 2017, 6:43 p.m. UTC
Since the cdrom driver 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 this is
not the case.

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>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Omar Sandoval <osandov@fb.com>
Cc: linux-block@vger.kernel.org
---
 drivers/cdrom/cdrom.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Christoph Hellwig May 26, 2017, 6:08 a.m. UTC | #1
On Thu, May 25, 2017 at 11:43:13AM -0700, Bart Van Assche wrote:
> Since the cdrom driver 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 this is
> not the case.

Hmm.  I think we have a deeper issue there.  The cdrom layer usually
sends packets commands through the cdrom ops ->generic_packet
method, but one function (cdrom_read_cdda_bpc) seems to directly
send a scsi passthrough request.  It is only used if the cdda_method
is not CDDA_OLD, which is set if the cdrom_device_info structure
does not have a gendisk pointer hanging off it.  It seems like
the legacy cdrom drivers fall into that category and would be
broken by this change.
Bart Van Assche May 26, 2017, 3:50 p.m. UTC | #2
On Fri, 2017-05-26 at 08:08 +0200, Christoph Hellwig wrote:
> On Thu, May 25, 2017 at 11:43:13AM -0700, Bart Van Assche wrote:
> > Since the cdrom driver 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 this is
> > not the case.
> 
> Hmm.  I think we have a deeper issue there.  The cdrom layer usually
> sends packets commands through the cdrom ops ->generic_packet
> method, but one function (cdrom_read_cdda_bpc) seems to directly
> send a scsi passthrough request.  It is only used if the cdda_method
> is not CDDA_OLD, which is set if the cdrom_device_info structure
> does not have a gendisk pointer hanging off it.  It seems like
> the legacy cdrom drivers fall into that category and would be
> broken by this change.

Hello Christoph,

How about moving the check into cdrom_read_cdda_bpc()? As far as I can see
that function is only called if a CDROMREADAUDIO ioctl is submitted. Although
Documentation/cdrom/cdrom-standard.tex mentions that that ioctl is unsupported
applications like cdparanoia use it.

Bart.
Christoph Hellwig May 28, 2017, 8:32 a.m. UTC | #3
On Fri, May 26, 2017 at 03:50:42PM +0000, Bart Van Assche wrote:
> On Fri, 2017-05-26 at 08:08 +0200, Christoph Hellwig wrote:
> > On Thu, May 25, 2017 at 11:43:13AM -0700, Bart Van Assche wrote:
> > > Since the cdrom driver 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 this is
> > > not the case.
> > 
> > Hmm.  I think we have a deeper issue there.  The cdrom layer usually
> > sends packets commands through the cdrom ops ->generic_packet
> > method, but one function (cdrom_read_cdda_bpc) seems to directly
> > send a scsi passthrough request.  It is only used if the cdda_method
> > is not CDDA_OLD, which is set if the cdrom_device_info structure
> > does not have a gendisk pointer hanging off it.  It seems like
> > the legacy cdrom drivers fall into that category and would be
> > broken by this change.
> 
> Hello Christoph,
> 
> How about moving the check into cdrom_read_cdda_bpc()? As far as I can see
> that function is only called if a CDROMREADAUDIO ioctl is submitted. Although
> Documentation/cdrom/cdrom-standard.tex mentions that that ioctl is unsupported
> applications like cdparanoia use it.

I guess that's fine for now.  In the long run we can probably replace
the current users of generic_packet method with direct scsi passthrough
requests, but that can be left for later.
diff mbox

Patch

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 76c952fd9ab9..5c1fec31b7ef 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -594,6 +594,10 @@  int register_cdrom(struct cdrom_device_info *cdi)
 
 	if (cdo->open == NULL || cdo->release == NULL)
 		return -EINVAL;
+	if (!blk_queue_scsi_pdu(cdi->disk->queue)) {
+		WARN_ONCE(true, "Attempt to register a non-SCSI queue\n");
+		return -EINVAL;
+	}
 	if (!banner_printed) {
 		pr_info("Uniform CD-ROM driver " REVISION "\n");
 		banner_printed = 1;