1. 05 Oct, 2021 35 commits
  2. 29 Sep, 2021 5 commits
    • Damien Le Moal's avatar
      scsi: sd: Fix sd_do_mode_sense() buffer length handling · c749301e
      Damien Le Moal authored
      For devices that explicitly asked for MODE SENSE(10) use, make sure that
      scsi_mode_sense() is called with a buffer of at least 8 bytes so that the
      sense header fits.
      
      Link: https://lore.kernel.org/r/20210820070255.682775-4-damien.lemoal@wdc.comSigned-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      c749301e
    • Damien Le Moal's avatar
      scsi: core: Fix scsi_mode_select() buffer length handling · a7d6840b
      Damien Le Moal authored
      The MODE SELECT(6) command allows handling mode page buffers that are up to
      255 bytes, including the 4 byte header needed in front of the page
      buffer. For requests larger than this limit, automatically use the MODE
      SELECT(10) command.
      
      In both cases, since scsi_mode_select() adds the mode select page header,
      checks on the buffer length value must include this header size to avoid
      overflows of the command CDB allocation length field.
      
      While at it, use put_unaligned_be16() for setting the header block
      descriptor length and CDB allocation length when using MODE SELECT(10).
      
      [mkp: fix MODE SENSE vs. MODE SELECT confusion]
      
      Link: https://lore.kernel.org/r/20210820070255.682775-3-damien.lemoal@wdc.comSigned-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      a7d6840b
    • Damien Le Moal's avatar
      scsi: core: Fix scsi_mode_sense() buffer length handling · 17b49bcb
      Damien Le Moal authored
      Several problems exist with scsi_mode_sense() buffer length handling:
      
       1) The allocation length field of the MODE SENSE(10) command is 16-bits,
          occupying bytes 7 and 8 of the CDB. With this command, access to mode
          pages larger than 255 bytes is thus possible. However, the CDB
          allocation length field is set by assigning len to byte 8 only, thus
          truncating buffer length larger than 255.
      
       2) If scsi_mode_sense() is called with len smaller than 8 with
          sdev->use_10_for_ms set, or smaller than 4 otherwise, the buffer length
          is increased to 8 and 4 respectively, and the buffer is zero filled
          with these increased values, thus corrupting the memory following the
          buffer.
      
      Fix these 2 problems by using put_unaligned_be16() to set the allocation
      length field of MODE SENSE(10) CDB and by returning an error when len is
      too small.
      
      Furthermore, if len is larger than 255B, always try MODE SENSE(10) first,
      even if the device driver did not set sdev->use_10_for_ms. In case of
      invalid opcode error for MODE SENSE(10), access to mode pages larger than
      255 bytes are not retried using MODE SENSE(6). To avoid buffer length
      overflows for the MODE_SENSE(10) case, check that len is smaller than 65535
      bytes.
      
      While at it, also fix the folowing:
      
       * Use get_unaligned_be16() to retrieve the mode data length and block
         descriptor length fields of the mode sense reply header instead of using
         an open coded calculation.
      
       * Fix the kdoc dbd argument explanation: the DBD bit stands for Disable
         Block Descriptor, which is the opposite of what the dbd argument
         description was.
      
      Link: https://lore.kernel.org/r/20210820070255.682775-2-damien.lemoal@wdc.comSigned-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      17b49bcb
    • John Garry's avatar
      scsi: core: Delete scsi_{get,free}_host_dev() · 6bd49b1a
      John Garry authored
      Since commit 0653c358 ("scsi: Drop gdth driver"), functions
      scsi_{get,free}_host_dev() no longer have any in-tree users, so delete
      them.
      
      Link: https://lore.kernel.org/r/1631528047-30150-1-git-send-email-john.garry@huawei.comReviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Nacked-by: default avatarHannes Reinecke <hare@suse.de>
      6bd49b1a
    • Christophe JAILLET's avatar
      scsi: elx: efct: Switch from 'pci_' to 'dma_' API · ca4ff9e7
      Christophe JAILLET authored
      The wrappers in include/linux/pci-dma-compat.h should go away.
      
      The patch has been generated with the coccinelle script below.
      
      It has been hand modified to use 'dma_set_mask_and_coherent()' instead of
      'pci_set_dma_mask()/pci_set_consistent_dma_mask()' when applicable.
      This is less verbose.
      
      It has been compile tested.
      
      @@
      @@
      -    PCI_DMA_BIDIRECTIONAL
      +    DMA_BIDIRECTIONAL
      
      @@
      @@
      -    PCI_DMA_TODEVICE
      +    DMA_TO_DEVICE
      
      @@
      @@
      -    PCI_DMA_FROMDEVICE
      +    DMA_FROM_DEVICE
      
      @@
      @@
      -    PCI_DMA_NONE
      +    DMA_NONE
      
      @@
      expression e1, e2, e3;
      @@
      -    pci_alloc_consistent(e1, e2, e3)
      +    dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
      
      @@
      expression e1, e2, e3;
      @@
      -    pci_zalloc_consistent(e1, e2, e3)
      +    dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_free_consistent(e1, e2, e3, e4)
      +    dma_free_coherent(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_map_single(e1, e2, e3, e4)
      +    dma_map_single(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_unmap_single(e1, e2, e3, e4)
      +    dma_unmap_single(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4, e5;
      @@
      -    pci_map_page(e1, e2, e3, e4, e5)
      +    dma_map_page(&e1->dev, e2, e3, e4, e5)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_unmap_page(e1, e2, e3, e4)
      +    dma_unmap_page(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_map_sg(e1, e2, e3, e4)
      +    dma_map_sg(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_unmap_sg(e1, e2, e3, e4)
      +    dma_unmap_sg(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
      +    dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_dma_sync_single_for_device(e1, e2, e3, e4)
      +    dma_sync_single_for_device(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
      +    dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2, e3, e4;
      @@
      -    pci_dma_sync_sg_for_device(e1, e2, e3, e4)
      +    dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
      
      @@
      expression e1, e2;
      @@
      -    pci_dma_mapping_error(e1, e2)
      +    dma_mapping_error(&e1->dev, e2)
      
      @@
      expression e1, e2;
      @@
      -    pci_set_dma_mask(e1, e2)
      +    dma_set_mask(&e1->dev, e2)
      
      @@
      expression e1, e2;
      @@
      -    pci_set_consistent_dma_mask(e1, e2)
      +    dma_set_coherent_mask(&e1->dev, e2)
      
      Link: https://lore.kernel.org/r/3899b1ed4abac581c30845d82f33ec6df8b38976.1629633207.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      ca4ff9e7