Skip to content

Commit d6c9ad2

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
ksmbd: use the common definitions for NEGOTIATE_PROTOCOL
Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4355a8f commit d6c9ad2

File tree

4 files changed

+15
-167
lines changed

4 files changed

+15
-167
lines changed

fs/ksmbd/smb2ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
198198
conn->cmds = smb2_0_server_cmds;
199199
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
200200
conn->max_credits = SMB2_MAX_CREDITS;
201-
conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256;
201+
conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256_LE;
202202

203203
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
204204
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
@@ -216,7 +216,7 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
216216
conn->cmds = smb2_0_server_cmds;
217217
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
218218
conn->max_credits = SMB2_MAX_CREDITS;
219-
conn->signing_algorithm = SIGNING_ALG_AES_CMAC;
219+
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
220220

221221
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
222222
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
@@ -241,7 +241,7 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
241241
conn->cmds = smb2_0_server_cmds;
242242
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
243243
conn->max_credits = SMB2_MAX_CREDITS;
244-
conn->signing_algorithm = SIGNING_ALG_AES_CMAC;
244+
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
245245

246246
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
247247
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
@@ -266,7 +266,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
266266
conn->cmds = smb2_0_server_cmds;
267267
conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
268268
conn->max_credits = SMB2_MAX_CREDITS;
269-
conn->signing_algorithm = SIGNING_ALG_AES_CMAC;
269+
conn->signing_algorithm = SIGNING_ALG_AES_CMAC_LE;
270270

271271
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
272272
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;

fs/ksmbd/smb2pdu.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -751,16 +751,16 @@ static void build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt,
751751
pneg_ctxt->Ciphers[0] = cipher_type;
752752
}
753753

