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)", &p->hmacsha256);
39 rc = cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
45 cifs_free_hash(&p->hmacsha256);
50 smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
52 struct cifs_secmech *p = &server->secmech;
55 rc = cifs_alloc_hash("hmac(sha256)", &p->hmacsha256);
59 rc = cifs_alloc_hash("cmac(aes)", &p->aes_cmac);
63 rc = cifs_alloc_hash("sha512", &p->sha512);
70 cifs_free_hash(&p->aes_cmac);
71 cifs_free_hash(&p->hmacsha256);
77 int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
79 struct cifs_chan *chan;
80 struct TCP_Server_Info *pserver;
81 struct cifs_ses *ses = NULL;
84 bool is_binding = false;
86 spin_lock(&cifs_tcp_ses_lock);
88 /* If server is a channel, select the primary channel */
89 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
91 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
92 if (ses->Suid == ses_id)
95 trace_smb3_ses_not_found(ses_id);
96 cifs_server_dbg(FYI, "%s: Could not find session 0x%llx\n",
102 spin_lock(&ses->ses_lock);
103 spin_lock(&ses->chan_lock);
105 is_binding = (cifs_chan_needs_reconnect(ses, server) &&
106 ses->ses_status == SES_GOOD);
109 * If we are in the process of binding a new channel
110 * to an existing session, use the master connection
113 memcpy(key, ses->smb3signingkey, SMB3_SIGN_KEY_SIZE);
114 spin_unlock(&ses->chan_lock);
115 spin_unlock(&ses->ses_lock);
120 * Otherwise, use the channel key.
123 for (i = 0; i < ses->chan_count; i++) {
124 chan = ses->chans + i;
125 if (chan->server == server) {
126 memcpy(key, chan->signkey, SMB3_SIGN_KEY_SIZE);
127 spin_unlock(&ses->chan_lock);
128 spin_unlock(&ses->ses_lock);
132 spin_unlock(&ses->chan_lock);
133 spin_unlock(&ses->ses_lock);
136 "%s: Could not find channel signing key for session 0x%llx\n",
141 spin_unlock(&cifs_tcp_ses_lock);
145 static struct cifs_ses *
146 smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id)
148 struct TCP_Server_Info *pserver;
149 struct cifs_ses *ses;
151 /* If server is a channel, select the primary channel */
152 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
154 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
155 if (ses->Suid != ses_id)
158 spin_lock(&ses->ses_lock);
159 if (ses->ses_status == SES_EXITING) {
160 spin_unlock(&ses->ses_lock);
163 cifs_smb_ses_inc_refcount(ses);
164 spin_unlock(&ses->ses_lock);
172 smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id)
174 struct cifs_ses *ses;
176 spin_lock(&cifs_tcp_ses_lock);
177 ses = smb2_find_smb_ses_unlocked(server, ses_id);
178 spin_unlock(&cifs_tcp_ses_lock);
183 static struct cifs_tcon *
184 smb2_find_smb_sess_tcon_unlocked(struct cifs_ses *ses, __u32 tid)
186 struct cifs_tcon *tcon;
188 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
189 if (tcon->tid != tid)
199 * Obtain tcon corresponding to the tid in the given
204 smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32 tid)
206 struct cifs_ses *ses;
207 struct cifs_tcon *tcon;
209 spin_lock(&cifs_tcp_ses_lock);
210 ses = smb2_find_smb_ses_unlocked(server, ses_id);
212 spin_unlock(&cifs_tcp_ses_lock);
215 tcon = smb2_find_smb_sess_tcon_unlocked(ses, tid);
217 cifs_put_smb_ses(ses);
218 spin_unlock(&cifs_tcp_ses_lock);
221 spin_unlock(&cifs_tcp_ses_lock);
222 /* tcon already has a ref to ses, so we don't need ses anymore */
223 cifs_put_smb_ses(ses);
229 smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
230 bool allocate_crypto)
233 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
234 unsigned char *sigptr = smb2_signature;
235 struct kvec *iov = rqst->rq_iov;
236 struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0].iov_base;
237 struct cifs_ses *ses;
238 struct shash_desc *shash = NULL;
239 struct smb_rqst drqst;
241 ses = smb2_find_smb_ses(server, le64_to_cpu(shdr->SessionId));
242 if (unlikely(!ses)) {
243 cifs_server_dbg(VFS, "%s: Could not find session\n", __func__);
247 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
248 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
250 if (allocate_crypto) {
251 rc = cifs_alloc_hash("hmac(sha256)", &shash);
254 "%s: sha256 alloc failed\n", __func__);
258 shash = server->secmech.hmacsha256;
261 rc = crypto_shash_setkey(shash->tfm, ses->auth_key.response,
262 SMB2_NTLMV2_SESSKEY_SIZE);
265 "%s: Could not update with response\n",
270 rc = crypto_shash_init(shash);
272 cifs_server_dbg(VFS, "%s: Could not init sha256", __func__);
277 * For SMB2+, __cifs_calc_signature() expects to sign only the actual
278 * data, that is, iov[0] should not contain a rfc1002 length.
280 * Sign the rfc1002 length prior to passing the data (iov[1-N]) down to
281 * __cifs_calc_signature().
284 if (drqst.rq_nvec >= 2 && iov[0].iov_len == 4) {
285 rc = crypto_shash_update(shash, iov[0].iov_base,
289 "%s: Could not update with payload\n",
297 rc = __cifs_calc_signature(&drqst, server, sigptr, shash);
299 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
303 cifs_free_hash(&shash);
305 cifs_put_smb_ses(ses);
309 static int generate_key(struct cifs_ses *ses, struct kvec label,
310 struct kvec context, __u8 *key, unsigned int key_size)
312 unsigned char zero = 0x0;
313 __u8 i[4] = {0, 0, 0, 1};
314 __u8 L128[4] = {0, 0, 0, 128};
315 __u8 L256[4] = {0, 0, 1, 0};
317 unsigned char prfhash[SMB2_HMACSHA256_SIZE];
318 unsigned char *hashptr = prfhash;
319 struct TCP_Server_Info *server = ses->server;
321 memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
322 memset(key, 0x0, key_size);
324 rc = smb3_crypto_shash_allocate(server);
326 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
327 goto smb3signkey_ret;
330 rc = crypto_shash_setkey(server->secmech.hmacsha256->tfm,
331 ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
333 cifs_server_dbg(VFS, "%s: Could not set with session key\n", __func__);
334 goto smb3signkey_ret;
337 rc = crypto_shash_init(server->secmech.hmacsha256);
339 cifs_server_dbg(VFS, "%s: Could not init sign hmac\n", __func__);
340 goto smb3signkey_ret;
343 rc = crypto_shash_update(server->secmech.hmacsha256, i, 4);
345 cifs_server_dbg(VFS, "%s: Could not update with n\n", __func__);
346 goto smb3signkey_ret;
349 rc = crypto_shash_update(server->secmech.hmacsha256, label.iov_base, label.iov_len);
351 cifs_server_dbg(VFS, "%s: Could not update with label\n", __func__);
352 goto smb3signkey_ret;
355 rc = crypto_shash_update(server->secmech.hmacsha256, &zero, 1);
357 cifs_server_dbg(VFS, "%s: Could not update with zero\n", __func__);
358 goto smb3signkey_ret;
361 rc = crypto_shash_update(server->secmech.hmacsha256, context.iov_base, context.iov_len);
363 cifs_server_dbg(VFS, "%s: Could not update with context\n", __func__);
364 goto smb3signkey_ret;
367 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
368 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
369 rc = crypto_shash_update(server->secmech.hmacsha256, L256, 4);
371 rc = crypto_shash_update(server->secmech.hmacsha256, L128, 4);
374 cifs_server_dbg(VFS, "%s: Could not update with L\n", __func__);
375 goto smb3signkey_ret;
378 rc = crypto_shash_final(server->secmech.hmacsha256, hashptr);
380 cifs_server_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
381 goto smb3signkey_ret;
384 memcpy(key, hashptr, key_size);
395 struct derivation_triplet {
396 struct derivation signing;
397 struct derivation encryption;
398 struct derivation decryption;
402 generate_smb3signingkey(struct cifs_ses *ses,
403 struct TCP_Server_Info *server,
404 const struct derivation_triplet *ptriplet)
407 bool is_binding = false;
410 spin_lock(&ses->ses_lock);
411 spin_lock(&ses->chan_lock);
412 is_binding = (cifs_chan_needs_reconnect(ses, server) &&
413 ses->ses_status == SES_GOOD);
415 chan_index = cifs_ses_get_chan_index(ses, server);
416 /* TODO: introduce ref counting for channels when the can be freed */
417 spin_unlock(&ses->chan_lock);
418 spin_unlock(&ses->ses_lock);
421 * All channels use the same encryption/decryption keys but
422 * they have their own signing key.
424 * When we generate the keys, check if it is for a new channel
425 * (binding) in which case we only need to generate a signing
426 * key and store it in the channel as to not overwrite the
427 * master connection signing key stored in the session
431 rc = generate_key(ses, ptriplet->signing.label,
432 ptriplet->signing.context,
433 ses->chans[chan_index].signkey,
438 rc = generate_key(ses, ptriplet->signing.label,
439 ptriplet->signing.context,
445 /* safe to access primary channel, since it will never go away */
446 spin_lock(&ses->chan_lock);
447 memcpy(ses->chans[chan_index].signkey, ses->smb3signingkey,
449 spin_unlock(&ses->chan_lock);
451 rc = generate_key(ses, ptriplet->encryption.label,
452 ptriplet->encryption.context,
453 ses->smb3encryptionkey,
454 SMB3_ENC_DEC_KEY_SIZE);
457 rc = generate_key(ses, ptriplet->decryption.label,
458 ptriplet->decryption.context,
459 ses->smb3decryptionkey,
460 SMB3_ENC_DEC_KEY_SIZE);
465 #ifdef CONFIG_CIFS_DEBUG_DUMP_KEYS
466 cifs_dbg(VFS, "%s: dumping generated AES session keys\n", __func__);
468 * The session id is opaque in terms of endianness, so we can't
469 * print it as a long long. we dump it as we got it on the wire
471 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid),
473 cifs_dbg(VFS, "Cipher type %d\n", server->cipher_type);
474 cifs_dbg(VFS, "Session Key %*ph\n",
475 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response);
476 cifs_dbg(VFS, "Signing Key %*ph\n",
477 SMB3_SIGN_KEY_SIZE, ses->smb3signingkey);
478 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
479 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) {
480 cifs_dbg(VFS, "ServerIn Key %*ph\n",
481 SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3encryptionkey);
482 cifs_dbg(VFS, "ServerOut Key %*ph\n",
483 SMB3_GCM256_CRYPTKEY_SIZE, ses->smb3decryptionkey);
485 cifs_dbg(VFS, "ServerIn Key %*ph\n",
486 SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3encryptionkey);
487 cifs_dbg(VFS, "ServerOut Key %*ph\n",
488 SMB3_GCM128_CRYPTKEY_SIZE, ses->smb3decryptionkey);
495 generate_smb30signingkey(struct cifs_ses *ses,
496 struct TCP_Server_Info *server)
499 struct derivation_triplet triplet;
500 struct derivation *d;
502 d = &triplet.signing;
503 d->label.iov_base = "SMB2AESCMAC";
504 d->label.iov_len = 12;
505 d->context.iov_base = "SmbSign";
506 d->context.iov_len = 8;
508 d = &triplet.encryption;
509 d->label.iov_base = "SMB2AESCCM";
510 d->label.iov_len = 11;
511 d->context.iov_base = "ServerIn ";
512 d->context.iov_len = 10;
514 d = &triplet.decryption;
515 d->label.iov_base = "SMB2AESCCM";
516 d->label.iov_len = 11;
517 d->context.iov_base = "ServerOut";
518 d->context.iov_len = 10;
520 return generate_smb3signingkey(ses, server, &triplet);
524 generate_smb311signingkey(struct cifs_ses *ses,
525 struct TCP_Server_Info *server)
528 struct derivation_triplet triplet;
529 struct derivation *d;
531 d = &triplet.signing;
532 d->label.iov_base = "SMBSigningKey";
533 d->label.iov_len = 14;
534 d->context.iov_base = ses->preauth_sha_hash;
535 d->context.iov_len = 64;
537 d = &triplet.encryption;
538 d->label.iov_base = "SMBC2SCipherKey";
539 d->label.iov_len = 16;
540 d->context.iov_base = ses->preauth_sha_hash;
541 d->context.iov_len = 64;
543 d = &triplet.decryption;
544 d->label.iov_base = "SMBS2CCipherKey";
545 d->label.iov_len = 16;
546 d->context.iov_base = ses->preauth_sha_hash;
547 d->context.iov_len = 64;
549 return generate_smb3signingkey(ses, server, &triplet);
553 smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
554 bool allocate_crypto)
557 unsigned char smb3_signature[SMB2_CMACAES_SIZE];
558 unsigned char *sigptr = smb3_signature;
559 struct kvec *iov = rqst->rq_iov;
560 struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0].iov_base;
561 struct shash_desc *shash = NULL;
562 struct smb_rqst drqst;
563 u8 key[SMB3_SIGN_KEY_SIZE];
565 rc = smb2_get_sign_key(le64_to_cpu(shdr->SessionId), server, key);
567 cifs_server_dbg(FYI, "%s: Could not get signing key\n", __func__);
571 if (allocate_crypto) {
572 rc = cifs_alloc_hash("cmac(aes)", &shash);
576 shash = server->secmech.aes_cmac;
579 memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE);
580 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
582 rc = crypto_shash_setkey(shash->tfm, key, SMB2_CMACAES_SIZE);
584 cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
589 * we already allocate aes_cmac when we init smb3 signing key,
590 * so unlike smb2 case we do not have to check here if secmech are
593 rc = crypto_shash_init(shash);
595 cifs_server_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
600 * For SMB2+, __cifs_calc_signature() expects to sign only the actual
601 * data, that is, iov[0] should not contain a rfc1002 length.
603 * Sign the rfc1002 length prior to passing the data (iov[1-N]) down to
604 * __cifs_calc_signature().
607 if (drqst.rq_nvec >= 2 && iov[0].iov_len == 4) {
608 rc = crypto_shash_update(shash, iov[0].iov_base,
611 cifs_server_dbg(VFS, "%s: Could not update with payload\n",
619 rc = __cifs_calc_signature(&drqst, server, sigptr, shash);
621 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
625 cifs_free_hash(&shash);
629 /* must be called with server->srv_mutex held */
631 smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
634 struct smb2_hdr *shdr;
635 struct smb2_sess_setup_req *ssr;
639 shdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
640 ssr = (struct smb2_sess_setup_req *)shdr;
642 is_binding = shdr->Command == SMB2_SESSION_SETUP &&
643 (ssr->Flags & SMB2_SESSION_REQ_FLAG_BINDING);
644 is_signed = shdr->Flags & SMB2_FLAGS_SIGNED;
648 spin_lock(&server->srv_lock);
649 if (server->ops->need_neg &&
650 server->ops->need_neg(server)) {
651 spin_unlock(&server->srv_lock);
654 spin_unlock(&server->srv_lock);
655 if (!is_binding && !server->session_estab) {
656 strncpy(shdr->Signature, "BSRSPYL", 8);
660 rc = server->ops->calc_signature(rqst, server, false);
666 smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
669 char server_response_sig[SMB2_SIGNATURE_SIZE];
670 struct smb2_hdr *shdr =
671 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
673 if ((shdr->Command == SMB2_NEGOTIATE) ||
674 (shdr->Command == SMB2_SESSION_SETUP) ||
675 (shdr->Command == SMB2_OPLOCK_BREAK) ||
676 server->ignore_signature ||
677 (!server->session_estab))
681 * BB what if signatures are supposed to be on for session but
682 * server does not send one? BB
685 /* Do not need to verify session setups with signature "BSRSPYL " */
686 if (memcmp(shdr->Signature, "BSRSPYL ", 8) == 0)
687 cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
691 * Save off the origiginal signature so we can modify the smb and check
692 * our calculated signature against what the server sent.
694 memcpy(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE);
696 memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
698 rc = server->ops->calc_signature(rqst, server, true);
703 if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE)) {
704 cifs_dbg(VFS, "sign fail cmd 0x%x message id 0x%llx\n",
705 shdr->Command, shdr->MessageId);
712 * Set message id for the request. Should be called after wait_for_free_request
713 * and when srv_mutex is held.
716 smb2_seq_num_into_buf(struct TCP_Server_Info *server,
717 struct smb2_hdr *shdr)
719 unsigned int i, num = le16_to_cpu(shdr->CreditCharge);
721 shdr->MessageId = get_next_mid64(server);
722 /* skip message numbers according to CreditCharge field */
723 for (i = 1; i < num; i++)
724 get_next_mid(server);
727 static struct mid_q_entry *
728 smb2_mid_entry_alloc(const struct smb2_hdr *shdr,
729 struct TCP_Server_Info *server)
731 struct mid_q_entry *temp;
732 unsigned int credits = le16_to_cpu(shdr->CreditCharge);
734 if (server == NULL) {
735 cifs_dbg(VFS, "Null TCP session in smb2_mid_entry_alloc\n");
739 temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS);
740 memset(temp, 0, sizeof(struct mid_q_entry));
741 kref_init(&temp->refcount);
742 temp->mid = le64_to_cpu(shdr->MessageId);
743 temp->credits = credits > 0 ? credits : 1;
744 temp->pid = current->pid;
745 temp->command = shdr->Command; /* Always LE */
746 temp->when_alloc = jiffies;
747 temp->server = server;
750 * The default is for the mid to be synchronous, so the
751 * default callback just wakes up the current task.
753 get_task_struct(current);
754 temp->creator = current;
755 temp->callback = cifs_wake_up_task;
756 temp->callback_data = current;
758 atomic_inc(&mid_count);
759 temp->mid_state = MID_REQUEST_ALLOCATED;
760 trace_smb3_cmd_enter(le32_to_cpu(shdr->Id.SyncId.TreeId),
761 le64_to_cpu(shdr->SessionId),
762 le16_to_cpu(shdr->Command), temp->mid);
767 smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
768 struct smb2_hdr *shdr, struct mid_q_entry **mid)
770 spin_lock(&server->srv_lock);
771 if (server->tcpStatus == CifsExiting) {
772 spin_unlock(&server->srv_lock);
776 if (server->tcpStatus == CifsNeedReconnect) {
777 spin_unlock(&server->srv_lock);
778 cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
782 if (server->tcpStatus == CifsNeedNegotiate &&
783 shdr->Command != SMB2_NEGOTIATE) {
784 spin_unlock(&server->srv_lock);
787 spin_unlock(&server->srv_lock);
789 spin_lock(&ses->ses_lock);
790 if (ses->ses_status == SES_NEW) {
791 if ((shdr->Command != SMB2_SESSION_SETUP) &&
792 (shdr->Command != SMB2_NEGOTIATE)) {
793 spin_unlock(&ses->ses_lock);
796 /* else ok - we are setting up session */
799 if (ses->ses_status == SES_EXITING) {
800 if (shdr->Command != SMB2_LOGOFF) {
801 spin_unlock(&ses->ses_lock);
804 /* else ok - we are shutting down the session */
806 spin_unlock(&ses->ses_lock);
808 *mid = smb2_mid_entry_alloc(shdr, server);
811 spin_lock(&server->mid_lock);
812 list_add_tail(&(*mid)->qhead, &server->pending_mid_q);
813 spin_unlock(&server->mid_lock);
819 smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
822 unsigned int len = mid->resp_buf_size;
824 struct smb_rqst rqst = { .rq_iov = iov,
827 iov[0].iov_base = (char *)mid->resp_buf;
828 iov[0].iov_len = len;
830 dump_smb(mid->resp_buf, min_t(u32, 80, len));
831 /* convert the length into a more usable form */
832 if (len > 24 && server->sign && !mid->decrypted) {
835 rc = smb2_verify_signature(&rqst, server);
837 cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n",
841 return map_smb2_to_linux_error(mid->resp_buf, log_error);
845 smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server,
846 struct smb_rqst *rqst)
849 struct smb2_hdr *shdr =
850 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
851 struct mid_q_entry *mid;
853 smb2_seq_num_into_buf(server, shdr);
855 rc = smb2_get_mid_entry(ses, server, shdr, &mid);
857 revert_current_mid_from_hdr(server, shdr);
861 rc = smb2_sign_rqst(rqst, server);
863 revert_current_mid_from_hdr(server, shdr);
872 smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
875 struct smb2_hdr *shdr =
876 (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
877 struct mid_q_entry *mid;
879 spin_lock(&server->srv_lock);
880 if (server->tcpStatus == CifsNeedNegotiate &&
881 shdr->Command != SMB2_NEGOTIATE) {
882 spin_unlock(&server->srv_lock);
883 return ERR_PTR(-EAGAIN);
885 spin_unlock(&server->srv_lock);
887 smb2_seq_num_into_buf(server, shdr);
889 mid = smb2_mid_entry_alloc(shdr, server);
891 revert_current_mid_from_hdr(server, shdr);
892 return ERR_PTR(-ENOMEM);
895 rc = smb2_sign_rqst(rqst, server);
897 revert_current_mid_from_hdr(server, shdr);
906 smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
908 struct crypto_aead *tfm;
910 if (!server->secmech.enc) {
911 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
912 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
913 tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
915 tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
917 cifs_server_dbg(VFS, "%s: Failed alloc encrypt aead\n",
921 server->secmech.enc = tfm;
924 if (!server->secmech.dec) {
925 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
926 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
927 tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
929 tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
931 crypto_free_aead(server->secmech.enc);
932 server->secmech.enc = NULL;
933 cifs_server_dbg(VFS, "%s: Failed to alloc decrypt aead\n",
937 server->secmech.dec = tfm;