1. 01 Aug, 2022 6 commits
    • Hyunchul Lee's avatar
      ksmbd: prevent out of bound read for SMB2_TREE_CONNNECT · 824d4f64
      Hyunchul Lee authored
      if Status is not 0 and PathLength is long,
      smb_strndup_from_utf16 could make out of bound
      read in smb2_tree_connnect.
      
      This bug can lead an oops looking something like:
      
      [ 1553.882047] BUG: KASAN: slab-out-of-bounds in smb_strndup_from_utf16+0x469/0x4c0 [ksmbd]
      [ 1553.882064] Read of size 2 at addr ffff88802c4eda04 by task kworker/0:2/42805
      ...
      [ 1553.882095] Call Trace:
      [ 1553.882098]  <TASK>
      [ 1553.882101]  dump_stack_lvl+0x49/0x5f
      [ 1553.882107]  print_report.cold+0x5e/0x5cf
      [ 1553.882112]  ? smb_strndup_from_utf16+0x469/0x4c0 [ksmbd]
      [ 1553.882122]  kasan_report+0xaa/0x120
      [ 1553.882128]  ? smb_strndup_from_utf16+0x469/0x4c0 [ksmbd]
      [ 1553.882139]  __asan_report_load_n_noabort+0xf/0x20
      [ 1553.882143]  smb_strndup_from_utf16+0x469/0x4c0 [ksmbd]
      [ 1553.882155]  ? smb_strtoUTF16+0x3b0/0x3b0 [ksmbd]
      [ 1553.882166]  ? __kmalloc_node+0x185/0x430
      [ 1553.882171]  smb2_tree_connect+0x140/0xab0 [ksmbd]
      [ 1553.882185]  handle_ksmbd_work+0x30e/0x1020 [ksmbd]
      [ 1553.882197]  process_one_work+0x778/0x11c0
      [ 1553.882201]  ? _raw_spin_lock_irq+0x8e/0xe0
      [ 1553.882206]  worker_thread+0x544/0x1180
      [ 1553.882209]  ? __cpuidle_text_end+0x4/0x4
      [ 1553.882214]  kthread+0x282/0x320
      [ 1553.882218]  ? process_one_work+0x11c0/0x11c0
      [ 1553.882221]  ? kthread_complete_and_exit+0x30/0x30
      [ 1553.882225]  ret_from_fork+0x1f/0x30
      [ 1553.882231]  </TASK>
      
      There is no need to check error request validation in server.
      This check allow invalid requests not to validate message.
      
      Fixes: e2f34481 ("cifsd: add server-side procedures for SMB3")
      Cc: stable@vger.kernel.org
      Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17818
      Signed-off-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      824d4f64
    • Hyunchul Lee's avatar
      ksmbd: prevent out of bound read for SMB2_WRITE · ac60778b
      Hyunchul Lee authored
      OOB read memory can be written to a file,
      if DataOffset is 0 and Length is too large
      in SMB2_WRITE request of compound request.
      
      To prevent this, when checking the length of
      the data area of SMB2_WRITE in smb2_get_data_area_len(),
      let the minimum of DataOffset be the size of
      SMB2 header + the size of SMB2_WRITE header.
      
      This bug can lead an oops looking something like:
      
      [  798.008715] BUG: KASAN: slab-out-of-bounds in copy_page_from_iter_atomic+0xd3d/0x14b0
      [  798.008724] Read of size 252 at addr ffff88800f863e90 by task kworker/0:2/2859
      ...
      [  798.008754] Call Trace:
      [  798.008756]  <TASK>
      [  798.008759]  dump_stack_lvl+0x49/0x5f
      [  798.008764]  print_report.cold+0x5e/0x5cf
      [  798.008768]  ? __filemap_get_folio+0x285/0x6d0
      [  798.008774]  ? copy_page_from_iter_atomic+0xd3d/0x14b0
      [  798.008777]  kasan_report+0xaa/0x120
      [  798.008781]  ? copy_page_from_iter_atomic+0xd3d/0x14b0
      [  798.008784]  kasan_check_range+0x100/0x1e0
      [  798.008788]  memcpy+0x24/0x60
      [  798.008792]  copy_page_from_iter_atomic+0xd3d/0x14b0
      [  798.008795]  ? pagecache_get_page+0x53/0x160
      [  798.008799]  ? iov_iter_get_pages_alloc+0x1590/0x1590
      [  798.008803]  ? ext4_write_begin+0xfc0/0xfc0
      [  798.008807]  ? current_time+0x72/0x210
      [  798.008811]  generic_perform_write+0x2c8/0x530
      [  798.008816]  ? filemap_fdatawrite_wbc+0x180/0x180
      [  798.008820]  ? down_write+0xb4/0x120
      [  798.008824]  ? down_write_killable+0x130/0x130
      [  798.008829]  ext4_buffered_write_iter+0x137/0x2c0
      [  798.008833]  ext4_file_write_iter+0x40b/0x1490
      [  798.008837]  ? __fsnotify_parent+0x275/0xb20
      [  798.008842]  ? __fsnotify_update_child_dentry_flags+0x2c0/0x2c0
      [  798.008846]  ? ext4_buffered_write_iter+0x2c0/0x2c0
      [  798.008851]  __kernel_write+0x3a1/0xa70
      [  798.008855]  ? __x64_sys_preadv2+0x160/0x160
      [  798.008860]  ? security_file_permission+0x4a/0xa0
      [  798.008865]  kernel_write+0xbb/0x360
      [  798.008869]  ksmbd_vfs_write+0x27e/0xb90 [ksmbd]
      [  798.008881]  ? ksmbd_vfs_read+0x830/0x830 [ksmbd]
      [  798.008892]  ? _raw_read_unlock+0x2a/0x50
      [  798.008896]  smb2_write+0xb45/0x14e0 [ksmbd]
      [  798.008909]  ? __kasan_check_write+0x14/0x20
      [  798.008912]  ? _raw_spin_lock_bh+0xd0/0xe0
      [  798.008916]  ? smb2_read+0x15e0/0x15e0 [ksmbd]
      [  798.008927]  ? memcpy+0x4e/0x60
      [  798.008931]  ? _raw_spin_unlock+0x19/0x30
      [  798.008934]  ? ksmbd_smb2_check_message+0x16af/0x2350 [ksmbd]
      [  798.008946]  ? _raw_spin_lock_bh+0xe0/0xe0
      [  798.008950]  handle_ksmbd_work+0x30e/0x1020 [ksmbd]
      [  798.008962]  process_one_work+0x778/0x11c0
      [  798.008966]  ? _raw_spin_lock_irq+0x8e/0xe0
      [  798.008970]  worker_thread+0x544/0x1180
      [  798.008973]  ? __cpuidle_text_end+0x4/0x4
      [  798.008977]  kthread+0x282/0x320
      [  798.008982]  ? process_one_work+0x11c0/0x11c0
      [  798.008985]  ? kthread_complete_and_exit+0x30/0x30
      [  798.008989]  ret_from_fork+0x1f/0x30
      [  798.008995]  </TASK>
      
      Fixes: e2f34481 ("cifsd: add server-side procedures for SMB3")
      Cc: stable@vger.kernel.org
      Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17817
      Signed-off-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      ac60778b
    • Namjae Jeon's avatar
      ksmbd: fix use-after-free bug in smb2_tree_disconect · cf6531d9
      Namjae Jeon authored
      smb2_tree_disconnect() freed the struct ksmbd_tree_connect,
      but it left the dangling pointer. It can be accessed
      again under compound requests.
      
      This bug can lead an oops looking something link:
      
      [ 1685.468014 ] BUG: KASAN: use-after-free in ksmbd_tree_conn_disconnect+0x131/0x160 [ksmbd]
      [ 1685.468068 ] Read of size 4 at addr ffff888102172180 by task kworker/1:2/4807
      ...
      [ 1685.468130 ] Call Trace:
      [ 1685.468132 ]  <TASK>
      [ 1685.468135 ]  dump_stack_lvl+0x49/0x5f
      [ 1685.468141 ]  print_report.cold+0x5e/0x5cf
      [ 1685.468145 ]  ? ksmbd_tree_conn_disconnect+0x131/0x160 [ksmbd]
      [ 1685.468157 ]  kasan_report+0xaa/0x120
      [ 1685.468194 ]  ? ksmbd_tree_conn_disconnect+0x131/0x160 [ksmbd]
      [ 1685.468206 ]  __asan_report_load4_noabort+0x14/0x20
      [ 1685.468210 ]  ksmbd_tree_conn_disconnect+0x131/0x160 [ksmbd]
      [ 1685.468222 ]  smb2_tree_disconnect+0x175/0x250 [ksmbd]
      [ 1685.468235 ]  handle_ksmbd_work+0x30e/0x1020 [ksmbd]
      [ 1685.468247 ]  process_one_work+0x778/0x11c0
      [ 1685.468251 ]  ? _raw_spin_lock_irq+0x8e/0xe0
      [ 1685.468289 ]  worker_thread+0x544/0x1180
      [ 1685.468293 ]  ? __cpuidle_text_end+0x4/0x4
      [ 1685.468297 ]  kthread+0x282/0x320
      [ 1685.468301 ]  ? process_one_work+0x11c0/0x11c0
      [ 1685.468305 ]  ? kthread_complete_and_exit+0x30/0x30
      [ 1685.468309 ]  ret_from_fork+0x1f/0x30
      
      Fixes: e2f34481 ("cifsd: add server-side procedures for SMB3")
      Cc: stable@vger.kernel.org
      Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17816
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      cf6531d9
    • Namjae Jeon's avatar
      ksmbd: fix memory leak in smb2_handle_negotiate · aa7253c2
      Namjae Jeon authored
      The allocated memory didn't free under an error
      path in smb2_handle_negotiate().
      
      Fixes: e2f34481 ("cifsd: add server-side procedures for SMB3")
      Cc: stable@vger.kernel.org
      Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17815
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      aa7253c2
    • Namjae Jeon's avatar
      ksmbd: fix racy issue while destroying session on multichannel · af7c39d9
      Namjae Jeon authored
      After multi-channel connection with windows, Several channels of
      session are connected. Among them, if there is a problem in one channel,
      Windows connects again after disconnecting the channel. In this process,
      the session is released and a kernel oop can occurs while processing
      requests to other channels. When the channel is disconnected, if other
      channels still exist in the session after deleting the channel from
      the channel list in the session, the session should not be released.
      Finally, the session will be released after all channels are disconnected.
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      af7c39d9
    • Namjae Jeon's avatar
      ksmbd: use wait_event instead of schedule_timeout() · a14c5738
      Namjae Jeon authored
      ksmbd threads eating masses of cputime when connection is disconnected.
      If connection is disconnected, ksmbd thread waits for pending requests
      to be processed using schedule_timeout. schedule_timeout() incorrectly
      is used, and it is more efficient to use wait_event/wake_up than to check
      r_count every time with timeout.
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      a14c5738
  2. 27 Jul, 2022 3 commits
  3. 24 Jul, 2022 2 commits
  4. 17 Jul, 2022 15 commits
  5. 16 Jul, 2022 12 commits
  6. 15 Jul, 2022 2 commits
    • Linus Torvalds's avatar
      Merge tag 'riscv-for-linus-5.19-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux · 9b59ec8d
      Linus Torvalds authored
      Pull RISC-V fixes from Palmer Dabbelt:
      
       - A fix to avoid printing a warning when modules do not exercise any
         errata-dependent behavior and the SiFive errata are enabled.
      
       - A fix to the Microchip PFSOC to attach the L2 cache to the CPU nodes.
      
      * tag 'riscv-for-linus-5.19-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
        riscv: don't warn for sifive erratas in modules
        riscv: dts: microchip: hook up the mpfs' l2cache
      9b59ec8d
    • Linus Torvalds's avatar
      Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm · a8ebfcd3
      Linus Torvalds authored
      Pull KVM fixes from Paolo Bonzini:
       "RISC-V:
         - Fix missing PAGE_PFN_MASK
      
         - Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests()
      
        x86:
         - Fix for nested virtualization when TSC scaling is active
      
         - Estimate the size of fastcc subroutines conservatively, avoiding
           disastrous underestimation when return thunks are enabled
      
         - Avoid possible use of uninitialized fields of 'struct
           kvm_lapic_irq'
      
        Generic:
         - Mark as such the boolean values available from the statistics file
           descriptors
      
         - Clarify statistics documentation"
      
      * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
        KVM: emulate: do not adjust size of fastop and setcc subroutines
        KVM: x86: Fully initialize 'struct kvm_lapic_irq' in kvm_pv_kick_cpu_op()
        Documentation: kvm: clarify histogram units
        kvm: stats: tell userspace which values are boolean
        x86/kvm: fix FASTOP_SIZE when return thunks are enabled
        KVM: nVMX: Always enable TSC scaling for L2 when it was enabled for L1
        RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests()
        riscv: Fix missing PAGE_PFN_MASK
      a8ebfcd3