754-
static void build_compression_ctxt(struct smb2_compression_ctx *pneg_ctxt,
754+
static void build_compression_ctxt(struct smb2_compression_capabilities_context *pneg_ctxt,
755755
__le16 comp_algo)
756756
{
757757
pneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES;
758758
pneg_ctxt->DataLength =
759-
cpu_to_le16(sizeof(struct smb2_compression_ctx)
759+
cpu_to_le16(sizeof(struct smb2_compression_capabilities_context)
760760
- sizeof(struct smb2_neg_context));
761761
pneg_ctxt->Reserved = cpu_to_le32(0);
762762
pneg_ctxt->CompressionAlgorithmCount = cpu_to_le16(1);
763-
pneg_ctxt->Reserved1 = cpu_to_le32(0);
763+
pneg_ctxt->Flags = cpu_to_le32(0);
764764
pneg_ctxt->CompressionAlgorithms[0] = comp_algo;
765765
}
766766

@@ -837,12 +837,12 @@ static void assemble_neg_contexts(struct ksmbd_conn *conn,
837837
ksmbd_debug(SMB,
838838
"assemble SMB2_COMPRESSION_CAPABILITIES context\n");
839839
/* Temporarily set to SMB3_COMPRESS_NONE */
840-
build_compression_ctxt((struct smb2_compression_ctx *)pneg_ctxt,
840+
build_compression_ctxt((struct smb2_compression_capabilities_context *)pneg_ctxt,
841841
conn->compress_algorithm);
842842
rsp->NegotiateContextCount = cpu_to_le16(++neg_ctxt_cnt);
843-
ctxt_size += sizeof(struct smb2_compression_ctx) + 2;
843+
ctxt_size += sizeof(struct smb2_compression_capabilities_context) + 2;
844844
/* Round to 8 byte boundary */
845-
pneg_ctxt += round_up(sizeof(struct smb2_compression_ctx) + 2,
845+
pneg_ctxt += round_up(sizeof(struct smb2_compression_capabilities_context) + 2,
846846
8);
847847
}
848848

@@ -916,7 +916,7 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn,
916916
}
917917

918918
static void decode_compress_ctxt(struct ksmbd_conn *conn,
919-
struct smb2_compression_ctx *pneg_ctxt)
919+
struct smb2_compression_capabilities_context *pneg_ctxt)
920920
{
921921
conn->compress_algorithm = SMB3_COMPRESS_NONE;
922922
}
@@ -937,8 +937,8 @@ static void decode_sign_cap_ctxt(struct ksmbd_conn *conn,
937937
}
938938

939939
for (i = 0; i < sign_algo_cnt; i++) {
940-
if (pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_HMAC_SHA256 ||
941-
pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_AES_CMAC) {
940+
if (pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_HMAC_SHA256_LE ||
941+
pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_AES_CMAC_LE) {
942942
ksmbd_debug(SMB, "Signing Algorithm ID = 0x%x\n",
943943
pneg_ctxt->SigningAlgorithms[i]);
944944
conn->signing_negotiated = true;
@@ -1009,7 +1009,7 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,
10091009
break;
10101010

10111011
decode_compress_ctxt(conn,
1012-
(struct smb2_compression_ctx *)pctx);
1012+
(struct smb2_compression_capabilities_context *)pctx);
10131013
} else if (pctx->ContextType == SMB2_NETNAME_NEGOTIATE_CONTEXT_ID) {
10141014
ksmbd_debug(SMB,
10151015
"deassemble SMB2_NETNAME_NEGOTIATE_CONTEXT_ID context\n");

fs/ksmbd/smb2pdu.h

Lines changed: 1 addition & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
/* SMB2 Max Credits */
4343
#define SMB2_MAX_CREDITS 8192
4444

45-
#define SMB2_CLIENT_GUID_SIZE 16
46-
#define SMB2_CREATE_GUID_SIZE 16
47-
4845
/* Maximum buffer size value we can send with 1 credit */
4946
#define SMB2_MAX_BUFFER_SIZE 65536
5047

@@ -80,48 +77,11 @@ struct smb2_err_rsp {
8077
__u8 ErrorData[1]; /* variable length */
8178
} __packed;
8279

83-
struct smb2_negotiate_req {
84-
struct smb2_hdr hdr;
85-
__le16 StructureSize; /* Must be 36 */
86-
__le16 DialectCount;
87-
__le16 SecurityMode;
88-
__le16 Reserved; /* MBZ */
89-
__le32 Capabilities;
90-
__u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
91-
/* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
92-
__le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
93-
__le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
94-
__le16 Reserved2;
95-
__le16 Dialects[1]; /* One dialect (vers=) at a time for now */
96-
} __packed;
97-
98-
/* SecurityMode flags */
99-
#define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
100-
#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
101-
#define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
102-
/* Capabilities flags */
103-
#define SMB2_GLOBAL_CAP_DFS 0x00000001
104-
#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
105-
#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
106-
#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
107-
#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
108-
#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
109-
#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
110-
/* Internal types */
111-
#define SMB2_NT_FIND 0x00100000
112-
#define SMB2_LARGE_FILES 0x00200000
113-
114-
#define SMB311_SALT_SIZE 32
115-
/* Hash Algorithm Types */
116-
#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
117-
118-
#define PREAUTH_HASHVALUE_SIZE 64
119-
12080
struct preauth_integrity_info {
12181
/* PreAuth integrity Hash ID */
12282
__le16 Preauth_HashId;
12383
/* PreAuth integrity Hash Value */
124-
__u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
84+
__u8 Preauth_HashValue[SMB2_PREAUTH_HASH_SIZE];
12585
};
12686

12787
/* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
@@ -137,107 +97,6 @@ struct preauth_integrity_info {
13797
#define OFFSET_OF_NEG_CONTEXT 0xd0
13898
#endif
13999

140-
#define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
141-
#define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
142-
#define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
143-
#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
144-
#define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
145-
#define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
146-
147-
struct smb2_neg_context {
148-
__le16 ContextType;
149-
__le16 DataLength;
150-
__le32 Reserved;
151-
/* Followed by array of data */
152-
} __packed;
153-
154-
struct smb2_preauth_neg_context {
155-
__le16 ContextType; /* 1 */
156-
__le16 DataLength;
157-
__le32 Reserved;
158-
__le16 HashAlgorithmCount; /* 1 */
159-
__le16 SaltLength;
160-
__le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
161-
__u8 Salt[SMB311_SALT_SIZE];
162-
} __packed;
163-
164-
/* Encryption Algorithms Ciphers */
165-
#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
166-
#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
167-
#define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
168-
#define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
169-
170-
struct smb2_encryption_neg_context {
171-
__le16 ContextType; /* 2 */
172-
__le16 DataLength;
173-
__le32 Reserved;
174-
/* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
175-
__le16 CipherCount; /* AES-128-GCM and AES-128-CCM by default */
176-
__le16 Ciphers[];
177-
} __packed;
178-
179-
#define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
180-
#define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
181-
#define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
182-
#define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
183-
184-
struct smb2_compression_ctx {
185-
__le16 ContextType; /* 3 */
186-
__le16 DataLength;
187-
__le32 Reserved;
188-
__le16 CompressionAlgorithmCount;
189-
__u16 Padding;
190-
__le32 Reserved1;
191-
__le16 CompressionAlgorithms[];
192-
} __packed;
193-
194-
#define POSIX_CTXT_DATA_LEN 16
195-
struct smb2_posix_neg_context {
196-
__le16 ContextType; /* 0x100 */
197-
__le16 DataLength;
198-
__le32 Reserved;
199-
__u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
200-
} __packed;
201-
202-
struct smb2_netname_neg_context {
203-
__le16 ContextType; /* 0x100 */
204-
__le16 DataLength;
205-
__le32 Reserved;
206-
__le16 NetName[]; /* hostname of target converted to UCS-2 */
207-
} __packed;
208-
209-
/* Signing algorithms */
210-
#define SIGNING_ALG_HMAC_SHA256 cpu_to_le16(0)
211-
#define SIGNING_ALG_AES_CMAC cpu_to_le16(1)
212-
#define SIGNING_ALG_AES_GMAC cpu_to_le16(2)
213-
214-
struct smb2_signing_capabilities {
215-
__le16 ContextType; /* 8 */
216-
__le16 DataLength;
217-
__le32 Reserved;
218-
__le16 SigningAlgorithmCount;
219-
__le16 SigningAlgorithms[];
220-
} __packed;
221-
222-
struct smb2_negotiate_rsp {
223-
struct smb2_hdr hdr;
224-
__le16 StructureSize; /* Must be 65 */
225-
__le16 SecurityMode;
226-
__le16 DialectRevision;
227-
__le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
228-
__u8 ServerGUID[16];
229-
__le32 Capabilities;
230-
__le32 MaxTransactSize;
231-
__le32 MaxReadSize;
232-
__le32 MaxWriteSize;
233-
__le64 SystemTime; /* MBZ */
234-
__le64 ServerStartTime;
235-
__le16 SecurityBufferOffset;
236-
__le16 SecurityBufferLength;
237-
__le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
238-
__u8 Buffer[1]; /* variable length GSS security buffer */
239-
} __packed;
240-
241100
/* Flags */
242101
#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
243102
#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04

fs/ksmbd/smb_common.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@
3333
#define SMB302_VERSION_STRING "3.02"
3434
#define SMB311_VERSION_STRING "3.1.1"
3535

36-
/* Dialects */
37-
#define SMB10_PROT_ID 0x00
38-
#define SMB20_PROT_ID 0x0202
39-
#define SMB21_PROT_ID 0x0210
40-
/* multi-protocol negotiate request */
41-
#define SMB2X_PROT_ID 0x02FF
42-
#define SMB30_PROT_ID 0x0300
43-
#define SMB302_PROT_ID 0x0302
44-
#define SMB311_PROT_ID 0x0311
45-
#define BAD_PROT_ID 0xFFFF
46-
4736
#define SMB_ECHO_INTERVAL (60 * HZ)
4837

4938
#define CIFS_DEFAULT_IOSIZE (64 * 1024)

0 commit comments

Comments
 (0)