hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/cifs/smb2transport.c
....@@ -41,14 +41,6 @@
4141 #include "smb2glob.h"
4242
4343 static int
44
-smb2_crypto_shash_allocate(struct TCP_Server_Info *server)
45
-{
46
- return cifs_alloc_hash("hmac(sha256)",
47
- &server->secmech.hmacsha256,
48
- &server->secmech.sdeschmacsha256);
49
-}
50
-
51
-static int
5244 smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
5345 {
5446 struct cifs_secmech *p = &server->secmech;
....@@ -95,6 +87,62 @@
9587 err:
9688 cifs_free_hash(&p->cmacaes, &p->sdesccmacaes);
9789 cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
90
+ return rc;
91
+}
92
+
93
+
94
+static
95
+int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
96
+{
97
+ struct cifs_chan *chan;
98
+ struct cifs_ses *ses = NULL;
99
+ struct TCP_Server_Info *it = NULL;
100
+ int i;
101
+ int rc = 0;
102
+
103
+ spin_lock(&cifs_tcp_ses_lock);
104
+
105
+ list_for_each_entry(it, &cifs_tcp_ses_list, tcp_ses_list) {
106
+ list_for_each_entry(ses, &it->smb_ses_list, smb_ses_list) {
107
+ if (ses->Suid == ses_id)
108
+ goto found;
109
+ }
110
+ }
111
+ cifs_server_dbg(VFS, "%s: Could not find session 0x%llx\n",
112
+ __func__, ses_id);
113
+ rc = -ENOENT;
114
+ goto out;
115
+
116
+found:
117
+ if (ses->binding) {
118
+ /*
119
+ * If we are in the process of binding a new channel
120
+ * to an existing session, use the master connection
121
+ * session key
122
+ */
123
+ memcpy(key, ses->smb3signingkey, SMB3_SIGN_KEY_SIZE);
124
+ goto out;
125
+ }
126
+
127
+ /*
128
+ * Otherwise, use the channel key.
129
+ */
130
+
131
+ for (i = 0; i < ses->chan_count; i++) {
132
+ chan = ses->chans + i;
133
+ if (chan->server == server) {
134
+ memcpy(key, chan->signkey, SMB3_SIGN_KEY_SIZE);
135
+ goto out;
136
+ }
137
+ }
138
+
139
+ cifs_dbg(VFS,
140
+ "%s: Could not find channel signing key for session 0x%llx\n",
141
+ __func__, ses_id);
142
+ rc = -ENOENT;
143
+
144
+out:
145
+ spin_unlock(&cifs_tcp_ses_lock);
98146 return rc;
99147 }
100148
....@@ -163,7 +211,8 @@
163211 }
164212
165213 int
166
-smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
214
+smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
215
+ bool allocate_crypto)
167216 {
168217 int rc;
169218 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
....@@ -172,35 +221,45 @@
172221 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[0].iov_base;
173222 struct cifs_ses *ses;
174223 struct shash_desc *shash;
224
+ struct crypto_shash *hash;
225
+ struct sdesc *sdesc = NULL;
175226 struct smb_rqst drqst;
176227
177228 ses = smb2_find_smb_ses(server, shdr->SessionId);
178229 if (!ses) {
179
- cifs_dbg(VFS, "%s: Could not find session\n", __func__);
230
+ cifs_server_dbg(VFS, "%s: Could not find session\n", __func__);
180231 return 0;
181232 }
182233
183234 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
184235 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
185236
186
- rc = smb2_crypto_shash_allocate(server);
187
- if (rc) {
188
- cifs_dbg(VFS, "%s: sha256 alloc failed\n", __func__);
189
- return rc;
237
+ if (allocate_crypto) {
238
+ rc = cifs_alloc_hash("hmac(sha256)", &hash, &sdesc);
239
+ if (rc) {
240
+ cifs_server_dbg(VFS,
241
+ "%s: sha256 alloc failed\n", __func__);
242
+ return rc;
243
+ }
244
+ shash = &sdesc->shash;
245
+ } else {
246
+ hash = server->secmech.hmacsha256;
247
+ shash = &server->secmech.sdeschmacsha256->shash;
190248 }
191249
192
- rc = crypto_shash_setkey(server->secmech.hmacsha256,
193
- ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
250
+ rc = crypto_shash_setkey(hash, ses->auth_key.response,
251
+ SMB2_NTLMV2_SESSKEY_SIZE);
194252 if (rc) {
195
- cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
196
- return rc;
253
+ cifs_server_dbg(VFS,
254
+ "%s: Could not update with response\n",
255
+ __func__);
256
+ goto out;
197257 }
198258
199
- shash = &server->secmech.sdeschmacsha256->shash;
200259 rc = crypto_shash_init(shash);
201260 if (rc) {
202
- cifs_dbg(VFS, "%s: Could not init sha256", __func__);
203
- return rc;
261
+ cifs_server_dbg(VFS, "%s: Could not init sha256", __func__);
262
+ goto out;
204263 }
205264
206265 /*
....@@ -215,9 +274,10 @@
215274 rc = crypto_shash_update(shash, iov[0].iov_base,
216275 iov[0].iov_len);
217276 if (rc) {
218
- cifs_dbg(VFS, "%s: Could not update with payload\n",
219
- __func__);
220
- return rc;
277
+ cifs_server_dbg(VFS,
278
+ "%s: Could not update with payload\n",
279
+ __func__);
280
+ goto out;
221281 }
222282 drqst.rq_iov++;
223283 drqst.rq_nvec--;
....@@ -227,6 +287,9 @@
227287 if (!rc)
228288 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
229289
290
+out:
291
+ if (allocate_crypto)
292
+ cifs_free_hash(&hash, &sdesc);
230293 return rc;
231294 }
232295
....@@ -235,72 +298,80 @@
235298 {
236299 unsigned char zero = 0x0;
237300 __u8 i[4] = {0, 0, 0, 1};
238
- __u8 L[4] = {0, 0, 0, 128};
301
+ __u8 L128[4] = {0, 0, 0, 128};
302
+ __u8 L256[4] = {0, 0, 1, 0};
239303 int rc = 0;
240304 unsigned char prfhash[SMB2_HMACSHA256_SIZE];
241305 unsigned char *hashptr = prfhash;
306
+ struct TCP_Server_Info *server = ses->server;
242307
243308 memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
244309 memset(key, 0x0, key_size);
245310
246
- rc = smb3_crypto_shash_allocate(ses->server);
311
+ rc = smb3_crypto_shash_allocate(server);
247312 if (rc) {
248
- cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
313
+ cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
249314 goto smb3signkey_ret;
250315 }
251316
252
- rc = crypto_shash_setkey(ses->server->secmech.hmacsha256,
317
+ rc = crypto_shash_setkey(server->secmech.hmacsha256,
253318 ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
254319 if (rc) {
255
- cifs_dbg(VFS, "%s: Could not set with session key\n", __func__);
320
+ cifs_server_dbg(VFS, "%s: Could not set with session key\n", __func__);
256321 goto smb3signkey_ret;
257322 }
258323
259
- rc = crypto_shash_init(&ses->server->secmech.sdeschmacsha256->shash);
324
+ rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash);
260325 if (rc) {
261
- cifs_dbg(VFS, "%s: Could not init sign hmac\n", __func__);
326
+ cifs_server_dbg(VFS, "%s: Could not init sign hmac\n", __func__);
262327 goto smb3signkey_ret;
263328 }
264329
265
- rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
330
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
266331 i, 4);
267332 if (rc) {
268
- cifs_dbg(VFS, "%s: Could not update with n\n", __func__);
333
+ cifs_server_dbg(VFS, "%s: Could not update with n\n", __func__);
269334 goto smb3signkey_ret;
270335 }
271336
272
- rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
337
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
273338 label.iov_base, label.iov_len);
274339 if (rc) {
275
- cifs_dbg(VFS, "%s: Could not update with label\n", __func__);
340
+ cifs_server_dbg(VFS, "%s: Could not update with label\n", __func__);
276341 goto smb3signkey_ret;
277342 }
278343
279
- rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
344
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
280345 &zero, 1);
281346 if (rc) {
282
- cifs_dbg(VFS, "%s: Could not update with zero\n", __func__);
347
+ cifs_server_dbg(VFS, "%s: Could not update with zero\n", __func__);
283348 goto smb3signkey_ret;
284349 }
285350
286
- rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
351
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
287352 context.iov_base, context.iov_len);
288353 if (rc) {
289
- cifs_dbg(VFS, "%s: Could not update with context\n", __func__);
354
+ cifs_server_dbg(VFS, "%s: Could not update with context\n", __func__);
290355 goto smb3signkey_ret;
291356 }
292357
293
- rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
294
- L, 4);
358
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
359
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
360
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
361
+ L256, 4);
362
+ } else {
363
+ rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
364
+ L128, 4);
365
+ }
295366 if (rc) {
296
- cifs_dbg(VFS, "%s: Could not update with L\n", __func__);
367
+ cifs_server_dbg(VFS, "%s: Could not update with L\n", __func__);
297368 goto smb3signkey_ret;
298369 }
299370
300
- rc = crypto_shash_final(&ses->server->secmech.sdeschmacsha256->shash,
371
+ rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash,
301372 hashptr);
302373 if (rc) {
303
- cifs_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
374
+ cifs_server_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
304375 goto smb3signkey_ret;
305376 }
306377
....@@ -326,22 +397,49 @@
326397 const struct derivation_triplet *ptriplet)
327398 {
328399 int rc;
400
+#ifdef CONFIG_CIFS_DEBUG_DUMP_KEYS
401
+ struct TCP_Server_Info *server = ses->server;
402
+#endif
329403
330
- rc = generate_key(ses, ptriplet->signing.label,
331
- ptriplet->signing.context, ses->smb3signingkey,
332
- SMB3_SIGN_KEY_SIZE);
333
- if (rc)
334
- return rc;
404
+ /*
405
+ * All channels use the same encryption/decryption keys but
406
+ * they have their own signing key.
407
+ *
408
+ * When we generate the keys, check if it is for a new channel
409
+ * (binding) in which case we only need to generate a signing
410
+ * key and store it in the channel as to not overwrite the
411
+ * master connection signing key stored in the session
412
+ */
335413
336
- rc = generate_key(ses, ptriplet->encryption.label,
337
- ptriplet->encryption.context, ses->smb3encryptionkey,
338
- SMB3_SIGN_KEY_SIZE);
339
- if (rc)
340
- return rc;
414
+ if (ses->binding) {
415
+ rc = generate_key(ses, ptriplet->signing.label,
416
+ ptriplet->signing.context,
417
+ cifs_ses_binding_channel(ses)->signkey,
418
+ SMB3_SIGN_KEY_SIZE);
419
+ if (rc)
420
+ return rc;
421
+ } else {
422
+ rc = generate_key(ses, ptriplet->signing.label,
423
+ ptriplet->signing.context,
424
+ ses->smb3signingkey,
425
+ SMB3_SIGN_KEY_SIZE);
426
+ if (rc)
427
+ return rc;
341428
342
- rc = generate_key(ses, ptriplet->decryption.label,
343
- ptriplet->decryption.context,
344
- ses->smb3decryptionkey, SMB3_SIGN_KEY_SIZE);
429
+ memcpy(ses->chans[0].signkey, ses->smb3signingkey,
430
+ SMB3_SIGN_KEY_SIZE);
431
+
432
+ rc = generate_key(ses, ptriplet->encryption.label,
433
+ ptriplet->encryption.context,
434
+ ses->smb3encryptionkey,
435
+ SMB3_ENC_DEC_KEY_SIZE);
436
+ rc = generate_key(ses, ptriplet->decryption.label,
437
+ ptriplet->decryption.context,
438
+ ses->smb3decryptionkey,
439
+ SMB3_ENC_DEC_KEY_SIZE);
440
+ if (rc)
441
+ return rc;
442
+ }
345443
346444 if (rc)
347445 return rc;
....@@ -354,14 +452,23 @@
354452 */
355453 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid),
356454 &ses->Suid);
455
+ cifs_dbg(VFS, "Cipher type %d\n", server->cipher_type);
357456 cifs_dbg(VFS, "Session Key %*ph\n",
358457 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response);
359458 cifs_dbg(VFS, "Signing Key %*ph\n",
360459 SMB3_SIGN_KEY_SIZE, ses->smb3signingkey);
361
- cifs_dbg(VFS, "ServerIn Key %*ph\n",
362
- SMB3_SIGN_KEY_SIZE, ses->smb3encryptionkey);
363
- cifs_dbg(VFS, "ServerOut Key %*ph\n",
364
- SMB3_SIGN_KEY_SIZE, ses->smb3decryptionkey);
460
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
461
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
462
+ cifs_dbg(VFS, "ServerIn Key %*ph\n",
463
+ SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3encryptionkey);
464
+ cifs_dbg(VFS, "ServerOut Key %*ph\n",
465
+ SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3decryptionkey);
466
+ } else {
467
+ cifs_dbg(VFS, "ServerIn Key %*ph\n",
468
+ SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3encryptionkey);
469
+ cifs_dbg(VFS, "ServerOut Key %*ph\n",
470
+ SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3decryptionkey);
471
+ }
365472 #endif
366473 return rc;
367474 }
....@@ -423,31 +530,42 @@
423530 }
424531
425532 int
426
-smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
533
+smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
534
+ bool allocate_crypto)
427535 {
428536 int rc;
429537 unsigned char smb3_signature[SMB2_CMACAES_SIZE];
430538 unsigned char *sigptr = smb3_signature;
431539 struct kvec *iov = rqst->rq_iov;
432540 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[0].iov_base;
433
- struct cifs_ses *ses;
434
- struct shash_desc *shash = &server->secmech.sdesccmacaes->shash;
541
+ struct shash_desc *shash;
542
+ struct crypto_shash *hash;
543
+ struct sdesc *sdesc = NULL;
435544 struct smb_rqst drqst;
545
+ u8 key[SMB3_SIGN_KEY_SIZE];
436546
437
- ses = smb2_find_smb_ses(server, shdr->SessionId);
438
- if (!ses) {
439
- cifs_dbg(VFS, "%s: Could not find session\n", __func__);
547
+ rc = smb2_get_sign_key(shdr->SessionId, server, key);
548
+ if (rc)
440549 return 0;
550
+
551
+ if (allocate_crypto) {
552
+ rc = cifs_alloc_hash("cmac(aes)", &hash, &sdesc);
553
+ if (rc)
554
+ return rc;
555
+
556
+ shash = &sdesc->shash;
557
+ } else {
558
+ hash = server->secmech.cmacaes;
559
+ shash = &server->secmech.sdesccmacaes->shash;
441560 }
442561
443562 memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE);
444563 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
445564
446
- rc = crypto_shash_setkey(server->secmech.cmacaes,
447
- ses->smb3signingkey, SMB2_CMACAES_SIZE);
565
+ rc = crypto_shash_setkey(hash, key, SMB2_CMACAES_SIZE);
448566 if (rc) {
449
- cifs_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
450
- return rc;
567
+ cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
568
+ goto out;
451569 }
452570
453571 /*
....@@ -457,8 +575,8 @@
457575 */
458576 rc = crypto_shash_init(shash);
459577 if (rc) {
460
- cifs_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
461
- return rc;
578
+ cifs_server_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
579
+ goto out;
462580 }
463581
464582 /*
....@@ -473,9 +591,9 @@
473591 rc = crypto_shash_update(shash, iov[0].iov_base,
474592 iov[0].iov_len);
475593 if (rc) {
476
- cifs_dbg(VFS, "%s: Could not update with payload\n",
594
+ cifs_server_dbg(VFS, "%s: Could not update with payload\n",
477595 __func__);
478
- return rc;
596
+ goto out;
479597 }
480598 drqst.rq_iov++;
481599 drqst.rq_nvec--;
....@@ -485,6 +603,9 @@
485603 if (!rc)
486604 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
487605
606
+out:
607
+ if (allocate_crypto)
608
+ cifs_free_hash(&hash, &sdesc);
488609 return rc;
489610 }
490611
....@@ -493,19 +614,28 @@
493614 smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
494615 {
495616 int rc = 0;
496
- struct smb2_sync_hdr *shdr =
497
- (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
617
+ struct smb2_sync_hdr *shdr;
618
+ struct smb2_sess_setup_req *ssr;
619
+ bool is_binding;
620
+ bool is_signed;
498621
499
- if (!(shdr->Flags & SMB2_FLAGS_SIGNED) ||
500
- server->tcpStatus == CifsNeedNegotiate)
501
- return rc;
622
+ shdr = (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
623
+ ssr = (struct smb2_sess_setup_req *)shdr;
502624
503
- if (!server->session_estab) {
625
+ is_binding = shdr->Command == SMB2_SESSION_SETUP &&
626
+ (ssr->Flags & SMB2_SESSION_REQ_FLAG_BINDING);
627
+ is_signed = shdr->Flags & SMB2_FLAGS_SIGNED;
628
+
629
+ if (!is_signed)
630
+ return 0;
631
+ if (server->tcpStatus == CifsNeedNegotiate)
632
+ return 0;
633
+ if (!is_binding && !server->session_estab) {
504634 strncpy(shdr->Signature, "BSRSPYL", 8);
505
- return rc;
635
+ return 0;
506636 }
507637
508
- rc = server->ops->calc_signature(rqst, server);
638
+ rc = server->ops->calc_signature(rqst, server, false);
509639
510640 return rc;
511641 }
....@@ -514,13 +644,14 @@
514644 smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
515645 {
516646 unsigned int rc;
517
- char server_response_sig[16];
647
+ char server_response_sig[SMB2_SIGNATURE_SIZE];
518648 struct smb2_sync_hdr *shdr =
519649 (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
520650
521651 if ((shdr->Command == SMB2_NEGOTIATE) ||
522652 (shdr->Command == SMB2_SESSION_SETUP) ||
523653 (shdr->Command == SMB2_OPLOCK_BREAK) ||
654
+ server->ignore_signature ||
524655 (!server->session_estab))
525656 return 0;
526657
....@@ -542,16 +673,16 @@
542673
543674 memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
544675
545
- mutex_lock(&server->srv_mutex);
546
- rc = server->ops->calc_signature(rqst, server);
547
- mutex_unlock(&server->srv_mutex);
676
+ rc = server->ops->calc_signature(rqst, server, true);
548677
549678 if (rc)
550679 return rc;
551680
552
- if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE))
681
+ if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE)) {
682
+ cifs_dbg(VFS, "sign fail cmd 0x%x message id 0x%llx\n",
683
+ shdr->Command, shdr->MessageId);
553684 return -EACCES;
554
- else
685
+ } else
555686 return 0;
556687 }
557688
....@@ -597,25 +728,33 @@
597728 * The default is for the mid to be synchronous, so the
598729 * default callback just wakes up the current task.
599730 */
731
+ get_task_struct(current);
732
+ temp->creator = current;
600733 temp->callback = cifs_wake_up_task;
601734 temp->callback_data = current;
602735
603736 atomic_inc(&midCount);
604737 temp->mid_state = MID_REQUEST_ALLOCATED;
738
+ trace_smb3_cmd_enter(shdr->TreeId, shdr->SessionId,
739
+ le16_to_cpu(shdr->Command), temp->mid);
605740 return temp;
606741 }
607742
608743 static int
609
-smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_sync_hdr *shdr,
610
- struct mid_q_entry **mid)
744
+smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
745
+ struct smb2_sync_hdr *shdr, struct mid_q_entry **mid)
611746 {
612
- if (ses->server->tcpStatus == CifsExiting)
747
+ if (server->tcpStatus == CifsExiting)
613748 return -ENOENT;
614749
615
- if (ses->server->tcpStatus == CifsNeedReconnect) {
750
+ if (server->tcpStatus == CifsNeedReconnect) {
616751 cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
617752 return -EAGAIN;
618753 }
754
+
755
+ if (server->tcpStatus == CifsNeedNegotiate &&
756
+ shdr->Command != SMB2_NEGOTIATE)
757
+ return -EAGAIN;
619758
620759 if (ses->status == CifsNew) {
621760 if ((shdr->Command != SMB2_SESSION_SETUP) &&
....@@ -630,12 +769,13 @@
630769 /* else ok - we are shutting down the session */
631770 }
632771
633
- *mid = smb2_mid_entry_alloc(shdr, ses->server);
772
+ *mid = smb2_mid_entry_alloc(shdr, server);
634773 if (*mid == NULL)
635774 return -ENOMEM;
636775 spin_lock(&GlobalMid_Lock);
637
- list_add_tail(&(*mid)->qhead, &ses->server->pending_mid_q);
776
+ list_add_tail(&(*mid)->qhead, &server->pending_mid_q);
638777 spin_unlock(&GlobalMid_Lock);
778
+
639779 return 0;
640780 }
641781
....@@ -658,7 +798,7 @@
658798
659799 rc = smb2_verify_signature(&rqst, server);
660800 if (rc)
661
- cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
801
+ cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n",
662802 rc);
663803 }
664804
....@@ -666,24 +806,25 @@
666806 }
667807
668808 struct mid_q_entry *
669
-smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
809
+smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server,
810
+ struct smb_rqst *rqst)
670811 {
671812 int rc;
672813 struct smb2_sync_hdr *shdr =
673814 (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
674815 struct mid_q_entry *mid;
675816
676
- smb2_seq_num_into_buf(ses->server, shdr);
817
+ smb2_seq_num_into_buf(server, shdr);
677818
678
- rc = smb2_get_mid_entry(ses, shdr, &mid);
819
+ rc = smb2_get_mid_entry(ses, server, shdr, &mid);
679820 if (rc) {
680
- revert_current_mid_from_hdr(ses->server, shdr);
821
+ revert_current_mid_from_hdr(server, shdr);
681822 return ERR_PTR(rc);
682823 }
683824
684
- rc = smb2_sign_rqst(rqst, ses->server);
825
+ rc = smb2_sign_rqst(rqst, server);
685826 if (rc) {
686
- revert_current_mid_from_hdr(ses->server, shdr);
827
+ revert_current_mid_from_hdr(server, shdr);
687828 cifs_delete_mid(mid);
688829 return ERR_PTR(rc);
689830 }
....@@ -698,6 +839,10 @@
698839 struct smb2_sync_hdr *shdr =
699840 (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
700841 struct mid_q_entry *mid;
842
+
843
+ if (server->tcpStatus == CifsNeedNegotiate &&
844
+ shdr->Command != SMB2_NEGOTIATE)
845
+ return ERR_PTR(-EAGAIN);
701846
702847 smb2_seq_num_into_buf(server, shdr);
703848
....@@ -723,9 +868,13 @@
723868 struct crypto_aead *tfm;
724869
725870 if (!server->secmech.ccmaesencrypt) {
726
- tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
871
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
872
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
873
+ tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
874
+ else
875
+ tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
727876 if (IS_ERR(tfm)) {
728
- cifs_dbg(VFS, "%s: Failed to alloc encrypt aead\n",
877
+ cifs_server_dbg(VFS, "%s: Failed alloc encrypt aead\n",
729878 __func__);
730879 return PTR_ERR(tfm);
731880 }
....@@ -733,11 +882,15 @@
733882 }
734883
735884 if (!server->secmech.ccmaesdecrypt) {
736
- tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
885
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
886
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
887
+ tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
888
+ else
889
+ tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
737890 if (IS_ERR(tfm)) {
738891 crypto_free_aead(server->secmech.ccmaesencrypt);
739892 server->secmech.ccmaesencrypt = NULL;
740
- cifs_dbg(VFS, "%s: Failed to alloc decrypt aead\n",
893
+ cifs_server_dbg(VFS, "%s: Failed to alloc decrypt aead\n",
741894 __func__);
742895 return PTR_ERR(tfm);
743896 }