Ver Fonte

snic: Fix use-after-free in case of a dma mapping error

If there is a dma mapping error snic kfree()s buf right before printing
it.  Change the order to not accidently trip on memory that's not owned
by us anymore.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Acked-by: Narsimhulu Musini <nmusini@cisco.com>
Reviewed-by: Laurence Oberman <loberman@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Johannes Thumshirn há 9 anos atrás
pai
commit
2a6a20ea7d
1 ficheiros alterados com 2 adições e 2 exclusões
  1. 2 2
      drivers/scsi/snic/snic_disc.c

+ 2 - 2
drivers/scsi/snic/snic_disc.c

@@ -113,11 +113,11 @@ snic_queue_report_tgt_req(struct snic *snic)
 
 
 	pa = pci_map_single(snic->pdev, buf, buf_len, PCI_DMA_FROMDEVICE);
 	pa = pci_map_single(snic->pdev, buf, buf_len, PCI_DMA_FROMDEVICE);
 	if (pci_dma_mapping_error(snic->pdev, pa)) {
 	if (pci_dma_mapping_error(snic->pdev, pa)) {
-		kfree(buf);
-		snic_req_free(snic, rqi);
 		SNIC_HOST_ERR(snic->shost,
 		SNIC_HOST_ERR(snic->shost,
 			      "Rpt-tgt rspbuf %p: PCI DMA Mapping Failed\n",
 			      "Rpt-tgt rspbuf %p: PCI DMA Mapping Failed\n",
 			      buf);
 			      buf);
+		kfree(buf);
+		snic_req_free(snic, rqi);
 		ret = -EINVAL;
 		ret = -EINVAL;
 
 
 		goto error;
 		goto error;