Skip to content

Commit 15e7b6d

Browse files
committed
smb3: move defines for ioctl protocol header and SMB2 sizes to smbfs_common
The definitions for the ioctl SMB3 request and response as well as length of various fields defined in the protocol documentation were duplicated in fs/ksmbd and fs/cifs. Move these to the common code in fs/smbfs_common/smb2pdu.h Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 113be37 commit 15e7b6d

7 files changed

Lines changed: 88 additions & 143 deletions

File tree

fs/cifs/cifsglob.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,7 @@ compare_mid(__u16 mid, const struct smb_hdr *smb)
852852
#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
853853
#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4)
854854

855-
/*
856-
* The default wsize is 1M. find_get_pages seems to return a maximum of 256
857-
* pages in a single call. With PAGE_SIZE == 4k, this means we can fill
858-
* a single wsize request with a single call.
859-
*/
860855
#define CIFS_DEFAULT_IOSIZE (1024 * 1024)
861-
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
862856

863857
/*
864858
* Windows only supports a max of 60kb reads and 65535 byte writes. Default to

fs/cifs/cifspdu.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@
123123
*/
124124
#define CIFS_SESS_KEY_SIZE (16)
125125

126-
/*
127-
* Size of the smb3 signing key
128-
*/
129-
#define SMB3_SIGN_KEY_SIZE (16)
130-
131-
/*
132-
* Size of the smb3 encryption/decryption key storage.
133-
* This size is big enough to store any cipher key types.
134-
*/
135-
#define SMB3_ENC_DEC_KEY_SIZE (32)
136-
137-
#define CIFS_CLIENT_CHALLENGE_SIZE (8)
138126
#define CIFS_SERVER_CHALLENGE_SIZE (8)
139127
#define CIFS_HMAC_MD5_HASH_SIZE (16)
140128
#define CIFS_CPHTXT_SIZE (16)

fs/cifs/smb2glob.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,4 @@
4141
#define END_OF_CHAIN 4
4242
#define RELATED_REQUEST 8
4343

44-
#define SMB2_SIGNATURE_SIZE (16)
45-
#define SMB2_NTLMV2_SESSKEY_SIZE (16)
46-
#define SMB2_HMACSHA256_SIZE (32)
47-
#define SMB2_CMACAES_SIZE (16)
48-
#define SMB3_SIGNKEY_SIZE (16)
49-
#define SMB3_GCM128_CRYPTKEY_SIZE (16)
50-
#define SMB3_GCM256_CRYPTKEY_SIZE (32)
51-
52-
/* Maximum buffer size value we can send with 1 credit */
53-
#define SMB2_MAX_BUFFER_SIZE 65536
54-
5544
#endif /* _SMB2_GLOB_H */

fs/cifs/smb2pdu.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ struct create_durable {
141141
} Data;
142142
} __packed;
143143

144-
struct create_posix {
145-
struct create_context ccontext;
146-
__u8 Name[16];
147-
__le32 Mode;
148-
__u32 Reserved;
149-
} __packed;
150-
151144
/* See MS-SMB2 2.2.13.2.11 */
152145
/* Flags */
153146
#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
@@ -428,40 +421,6 @@ struct duplicate_extents_to_file {
428421
*/
429422
#define SMB2_IOCTL_IOV_SIZE 2
430423

431-
struct smb2_ioctl_req {
432-
struct smb2_hdr hdr;
433-
__le16 StructureSize; /* Must be 57 */
434-
__u16 Reserved;
435-
__le32 CtlCode;
436-
__u64 PersistentFileId; /* opaque endianness */
437-
__u64 VolatileFileId; /* opaque endianness */
438-
__le32 InputOffset;
439-
__le32 InputCount;
440-
__le32 MaxInputResponse;
441-
__le32 OutputOffset;
442-
__le32 OutputCount;
443-
__le32 MaxOutputResponse;
444-
__le32 Flags;
445-
__u32 Reserved2;
446-
__u8 Buffer[];
447-
} __packed;
448-
449-
struct smb2_ioctl_rsp {
450-
struct smb2_hdr hdr;
451-
__le16 StructureSize; /* Must be 57 */
452-
__u16 Reserved;
453-
__le32 CtlCode;
454-
__u64 PersistentFileId; /* opaque endianness */
455-
__u64 VolatileFileId; /* opaque endianness */
456-
__le32 InputOffset;
457-
__le32 InputCount;
458-
__le32 OutputOffset;
459-
__le32 OutputCount;
460-
__le32 Flags;
461-
__u32 Reserved2;
462-
/* char * buffer[] */
463-
} __packed;
464-
465424
#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
466425
#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
467426
#define SMB2_LOCKFLAG_UNLOCK 0x0004

fs/ksmbd/smb2pdu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7581,7 +7581,7 @@ int smb2_ioctl(struct ksmbd_work *work)
75817581
goto out;
75827582
}
75837583

