From SambaWiki
Revision as of 02:18, 21 September 2021 by Sahlberg (talk | contribs) (I don;t know what was going on here)

There are various checks that are especially important for SMB3 servers. They fall into multiple categories:

  • packet processing checks to make sure buffers do not overflow, allowing access to data outside the SMB request
  • path processing checks to make sure access to files outside the share is not permitted, these include checks for ".." or "../.." to make sure they do not go outside the share, and checks for symlinks in paths and checks to ensure paths do not allow a processed path e.g. with "\" or "/" to go outside the share. These primarily impact three operations (open, query directory and rename) as unlike SMB1 most SMB2/SMB3 operations are handle based, not path based.
  • denial of service and resource checks (e.g. ensure that no single client can exhaust the server by opening millions of files, or use so many credits that they submit thousands of simultaneous requests starving other clients)

In addition, it is important that servers only implement reasonably secure dialects and authentication mechanisms by default. For example SMB2.1 or later supports protection against "man in the middle" attacks, and should be the minimum version supported by default. In addition, NTLMv1 authentication should be disabled (NTLMv2 can be allowed, although 8 character and longer passwords may be a good minimum to require by default). Kerberos authentication should also be supported. In the longer run, especially to support Macs (which allow at least two additional peer-to-peer authentication mechanisms which look promising) we can consider adding additional mechanisms, but currently NTLMv2 (encapsulated in NTLMSSP during negotiation) is for "peer to peer" use cases, and Kerberos for domain joined cases.

SMB3.1.1 supports very strong signing and encryption options (e.g. GCM256 encryption), and it may be helpful to ensure that users know about the advantages of using current SMB3.1.1 so they don't choose less secure options.

Packet processing checks in ksmbd
Type of check Status (submitted, reviewed) Function(s) including the check (and patch name if not included yet) Additional work if any
SMB3 header validation Already implemented See ksmbd_smb2_check_message function in smb2misc.c and ksmbd_verify_smb_message
StructureSize field check for all 19 SMB3 commands Already implemented See smb2_get_data_area_len function and smb2_req_struct_sizes in smb2misc.c
check for overflow of SET_INFO command patches submitted, partially reviewed "ksmbd: add request buffer validation in smb2_set_info"
check for overflow of FSCTL command patch submitted, partially reviewed "ksmbd: add validation in smb2_ioctl", smb2pdu.c
Generic check for packet overflow Already implmented See ksmb2_check_message and smb2_calc_size functions
Packet Signing Check (for packet corruption and man-in-the-middle attacks) Already implemented check_sign_req function in smb2pdu.c
Check for open context overflow patch submitted, partially reviewed See "ksmbd: add buffer validation for SMB2_CREATE_CONTEXT", oplock.c smb2pdu.c
Check for overflow of ACL patch submitted, partially reviewed See "ksmbd: add buffer validation for SMB2_CREATE_CONTEXT", smbacl.c (parse_dacl and parse_sec_desc functions)
Check for negotiate context overflow Already implemented See deassemble_neg_contexts function (in smb2pdu.c) and also decode_encrypt_context and decode_sign_cap_ctxt Some contexts (such as compression context) are ignored (set to none) and may need additional checks in future when implemented
Path processing checks in ksmbd
Type of check Status (submitted, reviewed) Function(s) including the check (and patch name if not included yet) Additional work if any
checks for .. escaping the share patch submitted, reviewed, tested multiple ways (libsmb2, smbclient) "ksmbd: prevent out of share access" (see ksmbd_conv_path_to_unix function in misc.c and its use in smb2pdu.c)
checks for symlinks in path components patch submitted, partially reviewed "ksmbd: use LOOKUP_NO_SYMLINKS flags for default lookup" See smb2_open, and ksmbd_vfs_create, ksmbd_vfs_mkdir, ksmb_vfs_link and ksmbd_remove_file and ksmbd_vfs_fp_rename
checks for resolved path never being / or \ (outside the share) (also see additional restrictions made possible by ksmbd_share_veto_filename function in mgmt/share_config.c, and ksmbd_validate_filename in misc.c)

Denial of Service checks
Type of check Status (submitted, reviewed) Function(s) including the check (and patch name if not included yet) Additional work if any
checks for opening too many files Would additional checks be helpful e.g. see smb2_open in smb2pdu.c and ksmbd_open_fd in vfs_cache.c?
checks for allowing too many requests (crediting) See smb2_set_rsp_credits and conn->max_credits field, and conn->total_credits in smb2_consume_credit_charge to investigate this

Also helpful will be a careful re-review of each of the PDU processing functions, ideally two reviews for each of the below. See below.

