1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
13 /*Create Action Flags*/
14 #define FILE_SUPERSEDED 0x00000000
15 #define FILE_OPENED 0x00000001
16 #define FILE_CREATED 0x00000002
17 #define FILE_OVERWRITTEN 0x00000003
19 /* SMB2 Max Credits */
20 #define SMB2_MAX_CREDITS 8192
22 /* BB FIXME - analyze following length BB */
23 #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
25 #define SMB21_DEFAULT_IOSIZE (1024 * 1024)
26 #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
27 #define SMB3_MIN_IOSIZE (64 * 1024)
28 #define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
29 #define SMB3_MAX_MSGSIZE (4 * 4096)
32 * Definitions for SMB2 Protocol Data Units (network frames)
34 * See MS-SMB2.PDF specification for protocol details.
35 * The Naming convention is the lower case version of the SMB2
36 * command code name for the struct. Note that structures must be packed.
40 struct preauth_integrity_info {
41 /* PreAuth integrity Hash ID */
42 __le16 Preauth_HashId;
43 /* PreAuth integrity Hash Value */
44 __u8 Preauth_HashValue[SMB2_PREAUTH_HASH_SIZE];
47 /* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
48 #ifdef CONFIG_SMB_SERVER_KERBEROS5
49 /* sizeof(struct smb2_negotiate_rsp) =
50 * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
52 #define OFFSET_OF_NEG_CONTEXT 0xe0
54 /* sizeof(struct smb2_negotiate_rsp) =
55 * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
57 #define OFFSET_OF_NEG_CONTEXT 0xd0
60 #define SMB2_SESSION_EXPIRED (0)
61 #define SMB2_SESSION_IN_PROGRESS BIT(0)
62 #define SMB2_SESSION_VALID BIT(1)
64 struct create_durable_req_v2 {
65 struct create_context ccontext;
73 struct create_durable_reconn_v2_req {
74 struct create_context ccontext;
77 __u64 PersistentFileId;
84 struct create_alloc_size_req {
85 struct create_context ccontext;
87 __le64 AllocationSize;
90 struct create_durable_rsp {
91 struct create_context ccontext;
99 struct create_durable_v2_rsp {
100 struct create_context ccontext;
106 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
107 struct create_posix_rsp {
108 struct create_context ccontext;
113 /* SidBuffer contain two sids(Domain sid(28), UNIX group sid(16)) */
117 struct smb2_buffer_desc_v1 {
123 #define SMB2_0_IOCTL_IS_FSCTL 0x00000001
125 struct smb_sockaddr_in {
131 struct smb_sockaddr_in6 {
134 __u8 IPv6address[16];
138 #define INTERNETWORK 0x0002
139 #define INTERNETWORKV6 0x0017
141 struct sockaddr_storage_rsp {
144 struct smb_sockaddr_in addr4;
145 struct smb_sockaddr_in6 addr6;
149 #define RSS_CAPABLE 0x00000001
150 #define RDMA_CAPABLE 0x00000002
152 struct network_interface_info_ioctl_rsp {
153 __le32 Next; /* next interface. zero if this is last one */
155 __le32 Capability; /* RSS or RDMA Capable */
158 char SockAddr_Storage[128];
161 struct file_object_buf_type1_ioctl_rsp {
163 __u8 BirthVolumeId[16];
164 __u8 BirthObjectId[16];
168 struct resume_key_ioctl_rsp {
170 __le32 ContextLength;
171 __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
174 struct copychunk_ioctl_req {
178 __u8 Chunks[1]; /* array of srv_copychunk */
181 struct srv_copychunk {
188 struct copychunk_ioctl_rsp {
189 __le32 ChunksWritten;
190 __le32 ChunkBytesWritten;
191 __le32 TotalBytesWritten;
198 /* FILE Info response size */
199 #define FILE_DIRECTORY_INFORMATION_SIZE 1
200 #define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
201 #define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3
202 #define FILE_BASIC_INFORMATION_SIZE 40
203 #define FILE_STANDARD_INFORMATION_SIZE 24
204 #define FILE_INTERNAL_INFORMATION_SIZE 8
205 #define FILE_EA_INFORMATION_SIZE 4
206 #define FILE_ACCESS_INFORMATION_SIZE 4
207 #define FILE_NAME_INFORMATION_SIZE 9
208 #define FILE_RENAME_INFORMATION_SIZE 10
209 #define FILE_LINK_INFORMATION_SIZE 11
210 #define FILE_NAMES_INFORMATION_SIZE 12
211 #define FILE_DISPOSITION_INFORMATION_SIZE 13
212 #define FILE_POSITION_INFORMATION_SIZE 14
213 #define FILE_FULL_EA_INFORMATION_SIZE 15
214 #define FILE_MODE_INFORMATION_SIZE 4
215 #define FILE_ALIGNMENT_INFORMATION_SIZE 4
216 #define FILE_ALL_INFORMATION_SIZE 104
217 #define FILE_ALLOCATION_INFORMATION_SIZE 19
218 #define FILE_END_OF_FILE_INFORMATION_SIZE 20
219 #define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8
220 #define FILE_STREAM_INFORMATION_SIZE 32
221 #define FILE_PIPE_INFORMATION_SIZE 23
222 #define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
223 #define FILE_PIPE_REMOTE_INFORMATION_SIZE 25
224 #define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26
225 #define FILE_MAILSLOT_SET_INFORMATION_SIZE 27
226 #define FILE_COMPRESSION_INFORMATION_SIZE 16
227 #define FILE_OBJECT_ID_INFORMATION_SIZE 29
228 /* Number 30 not defined in documents */
229 #define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31
230 #define FILE_QUOTA_INFORMATION_SIZE 32
231 #define FILE_REPARSE_POINT_INFORMATION_SIZE 33
232 #define FILE_NETWORK_OPEN_INFORMATION_SIZE 56
233 #define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8
235 /* FS Info response size */
236 #define FS_DEVICE_INFORMATION_SIZE 8
237 #define FS_ATTRIBUTE_INFORMATION_SIZE 16
238 #define FS_VOLUME_INFORMATION_SIZE 24
239 #define FS_SIZE_INFORMATION_SIZE 24
240 #define FS_FULL_SIZE_INFORMATION_SIZE 32
241 #define FS_SECTOR_SIZE_INFORMATION_SIZE 28
242 #define FS_OBJECT_ID_INFORMATION_SIZE 64
243 #define FS_CONTROL_INFORMATION_SIZE 48
244 #define FS_POSIX_INFORMATION_SIZE 56
246 /* FS_ATTRIBUTE_File_System_Name */
247 #define FS_TYPE_SUPPORT_SIZE 44
248 struct fs_type_info {
254 * PDU query infolevel structure definitions
255 * BB consider moving to a different header
258 struct smb2_file_access_info {
262 struct smb2_file_alignment_info {
263 __le32 AlignmentRequirement;
266 struct smb2_file_basic_info { /* data block encoding of response to level 18 */
267 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
268 __le64 LastAccessTime;
269 __le64 LastWriteTime;
272 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
275 struct smb2_file_alt_name_info {
276 __le32 FileNameLength;
280 struct smb2_file_stream_info {
281 __le32 NextEntryOffset;
282 __le32 StreamNameLength;
284 __le64 StreamAllocationSize;
288 struct smb2_file_ntwrk_info {
290 __le64 LastAccessTime;
291 __le64 LastWriteTime;
293 __le64 AllocationSize;
299 struct smb2_file_standard_info {
300 __le64 AllocationSize;
302 __le32 NumberOfLinks; /* hard links */
306 } __packed; /* level 18 Query */
308 struct smb2_file_ea_info {
312 struct smb2_file_alloc_info {
313 __le64 AllocationSize;
316 struct smb2_file_disposition_info {
320 struct smb2_file_pos_info {
321 __le64 CurrentByteOffset;
324 #define FILE_MODE_INFO_MASK cpu_to_le32(0x0000100e)
326 struct smb2_file_mode_info {
330 #define COMPRESSION_FORMAT_NONE 0x0000
331 #define COMPRESSION_FORMAT_LZNT1 0x0002
333 struct smb2_file_comp_info {
334 __le64 CompressedFileSize;
335 __le16 CompressionFormat;
336 __u8 CompressionUnitShift;
342 struct smb2_file_attr_tag_info {
343 __le32 FileAttributes;
347 #define SL_RESTART_SCAN 0x00000001
348 #define SL_RETURN_SINGLE_ENTRY 0x00000002
349 #define SL_INDEX_SPECIFIED 0x00000004
351 struct smb2_ea_info_req {
352 __le32 NextEntryOffset;
355 } __packed; /* level 15 Query */
357 struct smb2_ea_info {
358 __le32 NextEntryOffset;
361 __le16 EaValueLength;
363 /* optionally followed by value */
364 } __packed; /* level 15 Query */
366 struct create_ea_buf_req {
367 struct create_context ccontext;
369 struct smb2_ea_info ea;
372 struct create_sd_buf_req {
373 struct create_context ccontext;
375 struct smb_ntsd ntsd;
378 struct smb2_posix_info {
379 __le32 NextEntryOffset;
382 __le64 LastAccessTime;
383 __le64 LastWriteTime;
386 __le64 AllocationSize;
387 __le32 DosAttributes;
391 /* beginning of POSIX Create Context Response */
395 /* SidBuffer contain two sids (UNIX user sid(16), UNIX group sid(16)) */
400 * var sized owner SID
401 * var sized group SID
402 * le32 filenamelength
408 void init_smb2_1_server(struct ksmbd_conn *conn);
409 void init_smb3_0_server(struct ksmbd_conn *conn);
410 void init_smb3_02_server(struct ksmbd_conn *conn);
411 int init_smb3_11_server(struct ksmbd_conn *conn);
413 void init_smb2_max_read_size(unsigned int sz);
414 void init_smb2_max_write_size(unsigned int sz);
415 void init_smb2_max_trans_size(unsigned int sz);
416 void init_smb2_max_credits(unsigned int sz);
418 bool is_smb2_neg_cmd(struct ksmbd_work *work);
419 bool is_smb2_rsp(struct ksmbd_work *work);
421 u16 get_smb2_cmd_val(struct ksmbd_work *work);
422 void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
423 int init_smb2_rsp_hdr(struct ksmbd_work *work);
424 int smb2_allocate_rsp_buf(struct ksmbd_work *work);
425 bool is_chained_smb2_message(struct ksmbd_work *work);
426 int init_smb2_neg_rsp(struct ksmbd_work *work);
427 void smb2_set_err_rsp(struct ksmbd_work *work);
428 int smb2_check_user_session(struct ksmbd_work *work);
429 int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
430 bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
431 int smb2_check_sign_req(struct ksmbd_work *work);
432 void smb2_set_sign_rsp(struct ksmbd_work *work);
433 int smb3_check_sign_req(struct ksmbd_work *work);
434 void smb3_set_sign_rsp(struct ksmbd_work *work);
435 int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
436 __le16 dialects_count);
437 struct file_lock *smb_flock_init(struct file *f);
438 int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
440 void release_async_work(struct ksmbd_work *work);
441 void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
442 struct channel *lookup_chann_list(struct ksmbd_session *sess,
443 struct ksmbd_conn *conn);
444 void smb3_preauth_hash_rsp(struct ksmbd_work *work);
445 bool smb3_is_transform_hdr(void *buf);
446 int smb3_decrypt_req(struct ksmbd_work *work);
447 int smb3_encrypt_resp(struct ksmbd_work *work);
448 bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
449 int smb2_set_rsp_credits(struct ksmbd_work *work);
450 bool smb3_encryption_negotiated(struct ksmbd_conn *conn);
452 /* smb2 misc functions */
453 int ksmbd_smb2_check_message(struct ksmbd_work *work);
455 /* smb2 command handlers */
456 int smb2_handle_negotiate(struct ksmbd_work *work);
457 int smb2_negotiate_request(struct ksmbd_work *work);
458 int smb2_sess_setup(struct ksmbd_work *work);
459 int smb2_tree_connect(struct ksmbd_work *work);
460 int smb2_tree_disconnect(struct ksmbd_work *work);
461 int smb2_session_logoff(struct ksmbd_work *work);
462 int smb2_open(struct ksmbd_work *work);
463 int smb2_query_info(struct ksmbd_work *work);
464 int smb2_query_dir(struct ksmbd_work *work);
465 int smb2_close(struct ksmbd_work *work);
466 int smb2_echo(struct ksmbd_work *work);
467 int smb2_set_info(struct ksmbd_work *work);
468 int smb2_read(struct ksmbd_work *work);
469 int smb2_write(struct ksmbd_work *work);
470 int smb2_flush(struct ksmbd_work *work);
471 int smb2_cancel(struct ksmbd_work *work);
472 int smb2_lock(struct ksmbd_work *work);
473 int smb2_ioctl(struct ksmbd_work *work);
474 int smb2_oplock_break(struct ksmbd_work *work);
475 int smb2_notify(struct ksmbd_work *ksmbd_work);
478 * Get the body of the smb2 message excluding the 4 byte rfc1002 headers
479 * from request/response buffer.
481 static inline void *smb2_get_msg(void *buf)
486 #endif /* _SMB2PDU_H */