blob: 725b800c29c8a02a7abbd27f3565ad25dce91f36 [file] [log] [blame]
Namjae Jeone2f34482021-03-16 10:49:09 +09001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
5 */
6
7#ifndef _SMB2PDU_H
8#define _SMB2PDU_H
9
10#include "ntlmssp.h"
11#include "smbacl.h"
12
Namjae Jeone2f34482021-03-16 10:49:09 +090013/*Create Action Flags*/
14#define FILE_SUPERSEDED 0x00000000
15#define FILE_OPENED 0x00000001
16#define FILE_CREATED 0x00000002
17#define FILE_OVERWRITTEN 0x00000003
18
19/*
20 * Size of the session key (crypto key encrypted with the password
21 */
22#define SMB2_NTLMV2_SESSKEY_SIZE 16
23#define SMB2_SIGNATURE_SIZE 16
24#define SMB2_HMACSHA256_SIZE 32
25#define SMB2_CMACAES_SIZE 16
Namjae Jeon5a0ca772021-05-06 11:43:37 +090026#define SMB3_GCM128_CRYPTKEY_SIZE 16
27#define SMB3_GCM256_CRYPTKEY_SIZE 32
28
29/*
30 * Size of the smb3 encryption/decryption keys
31 */
32#define SMB3_ENC_DEC_KEY_SIZE 32
Namjae Jeone2f34482021-03-16 10:49:09 +090033
34/*
35 * Size of the smb3 signing key
36 */
37#define SMB3_SIGN_KEY_SIZE 16
38
39#define CIFS_CLIENT_CHALLENGE_SIZE 8
40#define SMB_SERVER_CHALLENGE_SIZE 8
41
42/* SMB2 Max Credits */
43#define SMB2_MAX_CREDITS 8192
44
Namjae Jeone2f34482021-03-16 10:49:09 +090045/* Maximum buffer size value we can send with 1 credit */
46#define SMB2_MAX_BUFFER_SIZE 65536
47
48#define NUMBER_OF_SMB2_COMMANDS 0x0013
49
50/* BB FIXME - analyze following length BB */
51#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
52
Namjae Jeone2f34482021-03-16 10:49:09 +090053#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
54#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
55#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
Namjae Jeon4bc59472021-10-15 17:14:02 +090056#define SMB3_MIN_IOSIZE (64 * 1024)
57#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
Namjae Jeone2f34482021-03-16 10:49:09 +090058
59/*
Namjae Jeone2f34482021-03-16 10:49:09 +090060 * Definitions for SMB2 Protocol Data Units (network frames)
61 *
62 * See MS-SMB2.PDF specification for protocol details.
63 * The Naming convention is the lower case version of the SMB2
64 * command code name for the struct. Note that structures must be packed.
65 *
66 */
67
68#define SMB2_ERROR_STRUCTURE_SIZE2 9
69#define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
70
71struct smb2_err_rsp {
72 struct smb2_hdr hdr;
73 __le16 StructureSize;
74 __u8 ErrorContextCount;
75 __u8 Reserved;
76 __le32 ByteCount; /* even if zero, at least one byte follows */
77 __u8 ErrorData[1]; /* variable length */
78} __packed;
79
Namjae Jeone2f34482021-03-16 10:49:09 +090080struct preauth_integrity_info {
81 /* PreAuth integrity Hash ID */
82 __le16 Preauth_HashId;
83 /* PreAuth integrity Hash Value */
Ronnie Sahlbergd6c9ad23b2021-11-03 08:44:38 +090084 __u8 Preauth_HashValue[SMB2_PREAUTH_HASH_SIZE];
Namjae Jeone2f34482021-03-16 10:49:09 +090085};
86
Namjae Jeoncb451722021-11-03 08:08:44 +090087/* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
Namjae Jeone2f34482021-03-16 10:49:09 +090088#ifdef CONFIG_SMB_SERVER_KERBEROS5
Namjae Jeoncb451722021-11-03 08:08:44 +090089/* sizeof(struct smb2_negotiate_rsp) =
Namjae Jeone2f34482021-03-16 10:49:09 +090090 * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
91 */
92#define OFFSET_OF_NEG_CONTEXT 0xe0
93#else
Namjae Jeoncb451722021-11-03 08:08:44 +090094/* sizeof(struct smb2_negotiate_rsp) =
Namjae Jeone2f34482021-03-16 10:49:09 +090095 * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
96 */
97#define OFFSET_OF_NEG_CONTEXT 0xd0
98#endif
99
Namjae Jeone2f34482021-03-16 10:49:09 +0900100#define SMB2_SESSION_EXPIRED (0)
Namjae Jeon64b39f42021-03-30 14:25:35 +0900101#define SMB2_SESSION_IN_PROGRESS BIT(0)
102#define SMB2_SESSION_VALID BIT(1)
Namjae Jeone2f34482021-03-16 10:49:09 +0900103
Namjae Jeone2f34482021-03-16 10:49:09 +0900104struct create_durable_req_v2 {
105 struct create_context ccontext;
106 __u8 Name[8];
107 __le32 Timeout;
108 __le32 Flags;
109 __u8 Reserved[8];
110 __u8 CreateGuid[16];
111} __packed;
112
113struct create_durable_reconn_req {
114 struct create_context ccontext;
115 __u8 Name[8];
116 union {
117 __u8 Reserved[16];
118 struct {
119 __le64 PersistentFileId;
120 __le64 VolatileFileId;
121 } Fid;
122 } Data;
123} __packed;
124
125struct create_durable_reconn_v2_req {
126 struct create_context ccontext;
127 __u8 Name[8];
128 struct {
129 __le64 PersistentFileId;
130 __le64 VolatileFileId;
131 } Fid;
132 __u8 CreateGuid[16];
133 __le32 Flags;
134} __packed;
135
136struct create_app_inst_id {
137 struct create_context ccontext;
138 __u8 Name[8];
139 __u8 Reserved[8];
140 __u8 AppInstanceId[16];
141} __packed;
142
143struct create_app_inst_id_vers {
144 struct create_context ccontext;
145 __u8 Name[8];
146 __u8 Reserved[2];
147 __u8 Padding[4];
148 __le64 AppInstanceVersionHigh;
149 __le64 AppInstanceVersionLow;
150} __packed;
151
152struct create_mxac_req {
153 struct create_context ccontext;
154 __u8 Name[8];
155 __le64 Timestamp;
156} __packed;
157
158struct create_alloc_size_req {
159 struct create_context ccontext;
160 __u8 Name[8];
161 __le64 AllocationSize;
162} __packed;
163
164struct create_posix {
165 struct create_context ccontext;
166 __u8 Name[16];
167 __le32 Mode;
168 __u32 Reserved;
169} __packed;
170
171struct create_durable_rsp {
172 struct create_context ccontext;
173 __u8 Name[8];
174 union {
175 __u8 Reserved[8];
176 __u64 data;
177 } Data;
178} __packed;
179
180struct create_durable_v2_rsp {
181 struct create_context ccontext;
182 __u8 Name[8];
183 __le32 Timeout;
184 __le32 Flags;
185} __packed;
186
187struct create_mxac_rsp {
188 struct create_context ccontext;
189 __u8 Name[8];
190 __le32 QueryStatus;
191 __le32 MaximalAccess;
192} __packed;
193
194struct create_disk_id_rsp {
195 struct create_context ccontext;
196 __u8 Name[8];
197 __le64 DiskFileId;
198 __le64 VolumeId;
199 __u8 Reserved[16];
200} __packed;
201
202/* equivalent of the contents of SMB3.1.1 POSIX open context response */
203struct create_posix_rsp {
204 struct create_context ccontext;
205 __u8 Name[16];
206 __le32 nlink;
207 __le32 reparse_tag;
208 __le32 mode;
209 u8 SidBuffer[40];
210} __packed;
211
212#define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
213#define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
214#define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
215#define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
216
217#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
218
Namjae Jeon2734b692021-09-09 12:28:18 +0900219#define SMB2_LEASE_KEY_SIZE 16
220
Namjae Jeone2f34482021-03-16 10:49:09 +0900221struct lease_context {
Namjae Jeon2734b692021-09-09 12:28:18 +0900222 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Namjae Jeone2f34482021-03-16 10:49:09 +0900223 __le32 LeaseState;
224 __le32 LeaseFlags;
225 __le64 LeaseDuration;
226} __packed;
227
Namjae Jeonade62d82021-06-07 09:22:22 +0900228struct lease_context_v2 {
Namjae Jeon2734b692021-09-09 12:28:18 +0900229 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Namjae Jeonade62d82021-06-07 09:22:22 +0900230 __le32 LeaseState;
231 __le32 LeaseFlags;
232 __le64 LeaseDuration;
Namjae Jeon2734b692021-09-09 12:28:18 +0900233 __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
Namjae Jeonade62d82021-06-07 09:22:22 +0900234 __le16 Epoch;
235 __le16 Reserved;
236} __packed;
237
Namjae Jeone2f34482021-03-16 10:49:09 +0900238struct create_lease {
239 struct create_context ccontext;
240 __u8 Name[8];
241 struct lease_context lcontext;
242} __packed;
243
Namjae Jeonade62d82021-06-07 09:22:22 +0900244struct create_lease_v2 {
245 struct create_context ccontext;
246 __u8 Name[8];
247 struct lease_context_v2 lcontext;
248 __u8 Pad[4];
249} __packed;
250
Namjae Jeone2f34482021-03-16 10:49:09 +0900251struct smb2_buffer_desc_v1 {
252 __le64 offset;
253 __le32 token;
254 __le32 length;
255} __packed;
256
Namjae Jeone2f34482021-03-16 10:49:09 +0900257#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
258
Namjae Jeoneb817362021-05-18 10:37:59 +0900259struct duplicate_extents_to_file {
260 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
261 __u64 VolatileFileHandle;
262 __le64 SourceFileOffset;
263 __le64 TargetFileOffset;
264 __le64 ByteCount; /* Bytes to be copied */
265} __packed;
266
Namjae Jeone2f34482021-03-16 10:49:09 +0900267struct smb2_ioctl_req {
268 struct smb2_hdr hdr;
269 __le16 StructureSize; /* Must be 57 */
270 __le16 Reserved; /* offset from start of SMB2 header to write data */
271 __le32 CntCode;
272 __le64 PersistentFileId;
273 __le64 VolatileFileId;
274 __le32 InputOffset; /* Reserved MBZ */
275 __le32 InputCount;
276 __le32 MaxInputResponse;
277 __le32 OutputOffset;
278 __le32 OutputCount;
279 __le32 MaxOutputResponse;
280 __le32 Flags;
281 __le32 Reserved2;
282 __u8 Buffer[1];
283} __packed;
284
285struct smb2_ioctl_rsp {
286 struct smb2_hdr hdr;
287 __le16 StructureSize; /* Must be 49 */
288 __le16 Reserved; /* offset from start of SMB2 header to write data */
289 __le32 CntCode;
290 __le64 PersistentFileId;
291 __le64 VolatileFileId;
292 __le32 InputOffset; /* Reserved MBZ */
293 __le32 InputCount;
294 __le32 OutputOffset;
295 __le32 OutputCount;
296 __le32 Flags;
297 __le32 Reserved2;
298 __u8 Buffer[1];
299} __packed;
300
301struct validate_negotiate_info_req {
302 __le32 Capabilities;
303 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
304 __le16 SecurityMode;
305 __le16 DialectCount;
306 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
307} __packed;
308
309struct validate_negotiate_info_rsp {
310 __le32 Capabilities;
311 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
312 __le16 SecurityMode;
313 __le16 Dialect; /* Dialect in use for the connection */
314} __packed;
315
316struct smb_sockaddr_in {
317 __be16 Port;
318 __be32 IPv4address;
319 __u8 Reserved[8];
320} __packed;
321
322struct smb_sockaddr_in6 {
323 __be16 Port;
324 __be32 FlowInfo;
325 __u8 IPv6address[16];
326 __be32 ScopeId;
327} __packed;
328
329#define INTERNETWORK 0x0002
330#define INTERNETWORKV6 0x0017
331
332struct sockaddr_storage_rsp {
333 __le16 Family;
334 union {
335 struct smb_sockaddr_in addr4;
336 struct smb_sockaddr_in6 addr6;
337 };
338} __packed;
339
340#define RSS_CAPABLE 0x00000001
341#define RDMA_CAPABLE 0x00000002
342
343struct network_interface_info_ioctl_rsp {
344 __le32 Next; /* next interface. zero if this is last one */
345 __le32 IfIndex;
346 __le32 Capability; /* RSS or RDMA Capable */
347 __le32 Reserved;
348 __le64 LinkSpeed;
349 char SockAddr_Storage[128];
350} __packed;
351
352struct file_object_buf_type1_ioctl_rsp {
353 __u8 ObjectId[16];
354 __u8 BirthVolumeId[16];
355 __u8 BirthObjectId[16];
356 __u8 DomainId[16];
357} __packed;
358
359struct resume_key_ioctl_rsp {
360 __le64 ResumeKey[3];
361 __le32 ContextLength;
362 __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
363} __packed;
364
365struct copychunk_ioctl_req {
366 __le64 ResumeKey[3];
367 __le32 ChunkCount;
368 __le32 Reserved;
369 __u8 Chunks[1]; /* array of srv_copychunk */
370} __packed;
371
372struct srv_copychunk {
373 __le64 SourceOffset;
374 __le64 TargetOffset;
375 __le32 Length;
376 __le32 Reserved;
377} __packed;
378
379struct copychunk_ioctl_rsp {
380 __le32 ChunksWritten;
381 __le32 ChunkBytesWritten;
382 __le32 TotalBytesWritten;
383} __packed;
384
385struct file_sparse {
386 __u8 SetSparse;
387} __packed;
388
389struct file_zero_data_information {
390 __le64 FileOffset;
391 __le64 BeyondFinalZero;
392} __packed;
393
394struct file_allocated_range_buffer {
395 __le64 file_offset;
396 __le64 length;
397} __packed;
398
399struct reparse_data_buffer {
400 __le32 ReparseTag;
401 __le16 ReparseDataLength;
402 __u16 Reserved;
403 __u8 DataBuffer[]; /* Variable Length */
404} __packed;
405
Namjae Jeone2f34482021-03-16 10:49:09 +0900406/* SMB2 Notify Action Flags */
407#define FILE_ACTION_ADDED 0x00000001
408#define FILE_ACTION_REMOVED 0x00000002
409#define FILE_ACTION_MODIFIED 0x00000003
410#define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
411#define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
412#define FILE_ACTION_ADDED_STREAM 0x00000006
413#define FILE_ACTION_REMOVED_STREAM 0x00000007
414#define FILE_ACTION_MODIFIED_STREAM 0x00000008
415#define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
416
417#define SMB2_LOCKFLAG_SHARED 0x0001
418#define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
419#define SMB2_LOCKFLAG_UNLOCK 0x0004
420#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
421#define SMB2_LOCKFLAG_MASK 0x0007
422
423struct smb2_lock_element {
424 __le64 Offset;
425 __le64 Length;
426 __le32 Flags;
427 __le32 Reserved;
428} __packed;
429
430struct smb2_lock_req {
431 struct smb2_hdr hdr;
432 __le16 StructureSize; /* Must be 48 */
433 __le16 LockCount;
434 __le32 Reserved;
435 __le64 PersistentFileId;
436 __le64 VolatileFileId;
437 /* Followed by at least one */
438 struct smb2_lock_element locks[1];
439} __packed;
440
441struct smb2_lock_rsp {
442 struct smb2_hdr hdr;
443 __le16 StructureSize; /* Must be 4 */
444 __le16 Reserved;
445} __packed;
446
447struct smb2_echo_req {
448 struct smb2_hdr hdr;
449 __le16 StructureSize; /* Must be 4 */
450 __u16 Reserved;
451} __packed;
452
453struct smb2_echo_rsp {
454 struct smb2_hdr hdr;
455 __le16 StructureSize; /* Must be 4 */
456 __u16 Reserved;
457} __packed;
458
459/* search (query_directory) Flags field */
460#define SMB2_RESTART_SCANS 0x01
461#define SMB2_RETURN_SINGLE_ENTRY 0x02
462#define SMB2_INDEX_SPECIFIED 0x04
463#define SMB2_REOPEN 0x10
464
465struct smb2_query_directory_req {
466 struct smb2_hdr hdr;
467 __le16 StructureSize; /* Must be 33 */
468 __u8 FileInformationClass;
469 __u8 Flags;
470 __le32 FileIndex;
471 __le64 PersistentFileId;
472 __le64 VolatileFileId;
473 __le16 FileNameOffset;
474 __le16 FileNameLength;
475 __le32 OutputBufferLength;
476 __u8 Buffer[1];
477} __packed;
478
479struct smb2_query_directory_rsp {
480 struct smb2_hdr hdr;
481 __le16 StructureSize; /* Must be 9 */
482 __le16 OutputBufferOffset;
483 __le32 OutputBufferLength;
484 __u8 Buffer[1];
485} __packed;
486
487/* Possible InfoType values */
488#define SMB2_O_INFO_FILE 0x01
489#define SMB2_O_INFO_FILESYSTEM 0x02
490#define SMB2_O_INFO_SECURITY 0x03
491#define SMB2_O_INFO_QUOTA 0x04
492
493/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
494#define OWNER_SECINFO 0x00000001
495#define GROUP_SECINFO 0x00000002
496#define DACL_SECINFO 0x00000004
497#define SACL_SECINFO 0x00000008
498#define LABEL_SECINFO 0x00000010
499#define ATTRIBUTE_SECINFO 0x00000020
500#define SCOPE_SECINFO 0x00000040
501#define BACKUP_SECINFO 0x00010000
502#define UNPROTECTED_SACL_SECINFO 0x10000000
503#define UNPROTECTED_DACL_SECINFO 0x20000000
504#define PROTECTED_SACL_SECINFO 0x40000000
505#define PROTECTED_DACL_SECINFO 0x80000000
506
507struct smb2_query_info_req {
508 struct smb2_hdr hdr;
509 __le16 StructureSize; /* Must be 41 */
510 __u8 InfoType;
511 __u8 FileInfoClass;
512 __le32 OutputBufferLength;
513 __le16 InputBufferOffset;
514 __u16 Reserved;
515 __le32 InputBufferLength;
516 __le32 AdditionalInformation;
517 __le32 Flags;
518 __le64 PersistentFileId;
519 __le64 VolatileFileId;
520 __u8 Buffer[1];
521} __packed;
522
523struct smb2_query_info_rsp {
524 struct smb2_hdr hdr;
525 __le16 StructureSize; /* Must be 9 */
526 __le16 OutputBufferOffset;
527 __le32 OutputBufferLength;
528 __u8 Buffer[1];
529} __packed;
530
531struct smb2_set_info_req {
532 struct smb2_hdr hdr;
533 __le16 StructureSize; /* Must be 33 */
534 __u8 InfoType;
535 __u8 FileInfoClass;
536 __le32 BufferLength;
537 __le16 BufferOffset;
538 __u16 Reserved;
539 __le32 AdditionalInformation;
540 __le64 PersistentFileId;
541 __le64 VolatileFileId;
542 __u8 Buffer[1];
543} __packed;
544
545struct smb2_set_info_rsp {
546 struct smb2_hdr hdr;
547 __le16 StructureSize; /* Must be 2 */
548} __packed;
549
Namjae Jeone2f34482021-03-16 10:49:09 +0900550/* FILE Info response size */
551#define FILE_DIRECTORY_INFORMATION_SIZE 1
552#define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
553#define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3
554#define FILE_BASIC_INFORMATION_SIZE 40
555#define FILE_STANDARD_INFORMATION_SIZE 24
556#define FILE_INTERNAL_INFORMATION_SIZE 8
557#define FILE_EA_INFORMATION_SIZE 4
558#define FILE_ACCESS_INFORMATION_SIZE 4
559#define FILE_NAME_INFORMATION_SIZE 9
560#define FILE_RENAME_INFORMATION_SIZE 10
561#define FILE_LINK_INFORMATION_SIZE 11
562#define FILE_NAMES_INFORMATION_SIZE 12
563#define FILE_DISPOSITION_INFORMATION_SIZE 13
564#define FILE_POSITION_INFORMATION_SIZE 14
565#define FILE_FULL_EA_INFORMATION_SIZE 15
566#define FILE_MODE_INFORMATION_SIZE 4
567#define FILE_ALIGNMENT_INFORMATION_SIZE 4
568#define FILE_ALL_INFORMATION_SIZE 104
569#define FILE_ALLOCATION_INFORMATION_SIZE 19
570#define FILE_END_OF_FILE_INFORMATION_SIZE 20
571#define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8
572#define FILE_STREAM_INFORMATION_SIZE 32
573#define FILE_PIPE_INFORMATION_SIZE 23
574#define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
575#define FILE_PIPE_REMOTE_INFORMATION_SIZE 25
576#define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26
577#define FILE_MAILSLOT_SET_INFORMATION_SIZE 27
578#define FILE_COMPRESSION_INFORMATION_SIZE 16
579#define FILE_OBJECT_ID_INFORMATION_SIZE 29
580/* Number 30 not defined in documents */
581#define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31
582#define FILE_QUOTA_INFORMATION_SIZE 32
583#define FILE_REPARSE_POINT_INFORMATION_SIZE 33
584#define FILE_NETWORK_OPEN_INFORMATION_SIZE 56
585#define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8
586
Namjae Jeone2f34482021-03-16 10:49:09 +0900587/* FS Info response size */
588#define FS_DEVICE_INFORMATION_SIZE 8
589#define FS_ATTRIBUTE_INFORMATION_SIZE 16
590#define FS_VOLUME_INFORMATION_SIZE 24
591#define FS_SIZE_INFORMATION_SIZE 24
592#define FS_FULL_SIZE_INFORMATION_SIZE 32
593#define FS_SECTOR_SIZE_INFORMATION_SIZE 28
594#define FS_OBJECT_ID_INFORMATION_SIZE 64
595#define FS_CONTROL_INFORMATION_SIZE 48
596#define FS_POSIX_INFORMATION_SIZE 56
597
598/* FS_ATTRIBUTE_File_System_Name */
599#define FS_TYPE_SUPPORT_SIZE 44
600struct fs_type_info {
601 char *fs_name;
602 long magic_number;
603} __packed;
604
605struct smb2_oplock_break {
606 struct smb2_hdr hdr;
607 __le16 StructureSize; /* Must be 24 */
608 __u8 OplockLevel;
609 __u8 Reserved;
610 __le32 Reserved2;
611 __le64 PersistentFid;
612 __le64 VolatileFid;
613} __packed;
614
615#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
616
617struct smb2_lease_break {
618 struct smb2_hdr hdr;
619 __le16 StructureSize; /* Must be 44 */
Namjae Jeonade62d82021-06-07 09:22:22 +0900620 __le16 Epoch;
Namjae Jeone2f34482021-03-16 10:49:09 +0900621 __le32 Flags;
622 __u8 LeaseKey[16];
623 __le32 CurrentLeaseState;
624 __le32 NewLeaseState;
625 __le32 BreakReason;
626 __le32 AccessMaskHint;
627 __le32 ShareMaskHint;
628} __packed;
629
630struct smb2_lease_ack {
631 struct smb2_hdr hdr;
632 __le16 StructureSize; /* Must be 36 */
633 __le16 Reserved;
634 __le32 Flags;
635 __u8 LeaseKey[16];
636 __le32 LeaseState;
637 __le64 LeaseDuration;
638} __packed;
639
640/*
641 * PDU infolevel structure definitions
642 * BB consider moving to a different header
643 */
644
645/* File System Information Classes */
646#define FS_VOLUME_INFORMATION 1 /* Query */
647#define FS_LABEL_INFORMATION 2 /* Set */
648#define FS_SIZE_INFORMATION 3 /* Query */
649#define FS_DEVICE_INFORMATION 4 /* Query */
650#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
651#define FS_CONTROL_INFORMATION 6 /* Query, Set */
652#define FS_FULL_SIZE_INFORMATION 7 /* Query */
653#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
654#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
655#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
656#define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
657
658struct smb2_fs_full_size_info {
659 __le64 TotalAllocationUnits;
660 __le64 CallerAvailableAllocationUnits;
661 __le64 ActualAvailableAllocationUnits;
662 __le32 SectorsPerAllocationUnit;
663 __le32 BytesPerSector;
664} __packed;
665
666#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
667#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
668#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
669#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
670
671/* sector size info struct */
672struct smb3_fs_ss_info {
673 __le32 LogicalBytesPerSector;
674 __le32 PhysicalBytesPerSectorForAtomicity;
675 __le32 PhysicalBytesPerSectorForPerf;
676 __le32 FSEffPhysicalBytesPerSectorForAtomicity;
677 __le32 Flags;
678 __le32 ByteOffsetForSectorAlignment;
679 __le32 ByteOffsetForPartitionAlignment;
680} __packed;
681
682/* File System Control Information */
683struct smb2_fs_control_info {
684 __le64 FreeSpaceStartFiltering;
685 __le64 FreeSpaceThreshold;
686 __le64 FreeSpaceStopFiltering;
687 __le64 DefaultQuotaThreshold;
688 __le64 DefaultQuotaLimit;
689 __le32 FileSystemControlFlags;
690 __le32 Padding;
691} __packed;
692
693/* partial list of QUERY INFO levels */
694#define FILE_DIRECTORY_INFORMATION 1
695#define FILE_FULL_DIRECTORY_INFORMATION 2
696#define FILE_BOTH_DIRECTORY_INFORMATION 3
697#define FILE_BASIC_INFORMATION 4
698#define FILE_STANDARD_INFORMATION 5
699#define FILE_INTERNAL_INFORMATION 6
700#define FILE_EA_INFORMATION 7
701#define FILE_ACCESS_INFORMATION 8
702#define FILE_NAME_INFORMATION 9
703#define FILE_RENAME_INFORMATION 10
704#define FILE_LINK_INFORMATION 11
705#define FILE_NAMES_INFORMATION 12
706#define FILE_DISPOSITION_INFORMATION 13
707#define FILE_POSITION_INFORMATION 14
708#define FILE_FULL_EA_INFORMATION 15
709#define FILE_MODE_INFORMATION 16
710#define FILE_ALIGNMENT_INFORMATION 17
711#define FILE_ALL_INFORMATION 18
712#define FILE_ALLOCATION_INFORMATION 19
713#define FILE_END_OF_FILE_INFORMATION 20
714#define FILE_ALTERNATE_NAME_INFORMATION 21
715#define FILE_STREAM_INFORMATION 22
716#define FILE_PIPE_INFORMATION 23
717#define FILE_PIPE_LOCAL_INFORMATION 24
718#define FILE_PIPE_REMOTE_INFORMATION 25
719#define FILE_MAILSLOT_QUERY_INFORMATION 26
720#define FILE_MAILSLOT_SET_INFORMATION 27
721#define FILE_COMPRESSION_INFORMATION 28
722#define FILE_OBJECT_ID_INFORMATION 29
723/* Number 30 not defined in documents */
724#define FILE_MOVE_CLUSTER_INFORMATION 31
725#define FILE_QUOTA_INFORMATION 32
726#define FILE_REPARSE_POINT_INFORMATION 33
727#define FILE_NETWORK_OPEN_INFORMATION 34
728#define FILE_ATTRIBUTE_TAG_INFORMATION 35
729#define FILE_TRACKING_INFORMATION 36
730#define FILEID_BOTH_DIRECTORY_INFORMATION 37
731#define FILEID_FULL_DIRECTORY_INFORMATION 38
732#define FILE_VALID_DATA_LENGTH_INFORMATION 39
733#define FILE_SHORT_NAME_INFORMATION 40
734#define FILE_SFIO_RESERVE_INFORMATION 44
735#define FILE_SFIO_VOLUME_INFORMATION 45
736#define FILE_HARD_LINK_INFORMATION 46
737#define FILE_NORMALIZED_NAME_INFORMATION 48
738#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
739#define FILE_STANDARD_LINK_INFORMATION 54
740
741#define OP_BREAK_STRUCT_SIZE_20 24
742#define OP_BREAK_STRUCT_SIZE_21 36
743
744struct smb2_file_access_info {
745 __le32 AccessFlags;
746} __packed;
747
748struct smb2_file_alignment_info {
749 __le32 AlignmentRequirement;
750} __packed;
751
752struct smb2_file_internal_info {
753 __le64 IndexNumber;
754} __packed; /* level 6 Query */
755
756struct smb2_file_rename_info { /* encoding of request for level 10 */
757 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
758 /* 0 = fail if target already exists */
759 __u8 Reserved[7];
760 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
761 __le32 FileNameLength;
762 char FileName[0]; /* New name to be assigned */
763} __packed; /* level 10 Set */
764
765struct smb2_file_link_info { /* encoding of request for level 11 */
766 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
767 /* 0 = fail if link already exists */
768 __u8 Reserved[7];
769 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
770 __le32 FileNameLength;
771 char FileName[0]; /* Name to be assigned to new link */
772} __packed; /* level 11 Set */
773
774/*
775 * This level 18, although with struct with same name is different from cifs
776 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
777 * CurrentByteOffset.
778 */
779struct smb2_file_all_info { /* data block encoding of response to level 18 */
780 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
781 __le64 LastAccessTime;
782 __le64 LastWriteTime;
783 __le64 ChangeTime;
784 __le32 Attributes;
785 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
786 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
787 __le64 EndOfFile; /* size ie offset to first free byte in file */
788 __le32 NumberOfLinks; /* hard links */
789 __u8 DeletePending;
790 __u8 Directory;
791 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
792 __le64 IndexNumber;
793 __le32 EASize;
794 __le32 AccessFlags;
795 __le64 CurrentByteOffset;
796 __le32 Mode;
797 __le32 AlignmentRequirement;
798 __le32 FileNameLength;
799 char FileName[1];
800} __packed; /* level 18 Query */
801
Namjae Jeon88d30052021-09-29 15:37:18 +0900802struct smb2_file_basic_info { /* data block encoding of response to level 18 */
803 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
804 __le64 LastAccessTime;
805 __le64 LastWriteTime;
806 __le64 ChangeTime;
807 __le32 Attributes;
808 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
809} __packed;
810
Namjae Jeone2f34482021-03-16 10:49:09 +0900811struct smb2_file_alt_name_info {
812 __le32 FileNameLength;
813 char FileName[0];
814} __packed;
815
816struct smb2_file_stream_info {
817 __le32 NextEntryOffset;
818 __le32 StreamNameLength;
819 __le64 StreamSize;
820 __le64 StreamAllocationSize;
821 char StreamName[0];
822} __packed;
823
824struct smb2_file_eof_info { /* encoding of request for level 10 */
825 __le64 EndOfFile; /* new end of file value */
826} __packed; /* level 20 Set */
827
828struct smb2_file_ntwrk_info {
829 __le64 CreationTime;
830 __le64 LastAccessTime;
831 __le64 LastWriteTime;
832 __le64 ChangeTime;
833 __le64 AllocationSize;
834 __le64 EndOfFile;
835 __le32 Attributes;
836 __le32 Reserved;
837} __packed;
838
839struct smb2_file_standard_info {
840 __le64 AllocationSize;
841 __le64 EndOfFile;
842 __le32 NumberOfLinks; /* hard links */
843 __u8 DeletePending;
844 __u8 Directory;
845 __le16 Reserved;
846} __packed; /* level 18 Query */
847
848struct smb2_file_ea_info {
849 __le32 EASize;
850} __packed;
851
852struct smb2_file_alloc_info {
853 __le64 AllocationSize;
854} __packed;
855
856struct smb2_file_disposition_info {
857 __u8 DeletePending;
858} __packed;
859
860struct smb2_file_pos_info {
861 __le64 CurrentByteOffset;
862} __packed;
863
Ronnie Sahlberg26a27872021-11-03 08:45:52 +0900864#define FILE_MODE_INFO_MASK cpu_to_le32(0x0000100e)
Namjae Jeone2f34482021-03-16 10:49:09 +0900865
866struct smb2_file_mode_info {
867 __le32 Mode;
868} __packed;
869
870#define COMPRESSION_FORMAT_NONE 0x0000
871#define COMPRESSION_FORMAT_LZNT1 0x0002
872
873struct smb2_file_comp_info {
874 __le64 CompressedFileSize;
875 __le16 CompressionFormat;
876 __u8 CompressionUnitShift;
877 __u8 ChunkShift;
878 __u8 ClusterShift;
879 __u8 Reserved[3];
880} __packed;
881
882struct smb2_file_attr_tag_info {
883 __le32 FileAttributes;
884 __le32 ReparseTag;
885} __packed;
886
887#define SL_RESTART_SCAN 0x00000001
888#define SL_RETURN_SINGLE_ENTRY 0x00000002
889#define SL_INDEX_SPECIFIED 0x00000004
890
891struct smb2_ea_info_req {
892 __le32 NextEntryOffset;
893 __u8 EaNameLength;
894 char name[1];
895} __packed; /* level 15 Query */
896
897struct smb2_ea_info {
898 __le32 NextEntryOffset;
899 __u8 Flags;
900 __u8 EaNameLength;
901 __le16 EaValueLength;
902 char name[1];
903 /* optionally followed by value */
904} __packed; /* level 15 Query */
905
906struct create_ea_buf_req {
907 struct create_context ccontext;
908 __u8 Name[8];
909 struct smb2_ea_info ea;
910} __packed;
911
912struct create_sd_buf_req {
913 struct create_context ccontext;
914 __u8 Name[8];
915 struct smb_ntsd ntsd;
916} __packed;
917
918/* Find File infolevels */
919#define SMB_FIND_FILE_POSIX_INFO 0x064
920
921/* Level 100 query info */
922struct smb311_posix_qinfo {
923 __le64 CreationTime;
924 __le64 LastAccessTime;
925 __le64 LastWriteTime;
926 __le64 ChangeTime;
927 __le64 EndOfFile;
928 __le64 AllocationSize;
929 __le32 DosAttributes;
930 __le64 Inode;
931 __le32 DeviceId;
932 __le32 Zero;
933 /* beginning of POSIX Create Context Response */
934 __le32 HardLinks;
935 __le32 ReparseTag;
936 __le32 Mode;
937 u8 Sids[];
938 /*
939 * var sized owner SID
940 * var sized group SID
941 * le32 filenamelength
942 * u8 filename[]
943 */
944} __packed;
945
946struct smb2_posix_info {
947 __le32 NextEntryOffset;
948 __u32 Ignored;
949 __le64 CreationTime;
950 __le64 LastAccessTime;
951 __le64 LastWriteTime;
952 __le64 ChangeTime;
953 __le64 EndOfFile;
954 __le64 AllocationSize;
955 __le32 DosAttributes;
956 __le64 Inode;
957 __le32 DeviceId;
958 __le32 Zero;
959 /* beginning of POSIX Create Context Response */
960 __le32 HardLinks;
961 __le32 ReparseTag;
962 __le32 Mode;
963 u8 SidBuffer[40];
964 __le32 name_len;
965 u8 name[1];
966 /*
967 * var sized owner SID
968 * var sized group SID
969 * le32 filenamelength
970 * u8 filename[]
971 */
972} __packed;
973
974/* functions */
Namjae Jeon64b39f42021-03-30 14:25:35 +0900975void init_smb2_1_server(struct ksmbd_conn *conn);
976void init_smb3_0_server(struct ksmbd_conn *conn);
977void init_smb3_02_server(struct ksmbd_conn *conn);
978int init_smb3_11_server(struct ksmbd_conn *conn);
Namjae Jeone2f34482021-03-16 10:49:09 +0900979
Namjae Jeon64b39f42021-03-30 14:25:35 +0900980void init_smb2_max_read_size(unsigned int sz);
981void init_smb2_max_write_size(unsigned int sz);
982void init_smb2_max_trans_size(unsigned int sz);
Namjae Jeon004443b2021-12-29 23:08:46 +0900983void init_smb2_max_credits(unsigned int sz);
Namjae Jeone2f34482021-03-16 10:49:09 +0900984
Namjae Jeonf4228b62021-08-12 10:16:40 +0900985bool is_smb2_neg_cmd(struct ksmbd_work *work);
986bool is_smb2_rsp(struct ksmbd_work *work);
Namjae Jeone2f34482021-03-16 10:49:09 +0900987
Namjae Jeon64b39f42021-03-30 14:25:35 +0900988u16 get_smb2_cmd_val(struct ksmbd_work *work);
989void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
990int init_smb2_rsp_hdr(struct ksmbd_work *work);
991int smb2_allocate_rsp_buf(struct ksmbd_work *work);
992bool is_chained_smb2_message(struct ksmbd_work *work);
993int init_smb2_neg_rsp(struct ksmbd_work *work);
994void smb2_set_err_rsp(struct ksmbd_work *work);
995int smb2_check_user_session(struct ksmbd_work *work);
996int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
997bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
998int smb2_check_sign_req(struct ksmbd_work *work);
999void smb2_set_sign_rsp(struct ksmbd_work *work);
1000int smb3_check_sign_req(struct ksmbd_work *work);
1001void smb3_set_sign_rsp(struct ksmbd_work *work);
1002int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
Hyunchul Leed7e58522021-05-29 09:59:59 +09001003 __le16 dialects_count);
Namjae Jeon64b39f42021-03-30 14:25:35 +09001004struct file_lock *smb_flock_init(struct file *f);
1005int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
Hyunchul Leed7e58522021-05-29 09:59:59 +09001006 void **arg);
Namjae Jeon64b39f42021-03-30 14:25:35 +09001007void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
Namjae Jeonf5a544e2021-06-18 10:04:19 +09001008struct channel *lookup_chann_list(struct ksmbd_session *sess,
1009 struct ksmbd_conn *conn);
Namjae Jeon64b39f42021-03-30 14:25:35 +09001010void smb3_preauth_hash_rsp(struct ksmbd_work *work);
Namjae Jeonf4228b62021-08-12 10:16:40 +09001011bool smb3_is_transform_hdr(void *buf);
Namjae Jeon64b39f42021-03-30 14:25:35 +09001012int smb3_decrypt_req(struct ksmbd_work *work);
1013int smb3_encrypt_resp(struct ksmbd_work *work);
1014bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
1015int smb2_set_rsp_credits(struct ksmbd_work *work);
Namjae Jeone2f34482021-03-16 10:49:09 +09001016
1017/* smb2 misc functions */
Namjae Jeon64b39f42021-03-30 14:25:35 +09001018int ksmbd_smb2_check_message(struct ksmbd_work *work);
Namjae Jeone2f34482021-03-16 10:49:09 +09001019
1020/* smb2 command handlers */
Namjae Jeon64b39f42021-03-30 14:25:35 +09001021int smb2_handle_negotiate(struct ksmbd_work *work);
1022int smb2_negotiate_request(struct ksmbd_work *work);
1023int smb2_sess_setup(struct ksmbd_work *work);
1024int smb2_tree_connect(struct ksmbd_work *work);
1025int smb2_tree_disconnect(struct ksmbd_work *work);
1026int smb2_session_logoff(struct ksmbd_work *work);
1027int smb2_open(struct ksmbd_work *work);
1028int smb2_query_info(struct ksmbd_work *work);
1029int smb2_query_dir(struct ksmbd_work *work);
1030int smb2_close(struct ksmbd_work *work);
1031int smb2_echo(struct ksmbd_work *work);
1032int smb2_set_info(struct ksmbd_work *work);
1033int smb2_read(struct ksmbd_work *work);
1034int smb2_write(struct ksmbd_work *work);
1035int smb2_flush(struct ksmbd_work *work);
1036int smb2_cancel(struct ksmbd_work *work);
1037int smb2_lock(struct ksmbd_work *work);
1038int smb2_ioctl(struct ksmbd_work *work);
1039int smb2_oplock_break(struct ksmbd_work *work);
1040int smb2_notify(struct ksmbd_work *ksmbd_work);
Namjae Jeone2f34482021-03-16 10:49:09 +09001041
Namjae Jeoncb451722021-11-03 08:08:44 +09001042/*
1043 * Get the body of the smb2 message excluding the 4 byte rfc1002 headers
1044 * from request/response buffer.
1045 */
1046static inline void *smb2_get_msg(void *buf)
1047{
1048 return buf + 4;
1049}
1050
Namjae Jeone2f34482021-03-16 10:49:09 +09001051#endif /* _SMB2PDU_H */