smb3: move defines for ioctl protocol header and SMB2 sizes to smbfs_common
authorSteve French <stfrench@microsoft.com>
Sat, 26 Mar 2022 17:47:57 +0000 (12:47 -0500)
committerSteve French <stfrench@microsoft.com>
Thu, 21 Jul 2022 15:40:01 +0000 (10:40 -0500)
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>
fs/cifs/cifsglob.h
fs/cifs/cifspdu.h
fs/cifs/smb2glob.h
fs/cifs/smb2pdu.h
fs/smbfs_common/smb2pdu.h

index cace0818d5108571f2c3d52ccc9fb02b483facce..45abee59ab3c629578abafdef2be6cd94f275a8f 100644 (file)
@@ -855,13 +855,7 @@ compare_mid(__u16 mid, const struct smb_hdr *smb)
 #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
 #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4)
 
-/*
- * The default wsize is 1M. find_get_pages seems to return a maximum of 256
- * pages in a single call. With PAGE_SIZE == 4k, this means we can fill
- * a single wsize request with a single call.
- */
 #define CIFS_DEFAULT_IOSIZE (1024 * 1024)
-#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
 
 /*
  * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
index 68b9a436af4bf322c5958ac2283a8e59e160ee7a..f214cbeb2a364867548ebd10eaacd854f01b9de5 100644 (file)
  */
 #define CIFS_SESS_KEY_SIZE (16)
 
-/*
- * Size of the smb3 signing key
- */
-#define SMB3_SIGN_KEY_SIZE (16)
-
-/*
- * Size of the smb3 encryption/decryption key storage.
- * This size is big enough to store any cipher key types.
- */
-#define SMB3_ENC_DEC_KEY_SIZE (32)
-
-#define CIFS_CLIENT_CHALLENGE_SIZE (8)
 #define CIFS_SERVER_CHALLENGE_SIZE (8)
 #define CIFS_HMAC_MD5_HASH_SIZE (16)
 #define CIFS_CPHTXT_SIZE (16)
index 4125fd113cfbaedd36ba86ae6d2f7da486123402..82e916ad167c00b9fac7c5ea36756302b867287e 100644 (file)
 #define END_OF_CHAIN 4
 #define RELATED_REQUEST 8
 
-#define SMB2_SIGNATURE_SIZE (16)
-#define SMB2_NTLMV2_SESSKEY_SIZE (16)
-#define SMB2_HMACSHA256_SIZE (32)
-#define SMB2_CMACAES_SIZE (16)
-#define SMB3_SIGNKEY_SIZE (16)
-#define SMB3_GCM128_CRYPTKEY_SIZE (16)
-#define SMB3_GCM256_CRYPTKEY_SIZE (32)
-
-/* Maximum buffer size value we can send with 1 credit */
-#define SMB2_MAX_BUFFER_SIZE 65536
-
 #endif /* _SMB2_GLOB_H */
index 9aa2ab8ca5aebe63320cbbec8c96918fd83ffc7d..162f1be886fef6df6e8fa1558290d2639fb1d986 100644 (file)
@@ -141,13 +141,6 @@ struct create_durable {
        } Data;
 } __packed;
 
-struct create_posix {
-       struct create_context ccontext;
-       __u8    Name[16];
-       __le32  Mode;
-       __u32   Reserved;
-} __packed;
-
 /* See MS-SMB2 2.2.13.2.11 */
 /* Flags */
 #define SMB2_DHANDLE_FLAG_PERSISTENT   0x00000002