7584-
cnt_code = le32_to_cpu(req->CntCode);
7584+
cnt_code = le32_to_cpu(req->CtlCode);
75857585
ret = smb2_calc_max_out_buf_len(work, 48,
75867586
le32_to_cpu(req->MaxOutputResponse));
75877587
if (ret < 0) {
@@ -7687,7 +7687,7 @@ int smb2_ioctl(struct ksmbd_work *work)
76877687
rsp->PersistentFileId = req->PersistentFileId;
76887688
fsctl_copychunk(work,
76897689
(struct copychunk_ioctl_req *)&req->Buffer[0],
7690-
le32_to_cpu(req->CntCode),
7690+
le32_to_cpu(req->CtlCode),
76917691
le32_to_cpu(req->InputCount),
76927692
req->VolatileFileId,
76937693
req->PersistentFileId,
@@ -7841,7 +7841,7 @@ int smb2_ioctl(struct ksmbd_work *work)
78417841
goto out;
78427842
}
78437843

7844-
rsp->CntCode = cpu_to_le32(cnt_code);
7844+
rsp->CtlCode = cpu_to_le32(cnt_code);
78457845
rsp->InputCount = cpu_to_le32(0);
78467846
rsp->InputOffset = cpu_to_le32(112);
78477847
rsp->OutputOffset = cpu_to_le32(112);

fs/ksmbd/smb2pdu.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,13 @@
1616
#define FILE_CREATED 0x00000002
1717
#define FILE_OVERWRITTEN 0x00000003
1818

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
26-
#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
33-
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-
4219
/* SMB2 Max Credits */
4320
#define SMB2_MAX_CREDITS 8192
4421

45-
/* 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-
5022
/* BB FIXME - analyze following length BB */
5123
#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
5224

5325
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
54-
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
5526
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
5627
#define SMB3_MIN_IOSIZE (64 * 1024)
5728
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
@@ -149,13 +120,6 @@ struct create_alloc_size_req {
149120
__le64 AllocationSize;
150121
} __packed;
151122

152-
struct create_posix {
153-
struct create_context ccontext;
154-
__u8 Name[16];
155-
__le32 Mode;
156-
__u32 Reserved;
157-
} __packed;
158-
159123
struct create_durable_rsp {
160124
struct create_context ccontext;
161125
__u8 Name[8];
@@ -213,40 +177,6 @@ struct duplicate_extents_to_file {
213177
__le64 ByteCount; /* Bytes to be copied */
214178
} __packed;
215179

216-
struct smb2_ioctl_req {
217-
struct smb2_hdr hdr;
218-
__le16 StructureSize; /* Must be 57 */
219-
__le16 Reserved; /* offset from start of SMB2 header to write data */
220-
__le32 CntCode;
221-
__u64 PersistentFileId;
222-
__u64 VolatileFileId;
223-
__le32 InputOffset; /* Reserved MBZ */
224-
__le32 InputCount;
225-
__le32 MaxInputResponse;
226-
__le32 OutputOffset;
227-
__le32 OutputCount;
228-
__le32 MaxOutputResponse;
229-
__le32 Flags;
230-
__le32 Reserved2;
231-
__u8 Buffer[1];
232-
} __packed;
233-
234-
struct smb2_ioctl_rsp {
235-
struct smb2_hdr hdr;
236-
__le16 StructureSize; /* Must be 49 */
237-
__le16 Reserved; /* offset from start of SMB2 header to write data */
238-
__le32 CntCode;
239-
__u64 PersistentFileId;
240-
__u64 VolatileFileId;
241-
__le32 InputOffset; /* Reserved MBZ */
242-
__le32 InputCount;
243-
__le32 OutputOffset;
244-
__le32 OutputCount;
245-
__le32 Flags;
246-
__le32 Reserved2;
247-
__u8 Buffer[1];
248-
} __packed;
249-
250180
struct validate_negotiate_info_req {
251181
__le32 Capabilities;
252182
__u8 Guid[SMB2_CLIENT_GUID_SIZE];

fs/smbfs_common/smb2pdu.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,40 @@
6060

6161
#define NUMBER_OF_SMB2_COMMANDS 0x0013
6262

63+
/*
64+
* Size of the session key (crypto key encrypted with the password
65+
*/
66+
#define SMB2_NTLMV2_SESSKEY_SIZE 16
67+
#define SMB2_SIGNATURE_SIZE 16
68+
#define SMB2_HMACSHA256_SIZE 32
69+
#define SMB2_CMACAES_SIZE 16
70+
#define SMB3_GCM128_CRYPTKEY_SIZE 16
71+
#define SMB3_GCM256_CRYPTKEY_SIZE 32
72+
73+
/*
74+
* Size of the smb3 encryption/decryption keys
75+
* This size is big enough to store any cipher key types.
76+
*/
77+
#define SMB3_ENC_DEC_KEY_SIZE 32
78+
79+
/*
80+
* Size of the smb3 signing key
81+
*/
82+
#define SMB3_SIGN_KEY_SIZE 16
83+
84+
#define CIFS_CLIENT_CHALLENGE_SIZE 8
85+
86+
/* Maximum buffer size value we can send with 1 credit */
87+
#define SMB2_MAX_BUFFER_SIZE 65536
88+
89+
/*
90+
* The default wsize is 1M for SMB2 (and for some CIFS cases).
91+
* find_get_pages seems to return a maximum of 256
92+
* pages in a single call. With PAGE_SIZE == 4k, this means we can
93+
* fill a single wsize request with a single call.
94+
*/
95+
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
96+
6397
/*
6498
* SMB2 Header Definition
6599
*
@@ -88,6 +122,15 @@
88122
#define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
89123
#define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
90124

125+
/*
126+
* Definitions for SMB2 Protocol Data Units (network frames)
127+
*
128+
* See MS-SMB2.PDF specification for protocol details.
129+
* The Naming convention is the lower case version of the SMB2
130+
* command code name for the struct. Note that structures must be packed.
131+
*
132+
*/
133+
91134
/* See MS-SMB2 section 2.2.1 */
92135
struct smb2_hdr {
93136
__le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
@@ -997,6 +1040,13 @@ struct smb2_create_rsp {
9971040
__u8 Buffer[1];
9981041
} __packed;
9991042

1043+
struct create_posix {
1044+
struct create_context ccontext;
1045+
__u8 Name[16];
1046+
__le32 Mode;
1047+
__u32 Reserved;
1048+
} __packed;
1049+
10001050
#define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
10011051
#define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
10021052
#define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
@@ -1036,6 +1086,41 @@ struct create_lease_v2 {
10361086
__u8 Pad[4];
10371087
} __packed;
10381088

1089+
/* See MS-SMB2 2.2.31 and 2.2.32 */
1090+
struct smb2_ioctl_req {
1091+
struct smb2_hdr hdr;
1092+
__le16 StructureSize; /* Must be 57 */
1093+
__le16 Reserved; /* offset from start of SMB2 header to write data */
1094+
__le32 CtlCode;
1095+
__u64 PersistentFileId;
1096+
__u64 VolatileFileId;
1097+
__le32 InputOffset; /* Reserved MBZ */
1098+
__le32 InputCount;
1099+
__le32 MaxInputResponse;
1100+
__le32 OutputOffset;
1101+
__le32 OutputCount;
1102+
__le32 MaxOutputResponse;
1103+
__le32 Flags;
1104+
__le32 Reserved2;
1105+
__u8 Buffer[];
1106+
} __packed;
1107+
1108+
struct smb2_ioctl_rsp {
1109+
struct smb2_hdr hdr;
1110+
__le16 StructureSize; /* Must be 49 */
1111+
__le16 Reserved;
1112+
__le32 CtlCode;
1113+
__u64 PersistentFileId;
1114+
__u64 VolatileFileId;
1115+
__le32 InputOffset; /* Reserved MBZ */
1116+
__le32 InputCount;
1117+
__le32 OutputOffset;
1118+
__le32 OutputCount;
1119+
__le32 Flags;
1120+
__le32 Reserved2;
1121+
__u8 Buffer[];
1122+
} __packed;
1123+
10391124
/* Possible InfoType values */
10401125
#define SMB2_O_INFO_FILE 0x01
10411126
#define SMB2_O_INFO_FILESYSTEM 0x02

0 commit comments

Comments
 (0)