1. 15 3月, 2023 2 次提交
    • M
      scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress · 744050c7
      Mike Christie 提交于
      mainline inclusion
      from mainline-v6.2-rc6
      commit 6f1d64b1
      category: bugfix
      bugzilla: 188443, https://gitee.com/openeuler/kernel/issues/I6I8YD
      CVE: NA
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6f1d64b13097e85abda0f91b5638000afc5f9a06
      
      ----------------------------------------
      
      Bug report and analysis from Ding Hui.
      
      During iSCSI session logout, if another task accesses the shost ipaddress
      attr, we can get a KASAN UAF report like this:
      
      [  276.942144] BUG: KASAN: use-after-free in _raw_spin_lock_bh+0x78/0xe0
      [  276.942535] Write of size 4 at addr ffff8881053b45b8 by task cat/4088
      [  276.943511] CPU: 2 PID: 4088 Comm: cat Tainted: G            E      6.1.0-rc8+ #3
      [  276.943997] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020
      [  276.944470] Call Trace:
      [  276.944943]  <TASK>
      [  276.945397]  dump_stack_lvl+0x34/0x48
      [  276.945887]  print_address_description.constprop.0+0x86/0x1e7
      [  276.946421]  print_report+0x36/0x4f
      [  276.947358]  kasan_report+0xad/0x130
      [  276.948234]  kasan_check_range+0x35/0x1c0
      [  276.948674]  _raw_spin_lock_bh+0x78/0xe0
      [  276.949989]  iscsi_sw_tcp_host_get_param+0xad/0x2e0 [iscsi_tcp]
      [  276.951765]  show_host_param_ISCSI_HOST_PARAM_IPADDRESS+0xe9/0x130 [scsi_transport_iscsi]
      [  276.952185]  dev_attr_show+0x3f/0x80
      [  276.953005]  sysfs_kf_seq_show+0x1fb/0x3e0
      [  276.953401]  seq_read_iter+0x402/0x1020
      [  276.954260]  vfs_read+0x532/0x7b0
      [  276.955113]  ksys_read+0xed/0x1c0
      [  276.955952]  do_syscall_64+0x38/0x90
      [  276.956347]  entry_SYSCALL_64_after_hwframe+0x63/0xcd
      [  276.956769] RIP: 0033:0x7f5d3a679222
      [  276.957161] Code: c0 e9 b2 fe ff ff 50 48 8d 3d 32 c0 0b 00 e8 a5 fe 01 00 0f 1f 44 00 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 0f 05 <48> 3d 00 f0 ff ff 77 56 c3 0f 1f 44 00 00 48 83 ec 28 48 89 54 24
      [  276.958009] RSP: 002b:00007ffc864d16a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
      [  276.958431] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f5d3a679222
      [  276.958857] RDX: 0000000000020000 RSI: 00007f5d3a4fe000 RDI: 0000000000000003
      [  276.959281] RBP: 00007f5d3a4fe000 R08: 00000000ffffffff R09: 0000000000000000
      [  276.959682] R10: 0000000000000022 R11: 0000000000000246 R12: 0000000000020000
      [  276.960126] R13: 0000000000000003 R14: 0000000000000000 R15: 0000557a26dada58
      [  276.960536]  </TASK>
      [  276.961357] Allocated by task 2209:
      [  276.961756]  kasan_save_stack+0x1e/0x40
      [  276.962170]  kasan_set_track+0x21/0x30
      [  276.962557]  __kasan_kmalloc+0x7e/0x90
      [  276.962923]  __kmalloc+0x5b/0x140
      [  276.963308]  iscsi_alloc_session+0x28/0x840 [scsi_transport_iscsi]
      [  276.963712]  iscsi_session_setup+0xda/0xba0 [libiscsi]
      [  276.964078]  iscsi_sw_tcp_session_create+0x1fd/0x330 [iscsi_tcp]
      [  276.964431]  iscsi_if_create_session.isra.0+0x50/0x260 [scsi_transport_iscsi]
      [  276.964793]  iscsi_if_recv_msg+0xc5a/0x2660 [scsi_transport_iscsi]
      [  276.965153]  iscsi_if_rx+0x198/0x4b0 [scsi_transport_iscsi]
      [  276.965546]  netlink_unicast+0x4d5/0x7b0
      [  276.965905]  netlink_sendmsg+0x78d/0xc30
      [  276.966236]  sock_sendmsg+0xe5/0x120
      [  276.966576]  ____sys_sendmsg+0x5fe/0x860
      [  276.966923]  ___sys_sendmsg+0xe0/0x170
      [  276.967300]  __sys_sendmsg+0xc8/0x170
      [  276.967666]  do_syscall_64+0x38/0x90
      [  276.968028]  entry_SYSCALL_64_after_hwframe+0x63/0xcd
      [  276.968773] Freed by task 2209:
      [  276.969111]  kasan_save_stack+0x1e/0x40
      [  276.969449]  kasan_set_track+0x21/0x30
      [  276.969789]  kasan_save_free_info+0x2a/0x50
      [  276.970146]  __kasan_slab_free+0x106/0x190
      [  276.970470]  __kmem_cache_free+0x133/0x270
      [  276.970816]  device_release+0x98/0x210
      [  276.971145]  kobject_cleanup+0x101/0x360
      [  276.971462]  iscsi_session_teardown+0x3fb/0x530 [libiscsi]
      [  276.971775]  iscsi_sw_tcp_session_destroy+0xd8/0x130 [iscsi_tcp]
      [  276.972143]  iscsi_if_recv_msg+0x1bf1/0x2660 [scsi_transport_iscsi]
      [  276.972485]  iscsi_if_rx+0x198/0x4b0 [scsi_transport_iscsi]
      [  276.972808]  netlink_unicast+0x4d5/0x7b0
      [  276.973201]  netlink_sendmsg+0x78d/0xc30
      [  276.973544]  sock_sendmsg+0xe5/0x120
      [  276.973864]  ____sys_sendmsg+0x5fe/0x860
      [  276.974248]  ___sys_sendmsg+0xe0/0x170
      [  276.974583]  __sys_sendmsg+0xc8/0x170
      [  276.974891]  do_syscall_64+0x38/0x90
      [  276.975216]  entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      We can easily reproduce by two tasks:
      1. while :; do iscsiadm -m node --login; iscsiadm -m node --logout; done
      2. while :; do cat \
      /sys/devices/platform/host*/iscsi_host/host*/ipaddress; done
      
                  iscsid              |        cat
      --------------------------------+---------------------------------------
      |- iscsi_sw_tcp_session_destroy |
        |- iscsi_session_teardown     |
          |- device_release           |
            |- iscsi_session_release  ||- dev_attr_show
              |- kfree                |  |- show_host_param_
                                      |             ISCSI_HOST_PARAM_IPADDRESS
                                      |    |- iscsi_sw_tcp_host_get_param
                                      |      |- r/w tcp_sw_host->session (UAF)
        |- iscsi_host_remove          |
        |- iscsi_host_free            |
      
      Fix the above bug by splitting the session removal into 2 parts:
      
       1. removal from iSCSI class which includes sysfs and removal from host
          tracking.
      
       2. freeing of session.
      
      During iscsi_tcp host and session removal we can remove the session from
      sysfs then remove the host from sysfs. At this point we know userspace is
      not accessing the kernel via sysfs so we can free the session and host.
      
      Link: https://lore.kernel.org/r/20230117193937.21244-2-michael.christie@oracle.comSigned-off-by: NMike Christie <michael.christie@oracle.com>
      Reviewed-by: NLee Duncan <lduncan@suse.com>
      Acked-by: NDing Hui <dinghui@sangfor.com.cn>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NZhong Jinghua <zhongjinghua@huawei.com>
      conflicts:
      	drivers/scsi/iscsi_tcp.c
      Reviewed-by: NHou Tao <houtao1@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      744050c7
    • M
      scsi: iscsi: Move pool freeing · 7883e908
      Mike Christie 提交于
      mainline inclusion
      from mainline-v5.14-rc1
      commit a1f3486b
      category: bugfix
      bugzilla: 188443, https://gitee.com/openeuler/kernel/issues/I6I8YD
      CVE: NA
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a1f3486b3b095ed2259d7a1fc021a8b6e72a5365
      
      ----------------------------------------
      
      This doesn't fix any bugs, but it makes more sense to free the pool after
      we have removed the session. At that time we know nothing is touching any
      of the session fields, because all devices have been removed and scans are
      stopped.
      
      Link: https://lore.kernel.org/r/20210525181821.7617-19-michael.christie@oracle.comReviewed-by: NLee Duncan <lduncan@suse.com>
      Signed-off-by: NMike Christie <michael.christie@oracle.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NZhong Jinghua <zhongjinghua@huawei.com>
      Reviewed-by: NHou Tao <houtao1@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      7883e908
  2. 21 9月, 2022 2 次提交
  3. 19 7月, 2022 1 次提交
  4. 28 1月, 2022 1 次提交
  5. 26 11月, 2021 1 次提交
    • B
      iscsi: use dynamic single thread workqueue to improve performance · 4728ac82
      Biaoxiang Ye 提交于
      euleros inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4IZNO
      CVE: NA
      
      -------------------------------------------------
      
      On aarch64 NUMA machines, the kworker of iscsi created always jump
      around across node boundaries. If it work on the different node even
      different cpu package with the softirq of network interface, memcpy
      with in iscsi_tcp_segment_recv will be slow down, and iscsi got an
      terrible performance.
      
      In this patch, we trace the cpu of softirq, and tell queue_work_on
      to execute iscsi_xmitworker on the same NUMA node.
      
      The performance data as below:
      fio cmd:
      fio -filename=/dev/disk/by-id/wwn-0x6883fd3100a2ad260036281700000000
      -direct=1 -iodepth=32 -rw=read -bs=64k -size=30G -ioengine=libaio
      -numjobs=1 -group_reporting -name=mytest -time_based -ramp_time=60
      -runtime=60
      
      before patch:
      Jobs: 1 (f=1): [R] [52.5% done] [852.3MB/0KB/0KB /s] [13.7K/0/0 iops] [eta 00m:57s]
      Jobs: 1 (f=1): [R] [53.3% done] [861.4MB/0KB/0KB /s] [13.8K/0/0 iops] [eta 00m:56s]
      Jobs: 1 (f=1): [R] [54.2% done] [868.2MB/0KB/0KB /s] [13.9K/0/0 iops] [eta 00m:55s]
      
      after pactch:
      Jobs: 1 (f=1): [R] [53.3% done] [1070MB/0KB/0KB /s] [17.2K/0/0 iops] [eta 00m:56s]
      Jobs: 1 (f=1): [R] [55.0% done] [1064MB/0KB/0KB /s] [17.3K/0/0 iops] [eta 00m:54s]
      Jobs: 1 (f=1): [R] [56.7% done] [1069MB/0KB/0KB /s] [17.1K/0/0 iops] [eta 00m:52s]
      
      cpu info:
      Architecture:          aarch64
      Byte Order:            Little Endian
      CPU(s):                128
      On-line CPU(s) list:   0-127
      Thread(s) per core:    1
      Core(s) per socket:    64
      Socket(s):             2
      NUMA node(s):          4
      Model:                 0
      CPU max MHz:           2600.0000
      CPU min MHz:           200.0000
      BogoMIPS:              200.00
      L1d cache:             64K
      L1i cache:             64K
      L2 cache:              512K
      L3 cache:              32768K
      NUMA node0 CPU(s):     0-31
      NUMA node1 CPU(s):     32-63
      NUMA node2 CPU(s):     64-95
      NUMA node3 CPU(s):     96-127
      Signed-off-by: NBiaoxiang Ye <yebiaoxiang@huawei.com>
      Acked-by: NHanjun Guo <guohanjun@huawei.com>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: Nfang yi <eric.fangyi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      4728ac82
  6. 15 10月, 2021 2 次提交
  7. 03 7月, 2021 6 次提交
  8. 09 4月, 2021 2 次提交
  9. 17 11月, 2020 1 次提交
  10. 24 8月, 2020 1 次提交
  11. 03 7月, 2020 1 次提交
  12. 27 5月, 2020 1 次提交
  13. 27 3月, 2020 2 次提交
  14. 10 12月, 2019 1 次提交
    • B
      scsi: iscsi: Fix a potential deadlock in the timeout handler · 5480e299
      Bart Van Assche 提交于
      Some time ago the block layer was modified such that timeout handlers are
      called from thread context instead of interrupt context. Make it safe to
      run the iSCSI timeout handler in thread context. This patch fixes the
      following lockdep complaint:
      
      ================================
      WARNING: inconsistent lock state
      5.5.1-dbg+ #11 Not tainted
      --------------------------------
      inconsistent {IN-SOFTIRQ-W} -> {SOFTIRQ-ON-W} usage.
      kworker/7:1H/206 [HC0[0]:SC0[0]:HE1:SE1] takes:
      ffff88802d9827e8 (&(&session->frwd_lock)->rlock){+.?.}, at: iscsi_eh_cmd_timed_out+0xa6/0x6d0 [libiscsi]
      {IN-SOFTIRQ-W} state was registered at:
        lock_acquire+0x106/0x240
        _raw_spin_lock+0x38/0x50
        iscsi_check_transport_timeouts+0x3e/0x210 [libiscsi]
        call_timer_fn+0x132/0x470
        __run_timers.part.0+0x39f/0x5b0
        run_timer_softirq+0x63/0xc0
        __do_softirq+0x12d/0x5fd
        irq_exit+0xb3/0x110
        smp_apic_timer_interrupt+0x131/0x3d0
        apic_timer_interrupt+0xf/0x20
        default_idle+0x31/0x230
        arch_cpu_idle+0x13/0x20
        default_idle_call+0x53/0x60
        do_idle+0x38a/0x3f0
        cpu_startup_entry+0x24/0x30
        start_secondary+0x222/0x290
        secondary_startup_64+0xa4/0xb0
      irq event stamp: 1383705
      hardirqs last  enabled at (1383705): [<ffffffff81aace5c>] _raw_spin_unlock_irq+0x2c/0x50
      hardirqs last disabled at (1383704): [<ffffffff81aacb98>] _raw_spin_lock_irq+0x18/0x50
      softirqs last  enabled at (1383690): [<ffffffffa0e2efea>] iscsi_queuecommand+0x76a/0xa20 [libiscsi]
      softirqs last disabled at (1383682): [<ffffffffa0e2e998>] iscsi_queuecommand+0x118/0xa20 [libiscsi]
      
      other info that might help us debug this:
       Possible unsafe locking scenario:
      
             CPU0
             ----
        lock(&(&session->frwd_lock)->rlock);
        <Interrupt>
          lock(&(&session->frwd_lock)->rlock);
      
       *** DEADLOCK ***
      
      2 locks held by kworker/7:1H/206:
       #0: ffff8880d57bf928 ((wq_completion)kblockd){+.+.}, at: process_one_work+0x472/0xab0
       #1: ffff88802b9c7de8 ((work_completion)(&q->timeout_work)){+.+.}, at: process_one_work+0x476/0xab0
      
      stack backtrace:
      CPU: 7 PID: 206 Comm: kworker/7:1H Not tainted 5.5.1-dbg+ #11
      Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      Workqueue: kblockd blk_mq_timeout_work
      Call Trace:
       dump_stack+0xa5/0xe6
       print_usage_bug.cold+0x232/0x23b
       mark_lock+0x8dc/0xa70
       __lock_acquire+0xcea/0x2af0
       lock_acquire+0x106/0x240
       _raw_spin_lock+0x38/0x50
       iscsi_eh_cmd_timed_out+0xa6/0x6d0 [libiscsi]
       scsi_times_out+0xf4/0x440 [scsi_mod]
       scsi_timeout+0x1d/0x20 [scsi_mod]
       blk_mq_check_expired+0x365/0x3a0
       bt_iter+0xd6/0xf0
       blk_mq_queue_tag_busy_iter+0x3de/0x650
       blk_mq_timeout_work+0x1af/0x380
       process_one_work+0x56d/0xab0
       worker_thread+0x7a/0x5d0
       kthread+0x1bc/0x210
       ret_from_fork+0x24/0x30
      
      Fixes: 287922eb ("block: defer timeouts to a workqueue")
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Lee Duncan <lduncan@suse.com>
      Cc: Chris Leech <cleech@redhat.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191209173457.187370-1-bvanassche@acm.orgSigned-off-by: NBart Van Assche <bvanassche@acm.org>
      Reviewed-by: NLee Duncan <lduncan@suse.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      5480e299
  15. 31 5月, 2019 1 次提交
  16. 21 5月, 2019 1 次提交
  17. 08 3月, 2019 1 次提交
  18. 16 2月, 2019 1 次提交
    • A
      scsi: libiscsi: Fix race between iscsi_xmit_task and iscsi_complete_task · 79edd00d
      Anoob Soman 提交于
      When a target sends Check Condition, whilst initiator is busy xmiting
      re-queued data, could lead to race between iscsi_complete_task() and
      iscsi_xmit_task() and eventually crashing with the following kernel
      backtrace.
      
      [3326150.987523] ALERT: BUG: unable to handle kernel NULL pointer dereference at 0000000000000078
      [3326150.987549] ALERT: IP: [<ffffffffa05ce70d>] iscsi_xmit_task+0x2d/0xc0 [libiscsi]
      [3326150.987571] WARN: PGD 569c8067 PUD 569c9067 PMD 0
      [3326150.987582] WARN: Oops: 0002 [#1] SMP
      [3326150.987593] WARN: Modules linked in: tun nfsv3 nfs fscache dm_round_robin
      [3326150.987762] WARN: CPU: 2 PID: 8399 Comm: kworker/u32:1 Tainted: G O 4.4.0+2 #1
      [3326150.987774] WARN: Hardware name: Dell Inc. PowerEdge R720/0W7JN5, BIOS 2.5.4 01/22/2016
      [3326150.987790] WARN: Workqueue: iscsi_q_13 iscsi_xmitworker [libiscsi]
      [3326150.987799] WARN: task: ffff8801d50f3800 ti: ffff8801f5458000 task.ti: ffff8801f5458000
      [3326150.987810] WARN: RIP: e030:[<ffffffffa05ce70d>] [<ffffffffa05ce70d>] iscsi_xmit_task+0x2d/0xc0 [libiscsi]
      [3326150.987825] WARN: RSP: e02b:ffff8801f545bdb0 EFLAGS: 00010246
      [3326150.987831] WARN: RAX: 00000000ffffffc3 RBX: ffff880282d2ab20 RCX: ffff88026b6ac480
      [3326150.987842] WARN: RDX: 0000000000000000 RSI: 00000000fffffe01 RDI: ffff880282d2ab20
      [3326150.987852] WARN: RBP: ffff8801f545bdc8 R08: 0000000000000000 R09: 0000000000000008
      [3326150.987862] WARN: R10: 0000000000000000 R11: 000000000000fe88 R12: 0000000000000000
      [3326150.987872] WARN: R13: ffff880282d2abe8 R14: ffff880282d2abd8 R15: ffff880282d2ac08
      [3326150.987890] WARN: FS: 00007f5a866b4840(0000) GS:ffff88028a640000(0000) knlGS:0000000000000000
      [3326150.987900] WARN: CS: e033 DS: 0000 ES: 0000 CR0: 0000000080050033
      [3326150.987907] WARN: CR2: 0000000000000078 CR3: 0000000070244000 CR4: 0000000000042660
      [3326150.987918] WARN: Stack:
      [3326150.987924] WARN: ffff880282d2ad58 ffff880282d2ab20 ffff880282d2abe8 ffff8801f545be18
      [3326150.987938] WARN: ffffffffa05cea90 ffff880282d2abf8 ffff88026b59cc80 ffff88026b59cc00
      [3326150.987951] WARN: ffff88022acf32c0 ffff880289491800 ffff880255a80800 0000000000000400
      [3326150.987964] WARN: Call Trace:
      [3326150.987975] WARN: [<ffffffffa05cea90>] iscsi_xmitworker+0x2f0/0x360 [libiscsi]
      [3326150.987988] WARN: [<ffffffff8108862c>] process_one_work+0x1fc/0x3b0
      [3326150.987997] WARN: [<ffffffff81088f95>] worker_thread+0x2a5/0x470
      [3326150.988006] WARN: [<ffffffff8159cad8>] ? __schedule+0x648/0x870
      [3326150.988015] WARN: [<ffffffff81088cf0>] ? rescuer_thread+0x300/0x300
      [3326150.988023] WARN: [<ffffffff8108ddf5>] kthread+0xd5/0xe0
      [3326150.988031] WARN: [<ffffffff8108dd20>] ? kthread_stop+0x110/0x110
      [3326150.988040] WARN: [<ffffffff815a0bcf>] ret_from_fork+0x3f/0x70
      [3326150.988048] WARN: [<ffffffff8108dd20>] ? kthread_stop+0x110/0x110
      [3326150.988127] ALERT: RIP [<ffffffffa05ce70d>] iscsi_xmit_task+0x2d/0xc0 [libiscsi]
      [3326150.988138] WARN: RSP <ffff8801f545bdb0>
      [3326150.988144] WARN: CR2: 0000000000000078
      [3326151.020366] WARN: ---[ end trace 1c60974d4678d81b ]---
      
      Commit 6f8830f5 ("scsi: libiscsi: add lock around task lists to fix
      list corruption regression") introduced "taskqueuelock" to fix list
      corruption during the race, but this wasn't enough.
      
      Re-setting of conn->task to NULL, could race with iscsi_xmit_task().
      iscsi_complete_task()
      {
          ....
          if (conn->task == task)
              conn->task = NULL;
      }
      
      conn->task in iscsi_xmit_task() could be NULL and so will be task.
      __iscsi_get_task(task) will crash (NullPtr de-ref), trying to access
      refcount.
      
      iscsi_xmit_task()
      {
          struct iscsi_task *task = conn->task;
      
          __iscsi_get_task(task);
      }
      
      This commit will take extra conn->session->back_lock in iscsi_xmit_task()
      to ensure iscsi_xmit_task() waits for iscsi_complete_task(), if
      iscsi_complete_task() wins the race.  If iscsi_xmit_task() wins the race,
      iscsi_xmit_task() increments task->refcount
      (__iscsi_get_task) ensuring iscsi_complete_task() will not iscsi_free_task().
      Signed-off-by: NAnoob Soman <anoob.soman@citrix.com>
      Signed-off-by: NBob Liu <bob.liu@oracle.com>
      Acked-by: NLee Duncan <lduncan@suse.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      79edd00d
  19. 13 2月, 2019 1 次提交
  20. 06 2月, 2019 1 次提交
  21. 21 12月, 2018 1 次提交
  22. 29 11月, 2018 1 次提交
  23. 31 7月, 2018 2 次提交
  24. 13 7月, 2018 1 次提交
    • V
      scsi: libiscsi: fix possible NULL pointer dereference in case of TMF · a17037e7
      Varun Prakash 提交于
      In iscsi_check_tmf_restrictions() task->hdr is dereferenced to print the
      opcode, it is possible that task->hdr is NULL.
      
      There are two cases based on opcode argument:
      
      1. ISCSI_OP_SCSI_CMD - In this case alloc_pdu() is called
      after iscsi_check_tmf_restrictions()
      
      iscsi_prep_scsi_cmd_pdu() -> iscsi_check_tmf_restrictions() -> alloc_pdu().
      
      Transport drivers allocate memory for iSCSI hdr in alloc_pdu() and assign
      it to task->hdr. In case of TMF task->hdr will be NULL resulting in NULL
      pointer dereference.
      
      2. ISCSI_OP_SCSI_DATA_OUT - In this case transport driver can free the
      memory for iSCSI hdr after transmitting the pdu so task->hdr can be NULL or
      invalid.
      
      This patch fixes this issue by removing task->hdr->opcode from the printk
      statement.
      Signed-off-by: NVarun Prakash <varun@chelsio.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      a17037e7
  25. 13 6月, 2018 1 次提交
    • K
      treewide: kvzalloc() -> kvcalloc() · 778e1cdd
      Kees Cook 提交于
      The kvzalloc() function has a 2-factor argument form, kvcalloc(). This
      patch replaces cases of:
      
              kvzalloc(a * b, gfp)
      
      with:
              kvcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kvzalloc(a * b * c, gfp)
      
      with:
      
              kvzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kvcalloc(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kvzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kvzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kvzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kvzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kvzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kvzalloc
      + kvcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kvzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kvzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kvzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kvzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kvzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kvzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kvzalloc(C1 * C2 * C3, ...)
      |
        kvzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kvzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kvzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kvzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kvzalloc(sizeof(THING) * C2, ...)
      |
        kvzalloc(sizeof(TYPE) * C2, ...)
      |
        kvzalloc(C1 * C2 * C3, ...)
      |
        kvzalloc(C1 * C2, ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kvzalloc
      + kvcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      778e1cdd
  26. 29 5月, 2018 2 次提交
  27. 04 1月, 2018 2 次提交
    • R
      scsi: doc: fix iscsi-related kernel-doc warnings · ccd4a430
      Randy Dunlap 提交于
      Fix kernel-doc warnings in drivers/scsi/ that are related to iscsi
      support interfaces.
      
      Fixes these kernel-doc warnings: (tested by adding these files to a new
      target.rst documentation file: WIP)
      
      ../drivers/scsi/libiscsi.c:2740: warning: No description found for parameter 'dd_size'
      ../drivers/scsi/libiscsi.c:2740: warning: No description found for parameter 'id'
      ../drivers/scsi/libiscsi.c:2961: warning: No description found for parameter 'cls_conn'
      ../drivers/scsi/iscsi_tcp.c:313: warning: No description found for parameter 'conn'
      ../drivers/scsi/iscsi_tcp.c:363: warning: No description found for parameter 'conn'
      ../drivers/scsi/libiscsi_tcp.c:810: warning: No description found for parameter 'tcp_conn'
      ../drivers/scsi/libiscsi_tcp.c:810: warning: No description found for parameter 'segment'
      ../drivers/scsi/libiscsi_tcp.c:887: warning: No description found for parameter 'offloaded'
      ../drivers/scsi/libiscsi_tcp.c:887: warning: No description found for parameter 'status'
      ../drivers/scsi/libiscsi_tcp.c:887: warning: Excess function parameter 'offload' description in 'iscsi_tcp_recv_skb'
      ../drivers/scsi/libiscsi_tcp.c:964: warning: Excess function parameter 'conn' description in 'iscsi_tcp_task_init'
      ../drivers/scsi/libiscsi_tcp.c:964: warning: Excess function parameter 'sc' description in 'iscsi_tcp_task_init'
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
      Cc: linux-scsi@vger.kernel.org
      Cc: target-devel@vger.kernel.org
      Cc: Sagi Grimberg <sagi@grimberg.me>
      Cc: linux-rdma@vger.kernel.org
      Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      ccd4a430
    • R
      scsi: libiscsi: Allow sd_shutdown on bad transport · d7549412
      Rafael David Tinoco 提交于
      If, for any reason, userland shuts down iscsi transport interfaces
      before proper logouts - like when logging in to LUNs manually, without
      logging out on server shutdown, or when automated scripts can't
      umount/logout from logged LUNs - kernel will hang forever on its
      sd_sync_cache() logic, after issuing the SYNCHRONIZE_CACHE cmd to all
      still existent paths.
      
      PID: 1 TASK: ffff8801a69b8000 CPU: 1 COMMAND: "systemd-shutdow"
       #0 [ffff8801a69c3a30] __schedule at ffffffff8183e9ee
       #1 [ffff8801a69c3a80] schedule at ffffffff8183f0d5
       #2 [ffff8801a69c3a98] schedule_timeout at ffffffff81842199
       #3 [ffff8801a69c3b40] io_schedule_timeout at ffffffff8183e604
       #4 [ffff8801a69c3b70] wait_for_completion_io_timeout at ffffffff8183fc6c
       #5 [ffff8801a69c3bd0] blk_execute_rq at ffffffff813cfe10
       #6 [ffff8801a69c3c88] scsi_execute at ffffffff815c3fc7
       #7 [ffff8801a69c3cc8] scsi_execute_req_flags at ffffffff815c60fe
       #8 [ffff8801a69c3d30] sd_sync_cache at ffffffff815d37d7
       #9 [ffff8801a69c3da8] sd_shutdown at ffffffff815d3c3c
      
      This happens because iscsi_eh_cmd_timed_out(), the transport layer
      timeout helper, would tell the queue timeout function (scsi_times_out)
      to reset the request timer over and over, until the session state is
      back to logged in state. Unfortunately, during server shutdown, this
      might never happen again.
      
      Other option would be "not to handle" the issue in the transport
      layer. That would trigger the error handler logic, which would also need
      the session state to be logged in again.
      
      Best option, for such case, is to tell upper layers that the command was
      handled during the transport layer error handler helper, marking it as
      DID_NO_CONNECT, which will allow completion and inform about the
      problem.
      
      After the session was marked as ISCSI_STATE_FAILED, due to the first
      timeout during the server shutdown phase, all subsequent cmds will fail
      to be queued, allowing upper logic to fail faster.
      Signed-off-by: NRafael David Tinoco <rafael.tinoco@canonical.com>
      Reviewed-by: NLee Duncan <lduncan@suse.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      d7549412