@@ -428,40 +421,6 @@ struct duplicate_extents_to_file {
  */
 #define SMB2_IOCTL_IOV_SIZE 2
 
-struct smb2_ioctl_req {
-       struct smb2_hdr hdr;
-       __le16 StructureSize;   /* Must be 57 */
-       __u16 Reserved;
-       __le32 CtlCode;
-       __u64  PersistentFileId; /* opaque endianness */
-       __u64  VolatileFileId; /* opaque endianness */
-       __le32 InputOffset;
-       __le32 InputCount;
-       __le32 MaxInputResponse;
-       __le32 OutputOffset;
-       __le32 OutputCount;
-       __le32 MaxOutputResponse;
-       __le32 Flags;
-       __u32  Reserved2;
-       __u8   Buffer[];
-} __packed;
-
-struct smb2_ioctl_rsp {
-       struct smb2_hdr hdr;
-       __le16 StructureSize;   /* Must be 57 */
-       __u16 Reserved;
-       __le32 CtlCode;
-       __u64  PersistentFileId; /* opaque endianness */
-       __u64  VolatileFileId; /* opaque endianness */
-       __le32 InputOffset;
-       __le32 InputCount;
-       __le32 OutputOffset;
-       __le32 OutputCount;
-       __le32 Flags;
-       __u32  Reserved2;
-       /* char * buffer[] */
-} __packed;
-
 #define SMB2_LOCKFLAG_SHARED_LOCK      0x0001
 #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK   0x0002
 #define SMB2_LOCKFLAG_UNLOCK           0x0004
index c21ecc4806f1af84903ad75059003623b28eb771..67b41f0830252f6128eb848c4a5b7daf26f6ebbd 100644 (file)
 
 #define NUMBER_OF_SMB2_COMMANDS        0x0013
 
+/*
+ * Size of the session key (crypto key encrypted with the password
+ */
+#define SMB2_NTLMV2_SESSKEY_SIZE       16
+#define SMB2_SIGNATURE_SIZE            16
+#define SMB2_HMACSHA256_SIZE           32
+#define SMB2_CMACAES_SIZE              16
+#define SMB3_GCM128_CRYPTKEY_SIZE      16
+#define SMB3_GCM256_CRYPTKEY_SIZE      32
+
+/*
+ * Size of the smb3 encryption/decryption keys
+ * This size is big enough to store any cipher key types.
+ */
+#define SMB3_ENC_DEC_KEY_SIZE          32
+
+/*
+ * Size of the smb3 signing key
+ */
+#define SMB3_SIGN_KEY_SIZE             16
+
+#define CIFS_CLIENT_CHALLENGE_SIZE     8
+
+/* Maximum buffer size value we can send with 1 credit */
+#define SMB2_MAX_BUFFER_SIZE 65536
+
+/*
+ * The default wsize is 1M for SMB2 (and for some CIFS cases).
+ * find_get_pages seems to return a maximum of 256
+ * pages in a single call. With PAGE_SIZE == 4k, this means we can
+ * fill a single wsize request with a single call.
+ */
+#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
+
 /*
  * SMB2 Header Definition
  *
 #define SMB2_FLAGS_DFS_OPERATIONS      cpu_to_le32(0x10000000)
 #define SMB2_FLAGS_REPLAY_OPERATION    cpu_to_le32(0x20000000) /* SMB3 & up */
 
+/*
+ *     Definitions for SMB2 Protocol Data Units (network frames)
+ *
+ *  See MS-SMB2.PDF specification for protocol details.
+ *  The Naming convention is the lower case version of the SMB2
+ *  command code name for the struct. Note that structures must be packed.
+ *
+ */
+
 /* See MS-SMB2 section 2.2.1 */
 struct smb2_hdr {
        __le32 ProtocolId;      /* 0xFE 'S' 'M' 'B' */
@@ -997,6 +1040,13 @@ struct smb2_create_rsp {
        __u8   Buffer[1];
 } __packed;
 
+struct create_posix {
+       struct create_context ccontext;
+       __u8    Name[16];
+       __le32  Mode;
+       __u32   Reserved;
+} __packed;
+
 #define SMB2_LEASE_NONE_LE                     cpu_to_le32(0x00)
 #define SMB2_LEASE_READ_CACHING_LE             cpu_to_le32(0x01)
 #define SMB2_LEASE_HANDLE_CACHING_LE           cpu_to_le32(0x02)
@@ -1036,6 +1086,41 @@ struct create_lease_v2 {
        __u8   Pad[4];
 } __packed;
 
+/* See MS-SMB2 2.2.31 and 2.2.32 */
+struct smb2_ioctl_req {
+       struct smb2_hdr hdr;
+       __le16 StructureSize; /* Must be 57 */
+       __le16 Reserved; /* offset from start of SMB2 header to write data */
+       __le32 CtlCode;
+       __u64  PersistentFileId;
+       __u64  VolatileFileId;
+       __le32 InputOffset; /* Reserved MBZ */
+       __le32 InputCount;
+       __le32 MaxInputResponse;
+       __le32 OutputOffset;
+       __le32 OutputCount;
+       __le32 MaxOutputResponse;
+       __le32 Flags;
+       __le32 Reserved2;
+       __u8   Buffer[];
+} __packed;
+
+struct smb2_ioctl_rsp {
+       struct smb2_hdr hdr;
+       __le16 StructureSize; /* Must be 49 */
+       __le16 Reserved;
+       __le32 CtlCode;
+       __u64  PersistentFileId;
+       __u64  VolatileFileId;
+       __le32 InputOffset; /* Reserved MBZ */
+       __le32 InputCount;
+       __le32 OutputOffset;
+       __le32 OutputCount;
+       __le32 Flags;
+       __le32 Reserved2;
+       __u8   Buffer[];
+} __packed;
+
 /* Possible InfoType values */
 #define SMB2_O_INFO_FILE       0x01
 #define SMB2_O_INFO_FILESYSTEM 0x02