18 Oct, 2018

1 commit

  • [ Upstream commit 679fcae46c8b2352bba3485d521da070cfbe68e6 ]

    Fedora got a bug report of a crash with iSCSI:

    kernel BUG at include/linux/scatterlist.h:143!
    ...
    RIP: 0010:iscsit_do_crypto_hash_buf+0x154/0x180 [iscsi_target_mod]
    ...
    Call Trace:
    ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
    iscsit_get_rx_pdu+0x4cd/0xa90 [iscsi_target_mod]
    ? native_sched_clock+0x3e/0xa0
    ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod]
    iscsi_target_rx_thread+0x81/0xf0 [iscsi_target_mod]
    kthread+0x120/0x140
    ? kthread_create_worker_on_cpu+0x70/0x70
    ret_from_fork+0x3a/0x50

    This is a BUG_ON for using a stack buffer with a scatterlist. There
    are two cases that trigger this bug. Switch to using a dynamically
    allocated buffer for one case and do not assign a NULL buffer in
    another case.

    Signed-off-by: Laura Abbott
    Reviewed-by: Mike Christie
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Laura Abbott
     

10 Oct, 2018

1 commit

  • [ Upstream commit 7915919bb94e12460c58e27c708472e6f85f6699 ]

    Fixes a use-after-free reported by KASAN when later
    iscsi_target_login_sess_out gets called and it tries to access
    conn->sess->se_sess:

    Disabling lock debugging due to kernel taint
    iSCSI Login timeout on Network Portal [::]:3260
    iSCSI Login negotiation failed.
    ==================================================================
    BUG: KASAN: use-after-free in
    iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod]
    Read of size 8 at addr ffff880109d070c8 by task iscsi_np/980

    CPU: 1 PID: 980 Comm: iscsi_np Tainted: G O
    4.17.8kasan.sess.connops+ #4
    Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB,
    BIOS 5.6.5 05/19/2014
    Call Trace:
    dump_stack+0x71/0xac
    print_address_description+0x65/0x22e
    ? iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod]
    kasan_report.cold.6+0x241/0x2fd
    iscsi_target_login_sess_out.cold.12+0x58/0xff [iscsi_target_mod]
    iscsi_target_login_thread+0x1086/0x1710 [iscsi_target_mod]
    ? __sched_text_start+0x8/0x8
    ? iscsi_target_login_sess_out+0x250/0x250 [iscsi_target_mod]
    ? __kthread_parkme+0xcc/0x100
    ? parse_args.cold.14+0xd3/0xd3
    ? iscsi_target_login_sess_out+0x250/0x250 [iscsi_target_mod]
    kthread+0x1a0/0x1c0
    ? kthread_bind+0x30/0x30
    ret_from_fork+0x35/0x40

    Allocated by task 980:
    kasan_kmalloc+0xbf/0xe0
    kmem_cache_alloc_trace+0x112/0x210
    iscsi_target_login_thread+0x816/0x1710 [iscsi_target_mod]
    kthread+0x1a0/0x1c0
    ret_from_fork+0x35/0x40

    Freed by task 980:
    __kasan_slab_free+0x125/0x170
    kfree+0x90/0x1d0
    iscsi_target_login_thread+0x1577/0x1710 [iscsi_target_mod]
    kthread+0x1a0/0x1c0
    ret_from_fork+0x35/0x40

    The buggy address belongs to the object at ffff880109d06f00
    which belongs to the cache kmalloc-512 of size 512
    The buggy address is located 456 bytes inside of
    512-byte region [ffff880109d06f00, ffff880109d07100)
    The buggy address belongs to the page:
    page:ffffea0004274180 count:1 mapcount:0 mapping:0000000000000000
    index:0x0 compound_mapcount: 0
    flags: 0x17fffc000008100(slab|head)
    raw: 017fffc000008100 0000000000000000 0000000000000000 00000001000c000c
    raw: dead000000000100 dead000000000200 ffff88011b002e00 0000000000000000
    page dumped because: kasan: bad access detected

    Memory state around the buggy address:
    ffff880109d06f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ffff880109d07000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    >ffff880109d07080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
    ^
    ffff880109d07100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    ffff880109d07180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    ==================================================================

    Signed-off-by: Vincent Pelletier
    [rebased against idr/ida changes and to handle ret review comments from Matthew]
    Signed-off-by: Mike Christie
    Cc: Matthew Wilcox
    Reviewed-by: Matthew Wilcox
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Vincent Pelletier
     

04 Oct, 2018

