1 // SPDX-License-Identifier: LGPL-2.1
4 * Copyright (C) International Business Machines Corp., 2002, 2011
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Jeremy Allison (jra@samba.org) 2006
8 * Pavel Shilovsky (pshilovsky@samba.org) 2012
13 #include <linux/list.h>
14 #include <linux/wait.h>
15 #include <linux/net.h>
16 #include <linux/delay.h>
17 #include <linux/uaccess.h>
18 #include <asm/processor.h>
19 #include <linux/mempool.h>
20 #include <linux/highmem.h>
21 #include <crypto/aead.h>
23 #include "cifsproto.h"
24 #include "smb2proto.h"
25 #include "cifs_debug.h"
26 #include "smb2status.h"
30 smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
32 struct cifs_secmech *p = &server->secmech;
35 rc = cifs_alloc_hash("hmac(sha256)",
41 rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
47 cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
52 smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
54 struct cifs_secmech *p = &server->secmech;
57 rc = cifs_alloc_hash("hmac(sha256)",
63 rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
67 rc = cifs_alloc_hash("sha512", &p->sha512, &p->sdescsha512);
74 cifs_free_hash(&p->cmacaes, &p->sdesccmacaes);
75 cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
81 int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
83 struct cifs_chan *chan;
84 struct cifs_ses *ses = NULL;
85 struct TCP_Server_Info *it = NULL;
89 spin_lock(&cifs_tcp_ses_lock);
91 list_for_each_entry(it, &cifs_tcp_ses_list, tcp_ses_list) {
92 list_for_each_entry(ses, &it->smb_ses_list, smb_ses_list) {
93 if (ses->Suid == ses_id)
97 cifs_server_dbg(VFS, "%s: Could not find session 0x%llx\n",
103 spin_lock(&ses->chan_lock);
104 if (cifs_chan_needs_reconnect(ses, server) &&
105 !CIFS_ALL_CHANS_NEED_RECONNECT(ses)) {
107 * If we are in the process of binding a new channel
108 * to an existing session, use the master connection
111 memcpy(key, ses->smb3signingkey, SMB3_SIGN_KEY_SIZE);
112 spin_unlock(&ses->chan_lock);
117 * Otherwise, use the channel key.
120 for (i = 0; i < ses->chan_count; i++) {
121 chan = ses->chans + i;
122 if (chan->server == server) {
123 memcpy(key, chan->signkey, SMB3_SIGN_KEY_SIZE);
124 spin_unlock(&ses->chan_lock);
128 spin_unlock(&ses->chan_lock);
131 "%s: Could not find channel signing key for session 0x%llx\n",
136 spin_unlock(&cifs_tcp_ses_lock);
140 static struct cifs_ses *
141 smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id)
143 struct cifs_ses *ses;
145 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
146 if (ses->Suid != ses_id)
156 smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id)
158 struct cifs_ses *ses;
160 spin_lock(&cifs_tcp_ses_lock);
161 ses = smb2_find_smb_ses_unlocked(server, ses_id);
162 spin_unlock(&cifs_tcp_ses_lock);
167 static struct cifs_tcon *
168 smb2_find_smb_sess_tcon_unlocked(struct cifs_ses *ses, __u32 tid)
170 struct cifs_tcon *tcon;
172 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
173 if (tcon->tid != tid)
183 * Obtain tcon corresponding to the tid in the given
188 smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32 tid)
190 struct cifs_ses *ses;
191 struct cifs_tcon *tcon;
193 spin_lock(&cifs_tcp_ses_lock);
194 ses = smb2_find_smb_ses_unlocked(server, ses_id);
196 spin_unlock(&cifs_tcp_ses_lock);
199 tcon = smb2_find_smb_sess_tcon_unlocked(ses, tid);
201 cifs_put_smb_ses(ses);
202 spin_unlock(&cifs_tcp_ses_lock);
205 spin_unlock(&cifs_tcp_ses_lock);
206 /* tcon already has a ref to ses, so we don't need ses anymore */
207 cifs_put_smb_ses(ses);
213 smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
214 bool allocate_crypto)
217 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
218 unsigned char *sigptr = smb2_signature;
219 struct kvec *iov = rqst->rq_iov;
220 struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0].iov_base;
221 struct cifs_ses *ses;
222 struct shash_desc *shash;
223 struct crypto_shash *hash;
224 struct sdesc *sdesc = NULL;
225 struct smb_rqst drqst;
227 ses = smb2_find_smb_ses(server, le64_to_cpu(shdr->SessionId));
229 cifs_server_dbg(VFS, "%s: Could not find session\n", __func__);
233 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
234 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
236 if (allocate_crypto) {
237 rc = cifs_alloc_hash("hmac(sha256)", &hash, &sdesc);
240 "%s: sha256 alloc failed\n", __func__);
243 shash = &sdesc->shash;
245 hash = server->secmech.hmacsha256;
246 shash = &server->secmech.sdeschmacsha256->shash;
249 rc = crypto_shash_setkey(hash, ses->auth_key.response,
250 SMB2_NTLMV2_SESSKEY_SIZE);
253 "%s: Could not update with response\n",
258 rc = crypto_shash_init(shash);
260 cifs_server_dbg(VFS, "%s: Could not init sha256", __func__);
265 * For SMB2+, __cifs_calc_signature() expects to sign only the actual
266 * data, that is, iov[0] should not contain a rfc1002 length.
268 * Sign the rfc1002 length prior to passing the data (iov[1-N]) down to
269 * __cifs_calc_signature().
272 if (drqst.rq_nvec >= 2 && iov[0].iov_len == 4) {
273 rc = crypto_shash_update(shash, iov[0].iov_base,
277 "%s: Could not update with payload\n",
285 rc = __cifs_calc_signature(&drqst, server, sigptr, shash);
287 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
291 cifs_free_hash(&hash, &sdesc);
293 cifs_put_smb_ses(ses);
297 static int generate_key(struct cifs_ses *ses, struct kvec label,
298 struct kvec context, __u8 *key, unsigned int key_size)
300 unsigned char zero = 0x0;
301 __u8 i[4] = {0, 0, 0, 1};
302 __u8 L128[4] = {0, 0, 0, 128};
303 __u8 L256[4] = {0, 0, 1, 0};
305 unsigned char prfhash[SMB2_HMACSHA256_SIZE];
306 unsigned char *hashptr = prfhash;
307 struct TCP_Server_Info *server = ses->server;
309 memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
310 memset(key, 0x0, key_size);
312 rc = smb3_crypto_shash_allocate(server);
314 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
315 goto smb3signkey_ret;
318 rc = crypto_shash_setkey(server->secmech.hmacsha256,
319 ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
321 cifs_server_dbg(VFS, "%s: Could not set with session key\n", __func__);
322 goto smb3signkey_ret;
325 rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash);
327 cifs_server_dbg(VFS, "%s: Could not init sign hmac\n", __func__);
328 goto smb3signkey_ret;
331 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
334 cifs_server_dbg(VFS, "%s: Could not update with n\n", __func__);
335 goto smb3signkey_ret;
338 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
339 label.iov_base, label.iov_len);
341 cifs_server_dbg(VFS, "%s: Could not update with label\n", __func__);
342 goto smb3signkey_ret;
345 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
348 cifs_server_dbg(VFS, "%s: Could not update with zero\n", __func__);
349 goto smb3signkey_ret;
352 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
353 context.iov_base, context.iov_len);
355 cifs_server_dbg(VFS, "%s: Could not update with context\n", __func__);
356 goto smb3signkey_ret;
359 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
360 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
361 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
364 rc = crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
368 cifs_server_dbg(VFS, "%s: Could not update with L\n", __func__);
369 goto smb3signkey_ret;
372 rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash,
375 cifs_server_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
376 goto smb3signkey_ret;
379 memcpy(key, hashptr, key_size);
390 struct derivation_triplet {
391 struct derivation signing;
392 struct derivation encryption;
393 struct derivation decryption;
397 generate_smb3signingkey(struct cifs_ses *ses,
398 struct TCP_Server_Info *server,
399 const struct derivation_triplet *ptriplet)
402 bool is_binding = false;
405 spin_lock(&ses->chan_lock);
406 is_binding = !CIFS_ALL_CHANS_NEED_RECONNECT(ses);
407 chan_index = cifs_ses_get_chan_index(ses, server);
408 /* TODO: introduce ref counting for channels when the can be freed */
409 spin_unlock(&ses->chan_lock);
412 * All channels use the same encryption/decryption keys but
413 * they have their own signing key.
415 * When we generate the keys, check if it is for a new channel
416 * (binding) in which case we only need to generate a signing
417 * key and store it in the channel as to not overwrite the
418 * master connection signing key stored in the session
422 rc = generate_key(ses, ptriplet->signing.label,
423 ptriplet->signing.context,
424 ses->chans[chan_index].signkey,
429 rc = generate_key(ses, ptriplet->signing.label,
430 ptriplet->signing.context,
436 /* safe to access primary channel, since it will never go away */
437 spin_lock(&ses->chan_lock);
438 memcpy(ses->chans[0].signkey, ses->smb3signingkey,
440 spin_unlock(&ses->chan_lock);
442 rc = generate_key(ses, ptriplet->encryption.label,
443 ptriplet->encryption.context,
444 ses->smb3encryptionkey,
445 SMB3_ENC_DEC_KEY_SIZE);
446 rc = generate_key(ses, ptriplet->decryption.label,
447 ptriplet->decryption.context,
448 ses->smb3decryptionkey,
449 SMB3_ENC_DEC_KEY_SIZE);
457 #ifdef CONFIG_CIFS_DEBUG_DUMP_KEYS
458 cifs_dbg(VFS, "%s: dumping generated AES session keys\n", __func__);
460 * The session id is opaque in terms of endianness, so we can't
461 * print it as a long long. we dump it as we got it on the wire
463 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid),
465 cifs_dbg(VFS, "Cipher type %d\n", server->cipher_type);
466 cifs_dbg(VFS, "Session Key %*ph\n",
467 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response);
468 cifs_dbg(VFS, "Signing Key %*ph\n",
469 SMB3_SIGN_KEY_SIZE, ses->smb3signingkey);
470 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
471 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
472 cifs_dbg(VFS, "ServerIn Key %*ph\n",
473 SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3encryptionkey);
474 cifs_dbg(VFS, "ServerOut Key %*ph\n",
475 SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3decryptionkey);
477 cifs_dbg(VFS, "ServerIn Key %*ph\n",
478 SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3encryptionkey);
479 cifs_dbg(VFS, "ServerOut Key %*ph\n",
480 SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3decryptionkey);
487 generate_smb30signingkey(struct cifs_ses *ses,
488 struct TCP_Server_Info *server)
491 struct derivation_triplet triplet;
492 struct derivation *d;
494 d = &triplet.signing;
495 d->label.iov_base = "SMB2AESCMAC";
496 d->label.iov_len = 12;
497 d->context.iov_base = "SmbSign";
498 d->context.iov_len = 8;
500 d = &triplet.encryption;
501 d->label.iov_base = "SMB2AESCCM";
502 d->label.iov_len = 11;
503 d->context.iov_base = "ServerIn ";
504 d->context.iov_len = 10;
506 d = &triplet.decryption;
507 d->label.iov_base = "SMB2AESCCM";
508 d->label.iov_len = 11;
509 d->context.iov_base = "ServerOut";
510 d->context.iov_len = 10;
512 return generate_smb3signingkey(ses, server, &triplet);
516 generate_smb311signingkey(struct cifs_ses *ses,
517 struct TCP_Server_Info *server)
520 struct derivation_triplet triplet;
521 struct derivation *d;
523 d = &triplet.signing;
524 d->label.iov_base = "SMBSigningKey";
525 d->label.iov_len = 14;
526 d->context.iov_base = ses->preauth_sha_hash;
527 d->context.iov_len = 64;
529 d = &triplet.encryption;
530 d->label.iov_base = "SMBC2SCipherKey";
531 d->label.iov_len = 16;
532 d->context.iov_base = ses->preauth_sha_hash;
533 d->context.iov_len = 64;
535 d = &triplet.decryption;
536 d->label.iov_base = "SMBS2CCipherKey";
537 d->label.iov_len = 16;
538 d->context.iov_base = ses->preauth_sha_hash;
539 d->context.iov_len = 64;
541 return generate_smb3signingkey(ses, server, &triplet);
545 smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
546 bool allocate_crypto)
549 unsigned char smb3_signature[SMB2_CMACAES_SIZE];
550 unsigned char *sigptr = smb3_signature;
551 struct kvec *iov = rqst->rq_iov;
552 struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0].iov_base;
553 struct shash_desc *shash;
554 struct crypto_shash *hash;
555 struct sdesc *sdesc = NULL;
556 struct smb_rqst drqst;
557 u8 key[SMB3_SIGN_KEY_SIZE];
559 rc = smb2_get_sign_key(le64_to_cpu(shdr->SessionId), server, key);
563 if (allocate_crypto) {
564 rc = cifs_alloc_hash("cmac(aes)", &hash, &sdesc);
568 shash = &sdesc->shash;
570 hash = server->secmech.cmacaes;
571 shash = &server->secmech.sdesccmacaes->shash;
574 memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE);
575 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
577 rc = crypto_shash_setkey(hash, key, SMB2_CMACAES_SIZE);
579 cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
584 * we already allocate sdesccmacaes when we init smb3 signing key,
585 * so unlike smb2 case we do not have to check here if secmech are
588 rc = crypto_shash_init(shash);
590 cifs_server_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
595 * For SMB2+, __cifs_calc_signature() expects to sign only the actual
596 * data, that is, iov[0] should not contain a rfc1002 length.
598 * Sign the rfc1002 length prior to passing the data (iov[1-N]) down to
599 * __cifs_calc_signature().
602 if (drqst.rq_nvec >= 2 && iov[0].iov_len == 4) {
603 rc = crypto_shash_update(shash, iov[0].iov_base,
606 cifs_server_dbg(VFS, "%s: Could not update with payload\n",
614 rc = __cifs_calc_signature(&drqst, server, sigptr, shash);
616 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
620 cifs_free_hash(&hash, &sdesc);
624 /* must be called with server->srv_mutex held */
626 smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
629 struct smb2_hdr *shdr;
630 struct smb2_sess_setup_req *ssr;
634 shdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
635 ssr = (struct smb2_sess_setup_req *)shdr;
637 is_binding = shdr->Command == SMB2_SESSION_SETUP &&
638 (ssr->Flags & SMB2_SESSION_REQ_FLAG_BINDING);
639 is_signed = shdr->Flags & SMB2_FLAGS_SIGNED;
643 spin_lock(&cifs_tcp_ses_lock);
644 if (server->tcpStatus == CifsNeedNegotiate) {
645 spin_unlock(&cifs_tcp_ses_lock);
648 spin_unlock(&cifs_tcp_ses_lock);
649 if (!is_binding && !server->session_estab) {
650 strncpy(shdr->Signature, "BSRSPYL", 8);
654 rc = server->ops->calc_signature(rqst, server, false);
660 smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
663 char server_response_sig[SMB2_SIGNATURE_SIZE];
664 struct smb2_hdr *shdr =
665 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
667 if ((shdr->Command == SMB2_NEGOTIATE) ||
668 (shdr->Command == SMB2_SESSION_SETUP) ||
669 (shdr->Command == SMB2_OPLOCK_BREAK) ||
670 server->ignore_signature ||
671 (!server->session_estab))
675 * BB what if signatures are supposed to be on for session but
676 * server does not send one? BB
679 /* Do not need to verify session setups with signature "BSRSPYL " */
680 if (memcmp(shdr->Signature, "BSRSPYL ", 8) == 0)
681 cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
685 * Save off the origiginal signature so we can modify the smb and check
686 * our calculated signature against what the server sent.
688 memcpy(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE);
690 memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
692 rc = server->ops->calc_signature(rqst, server, true);
697 if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE)) {
698 cifs_dbg(VFS, "sign fail cmd 0x%x message id 0x%llx\n",
699 shdr->Command, shdr->MessageId);
706 * Set message id for the request. Should be called after wait_for_free_request
707 * and when srv_mutex is held.
710 smb2_seq_num_into_buf(struct TCP_Server_Info *server,
711 struct smb2_hdr *shdr)
713 unsigned int i, num = le16_to_cpu(shdr->CreditCharge);
715 shdr->MessageId = get_next_mid64(server);
716 /* skip message numbers according to CreditCharge field */
717 for (i = 1; i < num; i++)
718 get_next_mid(server);
721 static struct mid_q_entry *
722 smb2_mid_entry_alloc(const struct smb2_hdr *shdr,
723 struct TCP_Server_Info *server)
725 struct mid_q_entry *temp;
726 unsigned int credits = le16_to_cpu(shdr->CreditCharge);
728 if (server == NULL) {
729 cifs_dbg(VFS, "Null TCP session in smb2_mid_entry_alloc\n");
733 temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS);
734 memset(temp, 0, sizeof(struct mid_q_entry));
735 kref_init(&temp->refcount);
736 temp->mid = le64_to_cpu(shdr->MessageId);
737 temp->credits = credits > 0 ? credits : 1;
738 temp->pid = current->pid;
739 temp->command = shdr->Command; /* Always LE */
740 temp->when_alloc = jiffies;
741 temp->server = server;
744 * The default is for the mid to be synchronous, so the
745 * default callback just wakes up the current task.
747 get_task_struct(current);
748 temp->creator = current;
749 temp->callback = cifs_wake_up_task;
750 temp->callback_data = current;
752 atomic_inc(&midCount);
753 temp->mid_state = MID_REQUEST_ALLOCATED;
754 trace_smb3_cmd_enter(le32_to_cpu(shdr->Id.SyncId.TreeId),
755 le64_to_cpu(shdr->SessionId),
756 le16_to_cpu(shdr->Command), temp->mid);
761 smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
762 struct smb2_hdr *shdr, struct mid_q_entry **mid)
764 spin_lock(&cifs_tcp_ses_lock);
765 if (server->tcpStatus == CifsExiting) {
766 spin_unlock(&cifs_tcp_ses_lock);
770 if (server->tcpStatus == CifsNeedReconnect) {
771 spin_unlock(&cifs_tcp_ses_lock);
772 cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
776 if (server->tcpStatus == CifsNeedNegotiate &&
777 shdr->Command != SMB2_NEGOTIATE) {
778 spin_unlock(&cifs_tcp_ses_lock);
782 if (ses->status == CifsNew) {
783 if ((shdr->Command != SMB2_SESSION_SETUP) &&
784 (shdr->Command != SMB2_NEGOTIATE)) {
785 spin_unlock(&cifs_tcp_ses_lock);
788 /* else ok - we are setting up session */
791 if (ses->status == CifsExiting) {
792 if (shdr->Command != SMB2_LOGOFF) {
793 spin_unlock(&cifs_tcp_ses_lock);
796 /* else ok - we are shutting down the session */
798 spin_unlock(&cifs_tcp_ses_lock);
800 *mid = smb2_mid_entry_alloc(shdr, server);
803 spin_lock(&GlobalMid_Lock);
804 list_add_tail(&(*mid)->qhead, &server->pending_mid_q);
805 spin_unlock(&GlobalMid_Lock);
811 smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
814 unsigned int len = mid->resp_buf_size;
816 struct smb_rqst rqst = { .rq_iov = iov,
819 iov[0].iov_base = (char *)mid->resp_buf;
820 iov[0].iov_len = len;
822 dump_smb(mid->resp_buf, min_t(u32, 80, len));
823 /* convert the length into a more usable form */
824 if (len > 24 && server->sign && !mid->decrypted) {
827 rc = smb2_verify_signature(&rqst, server);
829 cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n",
833 return map_smb2_to_linux_error(mid->resp_buf, log_error);
837 smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server,
838 struct smb_rqst *rqst)
841 struct smb2_hdr *shdr =
842 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
843 struct mid_q_entry *mid;
845 smb2_seq_num_into_buf(server, shdr);
847 rc = smb2_get_mid_entry(ses, server, shdr, &mid);
849 revert_current_mid_from_hdr(server, shdr);
853 rc = smb2_sign_rqst(rqst, server);
855 revert_current_mid_from_hdr(server, shdr);
856 cifs_delete_mid(mid);
864 smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
867 struct smb2_hdr *shdr =
868 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
869 struct mid_q_entry *mid;
871 spin_lock(&cifs_tcp_ses_lock);
872 if (server->tcpStatus == CifsNeedNegotiate &&
873 shdr->Command != SMB2_NEGOTIATE) {
874 spin_unlock(&cifs_tcp_ses_lock);
875 return ERR_PTR(-EAGAIN);
877 spin_unlock(&cifs_tcp_ses_lock);
879 smb2_seq_num_into_buf(server, shdr);
881 mid = smb2_mid_entry_alloc(shdr, server);
883 revert_current_mid_from_hdr(server, shdr);
884 return ERR_PTR(-ENOMEM);
887 rc = smb2_sign_rqst(rqst, server);
889 revert_current_mid_from_hdr(server, shdr);
890 DeleteMidQEntry(mid);
898 smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
900 struct crypto_aead *tfm;
902 if (!server->secmech.ccmaesencrypt) {
903 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
904 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
905 tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
907 tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
909 cifs_server_dbg(VFS, "%s: Failed alloc encrypt aead\n",
913 server->secmech.ccmaesencrypt = tfm;
916 if (!server->secmech.ccmaesdecrypt) {
917 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
918 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
919 tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
921 tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
923 crypto_free_aead(server->secmech.ccmaesencrypt);
924 server->secmech.ccmaesencrypt = NULL;
925 cifs_server_dbg(VFS, "%s: Failed to alloc decrypt aead\n",
929 server->secmech.ccmaesdecrypt = tfm;