Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+88 -143
-6
fs/cifs/cifsglob.h
··· 852 852 #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) 853 853 #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) 854 854 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 - */ 860 855 #define CIFS_DEFAULT_IOSIZE (1024 * 1024) 861 - #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024) 862 856 863 857 /* 864 858 * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
-12
fs/cifs/cifspdu.h
··· 123 123 */ 124 124 #define CIFS_SESS_KEY_SIZE (16) 125 125 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) 138 126 #define CIFS_SERVER_CHALLENGE_SIZE (8) 139 127 #define CIFS_HMAC_MD5_HASH_SIZE (16) 140 128 #define CIFS_CPHTXT_SIZE (16)
-11
fs/cifs/smb2glob.h
··· 41 41 #define END_OF_CHAIN 4 42 42 #define RELATED_REQUEST 8 43 43 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 - 55 44 #endif /* _SMB2_GLOB_H */
-41
fs/cifs/smb2pdu.h
··· 141 141 } Data; 142 142 } __packed; 143 143 144 - struct create_posix { 145 - struct create_context ccontext; 146 - __u8 Name[16]; 147 - __le32 Mode; 148 - __u32 Reserved; 149 - } __packed; 150 - 151 144 /* See MS-SMB2 2.2.13.2.11 */ 152 145 /* Flags */ 153 146 #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002 ··· 420 427 * [1] : in_data 421 428 */ 422 429 #define SMB2_IOCTL_IOV_SIZE 2 423 - 424 - struct smb2_ioctl_req { 425 - struct smb2_hdr hdr; 426 - __le16 StructureSize; /* Must be 57 */ 427 - __u16 Reserved; 428 - __le32 CtlCode; 429 - __u64 PersistentFileId; /* opaque endianness */ 430 - __u64 VolatileFileId; /* opaque endianness */ 431 - __le32 InputOffset; 432 - __le32 InputCount; 433 - __le32 MaxInputResponse; 434 - __le32 OutputOffset; 435 - __le32 OutputCount; 436 - __le32 MaxOutputResponse; 437 - __le32 Flags; 438 - __u32 Reserved2; 439 - __u8 Buffer[]; 440 - } __packed; 441 - 442 - struct smb2_ioctl_rsp { 443 - struct smb2_hdr hdr; 444 - __le16 StructureSize; /* Must be 57 */ 445 - __u16 Reserved; 446 - __le32 CtlCode; 447 - __u64 PersistentFileId; /* opaque endianness */ 448 - __u64 VolatileFileId; /* opaque endianness */ 449 - __le32 InputOffset; 450 - __le32 InputCount; 451 - __le32 OutputOffset; 452 - __le32 OutputCount; 453 - __le32 Flags; 454 - __u32 Reserved2; 455 - /* char * buffer[] */ 456 - } __packed; 457 430 458 431 #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001 459 432 #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
+3 -3
fs/ksmbd/smb2pdu.c
··· 7581 7581 goto out; 7582 7582 } 7583 7583 7584 - cnt_code = le32_to_cpu(req->CntCode); 7584 + cnt_code = le32_to_cpu(req->CtlCode); 7585 7585 ret = smb2_calc_max_out_buf_len(work, 48, 7586 7586 le32_to_cpu(req->MaxOutputResponse)); 7587 7587 if (ret < 0) { ··· 7687 7687 rsp->PersistentFileId = req->PersistentFileId; 7688 7688 fsctl_copychunk(work, 7689 7689 (struct copychunk_ioctl_req *)&req->Buffer[0], 7690 - le32_to_cpu(req->CntCode), 7690 + le32_to_cpu(req->CtlCode), 7691 7691 le32_to_cpu(req->InputCount), 7692 7692 req->VolatileFileId, 7693 7693 req->PersistentFileId, ··· 7841 7841 goto out; 7842 7842 } 7843 7843 7844 - rsp->CntCode = cpu_to_le32(cnt_code); 7844 + rsp->CtlCode = cpu_to_le32(cnt_code); 7845 7845 rsp->InputCount = cpu_to_le32(0); 7846 7846 rsp->InputOffset = cpu_to_le32(112); 7847 7847 rsp->OutputOffset = cpu_to_le32(112);
-70
fs/ksmbd/smb2pdu.h
··· 16 16 #define FILE_CREATED 0x00000002 17 17 #define FILE_OVERWRITTEN 0x00000003 18 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 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 - 42 19 /* SMB2 Max Credits */ 43 20 #define SMB2_MAX_CREDITS 8192 44 - 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 21 50 22 /* BB FIXME - analyze following length BB */ 51 23 #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */ 52 24 53 25 #define SMB21_DEFAULT_IOSIZE (1024 * 1024) 54 - #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024) 55 26 #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024) 56 27 #define SMB3_MIN_IOSIZE (64 * 1024) 57 28 #define SMB3_MAX_IOSIZE (8 * 1024 * 1024) ··· 120 149 __le64 AllocationSize; 121 150 } __packed; 122 151 123 - struct create_posix { 124 - struct create_context ccontext; 125 - __u8 Name[16]; 126 - __le32 Mode; 127 - __u32 Reserved; 128 - } __packed; 129 - 130 152 struct create_durable_rsp { 131 153 struct create_context ccontext; 132 154 __u8 Name[8]; ··· 175 211 __le64 SourceFileOffset; 176 212 __le64 TargetFileOffset; 177 213 __le64 ByteCount; /* Bytes to be copied */ 178 - } __packed; 179 - 180 - struct smb2_ioctl_req { 181 - struct smb2_hdr hdr; 182 - __le16 StructureSize; /* Must be 57 */ 183 - __le16 Reserved; /* offset from start of SMB2 header to write data */ 184 - __le32 CntCode; 185 - __u64 PersistentFileId; 186 - __u64 VolatileFileId; 187 - __le32 InputOffset; /* Reserved MBZ */ 188 - __le32 InputCount; 189 - __le32 MaxInputResponse; 190 - __le32 OutputOffset; 191 - __le32 OutputCount; 192 - __le32 MaxOutputResponse; 193 - __le32 Flags; 194 - __le32 Reserved2; 195 - __u8 Buffer[1]; 196 - } __packed; 197 - 198 - struct smb2_ioctl_rsp { 199 - struct smb2_hdr hdr; 200 - __le16 StructureSize; /* Must be 49 */ 201 - __le16 Reserved; /* offset from start of SMB2 header to write data */ 202 - __le32 CntCode; 203 - __u64 PersistentFileId; 204 - __u64 VolatileFileId; 205 - __le32 InputOffset; /* Reserved MBZ */ 206 - __le32 InputCount; 207 - __le32 OutputOffset; 208 - __le32 OutputCount; 209 - __le32 Flags; 210 - __le32 Reserved2; 211 - __u8 Buffer[1]; 212 214 } __packed; 213 215 214 216 struct validate_negotiate_info_req {
+85
fs/smbfs_common/smb2pdu.h
··· 61 61 #define NUMBER_OF_SMB2_COMMANDS 0x0013 62 62 63 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 + 97 + /* 64 98 * SMB2 Header Definition 65 99 * 66 100 * "MBZ" : Must be Zero ··· 121 87 #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */ 122 88 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000) 123 89 #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */ 90 + 91 + /* 92 + * Definitions for SMB2 Protocol Data Units (network frames) 93 + * 94 + * See MS-SMB2.PDF specification for protocol details. 95 + * The Naming convention is the lower case version of the SMB2 96 + * command code name for the struct. Note that structures must be packed. 97 + * 98 + */ 124 99 125 100 /* See MS-SMB2 section 2.2.1 */ 126 101 struct smb2_hdr { ··· 1040 997 __u8 Buffer[1]; 1041 998 } __packed; 1042 999 1000 + struct create_posix { 1001 + struct create_context ccontext; 1002 + __u8 Name[16]; 1003 + __le32 Mode; 1004 + __u32 Reserved; 1005 + } __packed; 1006 + 1043 1007 #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00) 1044 1008 #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01) 1045 1009 #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02) ··· 1084 1034 __u8 Name[8]; 1085 1035 struct lease_context_v2 lcontext; 1086 1036 __u8 Pad[4]; 1037 + } __packed; 1038 + 1039 + /* See MS-SMB2 2.2.31 and 2.2.32 */ 1040 + struct smb2_ioctl_req { 1041 + struct smb2_hdr hdr; 1042 + __le16 StructureSize; /* Must be 57 */ 1043 + __le16 Reserved; /* offset from start of SMB2 header to write data */ 1044 + __le32 CtlCode; 1045 + __u64 PersistentFileId; 1046 + __u64 VolatileFileId; 1047 + __le32 InputOffset; /* Reserved MBZ */ 1048 + __le32 InputCount; 1049 + __le32 MaxInputResponse; 1050 + __le32 OutputOffset; 1051 + __le32 OutputCount; 1052 + __le32 MaxOutputResponse; 1053 + __le32 Flags; 1054 + __le32 Reserved2; 1055 + __u8 Buffer[]; 1056 + } __packed; 1057 + 1058 + struct smb2_ioctl_rsp { 1059 + struct smb2_hdr hdr; 1060 + __le16 StructureSize; /* Must be 49 */ 1061 + __le16 Reserved; 1062 + __le32 CtlCode; 1063 + __u64 PersistentFileId; 1064 + __u64 VolatileFileId; 1065 + __le32 InputOffset; /* Reserved MBZ */ 1066 + __le32 InputCount; 1067 + __le32 OutputOffset; 1068 + __le32 OutputCount; 1069 + __le32 Flags; 1070 + __le32 Reserved2; 1071 + __u8 Buffer[]; 1087 1072 } __packed; 1088 1073 1089 1074 /* Possible InfoType values */