2 commits

  • [ Upstream commit 36d4cb460bcbe2a1323732a6e4bb9dd783284368 ]

    The approach for adding a device to the devices_idr data structure and for
    removing it is as follows:

    * &dev->dev_group.cg_item is initialized before a device is added to
    devices_idr.

    * If the reference count of a device drops to zero then
    target_free_device() removes the device from devices_idr.

    * All devices_idr manipulations are protected by device_mutex.

    This means that increasing the reference count of a device is sufficient to
    prevent removal from devices_idr and also that it is safe access
    dev_group.cg_item for any device that is referenced by devices_idr. Use
    this to modify target_find_device() and target_for_each_device() such that
    these functions no longer introduce a dependency between device_mutex and
    the configfs root inode mutex.

    Note: it is safe to pass a NULL pointer to config_item_put() and also to
    config_item_get_unless_zero().

    This patch prevents that lockdep reports the following complaint:

    ======================================================
    WARNING: possible circular locking dependency detected
    4.12.0-rc1-dbg+ #1 Not tainted
    ------------------------------------------------------
    rmdir/12053 is trying to acquire lock:
    (device_mutex#2){+.+.+.}, at: []
    target_free_device+0xae/0xf0 [target_core_mod]

    but task is already holding lock:
    (&sb->s_type->i_mutex_key#14){++++++}, at: []
    vfs_rmdir+0x50/0x140

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (&sb->s_type->i_mutex_key#14){++++++}:
    lock_acquire+0x59/0x80
    down_write+0x36/0x70
    configfs_depend_item+0x3a/0xb0 [configfs]
    target_depend_item+0x13/0x20 [target_core_mod]
    target_xcopy_locate_se_dev_e4_iter+0x87/0x100 [target_core_mod]
    target_devices_idr_iter+0x16/0x20 [target_core_mod]
    idr_for_each+0x39/0xc0
    target_for_each_device+0x36/0x50 [target_core_mod]
    target_xcopy_locate_se_dev_e4+0x28/0x80 [target_core_mod]
    target_xcopy_do_work+0x2e9/0xdd0 [target_core_mod]
    process_one_work+0x1ca/0x3f0
    worker_thread+0x49/0x3b0
    kthread+0x109/0x140
    ret_from_fork+0x31/0x40

    -> #0 (device_mutex#2){+.+.+.}:
    __lock_acquire+0x101f/0x11d0
    lock_acquire+0x59/0x80
    __mutex_lock+0x7e/0x950
    mutex_lock_nested+0x16/0x20
    target_free_device+0xae/0xf0 [target_core_mod]
    target_core_dev_release+0x10/0x20 [target_core_mod]
    config_item_put+0x6e/0xb0 [configfs]
    configfs_rmdir+0x1a6/0x300 [configfs]
    vfs_rmdir+0xb7/0x140
    do_rmdir+0x1f4/0x200
    SyS_rmdir+0x11/0x20
    entry_SYSCALL_64_fastpath+0x23/0xc2

    other info that might help us debug this:

    Possible unsafe locking scenario:

    CPU0 CPU1
    ---- ----
    lock(&sb->s_type->i_mutex_key#14);
    lock(device_mutex#2);
    lock(&sb->s_type->i_mutex_key#14);
    lock(device_mutex#2);

    *** DEADLOCK ***

    3 locks held by rmdir/12053:
    #0: (sb_writers#10){.+.+.+}, at: []
    mnt_want_write+0x1f/0x50
    #1: (&sb->s_type->i_mutex_key#14/1){+.+.+.}, at: []
    do_rmdir+0x15e/0x200
    #2: (&sb->s_type->i_mutex_key#14){++++++}, at: []
    vfs_rmdir+0x50/0x140

    stack backtrace:
    CPU: 3 PID: 12053 Comm: rmdir Not tainted 4.12.0-rc1-dbg+ #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
    1.0.0-prebuilt.qemu-project.org 04/01/2014
    Call Trace:
    dump_stack+0x86/0xcf
    print_circular_bug+0x1c7/0x220
    __lock_acquire+0x101f/0x11d0
    lock_acquire+0x59/0x80
    __mutex_lock+0x7e/0x950
    mutex_lock_nested+0x16/0x20
    target_free_device+0xae/0xf0 [target_core_mod]
    target_core_dev_release+0x10/0x20 [target_core_mod]
    config_item_put+0x6e/0xb0 [configfs]
    configfs_rmdir+0x1a6/0x300 [configfs]
    vfs_rmdir+0xb7/0x140
    do_rmdir+0x1f4/0x200
    SyS_rmdir+0x11/0x20
    entry_SYSCALL_64_fastpath+0x23/0xc2

    Signed-off-by: Bart Van Assche
    [Rebased to handle conflict withe target_find_device removal]
    Signed-off-by: Mike Christie

    Signed-off-by: Martin K. Petersen

    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     
  • [ Upstream commit 35bea5c84fd13c643cce63f0b5cd4b148f8c901d ]

    Fixes: e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
    Signed-off-by: Bart Van Assche
    Reviewed-by: Mike Christie
    Cc: Mike Christie
    Cc: Christoph Hellwig
    Cc: Hannes Reinecke
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     

29 Sep, 2018

2 commits

  • commit 8c39e2699f8acb2e29782a834e56306da24937fe upstream.

    Signed-off-by: Vincent Pelletier
    Reviewed-by: Mike Christie
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    Vincent Pelletier
     
  • commit 1816494330a83f2a064499d8ed2797045641f92c upstream.

    This change has the following effects, in order of descreasing importance:

    1) Prevent a stack buffer overflow

    2) Do not append an unnecessary NULL to an anyway binary buffer, which
    is writing one byte past client_digest when caller is:
    chap_string_to_hex(client_digest, chap_r, strlen(chap_r));

    The latter was found by KASAN (see below) when input value hes expected size
    (32 hex chars), and further analysis revealed a stack buffer overflow can
    happen when network-received value is longer, allowing an unauthenticated
    remote attacker to smash up to 17 bytes after destination buffer (16 bytes
    attacker-controlled and one null). As switching to hex2bin requires
    specifying destination buffer length, and does not internally append any null,
    it solves both issues.

    This addresses CVE-2018-14633.

    Beyond this:

    - Validate received value length and check hex2bin accepted the input, to log
    this rejection reason instead of just failing authentication.

    - Only log received CHAP_R and CHAP_C values once they passed sanity checks.

    ==================================================================
    BUG: KASAN: stack-out-of-bounds in chap_string_to_hex+0x32/0x60 [iscsi_target_mod]
    Write of size 1 at addr ffff8801090ef7c8 by task kworker/0:0/1021

    CPU: 0 PID: 1021 Comm: kworker/0:0 Tainted: G O 4.17.8kasan.sess.connops+ #2
    Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB, BIOS 5.6.5 05/19/2014
    Workqueue: events iscsi_target_do_login_rx [iscsi_target_mod]
    Call Trace:
    dump_stack+0x71/0xac
    print_address_description+0x65/0x22e
    ? chap_string_to_hex+0x32/0x60 [iscsi_target_mod]
    kasan_report.cold.6+0x241/0x2fd
    chap_string_to_hex+0x32/0x60 [iscsi_target_mod]
    chap_server_compute_md5.isra.2+0x2cb/0x860 [iscsi_target_mod]
    ? chap_binaryhex_to_asciihex.constprop.5+0x50/0x50 [iscsi_target_mod]
    ? ftrace_caller_op_ptr+0xe/0xe
    ? __orc_find+0x6f/0xc0
    ? unwind_next_frame+0x231/0x850
    ? kthread+0x1a0/0x1c0
    ? ret_from_fork+0x35/0x40
    ? ret_from_fork+0x35/0x40
    ? iscsi_target_do_login_rx+0x3bc/0x4c0 [iscsi_target_mod]
    ? deref_stack_reg+0xd0/0xd0
    ? iscsi_target_do_login_rx+0x3bc/0x4c0 [iscsi_target_mod]
    ? is_module_text_address+0xa/0x11
    ? kernel_text_address+0x4c/0x110
    ? __save_stack_trace+0x82/0x100
    ? ret_from_fork+0x35/0x40
    ? save_stack+0x8c/0xb0
    ? 0xffffffffc1660000
    ? iscsi_target_do_login+0x155/0x8d0 [iscsi_target_mod]
    ? iscsi_target_do_login_rx+0x3bc/0x4c0 [iscsi_target_mod]
    ? process_one_work+0x35c/0x640
    ? worker_thread+0x66/0x5d0
    ? kthread+0x1a0/0x1c0
    ? ret_from_fork+0x35/0x40
    ? iscsi_update_param_value+0x80/0x80 [iscsi_target_mod]
    ? iscsit_release_cmd+0x170/0x170 [iscsi_target_mod]
    chap_main_loop+0x172/0x570 [iscsi_target_mod]
    ? chap_server_compute_md5.isra.2+0x860/0x860 [iscsi_target_mod]
    ? rx_data+0xd6/0x120 [iscsi_target_mod]
    ? iscsit_print_session_params+0xd0/0xd0 [iscsi_target_mod]
    ? cyc2ns_read_begin.part.2+0x90/0x90
    ? _raw_spin_lock_irqsave+0x25/0x50
    ? memcmp+0x45/0x70
    iscsi_target_do_login+0x875/0x8d0 [iscsi_target_mod]
    ? iscsi_target_check_first_request.isra.5+0x1a0/0x1a0 [iscsi_target_mod]
    ? del_timer+0xe0/0xe0
    ? memset+0x1f/0x40
    ? flush_sigqueue+0x29/0xd0
    iscsi_target_do_login_rx+0x3bc/0x4c0 [iscsi_target_mod]
    ? iscsi_target_nego_release+0x80/0x80 [iscsi_target_mod]
    ? iscsi_target_restore_sock_callbacks+0x130/0x130 [iscsi_target_mod]
    process_one_work+0x35c/0x640
    worker_thread+0x66/0x5d0
    ? flush_rcu_work+0x40/0x40
    kthread+0x1a0/0x1c0
    ? kthread_bind+0x30/0x30
    ret_from_fork+0x35/0x40

    The buggy address belongs to the page:
    page:ffffea0004243bc0 count:0 mapcount:0 mapping:0000000000000000 index:0x0
    flags: 0x17fffc000000000()
    raw: 017fffc000000000 0000000000000000 0000000000000000 00000000ffffffff
    raw: ffffea0004243c20 ffffea0004243ba0 0000000000000000 0000000000000000
    page dumped because: kasan: bad access detected

    Memory state around the buggy address:
    ffff8801090ef680: f2 f2 f2 f2 f2 f2 f2 01 f2 f2 f2 f2 f2 f2 f2 00
    ffff8801090ef700: f2 f2 f2 f2 f2 f2 f2 00 02 f2 f2 f2 f2 f2 f2 00
    >ffff8801090ef780: 00 f2 f2 f2 f2 f2 f2 00 00 f2 f2 f2 f2 f2 f2 00
    ^
    ffff8801090ef800: 00 f2 f2 f2 f2 f2 f2 00 00 00 00 02 f2 f2 f2 f2
    ffff8801090ef880: f2 f2 f2 00 00 00 00 00 00 00 00 f2 f2 f2 f2 00
    ==================================================================

    Signed-off-by: Vincent Pelletier
    Reviewed-by: Mike Christie
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    Vincent Pelletier
     

20 Sep, 2018

1 commit

  • [ Upstream commit 6a64f6e1591322beb8ce16e952a53582caf2a15c ]

    When __transport_register_session is called from transport_register_session
    irqs will already have been disabled, so we do not want the unlock irq call
    to enable them until the higher level has done the final
    spin_unlock_irqrestore/ spin_unlock_irq.

    This has __transport_register_session use the save/restore call.

    Signed-off-by: Mike Christie
    Reviewed-by: Bart Van Assche
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Mike Christie
     

05 Sep, 2018

2 commits

  • commit 26abc916a898d34c5ad159315a2f683def3c5555 upstream.

    The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in
    iscsi_login_set_conn_values. If the function fails later like when we
    alloc the idr it does kfree(sess) and leaves the conn->sess pointer set.
    iscsi_login_zero_tsih_s1 then returns -Exyz and we then call
    iscsi_target_login_sess_out and access the freed memory.

    This patch has iscsi_login_zero_tsih_s1 either completely setup the
    session or completely tear it down, so later in
    iscsi_target_login_sess_out we can just check for it being set to the
    connection.

    Cc: stable@vger.kernel.org
    Fixes: 0957627a9960 ("iscsi-target: Fix sess allocation leak in...")
    Signed-off-by: Mike Christie
    Acked-by: Martin K. Petersen
    Signed-off-by: Matthew Wilcox
    Signed-off-by: Greg Kroah-Hartman

    Mike Christie
     
  • [ Upstream commit 1b350ea0c2f4df9aa30426614c8eb755a8c32814 ]

    - rounddown CXGBIT_MAX_ISO_PAYLOAD by csk->emss before calculating
    max_iso_npdu to get max TCP payload in multiple of mss.

    - call cxgbit_set_digest() before cxgbit_set_iso_npdu() to set
    csk->submode, it is used in calculating number of iso pdus.

    Signed-off-by: Varun Prakash
    Reviewed-by: Mike Christie
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Varun Prakash
     

11 Jul, 2018

1 commit

  • commit 63ce3c384db26494615e3c8972bcd419ed71f4c4 upstream.

    SPC5r17 states that the contents of the ADDITIONAL LENGTH field are not
    altered based on the allocation length, so always calculate and pack the
    full key list length even if the list itself is truncated.

    According to Maged:

    Yes it fixes the "Storage Spaces Persistent Reservation" test in the
    Windows 2016 Server Failover Cluster validation suites when having
    many connections that result in more than 8 registrations. I tested
    your patch on 4.17 with iblock.

    This behaviour can be tested using the libiscsi PrinReadKeys.Truncate test.

    Cc: stable@vger.kernel.org
    Signed-off-by: David Disseldorp
    Reviewed-by: Mike Christie
    Tested-by: Maged Mokhtar
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    David Disseldorp
     

21 Jun, 2018

1 commit

  • [ Upstream commit 8e1ceafe50ec4d1bcfae154dd70e7cb6946a6177 ]

    When the current page can't be added to bio, one new bio should be
    created for adding this page again, instead of ignoring this page.

    This patch fixes kernel crash with iscsi target and dvd, as reported by
    Wakko.

    Cc: Wakko Warner
    Cc: Bart Van Assche
    Cc: target-devel@vger.kernel.org
    Cc: linux-scsi@vger.kernel.org
    Cc: "Nicholas A. Bellinger"
    Cc: Christoph Hellwig
    Fixes: 84c8590646d5b35804 ("target: avoid accessing .bi_vcnt directly")
    Signed-off-by: Ming Lei
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Ming Lei
     

09 May, 2018

1 commit

  • commit f5957dade4f373b04fa1f5315a489f18cc2c4cb4 upstream.

    memcmp() requires the two buffers passed as arguments to be at least
    'size' bytes long, otherwise a fortify_panic will trigger.

    Use memchr_inv() instead of memcmp() to determine whether the received
    payload is zeroed or not.

    The bug was found by running a block backstore via LIO.

    [ 496.212958] Call Trace:
    [ 496.212960] [c0000007e58e3800] [c000000000cbbefc] fortify_panic+0x24/0x38 (unreliable)
    [ 496.212965] [c0000007e58e3860] [d00000000f150c28] iblock_execute_write_same+0x3b8/0x3c0 [target_core_iblock]
    [ 496.212976] [c0000007e58e3910] [d000000006c737d4] __target_execute_cmd+0x54/0x150 [target_core_mod]
    [ 496.212982] [c0000007e58e3940] [d000000006d32ce4] ibmvscsis_write_pending+0x74/0xe0 [ibmvscsis]
    [ 496.212991] [c0000007e58e39b0] [d000000006c74fc8] transport_generic_new_cmd+0x318/0x370 [target_core_mod]
    [ 496.213001] [c0000007e58e3a30] [d000000006c75084] transport_handle_cdb_direct+0x64/0xd0 [target_core_mod]
    [ 496.213011] [c0000007e58e3aa0] [d000000006c75298] target_submit_cmd_map_sgls+0x1a8/0x320 [target_core_mod]
    [ 496.213021] [c0000007e58e3b30] [d000000006c75458] target_submit_cmd+0x48/0x60 [target_core_mod]
    [ 496.213026] [c0000007e58e3bd0] [d000000006d34c20] ibmvscsis_scheduler+0x370/0x600 [ibmvscsis]
    [ 496.213031] [c0000007e58e3c90] [c00000000013135c] process_one_work+0x1ec/0x580
    [ 496.213035] [c0000007e58e3d20] [c000000000131798] worker_thread+0xa8/0x600
    [ 496.213039] [c0000007e58e3dc0] [c00000000013a468] kthread+0x168/0x1b0
    [ 496.213044] [c0000007e58e3e30] [c00000000000b528] ret_from_kernel_thread+0x5c/0xb4

    [mkp: tweaked commit message]

    Fixes: 2237498f0b5c ("target/iblock: Convert WRITE_SAME to blkdev_issue_zeroout")
    Signed-off-by: Bryant G. Ly
    Reviewed-by: Steven Royer
    Tested-by: Taylor Jakobson
    Cc: Christoph Hellwig
    Cc: Nicholas Bellinger
    Cc: # v4.13+
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Greg Kroah-Hartman

    Bryant G Ly
     

12 Apr, 2018

1 commit

  • [ Upstream commit 810b8153c4243d2012a6ec002ddd3bbc9a9ae8c2 ]

    If we cannot setup a cmd because we run out of ring space
    or global pages release the blocks before sleeping. This
    prevents a deadlock where dev0 has waiting_blocks set and
    needs N blocks, but dev1 to devX have each allocated N / X blocks
    and also hit the global block limit so they went to sleep.

    find_free_blocks is not able to take the sleeping dev's
    blocks becaause their waiting_blocks is set and even
    if it was not the block returned by find_last_bit could equal
    dbi_max. The latter will probably never happen because
    DATA_BLOCK_BITS is so high but in the next patches
    DATA_BLOCK_BITS and TCMU_GLOBAL_MAX_BLOCKS will be settable so
    it might be lower and could happen.

    Signed-off-by: Mike Christie
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Mike Christie
     

22 Feb, 2018

2 commits

  • commit 1c130ae00b769a2e2df41bad3d6051ee8234b636 upstream.

    Mike Christie reports:
    Starting in 4.14 iscsi logins will fail around 50% of the time.

    Problem appears to be that iscsi_target_sk_data_ready() callback may
    return without doing anything in case it finds the login work queue
    is still blocked in sock_recvmsg().

    Nicholas Bellinger says:
    It would indicate users providing their own ->sk_data_ready() callback
    must be responsible for waking up a kthread context blocked on
    sock_recvmsg(..., MSG_WAITALL), when a second ->sk_data_ready() is
    received before the first sock_recvmsg(..., MSG_WAITALL) completes.

    So, do this and invoke the original data_ready() callback -- in
    case of tcp sockets this takes care of waking the thread.

    Disclaimer: I do not understand why this problem did not show up before
    tcp prequeue removal.

    (Drop WARN_ON usage - nab)

    Reported-by: Mike Christie
    Bisected-by: Mike Christie
    Tested-by: Mike Christie
    Diagnosed-by: Nicholas Bellinger
    Fixes: e7942d0633c4 ("tcp: remove prequeue support")
    Signed-off-by: Florian Westphal
    Cc: stable@vger.kernel.org # 4.14+
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Florian Westphal
     
  • commit ce512d79d0466a604793addb6b769d12ee326822 upstream.

    If chap_server_compute_md5() fails early, e.g. via CHAP_N mismatch, then
    crypto_free_shash() is called with a NULL pointer which gets
    dereferenced in crypto_shash_tfm().

    Fixes: 69110e3cedbb ("iscsi-target: Use shash and ahash")
    Suggested-by: Markus Elfring
    Signed-off-by: David Disseldorp
    Cc: stable@vger.kernel.org # 4.6+
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    David Disseldorp
     

03 Jan, 2018

1 commit

  • commit 0abc2a10389f0c9070f76ca906c7382788036b93 upstream.

    Commit caa4b02476e3(blk-map: call blk_queue_bounce from blk_rq_append_bio)
    moves blk_queue_bounce() into blk_rq_append_bio(), but don't consider
    the fact that the bounced bio becomes invisible to caller since the
    parameter type is 'struct bio *'. Make it a pointer to a pointer to
    a bio, so the caller sees the right bio also after a bounce.

    Fixes: caa4b02476e3 ("blk-map: call blk_queue_bounce from blk_rq_append_bio")
    Cc: Christoph Hellwig
    Reported-by: Michele Ballabio
    (handling failure of blk_rq_append_bio(), only call bio_get() after
    blk_rq_append_bio() returns OK)
    Tested-by: Michele Ballabio
    Signed-off-by: Ming Lei
    Signed-off-by: Jens Axboe
    Signed-off-by: Greg Kroah-Hartman

    Jens Axboe
     

20 Dec, 2017

5 commits

  • [ Upstream commit 594e25e73440863981032d76c9b1e33409ceff6e ]

    The function fd_execute_unmap() in target_core_file.c calles

    ret = file->f_op->fallocate(file, mode, pos, len);

    Some filesystems implement fallocate() to return error if
    length is zero (e.g. btrfs) but according to SCSI Block
    Commands spec UNMAP should return success for zero length.

    Signed-off-by: Jiang Yi
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Jiang Yi
     
  • [ Upstream commit 24528f089d0a444070aa4f715ace537e8d6bf168 ]

    When is pr_reg->isid_present_at_reg is false,this function should return.

    This fixes a regression originally introduced by:

    commit d2843c173ee53cf4c12e7dfedc069a5bc76f0ac5
    Author: Andy Grover
    Date: Thu May 16 10:40:55 2013 -0700

    target: Alter core_pr_dump_initiator_port for ease of use

    Signed-off-by: tangwenji
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    tangwenji
     
  • [ Upstream commit 12d5a43b2dffb6cd28062b4e19024f7982393288 ]

    tpg must free when call core_tpg_register() return fail

    Signed-off-by: tangwenji
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    tangwenji
     
  • [ Upstream commit cfe2b621bb18d86e93271febf8c6e37622da2d14 ]

    Avoid that cmd->se_cmd.se_tfo is read after a command has already been
    freed.

    Signed-off-by: Bart Van Assche
    Cc: Christoph Hellwig
    Cc: Mike Christie
    Reviewed-by: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     
  • [ Upstream commit 6eaf69e4ec075f5af236c0c89f75639a195db904 ]

    Certain behavior of the initiator can cause the target driver to
    send both a reject and a SCSI response. If that happens two
    target_put_sess_cmd() calls will occur without the command having
    been removed from conn_cmd_list. In other words, conn_cmd_list
    will get corrupted once the freed memory is reused. Although the
    Linux kernel can detect list corruption if list debugging is
    enabled, in this case the context in which list corruption is
    detected is not related to the context that caused list corruption.
    Hence add WARN_ON() statements that report the context that is
    causing list corruption.

    Signed-off-by: Bart Van Assche
    Cc: Christoph Hellwig
    Cc: Mike Christie
    Reviewed-by: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Bart Van Assche
     

30 Nov, 2017

8 commits

  • commit 1c21a48055a67ceb693e9c2587824a8de60a217c upstream.

    This patch fixes bug where early se_cmd exceptions that occur
    before backend execution can result in use-after-free if/when
    a subsequent ABORT_TASK occurs for the same tag.

    Since an early se_cmd exception will have had se_cmd added to
    se_session->sess_cmd_list via target_get_sess_cmd(), it will
    not have CMD_T_COMPLETE set by the usual target_complete_cmd()
    backend completion path.

    This causes a subsequent ABORT_TASK + __target_check_io_state()
    to signal ABORT_TASK should proceed. As core_tmr_abort_task()
    executes, it will bring the outstanding se_cmd->cmd_kref count
    down to zero releasing se_cmd, after se_cmd has already been
    queued with error status into fabric driver response path code.

    To address this bug, introduce a CMD_T_PRE_EXECUTE bit that is
    set at target_get_sess_cmd() time, and cleared immediately before
    backend driver dispatch in target_execute_cmd() once CMD_T_ACTIVE
    is set.

    Then, check CMD_T_PRE_EXECUTE within __target_check_io_state() to
    determine when an early exception has occured, and avoid aborting
    this se_cmd since it will have already been queued into fabric
    driver response path code.

    Reported-by: Donald White
    Cc: Donald White
    Cc: Mike Christie
    Cc: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     
  • commit 9574a497df2bbc0a676b609ce0dd24d237cee3a6 upstream.

    This patch fixes a potential end-less loop during QUEUE_FULL,
    where cmd->se_tfo->write_pending() callback fails repeatedly
    but __transport_wait_for_tasks() has already been invoked to
    quiese the outstanding se_cmd descriptor.

    To address this bug, this patch adds a CMD_T_STOP|CMD_T_ABORTED
    check within transport_write_pending_qf() and invokes the
    existing se_cmd->t_transport_stop_comp to signal quiese
    completion back to __transport_wait_for_tasks().

    Cc: Mike Christie
    Cc: Hannes Reinecke
    Cc: Bryant G. Ly
    Cc: Michael Cyr
    Cc: Potnuri Bharat Teja
    Cc: Sagi Grimberg
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     
  • commit fd2f928b0ddd2fe8876d4f1344df2ace2b715a4d upstream.

    With the recent addition of transport_check_aborted_status() within
    transport_generic_request_failure() to avoid sending a SCSI status
    exception after CMD_T_ABORTED w/ TAS=1 has occured, it introduced
    a COMPARE_AND_WRITE early failure regression.

    Namely when COMPARE_AND_WRITE fails and se_device->caw_sem has
    been taken by sbc_compare_and_write(), if the new check for
    transport_check_aborted_status() returns true and exits,
    cmd->transport_complete_callback() -> compare_and_write_post()
    is skipped never releasing se_device->caw_sem.

    This regression was originally introduced by:

    commit e3b88ee95b4e4bf3e9729a4695d695b9c7c296c8
    Author: Bart Van Assche
    Date: Tue Feb 14 16:25:45 2017 -0800

    target: Fix handling of aborted failed commands

    To address this bug, move the transport_check_aborted_status()
    call after transport_complete_task_attr() and
    cmd->transport_complete_callback().

    Cc: Mike Christie
    Cc: Hannes Reinecke
    Cc: Bart Van Assche
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     
  • commit 1c79df1f349fb6050016cea4ef1dfbc3853a5685 upstream.

    This patch fixes a bug during QUEUE_FULL where transport_complete_qf()
    calls transport_complete_task_attr() after it's already been invoked
    by target_complete_ok_work() or transport_generic_request_failure()
    during initial completion, preceeding QUEUE_FULL.

    This will result in se_device->simple_cmds, se_device->dev_cur_ordered_id
    and/or se_device->dev_ordered_sync being updated multiple times for
    a single se_cmd.

    To address this bug, clear SCF_TASK_ATTR_SET after the first call
    to transport_complete_task_attr(), and avoid updating SCSI task
    attribute related counters for any subsequent calls.

    Also, when a se_cmd is deferred due to ordered tags and executed
    via target_restart_delayed_cmds(), set CMD_T_SENT before execution
    matching what target_execute_cmd() does.

    Cc: Michael Cyr
    Cc: Bryant G. Ly
    Cc: Mike Christie
    Cc: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     
  • commit c58a252beb04cf0e02d6a746b2ed7ea89b6deb71 upstream.

    When at least two initiators register pr on the same LUN,
    the target returns the exception data due to buffer offset
    error, therefore the initiator executes command 'sg_persist -s'
    may cause the initiator to appear segfault error.

    This fixes a regression originally introduced by:

    commit a85d667e58bddf73be84d1981b41eaac985ed216
    Author: Bart Van Assche
    Date: Tue May 23 16:48:27 2017 -0700

    target: Use {get,put}_unaligned_be*() instead of open coding these functions

    Signed-off-by: tangwenji
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    tangwenji
     
  • commit 88fb2fa7db7510bf1078226ab48d162d9854f3d4 upstream.

    The target system kernel crash when the initiator executes
    the sg_persist -A command,because of the second argument to
    be set to NULL when core_tmr_lun_reset is called in
    core_scsi3_pro_preempt function.

    This fixes a regression originally introduced by:

    commit 51ec502a32665fed66c7f03799ede4023b212536
    Author: Bart Van Assche
    Date: Tue Feb 14 16:25:54 2017 -0800

    target: Delete tmr from list before processing

    Signed-off-by: tangwenji
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    tangwenji
     
  • commit 3fc9fb13a4b2576aeab86c62fd64eb29ab68659c upstream.

    This patch fixes a se_cmd->cmd_kref reference leak that can
    occur when a non immediate TMR is proceeded our of command
    sequence number order, and CMDSN_LOWER_THAN_EXP is returned
    by iscsit_sequence_cmd().

    To address this bug, call target_put_sess_cmd() during this
    special case following what iscsit_process_scsi_cmd() does
    upon CMDSN_LOWER_THAN_EXP.

    Cc: Mike Christie
    Cc: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     
  • commit ae072726f6109bb1c94841d6fb3a82dde298ea85 upstream.

    Since commit 59b6986dbf fixed a potential NULL pointer dereference
    by allocating a se_tmr_req for ISCSI_TM_FUNC_TASK_REASSIGN, the
    se_tmr_req is currently leaked by iscsit_free_cmd() because no
    iscsi_cmd->se_cmd.se_tfo was associated.

    To address this, treat ISCSI_TM_FUNC_TASK_REASSIGN like any other
    TMR and call transport_init_se_cmd() + target_get_sess_cmd() to
    setup iscsi_cmd->se_cmd.se_tfo with se_cmd->cmd_kref of 2.

    This will ensure normal release operation once se_cmd->cmd_kref
    reaches zero and target_release_cmd_kref() is invoked, se_tmr_req
    will be released via existing target_free_cmd_mem() and
    core_tmr_release_req() code.

    Reported-by: Donald White
    Cc: Donald White
    Cc: Mike Christie
    Cc: Hannes Reinecke
    Signed-off-by: Nicholas Bellinger
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Bellinger
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

15 Sep, 2017

1 commit

  • Pull more set_fs removal from Al Viro:
    "Christoph's 'use kernel_read and friends rather than open-coding
    set_fs()' series"

    * 'work.set_fs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs: unexport vfs_readv and vfs_writev
    fs: unexport vfs_read and vfs_write
    fs: unexport __vfs_read/__vfs_write
    lustre: switch to kernel_write
    gadget/f_mass_storage: stop messing with the address limit
    mconsole: switch to kernel_read
    btrfs: switch write_buf to kernel_write
    net/9p: switch p9_fd_read to kernel_write
    mm/nommu: switch do_mmap_private to kernel_read
    serial2002: switch serial2002_tty_write to kernel_{read/write}
    fs: make the buf argument to __kernel_write a void pointer
    fs: fix kernel_write prototype
    fs: fix kernel_read prototype
    fs: move kernel_read to fs/read_write.c
    fs: move kernel_write to fs/read_write.c
    autofs4: switch autofs4_write to __kernel_write
    ashmem: switch to ->read_iter

    Linus Torvalds
     

08 Sep, 2017

1 commit

  • Pull block layer updates from Jens Axboe:
    "This is the first pull request for 4.14, containing most of the code
    changes. It's a quiet series this round, which I think we needed after
    the churn of the last few series. This contains:

    - Fix for a registration race in loop, from Anton Volkov.

    - Overflow complaint fix from Arnd for DAC960.

    - Series of drbd changes from the usual suspects.

    - Conversion of the stec/skd driver to blk-mq. From Bart.

    - A few BFQ improvements/fixes from Paolo.

    - CFQ improvement from Ritesh, allowing idling for group idle.

    - A few fixes found by Dan's smatch, courtesy of Dan.

    - A warning fixup for a race between changing the IO scheduler and
    device remova. From David Jeffery.

    - A few nbd fixes from Josef.

    - Support for cgroup info in blktrace, from Shaohua.

    - Also from Shaohua, new features in the null_blk driver to allow it
    to actually hold data, among other things.

    - Various corner cases and error handling fixes from Weiping Zhang.

    - Improvements to the IO stats tracking for blk-mq from me. Can
    drastically improve performance for fast devices and/or big
    machines.

    - Series from Christoph removing bi_bdev as being needed for IO
    submission, in preparation for nvme multipathing code.

    - Series from Bart, including various cleanups and fixes for switch
    fall through case complaints"

    * 'for-4.14/block' of git://git.kernel.dk/linux-block: (162 commits)
    kernfs: checking for IS_ERR() instead of NULL
    drbd: remove BIOSET_NEED_RESCUER flag from drbd_{md_,}io_bio_set
    drbd: Fix allyesconfig build, fix recent commit
    drbd: switch from kmalloc() to kmalloc_array()
    drbd: abort drbd_start_resync if there is no connection
    drbd: move global variables to drbd namespace and make some static
    drbd: rename "usermode_helper" to "drbd_usermode_helper"
    drbd: fix race between handshake and admin disconnect/down
    drbd: fix potential deadlock when trying to detach during handshake
    drbd: A single dot should be put into a sequence.
    drbd: fix rmmod cleanup, remove _all_ debugfs entries
    drbd: Use setup_timer() instead of init_timer() to simplify the code.
    drbd: fix potential get_ldev/put_ldev refcount imbalance during attach
    drbd: new disk-option disable-write-same
    drbd: Fix resource role for newly created resources in events2
    drbd: mark symbols static where possible
    drbd: Send P_NEG_ACK upon write error in protocol != C
    drbd: add explicit plugging when submitting batches
    drbd: change list_for_each_safe to while(list_first_entry_or_null)
    drbd: introduce drbd_recv_header_maybe_unplug
    ...

    Linus Torvalds
     

05 Sep, 2017

1 commit


24 Aug, 2017

1 commit

  • This way we don't need a block_device structure to submit I/O. The
    block_device has different life time rules from the gendisk and
    request_queue and is usually only available when the block device node
    is open. Other callers need to explicitly create one (e.g. the lightnvm
    passthrough code, or the new nvme multipathing code).

    For the actual I/O path all that we need is the gendisk, which exists
    once per block device. But given that the block layer also does
    partition remapping we additionally need a partition index, which is
    used for said remapping in generic_make_request.

    Note that all the block drivers generally want request_queue or
    sometimes the gendisk, so this removes a layer of indirection all
    over the stack.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

10 Aug, 2017

1 commit

  • This patch fixes a generate_node_acls = 1 + cache_dynamic_acls = 0
    regression, that was introduced by

    commit 01d4d673558985d9a118e1e05026633c3e2ade9b
    Author: Nicholas Bellinger
    Date: Wed Dec 7 12:55:54 2016 -0800

    which originally had the proper list_del_init() usage, but was
    dropped during list review as it was thought unnecessary by HCH.

    However, list_del_init() usage is required during the special
    generate_node_acls = 1 + cache_dynamic_acls = 0 case when
    transport_free_session() does a list_del(&se_nacl->acl_list),
    followed by target_complete_nacl() doing the same thing.

    This was manifesting as a general protection fault as reported
    by Justin:

    kernel: general protection fault: 0000 [#1] SMP
    kernel: Modules linked in:
    kernel: CPU: 0 PID: 11047 Comm: iscsi_ttx Not tainted 4.13.0-rc2.x86_64.1+ #20
    kernel: Hardware name: Intel Corporation S5500BC/S5500BC, BIOS S5500.86B.01.00.0064.050520141428 05/05/2014
    kernel: task: ffff88026939e800 task.stack: ffffc90007884000
    kernel: RIP: 0010:target_put_nacl+0x49/0xb0
    kernel: RSP: 0018:ffffc90007887d70 EFLAGS: 00010246
    kernel: RAX: dead000000000200 RBX: ffff8802556ca000 RCX: 0000000000000000
    kernel: RDX: dead000000000100 RSI: 0000000000000246 RDI: ffff8802556ce028
    kernel: RBP: ffffc90007887d88 R08: 0000000000000001 R09: 0000000000000000
    kernel: R10: ffffc90007887df8 R11: ffffea0009986900 R12: ffff8802556ce020
    kernel: R13: ffff8802556ce028 R14: ffff8802556ce028 R15: ffffffff88d85540
    kernel: FS: 0000000000000000(0000) GS:ffff88027fc00000(0000) knlGS:0000000000000000
    kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    kernel: CR2: 00007fffe36f5f94 CR3: 0000000009209000 CR4: 00000000003406f0
    kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    kernel: Call Trace:
    kernel: transport_free_session+0x67/0x140
    kernel: transport_deregister_session+0x7a/0xc0
    kernel: iscsit_close_session+0x92/0x210
    kernel: iscsit_close_connection+0x5f9/0x840
    kernel: iscsit_take_action_for_connection_exit+0xfe/0x110
    kernel: iscsi_target_tx_thread+0x140/0x1e0
    kernel: ? wait_woken+0x90/0x90
    kernel: kthread+0x124/0x160
    kernel: ? iscsit_thread_get_cpumask+0x90/0x90
    kernel: ? kthread_create_on_node+0x40/0x40
    kernel: ret_from_fork+0x22/0x30
    kernel: Code: 00 48 89 fb 4c 8b a7 48 01 00 00 74 68 4d 8d 6c 24 08 4c
    89 ef e8 e8 28 43 00 48 8b 93 20 04 00 00 48 8b 83 28 04 00 00 4c 89
    ef 89 42 08 48 89 10 48 b8 00 01 00 00 00 00 ad de 48 89 83 20
    kernel: RIP: target_put_nacl+0x49/0xb0 RSP: ffffc90007887d70
    kernel: ---[ end trace f12821adbfd46fed ]---

    To address this, go ahead and use proper list_del_list() for all
    cases of se_nacl->acl_list deletion.

    Reported-by: Justin Maggard
    Tested-by: Justin Maggard
    Cc: Justin Maggard
    Cc: stable@vger.kernel.org # 4.1+
    Signed-off-by: Nicholas Bellinger

    Nicholas Bellinger
     

07 Aug, 2017

1 commit

  • This patch fixes a bug associated with iscsit_reset_np_thread()
    that can occur during parallel configfs rmdir of a single iscsi_np
    used across multiple iscsi-target instances, that would result in
    hung task(s) similar to below where configfs rmdir process context
    was blocked indefinately waiting for iscsi_np->np_restart_comp
    to finish:

    [ 6726.112076] INFO: task dcp_proxy_node_:15550 blocked for more than 120 seconds.
    [ 6726.119440] Tainted: G W O 4.1.26-3321 #2
    [ 6726.125045] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    [ 6726.132927] dcp_proxy_node_ D ffff8803f202bc88 0 15550 1 0x00000000
    [ 6726.140058] ffff8803f202bc88 ffff88085c64d960 ffff88083b3b1ad0 ffff88087fffeb08
    [ 6726.147593] ffff8803f202c000 7fffffffffffffff ffff88083f459c28 ffff88083b3b1ad0
    [ 6726.155132] ffff88035373c100 ffff8803f202bca8 ffffffff8168ced2 ffff8803f202bcb8
    [ 6726.162667] Call Trace:
    [ 6726.165150] [] schedule+0x32/0x80
    [ 6726.170156] [] schedule_timeout+0x214/0x290
    [ 6726.176030] [] ? __send_signal+0x52/0x4a0
    [ 6726.181728] [] wait_for_completion+0x96/0x100
    [ 6726.187774] [] ? wake_up_state+0x10/0x10
    [ 6726.193395] [] iscsit_reset_np_thread+0x62/0xe0 [iscsi_target_mod]
    [ 6726.201278] [] iscsit_tpg_disable_portal_group+0x96/0x190 [iscsi_target_mod]
    [ 6726.210033] [] lio_target_tpg_store_enable+0x4f/0xc0 [iscsi_target_mod]
    [ 6726.218351] [] configfs_write_file+0xaa/0x110
    [ 6726.224392] [] vfs_write+0xa4/0x1b0
    [ 6726.229576] [] SyS_write+0x41/0xb0
    [ 6726.234659] [] system_call_fastpath+0x12/0x71

    It would happen because each iscsit_reset_np_thread() sets state
    to ISCSI_NP_THREAD_RESET, sends SIGINT, and then blocks waiting
    for completion on iscsi_np->np_restart_comp.

    However, if iscsi_np was active processing a login request and
    more than a single iscsit_reset_np_thread() caller to the same
    iscsi_np was blocked on iscsi_np->np_restart_comp, iscsi_np
    kthread process context in __iscsi_target_login_thread() would
    flush pending signals and only perform a single completion of
    np->np_restart_comp before going back to sleep within transport
    specific iscsit_transport->iscsi_accept_np code.

    To address this bug, add a iscsi_np->np_reset_count and update
    __iscsi_target_login_thread() to keep completing np->np_restart_comp
    until ->np_reset_count has reached zero.

    Reported-by: Gary Guo
    Tested-by: Gary Guo
    Cc: Mike Christie
    Cc: Hannes Reinecke
    Cc: stable@vger.kernel.org # 3.10+
    Signed-off-by: Nicholas Bellinger

    Nicholas Bellinger
     

31 Jul, 2017

4 commits

  • The current logic of calculating sg_nents can fail
    if data_offset % PAGE_SIZE is not zero.

    For example -
    PAGE_SIZE = 4096
    data_len = 3072
    data_offset = 3072

    As per current logic
    sg_nents = max(1UL, DIV_ROUND_UP(data_len, PAGE_SIZE));
    sg_nents = max(1UL, DIV_ROUND_UP(3072, 4096));
    sg_nents = 1

    But as data_offset % PAGE_SIZE = 3072 we should skip 3072 bytes
    skip = 3K
    sg_nents = max(1UL, DIV_ROUND_UP(3K(skip) + 3K(data_len), 4K(PAGE_SIZE));
    sg_nents = 2;

    This patch fixes this issue by adding skip to data_len.

    Signed-off-by: Varun Prakash
    Signed-off-by: Nicholas Bellinger

    Varun Prakash
     
  • In case of multiple text responses iscsi-target
    sets both 'F' and 'C' bit for the final text response
    pdu, this issue happens because hdr->flags is not
    zeroed out before ORing with 'F' bit.

    This patch removes the | operator to fix this issue.

    Signed-off-by: Varun Prakash
    Signed-off-by: Nicholas Bellinger

    Varun Prakash
     
  • On receiving text request iscsi-target allocates buffer for
    payload in iscsit_handle_text_cmd() and assigns buffer pointer
    to cmd->text_in_ptr, this buffer is currently freed in
    iscsit_release_cmd(), if iscsi-target sets 'C' bit in text
    response then it will receive another text request from the
    initiator with ttt != 0xffffffff in this case iscsi-target
    will find cmd using itt and call iscsit_setup_text_cmd()
    which will set cmd->text_in_ptr to NULL without freeing
    previously allocated buffer.

    This patch fixes this issue by calling kfree(cmd->text_in_ptr)
    in iscsit_setup_text_cmd() before assigning NULL to it.

    For the first text request cmd->text_in_ptr is NULL as
    cmd is memset to 0 in iscsit_allocate_cmd().

    Signed-off-by: Varun Prakash
    Cc: # 4.0+
    Signed-off-by: Nicholas Bellinger

    Varun Prakash
     
  • Call __kfree_skb() after processing skb to avoid
    memory leak.

    Signed-off-by: Varun Prakash
    Signed-off-by: Nicholas Bellinger

    Varun Prakash