smb2transport.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * fs/cifs/smb2transport.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002, 2011
  5. * Etersoft, 2012
  6. * Author(s): Steve French (sfrench@us.ibm.com)
  7. * Jeremy Allison (jra@samba.org) 2006
  8. * Pavel Shilovsky (pshilovsky@samba.org) 2012
  9. *
  10. * This library is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published
  12. * by the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  18. * the GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/fs.h>
  25. #include <linux/list.h>
  26. #include <linux/wait.h>
  27. #include <linux/net.h>
  28. #include <linux/delay.h>
  29. #include <linux/uaccess.h>
  30. #include <asm/processor.h>
  31. #include <linux/mempool.h>
  32. #include <linux/highmem.h>
  33. #include "smb2pdu.h"
  34. #include "cifsglob.h"
  35. #include "cifsproto.h"
  36. #include "smb2proto.h"
  37. #include "cifs_debug.h"
  38. #include "smb2status.h"
  39. #include "smb2glob.h"
  40. static int
  41. smb2_crypto_shash_allocate(struct TCP_Server_Info *server)
  42. {
  43. int rc;
  44. unsigned int size;
  45. if (server->secmech.sdeschmacsha256 != NULL)
  46. return 0; /* already allocated */
  47. server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0);
  48. if (IS_ERR(server->secmech.hmacsha256)) {
  49. cifs_dbg(VFS, "could not allocate crypto hmacsha256\n");
  50. rc = PTR_ERR(server->secmech.hmacsha256);
  51. server->secmech.hmacsha256 = NULL;
  52. return rc;
  53. }
  54. size = sizeof(struct shash_desc) +
  55. crypto_shash_descsize(server->secmech.hmacsha256);
  56. server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL);
  57. if (!server->secmech.sdeschmacsha256) {
  58. crypto_free_shash(server->secmech.hmacsha256);
  59. server->secmech.hmacsha256 = NULL;
  60. return -ENOMEM;
  61. }
  62. server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256;
  63. server->secmech.sdeschmacsha256->shash.flags = 0x0;
  64. return 0;
  65. }
  66. static int
  67. smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
  68. {
  69. unsigned int size;
  70. int rc;
  71. if (server->secmech.sdesccmacaes != NULL)
  72. return 0; /* already allocated */
  73. rc = smb2_crypto_shash_allocate(server);
  74. if (rc)
  75. return rc;
  76. server->secmech.cmacaes = crypto_alloc_shash("cmac(aes)", 0, 0);
  77. if (IS_ERR(server->secmech.cmacaes)) {
  78. cifs_dbg(VFS, "could not allocate crypto cmac-aes");
  79. kfree(server->secmech.sdeschmacsha256);
  80. server->secmech.sdeschmacsha256 = NULL;
  81. crypto_free_shash(server->secmech.hmacsha256);
  82. server->secmech.hmacsha256 = NULL;
  83. rc = PTR_ERR(server->secmech.cmacaes);
  84. server->secmech.cmacaes = NULL;
  85. return rc;
  86. }
  87. size = sizeof(struct shash_desc) +
  88. crypto_shash_descsize(server->secmech.cmacaes);
  89. server->secmech.sdesccmacaes = kmalloc(size, GFP_KERNEL);
  90. if (!server->secmech.sdesccmacaes) {
  91. cifs_dbg(VFS, "%s: Can't alloc cmacaes\n", __func__);
  92. kfree(server->secmech.sdeschmacsha256);
  93. server->secmech.sdeschmacsha256 = NULL;
  94. crypto_free_shash(server->secmech.hmacsha256);
  95. crypto_free_shash(server->secmech.cmacaes);
  96. server->secmech.hmacsha256 = NULL;
  97. server->secmech.cmacaes = NULL;
  98. return -ENOMEM;
  99. }
  100. server->secmech.sdesccmacaes->shash.tfm = server->secmech.cmacaes;
  101. server->secmech.sdesccmacaes->shash.flags = 0x0;
  102. return 0;
  103. }
  104. static struct cifs_ses *
  105. smb2_find_smb_ses(struct smb2_hdr *smb2hdr, struct TCP_Server_Info *server)
  106. {
  107. struct cifs_ses *ses;
  108. spin_lock(&cifs_tcp_ses_lock);
  109. list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
  110. if (ses->Suid != smb2hdr->SessionId)
  111. continue;
  112. spin_unlock(&cifs_tcp_ses_lock);
  113. return ses;
  114. }
  115. spin_unlock(&cifs_tcp_ses_lock);
  116. return NULL;
  117. }
  118. int
  119. smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
  120. {
  121. int i, rc;
  122. unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
  123. unsigned char *sigptr = smb2_signature;
  124. struct kvec *iov = rqst->rq_iov;
  125. int n_vec = rqst->rq_nvec;
  126. struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
  127. struct cifs_ses *ses;
  128. ses = smb2_find_smb_ses(smb2_pdu, server);
  129. if (!ses) {
  130. cifs_dbg(VFS, "%s: Could not find session\n", __func__);
  131. return 0;
  132. }
  133. memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
  134. memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE);
  135. rc = smb2_crypto_shash_allocate(server);
  136. if (rc) {
  137. cifs_dbg(VFS, "%s: shah256 alloc failed\n", __func__);
  138. return rc;
  139. }
  140. rc = crypto_shash_setkey(server->secmech.hmacsha256,
  141. ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
  142. if (rc) {
  143. cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
  144. return rc;
  145. }
  146. rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash);
  147. if (rc) {
  148. cifs_dbg(VFS, "%s: Could not init sha256", __func__);
  149. return rc;
  150. }
  151. for (i = 0; i < n_vec; i++) {
  152. if (iov[i].iov_len == 0)
  153. continue;
  154. if (iov[i].iov_base == NULL) {
  155. cifs_dbg(VFS, "null iovec entry\n");
  156. return -EIO;
  157. }
  158. /*
  159. * The first entry includes a length field (which does not get
  160. * signed that occupies the first 4 bytes before the header).
  161. */
  162. if (i == 0) {
  163. if (iov[0].iov_len <= 8) /* cmd field at offset 9 */
  164. break; /* nothing to sign or corrupt header */
  165. rc =
  166. crypto_shash_update(
  167. &server->secmech.sdeschmacsha256->shash,
  168. iov[i].iov_base + 4, iov[i].iov_len - 4);
  169. } else {
  170. rc =
  171. crypto_shash_update(
  172. &server->secmech.sdeschmacsha256->shash,
  173. iov[i].iov_base, iov[i].iov_len);
  174. }
  175. if (rc) {
  176. cifs_dbg(VFS, "%s: Could not update with payload\n",
  177. __func__);
  178. return rc;
  179. }
  180. }
  181. /* now hash over the rq_pages array */
  182. for (i = 0; i < rqst->rq_npages; i++) {
  183. struct kvec p_iov;
  184. cifs_rqst_page_to_kvec(rqst, i, &p_iov);
  185. crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
  186. p_iov.iov_base, p_iov.iov_len);
  187. kunmap(rqst->rq_pages[i]);
  188. }
  189. rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash,
  190. sigptr);
  191. if (rc)
  192. cifs_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
  193. memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE);
  194. return rc;
  195. }
  196. int
  197. generate_smb3signingkey(struct cifs_ses *ses)
  198. {
  199. unsigned char zero = 0x0;
  200. __u8 i[4] = {0, 0, 0, 1};
  201. __u8 L[4] = {0, 0, 0, 128};
  202. int rc = 0;
  203. unsigned char prfhash[SMB2_HMACSHA256_SIZE];
  204. unsigned char *hashptr = prfhash;
  205. memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE);
  206. memset(ses->smb3signingkey, 0x0, SMB3_SIGNKEY_SIZE);
  207. rc = smb3_crypto_shash_allocate(ses->server);
  208. if (rc) {
  209. cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
  210. goto smb3signkey_ret;
  211. }
  212. rc = crypto_shash_setkey(ses->server->secmech.hmacsha256,
  213. ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
  214. if (rc) {
  215. cifs_dbg(VFS, "%s: Could not set with session key\n", __func__);
  216. goto smb3signkey_ret;
  217. }
  218. rc = crypto_shash_init(&ses->server->secmech.sdeschmacsha256->shash);
  219. if (rc) {
  220. cifs_dbg(VFS, "%s: Could not init sign hmac\n", __func__);
  221. goto smb3signkey_ret;
  222. }
  223. rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
  224. i, 4);
  225. if (rc) {
  226. cifs_dbg(VFS, "%s: Could not update with n\n", __func__);
  227. goto smb3signkey_ret;
  228. }
  229. rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
  230. "SMB2AESCMAC", 12);
  231. if (rc) {
  232. cifs_dbg(VFS, "%s: Could not update with label\n", __func__);
  233. goto smb3signkey_ret;
  234. }
  235. rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
  236. &zero, 1);
  237. if (rc) {
  238. cifs_dbg(VFS, "%s: Could not update with zero\n", __func__);
  239. goto smb3signkey_ret;
  240. }
  241. rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
  242. "SmbSign", 8);
  243. if (rc) {
  244. cifs_dbg(VFS, "%s: Could not update with context\n", __func__);
  245. goto smb3signkey_ret;
  246. }
  247. rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash,
  248. L, 4);
  249. if (rc) {
  250. cifs_dbg(VFS, "%s: Could not update with L\n", __func__);
  251. goto smb3signkey_ret;
  252. }
  253. rc = crypto_shash_final(&ses->server->secmech.sdeschmacsha256->shash,
  254. hashptr);
  255. if (rc) {
  256. cifs_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__);
  257. goto smb3signkey_ret;
  258. }
  259. memcpy(ses->smb3signingkey, hashptr, SMB3_SIGNKEY_SIZE);
  260. smb3signkey_ret:
  261. return rc;
  262. }
  263. int
  264. smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
  265. {
  266. int i;
  267. int rc = 0;
  268. unsigned char smb3_signature[SMB2_CMACAES_SIZE];
  269. unsigned char *sigptr = smb3_signature;
  270. struct kvec *iov = rqst->rq_iov;
  271. int n_vec = rqst->rq_nvec;
  272. struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
  273. struct cifs_ses *ses;
  274. ses = smb2_find_smb_ses(smb2_pdu, server);
  275. if (!ses) {
  276. cifs_dbg(VFS, "%s: Could not find session\n", __func__);
  277. return 0;
  278. }
  279. memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE);
  280. memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE);
  281. rc = crypto_shash_setkey(server->secmech.cmacaes,
  282. ses->smb3signingkey, SMB2_CMACAES_SIZE);
  283. if (rc) {
  284. cifs_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
  285. return rc;
  286. }
  287. /*
  288. * we already allocate sdesccmacaes when we init smb3 signing key,
  289. * so unlike smb2 case we do not have to check here if secmech are
  290. * initialized
  291. */
  292. rc = crypto_shash_init(&server->secmech.sdesccmacaes->shash);
  293. if (rc) {
  294. cifs_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
  295. return rc;
  296. }
  297. for (i = 0; i < n_vec; i++) {
  298. if (iov[i].iov_len == 0)
  299. continue;
  300. if (iov[i].iov_base == NULL) {
  301. cifs_dbg(VFS, "null iovec entry");
  302. return -EIO;
  303. }
  304. /*
  305. * The first entry includes a length field (which does not get
  306. * signed that occupies the first 4 bytes before the header).
  307. */
  308. if (i == 0) {
  309. if (iov[0].iov_len <= 8) /* cmd field at offset 9 */
  310. break; /* nothing to sign or corrupt header */
  311. rc =
  312. crypto_shash_update(
  313. &server->secmech.sdesccmacaes->shash,
  314. iov[i].iov_base + 4, iov[i].iov_len - 4);
  315. } else {
  316. rc =
  317. crypto_shash_update(
  318. &server->secmech.sdesccmacaes->shash,
  319. iov[i].iov_base, iov[i].iov_len);
  320. }
  321. if (rc) {
  322. cifs_dbg(VFS, "%s: Couldn't update cmac aes with payload\n",
  323. __func__);
  324. return rc;
  325. }
  326. }
  327. /* now hash over the rq_pages array */
  328. for (i = 0; i < rqst->rq_npages; i++) {
  329. struct kvec p_iov;
  330. cifs_rqst_page_to_kvec(rqst, i, &p_iov);
  331. crypto_shash_update(&server->secmech.sdesccmacaes->shash,
  332. p_iov.iov_base, p_iov.iov_len);
  333. kunmap(rqst->rq_pages[i]);
  334. }
  335. rc = crypto_shash_final(&server->secmech.sdesccmacaes->shash,
  336. sigptr);
  337. if (rc)
  338. cifs_dbg(VFS, "%s: Could not generate cmac aes\n", __func__);
  339. memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE);
  340. return rc;
  341. }
  342. /* must be called with server->srv_mutex held */
  343. static int
  344. smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
  345. {
  346. int rc = 0;
  347. struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base;
  348. if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) ||
  349. server->tcpStatus == CifsNeedNegotiate)
  350. return rc;
  351. if (!server->session_estab) {
  352. strncpy(smb2_pdu->Signature, "BSRSPYL", 8);
  353. return rc;
  354. }
  355. rc = server->ops->calc_signature(rqst, server);
  356. return rc;
  357. }
  358. int
  359. smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
  360. {
  361. unsigned int rc;
  362. char server_response_sig[16];
  363. struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
  364. if ((smb2_pdu->Command == SMB2_NEGOTIATE) ||
  365. (smb2_pdu->Command == SMB2_SESSION_SETUP) ||
  366. (smb2_pdu->Command == SMB2_OPLOCK_BREAK) ||
  367. (!server->session_estab))
  368. return 0;
  369. /*
  370. * BB what if signatures are supposed to be on for session but
  371. * server does not send one? BB
  372. */
  373. /* Do not need to verify session setups with signature "BSRSPYL " */
  374. if (memcmp(smb2_pdu->Signature, "BSRSPYL ", 8) == 0)
  375. cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
  376. smb2_pdu->Command);
  377. /*
  378. * Save off the origiginal signature so we can modify the smb and check
  379. * our calculated signature against what the server sent.
  380. */
  381. memcpy(server_response_sig, smb2_pdu->Signature, SMB2_SIGNATURE_SIZE);
  382. memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE);
  383. mutex_lock(&server->srv_mutex);
  384. rc = server->ops->calc_signature(rqst, server);
  385. mutex_unlock(&server->srv_mutex);
  386. if (rc)
  387. return rc;
  388. if (memcmp(server_response_sig, smb2_pdu->Signature,
  389. SMB2_SIGNATURE_SIZE))
  390. return -EACCES;
  391. else
  392. return 0;
  393. }
  394. /*
  395. * Set message id for the request. Should be called after wait_for_free_request
  396. * and when srv_mutex is held.
  397. */
  398. static inline void
  399. smb2_seq_num_into_buf(struct TCP_Server_Info *server, struct smb2_hdr *hdr)
  400. {
  401. unsigned int i, num = le16_to_cpu(hdr->CreditCharge);
  402. hdr->MessageId = get_next_mid64(server);
  403. /* skip message numbers according to CreditCharge field */
  404. for (i = 1; i < num; i++)
  405. get_next_mid(server);
  406. }
  407. static struct mid_q_entry *
  408. smb2_mid_entry_alloc(const struct smb2_hdr *smb_buffer,
  409. struct TCP_Server_Info *server)
  410. {
  411. struct mid_q_entry *temp;
  412. if (server == NULL) {
  413. cifs_dbg(VFS, "Null TCP session in smb2_mid_entry_alloc\n");
  414. return NULL;
  415. }
  416. temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS);
  417. if (temp == NULL)
  418. return temp;
  419. else {
  420. memset(temp, 0, sizeof(struct mid_q_entry));
  421. temp->mid = le64_to_cpu(smb_buffer->MessageId);
  422. temp->pid = current->pid;
  423. temp->command = smb_buffer->Command; /* Always LE */
  424. temp->when_alloc = jiffies;
  425. temp->server = server;
  426. /*
  427. * The default is for the mid to be synchronous, so the
  428. * default callback just wakes up the current task.
  429. */
  430. temp->callback = cifs_wake_up_task;
  431. temp->callback_data = current;
  432. }
  433. atomic_inc(&midCount);
  434. temp->mid_state = MID_REQUEST_ALLOCATED;
  435. return temp;
  436. }
  437. static int
  438. smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
  439. struct mid_q_entry **mid)
  440. {
  441. if (ses->server->tcpStatus == CifsExiting)
  442. return -ENOENT;
  443. if (ses->server->tcpStatus == CifsNeedReconnect) {
  444. cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
  445. return -EAGAIN;
  446. }
  447. if (ses->status == CifsNew) {
  448. if ((buf->Command != SMB2_SESSION_SETUP) &&
  449. (buf->Command != SMB2_NEGOTIATE))
  450. return -EAGAIN;
  451. /* else ok - we are setting up session */
  452. }
  453. if (ses->status == CifsExiting) {
  454. if (buf->Command != SMB2_LOGOFF)
  455. return -EAGAIN;
  456. /* else ok - we are shutting down the session */
  457. }
  458. *mid = smb2_mid_entry_alloc(buf, ses->server);
  459. if (*mid == NULL)
  460. return -ENOMEM;
  461. spin_lock(&GlobalMid_Lock);
  462. list_add_tail(&(*mid)->qhead, &ses->server->pending_mid_q);
  463. spin_unlock(&GlobalMid_Lock);
  464. return 0;
  465. }
  466. int
  467. smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
  468. bool log_error)
  469. {
  470. unsigned int len = get_rfc1002_length(mid->resp_buf);
  471. struct kvec iov;
  472. struct smb_rqst rqst = { .rq_iov = &iov,
  473. .rq_nvec = 1 };
  474. iov.iov_base = (char *)mid->resp_buf;
  475. iov.iov_len = get_rfc1002_length(mid->resp_buf) + 4;
  476. dump_smb(mid->resp_buf, min_t(u32, 80, len));
  477. /* convert the length into a more usable form */
  478. if (len > 24 && server->sign) {
  479. int rc;
  480. rc = smb2_verify_signature(&rqst, server);
  481. if (rc)
  482. cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
  483. rc);
  484. }
  485. return map_smb2_to_linux_error(mid->resp_buf, log_error);
  486. }
  487. struct mid_q_entry *
  488. smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
  489. {
  490. int rc;
  491. struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
  492. struct mid_q_entry *mid;
  493. smb2_seq_num_into_buf(ses->server, hdr);
  494. rc = smb2_get_mid_entry(ses, hdr, &mid);
  495. if (rc)
  496. return ERR_PTR(rc);
  497. rc = smb2_sign_rqst(rqst, ses->server);
  498. if (rc) {
  499. cifs_delete_mid(mid);
  500. return ERR_PTR(rc);
  501. }
  502. return mid;
  503. }
  504. struct mid_q_entry *
  505. smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
  506. {
  507. int rc;
  508. struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
  509. struct mid_q_entry *mid;
  510. smb2_seq_num_into_buf(server, hdr);
  511. mid = smb2_mid_entry_alloc(hdr, server);
  512. if (mid == NULL)
  513. return ERR_PTR(-ENOMEM);
  514. rc = smb2_sign_rqst(rqst, server);
  515. if (rc) {
  516. DeleteMidQEntry(mid);
  517. return ERR_PTR(rc);
  518. }
  519. return mid;
  520. }