1. 20 7月, 2016 1 次提交
  2. 07 1月, 2016 1 次提交
  3. 29 11月, 2015 2 次提交
    • J
      target: fix COMPARE_AND_WRITE non zero SGL offset data corruption · d94e5a61
      Jan Engelhardt 提交于
      target_core_sbc's compare_and_write functionality suffers from taking
      data at the wrong memory location when writing a CAW request to disk
      when a SGL offset is non-zero.
      
      This can happen with loopback and vhost-scsi fabric drivers when
      SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC is used to map existing user-space
      SGL memory into COMPARE_AND_WRITE READ/WRITE payload buffers.
      
      Given the following sample LIO subtopology,
      
      % targetcli ls /loopback/
      o- loopback ................................. [1 Target]
        o- naa.6001405ebb8df14a ....... [naa.60014059143ed2b3]
          o- luns ................................... [2 LUNs]
            o- lun0 ................ [iblock/ram0 (/dev/ram0)]
            o- lun1 ................ [iblock/ram1 (/dev/ram1)]
      % lsscsi -g
      [3:0:1:0]    disk    LIO-ORG  IBLOCK           4.0   /dev/sdc   /dev/sg3
      [3:0:1:1]    disk    LIO-ORG  IBLOCK           4.0   /dev/sdd   /dev/sg4
      
      the following bug can be observed in Linux 4.3 and 4.4~rc1:
      
      % perl -e 'print chr$_ for 0..255,reverse 0..255' >rand
      % perl -e 'print "\0" x 512' >zero
      % cat rand >/dev/sdd
      % sg_compare_and_write -i rand -D zero --lba 0 /dev/sdd
      % sg_compare_and_write -i zero -D rand --lba 0 /dev/sdd
      Miscompare reported
      % hexdump -Cn 512 /dev/sdd
      00000000  0f 0e 0d 0c 0b 0a 09 08  07 06 05 04 03 02 01 00
      00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
      *
      00000200
      
      Rather than writing all-zeroes as instructed with the -D file, it
      corrupts the data in the sector by splicing some of the original
      bytes in. The page of the first entry of cmd->t_data_sg includes the
      CDB, and sg->offset is set to a position past the CDB. I presume that
      sg->offset is also the right choice to use for subsequent sglist
      members.
      Signed-off-by: NJan Engelhardt <jengelh@netitwork.de>
      Tested-by: NDouglas Gilbert <dgilbert@interlog.com>
      Cc: <stable@vger.kernel.org> # v3.12+
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      d94e5a61
    • N
      target: Fix race for SCF_COMPARE_AND_WRITE_POST checking · 057085e5
      Nicholas Bellinger 提交于
      This patch addresses a race + use after free where the first
      stage of COMPARE_AND_WRITE in compare_and_write_callback()
      is rescheduled after the backend sends the secondary WRITE,
      resulting in second stage compare_and_write_post() callback
      completing in target_complete_ok_work() before the first
      can return.
      
      Because current code depends on checking se_cmd->se_cmd_flags
      after return from se_cmd->transport_complete_callback(),
      this results in first stage having SCF_COMPARE_AND_WRITE_POST
      set, which incorrectly falls through into second stage CAW
      processing code, eventually triggering a NULL pointer
      dereference due to use after free.
      
      To address this bug, pass in a new *post_ret parameter into
      se_cmd->transport_complete_callback(), and depend upon this
      value instead of ->se_cmd_flags to determine when to return
      or fall through into ->queue_status() code for CAW.
      
      Cc: Sagi Grimberg <sagig@mellanox.com>
      Cc: <stable@vger.kernel.org> # v3.12+
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      057085e5
  4. 31 7月, 2015 2 次提交
  5. 07 7月, 2015 1 次提交
  6. 23 6月, 2015 3 次提交
  7. 02 6月, 2015 1 次提交
    • B
      target: Minimize SCSI header #include directives · ba929992
      Bart Van Assche 提交于
      Only include SCSI initiator header files in target code that needs
      these header files, namely the SCSI pass-through code and the tcm_loop
      driver. Change SCSI_SENSE_BUFFERSIZE into TRANSPORT_SENSE_BUFFER in
      target code because the former is intended for initiator code and the
      latter for target code. With this patch the only initiator include
      directives in target code that remain are as follows:
      
      $ git grep -nHE 'include .scsi/(scsi.h|scsi_host.h|scsi_device.h|scsi_cmnd.h)' drivers/target drivers/infiniband/ulp/{isert,srpt} drivers/usb/gadget/legacy/tcm_*.[ch] drivers/{vhost,xen} include/{target,trace/events/target.h}
      drivers/target/loopback/tcm_loop.c:29:#include <scsi/scsi.h>
      drivers/target/loopback/tcm_loop.c:31:#include <scsi/scsi_host.h>
      drivers/target/loopback/tcm_loop.c:32:#include <scsi/scsi_device.h>
      drivers/target/loopback/tcm_loop.c:33:#include <scsi/scsi_cmnd.h>
      drivers/target/target_core_pscsi.c:39:#include <scsi/scsi_device.h>
      drivers/target/target_core_pscsi.c:40:#include <scsi/scsi_host.h>
      drivers/xen/xen-scsiback.c:52:#include <scsi/scsi_host.h> /* SG_ALL */
      Signed-off-by: NBart Van Assche <bart.vanassche@sandisk.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJames Bottomley <JBottomley@Odin.com>
      ba929992
  8. 31 5月, 2015 5 次提交
    • A
      target: handle odd SG mapping for data transfer memory · 18213afb
      Akinobu Mita 提交于
      sbc_dif_generate() and sbc_dif_verify() currently assume that each
      SG element for data transfer memory doesn't straddle the block size
      boundary.
      
      However, when using SG_IO ioctl, we can choose the data transfer
      memory which doesn't satisfy that alignment requirement.
      
      In order to handle such cases correctly, this change inverts the outer
      loop to iterate data transfer memory and the inner loop to iterate
      protection information and enables to calculate CRC for a block which
      straddles multiple SG elements.
      Signed-off-by: NAkinobu Mita <akinobu.mita@gmail.com>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: linux-crypto@vger.kernel.org
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Sagi Grimberg <sagig@mellanox.com>
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: target-devel@vger.kernel.org
      Cc: linux-scsi@vger.kernel.org
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      18213afb
    • A
      target: Fix inconsistent address passed to kunmap_atomic() in sbc_dif_copy_prot() · 57636388
      Akinobu Mita 提交于
      In sbc_dif_copy_prot(), the addresses passed to kunmap_atomic() are
      inconsistent with the addresses which are mapped by kmap_atomic().
      That could be problematic if an SG element has its length larger than
      PAGE_SIZE as kunmap_atomic() will attempt to unmap different page.
      Signed-off-by: NAkinobu Mita <akinobu.mita@gmail.com>
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Sagi Grimberg <sagig@mellanox.com>
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: target-devel@vger.kernel.org
      Cc: linux-scsi@vger.kernel.org
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      57636388
    • C
      target: fix DPO and FUA bit checks · 814e5b45
      Christoph Hellwig 提交于
      Drivers may override the WCE flag, in which case the DPOFUA flag in
      MODE SENSE might differ from the check used to reject invalid FUA
      bits in sbc_check_dpofua.  Also now that we reject invalid FUA
      bits early there is no need to duplicate the same buggy check
      down in the fileio code.
      
      As the DPOFUA flag controls th support for FUA bits on read and
      write commands as well as DPO key off all the checks off a single
      helper, and deprecate the emulate_dpo and emulate_fua_read attributs.
      
      This fixes various failures in the libiscsi testsuite.
      
      Personally I'd prefer to also remove the emulate_fua_write attribute
      as there is no good reason to disable it, but I'll leave that for
      a separate discussion.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      814e5b45
    • S
      target/sbc: Fix sbc_dif_verify inconsistent map/unmap · 414e4627
      Sagi Grimberg 提交于
      Fix map/unmap consistency and get rid of a redundant
      local variable psg.
      Reported-by: NAkinobu Mita <akinobu.mita@gmail.com>
      Signed-off-by: NSagi Grimberg <sagig@mellanox.com>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      414e4627
    • S
      target: Merge sbc_verify_dif_read|write · f75b6fae
      Sagi Grimberg 提交于
      Instead of providing DIF verify routines for read/write
      that are almost identical and conditionally copy protection
      information, just let the caller do the right thing.
      
      Have a single sbc_dif_verify that handles an sgl (that
      does NOT copy any data) and a protection information copy
      routine used by rd_mcp and fileio backend.
      
      In the WRITE case, call sbc_dif_verify with cmd->t_prot_sg
      and then do the copy from it to local sgl (assuming the verify
      succeeded of course). In the READ case, call sbc_dif_verify
      with the local sgl and if it succeeds, copy it to t_prot_sg (or
      not if we are stripping it).
      
      (Fix apply breakage from commit c8367778 - nab)
      Tested-by: NAkinobu Mita <akinobu.mita@gmail.com>
      Signed-off-by: NSagi Grimberg <sagig@mellanox.com>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      f75b6fae
  9. 20 5月, 2015 1 次提交
  10. 16 4月, 2015 3 次提交
  11. 15 4月, 2015 1 次提交
    • N
      target: Fix COMPARE_AND_WRITE with SG_TO_MEM_NOALLOC handling · c8e63985
      Nicholas Bellinger 提交于
      This patch fixes a bug for COMPARE_AND_WRITE handling with
      fabrics using SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC.
      
      It adds the missing allocation for cmd->t_bidi_data_sg within
      transport_generic_new_cmd() that is used by COMPARE_AND_WRITE
      for the initial READ payload, even if the fabric is already
      providing a pre-allocated buffer for cmd->t_data_sg.
      
      Also, fix zero-length COMPARE_AND_WRITE handling within the
      compare_and_write_callback() and target_complete_ok_work()
      to queue the response, skipping the initial READ.
      
      This fixes COMPARE_AND_WRITE emulation with loopback, vhost,
      and xen-backend fabric drivers using SG_TO_MEM_NOALLOC.
      Reported-by: NChristoph Hellwig <hch@lst.de>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: <stable@vger.kernel.org> # v3.12+
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      c8e63985
  12. 08 4月, 2015 4 次提交
  13. 20 3月, 2015 1 次提交
  14. 14 2月, 2015 7 次提交
  15. 10 1月, 2015 1 次提交
    • N
      target: Drop arbitrary maximum I/O size limit · 046ba642
      Nicholas Bellinger 提交于
      This patch drops the arbitrary maximum I/O size limit in sbc_parse_cdb(),
      which currently for fabric_max_sectors is hardcoded to 8192 (4 MB for 512
      byte sector devices), and for hw_max_sectors is a backend driver dependent
      value.
      
      This limit is problematic because Linux initiators have only recently
      started to honor block limits MAXIMUM TRANSFER LENGTH, and other non-Linux
      based initiators (eg: MSFT Fibre Channel) can also generate I/Os larger
      than 4 MB in size.
      
      Currently when this happens, the following message will appear on the
      target resulting in I/Os being returned with non recoverable status:
      
        SCSI OP 28h with too big sectors 16384 exceeds fabric_max_sectors: 8192
      
      Instead, drop both [fabric,hw]_max_sector checks in sbc_parse_cdb(),
      and convert the existing hw_max_sectors into a purely informational
      attribute used to represent the granuality that backend driver and/or
      subsystem code is splitting I/Os upon.
      
      Also, update FILEIO with an explicit FD_MAX_BYTES check in fd_execute_rw()
      to deal with the one special iovec limitiation case.
      
      v2 changes:
        - Drop hw_max_sectors check in sbc_parse_cdb()
      Reported-by: NLance Gropper <lance.gropper@qosserver.com>
      Reported-by: NStefan Priebe <s.priebe@profihost.ag>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Cc: Roland Dreier <roland@purestorage.com>
      Cc: stable@vger.kernel.org # 3.4
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      046ba642
  16. 04 12月, 2014 1 次提交
  17. 25 11月, 2014 1 次提交
  18. 03 10月, 2014 1 次提交
  19. 12 6月, 2014 3 次提交