1. smb2 header (Reviewer: ) a. structure : smb2_hdr b. validation function : ksmbd_smb2_check_message()

2. smb2 negotiate (Reviewer: ) a. structure : smb2_negotiate_req b. validation functioin : smb2_handle_negotiate()

3. negotiate context (Reviewer: ) a. structure : smb2_neg_context, smb2_preauth_neg_context, smb2_encryption_neg_context, smb2_compression_ctx, smb2_posix_neg_context b. validation function : deassemble_neg_contexts()

5. smb2 session setup (Reviewer: ) a. structure : smb2_sess_setup_req b. validation function : smb2_sess_setup()

6. smb2 session logoff (Reviewer: ) a. struture : smb2_logoff_req b. validation functioin : smb2_session_logoff()

7. smb2 tree connect (Reviewer: ) a. structure : smb2_tree_connect_req b. validation function : smb2_tree_connect()

8. smb2 tree disconnect (Reviewer: ) a. structure : smb2_tree_disconnect_req b. validation function : smb2_tree_disconnect()

9. smb2 create (Reviewer: )

  9.1. smb2 create

a. structure : smb2_create_req b. validation function : smb2_open()

  9.2. create context
       a. structure : create_context, create_mxac_req, create_alloc_size_req,

create_posix, lease_context, lease_context_v2 b. validation function : smb2_find_context_vals(), smb2_open()

11. smb2 close (Reviewer: ) a. structure : smb2_close_req b. validation function : smb2_close()

12. smb2 flush (Reviewer: ) a. structure : smb2_flush_req b. validation function : smb2_flush()

13. smb2 read (Reviewer: ) a. structure : smb2_read_req b. validation function : smb2_read()

14. smb2 write (Reviewer: ) a. structure : smb2_write_req b. validation function : smb2_write()

15. smb2 ioctl (Reviewer: ) 15-1. FSCTL_VALIDATE_NEGOTIATE_INFO a. strcture : validate_negotiate_info_req b. validation function : smb2_ioctl(), fsctl_validate_negotiate_info() 15-2. FSCTL_QUERY_NETWORK_INTERFACE_INFO a. structure : network_interface_info_ioctl_rsp b. validation functioin : fsctl_query_iface_info_ioctl() 15-3. FSCTL_COPYCHUNK a. structure : copychunk_ioctl_req b. validation function : smb2_ioctl(), fsctl_copychunk() 15-4. FSCTL_SET_SPARSE a. structure : file_sparse b. validation function : smb2_ioctl() 15-5. FSCTL_SET_ZERO_DATA a. structure : file_zero_data_information b. validation function : smb2_ioctl() 15-6. FSCTL_REQUEST_RESUME_KEY a. structure : resume_key_ioctl_rsp b. validation function : smb2_ioctl() 15-7. FSCTL_QUERY_ALLOCATED_RANGES a. structure : file_allocated_range_buffer b. validation function : smb2_ioctl() 15-8. FSCTL_GET_REPARSE_POINT 15-9. FSCTL_DUPLICATE_EXTENTS_TO_FILE a. structure : duplicate_extents_to_file b. validation function : smb2_ioctl() 15-10. FSCTL_PIPE_TRANSCEIVE a. validation function : fsctl_pipe_transceive() 15-11. FSCTL_CREATE_OR_GET_OBJECT_ID a. structure : file_object_buf_type1_ioctl_rsp b. validation function : smb2_ioctl()

16. smb2 change notify (Reviewer: ) a. structure : smb2_notify_req b. validation function : smb2_notify()

17. smb2 lock (Reviewer: ) a. structure : smb2_lock_req b. validation functioin : smb2_lock()

18. smb2 echo (Reviewer: ) a. structure : smb2_echo_req b. validation function : smb2_echo()

19. smb2 query directory (Reviewer: ) a. smb2_query_directory_req b. validation function : smb2_query_dir()

