Skip to content

Commit cc29a1b

Browse files
lsgunthmartinkpetersen
authored andcommitted
scsi: isci: initialize shost fully before calling scsi_add_host()
scsi_mq_setup_tags(), which is called by scsi_add_host(), calculates the command size to allocate based on the prot_capabilities. In the isci driver, scsi_host_set_prot() is called after scsi_add_host() so the command size gets calculated to be smaller than it needs to be. Eventually, scsi_mq_init_request() locates the 'prot_sdb' after the command assuming it was sized correctly and a buffer overrun may occur. However, seeing blk_mq_alloc_rqs() rounds up to the nearest cache line size, the mistake can go unnoticed. The bug was noticed after the struct request size was reduced by commit 9d037ad ("block: remove req->timeout_list") Which likely reduced the allocated space for the request by an entire cache line, enough that the overflow could be hit and it caused a panic, on boot, at: RIP: 0010:t10_pi_complete+0x77/0x1c0 Call Trace: <IRQ> sd_done+0xf5/0x340 scsi_finish_command+0xc3/0x120 blk_done_softirq+0x83/0xb0 __do_softirq+0xa1/0x2e6 irq_exit+0xbc/0xd0 call_function_single_interrupt+0xf/0x20 </IRQ> sd_done() would call scsi_prot_sg_count() which reads the number of entities in 'prot_sdb', but seeing 'prot_sdb' is located after the end of the allocated space it reads a garbage number and erroneously calls t10_pi_complete(). To prevent this, the calls to scsi_host_set_prot() are moved into isci_host_alloc() before the call to scsi_add_host(). Out of caution, also move the similar call to scsi_host_set_guard(). Fixes: 3d2d752 ("[SCSI] isci: T10 DIF support") Link: http://lkml.kernel.org/r/da851333-eadd-163a-8c78-e1f4ec5ec857@deltatee.com Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Cc: Intel SCU Linux support <intel-linux-scu@intel.com> Cc: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com> Cc: "Martin K. Petersen" <martin.petersen@oracle.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Jens Axboe <axboe@kernel.dk> Cc: Jeff Moyer <jmoyer@redhat.com> Reviewed-by: Jeff Moyer <jmoyer@redhat.com> Reviewed-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5bd5f66 commit cc29a1b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/scsi/isci/init.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,13 @@ static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
576576
shost->max_lun = ~0;
577577
shost->max_cmd_len = MAX_COMMAND_SIZE;
578578

579+
/* turn on DIF support */
580+
scsi_host_set_prot(shost,
581+
SHOST_DIF_TYPE1_PROTECTION |
582+
SHOST_DIF_TYPE2_PROTECTION |
583+
SHOST_DIF_TYPE3_PROTECTION);
584+
scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
585+
579586
err = scsi_add_host(shost, &pdev->dev);
580587
if (err)
581588
goto err_shost;
@@ -663,13 +670,6 @@ static int isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
663670
goto err_host_alloc;
664671
}
665672
pci_info->hosts[i] = h;
666-
667-
/* turn on DIF support */
668-
scsi_host_set_prot(to_shost(h),
669-
SHOST_DIF_TYPE1_PROTECTION |
670-
SHOST_DIF_TYPE2_PROTECTION |
671-
SHOST_DIF_TYPE3_PROTECTION);
672-
scsi_host_set_guard(to_shost(h), SHOST_DIX_GUARD_CRC);
673673
}
674674

675675
err = isci_setup_interrupts(pdev);

0 commit comments

Comments
 (0)