1. 04 Aug, 2022 1 commit
    • Namjae Jeon's avatar
      ksmbd: fix heap-based overflow in set_ntacl_dacl() · 8f054118
      Namjae Jeon authored
      The testcase use SMB2_SET_INFO_HE command to set a malformed file attribute
      under the label `security.NTACL`. SMB2_QUERY_INFO_HE command in testcase
      trigger the following overflow.
      
      [ 4712.003781] ==================================================================
      [ 4712.003790] BUG: KASAN: slab-out-of-bounds in build_sec_desc+0x842/0x1dd0 [ksmbd]
      [ 4712.003807] Write of size 1060 at addr ffff88801e34c068 by task kworker/0:0/4190
      
      [ 4712.003813] CPU: 0 PID: 4190 Comm: kworker/0:0 Not tainted 5.19.0-rc5 #1
      [ 4712.003850] Workqueue: ksmbd-io handle_ksmbd_work [ksmbd]
      [ 4712.003867] Call Trace:
      [ 4712.003870]  <TASK>
      [ 4712.003873]  dump_stack_lvl+0x49/0x5f
      [ 4712.003935]  print_report.cold+0x5e/0x5cf
      [ 4712.003972]  ? ksmbd_vfs_get_sd_xattr+0x16d/0x500 [ksmbd]
      [ 4712.003984]  ? cmp_map_id+0x200/0x200
      [ 4712.003988]  ? build_sec_desc+0x842/0x1dd0 [ksmbd]
      [ 4712.004000]  kasan_report+0xaa/0x120
      [ 4712.004045]  ? build_sec_desc+0x842/0x1dd0 [ksmbd]
      [ 4712.004056]  kasan_check_range+0x100/0x1e0
      [ 4712.004060]  memcpy+0x3c/0x60
      [ 4712.004064]  build_sec_desc+0x842/0x1dd0 [ksmbd]
      [ 4712.004076]  ? parse_sec_desc+0x580/0x580 [ksmbd]
      [ 4712.004088]  ? ksmbd_acls_fattr+0x281/0x410 [ksmbd]
      [ 4712.004099]  smb2_query_info+0xa8f/0x6110 [ksmbd]
      [ 4712.004111]  ? psi_group_change+0x856/0xd70
      [ 4712.004148]  ? update_load_avg+0x1c3/0x1af0
      [ 4712.004152]  ? asym_cpu_capacity_scan+0x5d0/0x5d0
      [ 4712.004157]  ? xas_load+0x23/0x300
      [ 4712.004162]  ? smb2_query_dir+0x1530/0x1530 [ksmbd]
      [ 4712.004173]  ? _raw_spin_lock_bh+0xe0/0xe0
      [ 4712.004179]  handle_ksmbd_work+0x30e/0x1020 [ksmbd]
      [ 4712.004192]  process_one_work+0x778/0x11c0
      [ 4712.004227]  ? _raw_spin_lock_irq+0x8e/0xe0
      [ 4712.004231]  worker_thread+0x544/0x1180
      [ 4712.004234]  ? __cpuidle_text_end+0x4/0x4
      [ 4712.004239]  kthread+0x282/0x320
      [ 4712.004243]  ? process_one_work+0x11c0/0x11c0
      [ 4712.004246]  ? kthread_complete_and_exit+0x30/0x30
      [ 4712.004282]  ret_from_fork+0x1f/0x30
      
      This patch add the buffer validation for security descriptor that is
      stored by malformed SMB2_SET_INFO_HE command. and allocate large
      response buffer about SMB2_O_INFO_SECURITY file info class.
      
      Fixes: e2f34481 ("cifsd: add server-side procedures for SMB3")
      Cc: stable@vger.kernel.org
      Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-17771
      Reviewed-by: default avatarHyunchul Lee <hyc.lee@gmail.com>
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      8f054118
  2. 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
  3. 27 Jul, 2022 3 commits
  4. 24 Jul, 2022 2 commits
  5. 17 Jul, 2022 15 commits
  6. 16 Jul, 2022 12 commits
  7. 15 Jul, 2022 1 commit