20. smb2 query info (Reviewer: ) 20.1. SMB2_O_INFO_FILE 20.1.1. FILE_ACCESS_INFORMATION a. structure : smb2_file_access_info b. validation function : get_file_access_info() 20.1.2. FILE_BASIC_INFORMATION a. structure : smb2_file_all_info b. validation function : get_file_basic_info() 20.1.3. FILE_STANDARD_INFORMATION a. structure : smb2_file_standard_info b. validation function : get_file_standard_info() 20.1.4. FILE_ALIGNMENT_INFORMATION a. structure : smb2_file_alignment_info b. validation function : get_file_alignment_info() 20.1.5. FILE_ALL_INFORMATION a. structure : smb2_file_all_info b. validation function : get_file_all_info() 20.1.6. FILE_ALTERNATE_NAME_INFORMATION a. structure : smb2_file_alt_name_info b. validation function : get_file_alternate_info() 20.1.7. FILE_STREAM_INFORMATION a. structure : smb2_file_stream_info b. validation function : get_file_stream_info() 20.1.8. FILE_INTERNAL_INFORMATION a. structure : smb2_file_internal_info b. validation function : get_file_internal_info() 20.1.9. FILE_NETWORK_OPEN_INFORMATION a. structure : smb2_file_ntwrk_info b. validation function : get_file_network_open_info() 20.1.10. FILE_EA_INFORMATION a. structure : smb2_file_ea_info b. validation function : get_file_ea_info() 20.1.11. FILE_FULL_EA_INFORMATION a. structure : smb2_ea_info b. validation function : smb2_get_ea() 20.1.12. FILE_POSITION_INFORMATION a. structure : smb2_file_pos_info b. validation function : get_file_position_info() 20.1.13. FILE_MODE_INFORMATION a. structure : smb2_file_mode_info b. validation function : get_file_mode_info() 20.1.14. FILE_POSITION_INFORMATION a. structure : smb2_file_pos_info b. validation function : get_file_position_info() 20.1.15. FILE_MODE_INFORMATION a. structure : smb2_file_mode_info b. validation function : get_file_mode_info() 20.1.16. FILE_COMPRESSION_INFORMATION a. structure : smb2_file_comp_info b. validation function : get_file_compression_info() 20.1.17. FILE_ATTRIBUTE_TAG_INFORMATION a. structure : smb2_file_attr_tag_info b. validation function : get_file_attribute_tag_info() 20.1.18. SMB_FIND_FILE_POSIX_INFO a. structure : smb311_posix_qinfo b. validation function : find_file_posix_info()



a. structure : filesystem_device_info b. validation function : smb2_get_info_filesystem()


a. structure : filesystem_attribute_info b. validation function : smb2_get_info_filesystem()


a. structure : filesystem_vol_info b. validation function : smb2_get_info_filesystem()


a. structure : filesystem_info b. validation function : smb2_get_info_filesystem()


a. structure : smb2_fs_full_size_info b. validation function : smb2_get_info_filesystem()


a. structure : object_id_info b. validation function : smb2_get_info_filesystem()


a. structure : smb3_fs_ss_info b. validation function : smb2_get_info_filesystem()


a. structure : smb2_fs_control_info b. validation function : smb2_get_info_filesystem()


a. structure : filesystem_posix_info b. validation function : smb2_get_info_filesystem()

20.2. SMB2_O_INFO_SECURITY a. structure : smb_ntsd, smb_acl, smb_ace, smb_sid b. validation function : build_sec_desc()

21. smb2 set info (Reviewer: ) 21.1. SMB2_O_INFO_FILE 21.1.1 FILE_BASIC_INFORMATION a. structure : smb2_file_basic_info b. validation functioin : smb2_set_info_file() 21.1.2 FILE_ALLOCATION_INFORMATION a. structure : smb2_file_alloc_info b. validation functioin : smb2_set_info_file() 21.1.3 FILE_END_OF_FILE_INFORMATION a. structure : smb2_file_eof_info b. validation functioin : smb2_set_info_file() 21.1.4 FILE_RENAME_INFORMATION a. structure : smb2_file_rename_info b. validation functioin : smb2_set_info_file(), set_rename_info() 21.1.5 FILE_LINK_INFORMATION a. structure : smb2_file_link_info b. validation functioin : smb2_create_link() 21.1.6 FILE_DISPOSITION_INFORMATION a. structure : smb2_file_disposition_info b. validation functioin : smb2_set_info_file() 21.1.7 FILE_FULL_EA_INFORMATION a. structure : smb2_ea_info b. validation functioin : smb2_set_info_file(), smb2_set_ea 21.1.8 FILE_POSITION_INFORMATION a. structure : smb2_file_pos_info b. validation functioin : smb2_set_info_file() 21.1.9 FILE_MODE_INFORMATION a. structure : smb2_file_mode_info b. validation functioin : smb2_set_info_file()

22.1 SMB2_O_INFO_SECURITY a. structure : smb_ntsd, smb_acl, smb_ace, smb_sid b. validation function : parse_sec_desc()

22. smb2 oplock break ack (Reviewer: ) a. structure : smb2_oplock_break b. validation function : smb20_oplock_break_ack()

23. smb2 lease break ack (Reviewer: ) a. structure : smb2_lease_ack b. validation function : smb21_lease_break_ack()