* [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call [not found] <20190808093702.29512-1-kraxel@redhat.com> @ 2019-08-08 9:36 ` Gerd Hoffmann 2019-08-08 9:36 ` Gerd Hoffmann 2019-08-08 10:23 ` Gerd Hoffmann 0 siblings, 2 replies; 4+ messages in thread From: Gerd Hoffmann @ 2019-08-08 9:36 UTC (permalink / raw) To: dri-devel Cc: tzimmermann, Christoph Hellwig, Martin K . Petersen, James E.J. Bottomley, open list:SCSI SUBSYSTEM, open list From: Christoph Hellwig <hch@lst.de> We should only call dma_max_mapping_size for devices that have a DMA mask set, otherwise we can run into a NULL pointer dereference that will crash the system. Also we need to do right shift to get the sectors from the size in bytes, not a left shift. Fixes: bdd17bdef7d8 ("scsi: core: take the DMA max mapping size into account") Reported-by: Bart Van Assche <bvanassche@acm.org> Reported-by: Ming Lei <tom.leiming@gmail.com> Tested-by: Guilherme G. Piccoli <gpiccoli@canonical.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> (cherry picked from commit 1b5d9a6e98350e0713b4faa1b04e8f239f63b581) --- drivers/scsi/scsi_lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 9381171c2fc0..11e64b50497f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1784,8 +1784,10 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); } - shost->max_sectors = min_t(unsigned int, shost->max_sectors, - dma_max_mapping_size(dev) << SECTOR_SHIFT); + if (dev->dma_mask) { + shost->max_sectors = min_t(unsigned int, shost->max_sectors, + dma_max_mapping_size(dev) >> SECTOR_SHIFT); + } blk_queue_max_hw_sectors(q, shost->max_sectors); if (shost->unchecked_isa_dma) blk_queue_bounce_limit(q, BLK_BOUNCE_ISA); -- 2.18.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call 2019-08-08 9:36 ` [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call Gerd Hoffmann @ 2019-08-08 9:36 ` Gerd Hoffmann 2019-08-08 10:23 ` Gerd Hoffmann 1 sibling, 0 replies; 4+ messages in thread From: Gerd Hoffmann @ 2019-08-08 9:36 UTC (permalink / raw) To: dri-devel Cc: tzimmermann, Christoph Hellwig, Martin K . Petersen, James E.J. Bottomley, open list:SCSI SUBSYSTEM, open list From: Christoph Hellwig <hch@lst.de> We should only call dma_max_mapping_size for devices that have a DMA mask set, otherwise we can run into a NULL pointer dereference that will crash the system. Also we need to do right shift to get the sectors from the size in bytes, not a left shift. Fixes: bdd17bdef7d8 ("scsi: core: take the DMA max mapping size into account") Reported-by: Bart Van Assche <bvanassche@acm.org> Reported-by: Ming Lei <tom.leiming@gmail.com> Tested-by: Guilherme G. Piccoli <gpiccoli@canonical.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> (cherry picked from commit 1b5d9a6e98350e0713b4faa1b04e8f239f63b581) --- drivers/scsi/scsi_lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 9381171c2fc0..11e64b50497f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1784,8 +1784,10 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); } - shost->max_sectors = min_t(unsigned int, shost->max_sectors, - dma_max_mapping_size(dev) << SECTOR_SHIFT); + if (dev->dma_mask) { + shost->max_sectors = min_t(unsigned int, shost->max_sectors, + dma_max_mapping_size(dev) >> SECTOR_SHIFT); + } blk_queue_max_hw_sectors(q, shost->max_sectors); if (shost->unchecked_isa_dma) blk_queue_bounce_limit(q, BLK_BOUNCE_ISA); -- 2.18.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call 2019-08-08 9:36 ` [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call Gerd Hoffmann 2019-08-08 9:36 ` Gerd Hoffmann @ 2019-08-08 10:23 ` Gerd Hoffmann 2019-08-08 10:23 ` Gerd Hoffmann 1 sibling, 1 reply; 4+ messages in thread From: Gerd Hoffmann @ 2019-08-08 10:23 UTC (permalink / raw) To: dri-devel Cc: Martin K . Petersen, open list:SCSI SUBSYSTEM, James E.J. Bottomley, open list, tzimmermann, Christoph Hellwig On Thu, Aug 08, 2019 at 11:36:55AM +0200, Gerd Hoffmann wrote: > From: Christoph Hellwig <hch@lst.de> > > We should only call dma_max_mapping_size for devices that have a DMA mask > set, otherwise we can run into a NULL pointer dereference that will crash > the system. > > Also we need to do right shift to get the sectors from the size in bytes, > not a left shift. Oops, that wasn't meant to be re-sent, sorry. drm-misc-next maintainers: any chance for a backmerge to pick up this fix, so I don't have to carry it in my branches? thanks, Gerd ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call 2019-08-08 10:23 ` Gerd Hoffmann @ 2019-08-08 10:23 ` Gerd Hoffmann 0 siblings, 0 replies; 4+ messages in thread From: Gerd Hoffmann @ 2019-08-08 10:23 UTC (permalink / raw) To: dri-devel Cc: Martin K . Petersen, open list:SCSI SUBSYSTEM, James E.J. Bottomley, open list, tzimmermann, Christoph Hellwig On Thu, Aug 08, 2019 at 11:36:55AM +0200, Gerd Hoffmann wrote: > From: Christoph Hellwig <hch@lst.de> > > We should only call dma_max_mapping_size for devices that have a DMA mask > set, otherwise we can run into a NULL pointer dereference that will crash > the system. > > Also we need to do right shift to get the sectors from the size in bytes, > not a left shift. Oops, that wasn't meant to be re-sent, sorry. drm-misc-next maintainers: any chance for a backmerge to pick up this fix, so I don't have to carry it in my branches? thanks, Gerd ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-08 10:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20190808093702.29512-1-kraxel@redhat.com>
2019-08-08 9:36 ` [PATCH v3 1/8] scsi: core: fix the dma_max_mapping_size call Gerd Hoffmann
2019-08-08 9:36 ` Gerd Hoffmann
2019-08-08 10:23 ` Gerd Hoffmann
2019-08-08 10:23 ` Gerd Hoffmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox