Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 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 | |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/wait.h> |
| 28 | #include <linux/net.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/uaccess.h> |
| 31 | #include <asm/processor.h> |
| 32 | #include <linux/mempool.h> |
Jeff Layton | fb308a6 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 33 | #include <linux/highmem.h> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 34 | #include <crypto/aead.h> |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 35 | #include "smb2pdu.h" |
| 36 | #include "cifsglob.h" |
| 37 | #include "cifsproto.h" |
| 38 | #include "smb2proto.h" |
| 39 | #include "cifs_debug.h" |
| 40 | #include "smb2status.h" |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 41 | #include "smb2glob.h" |
| 42 | |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 43 | static int |
| 44 | smb2_crypto_shash_allocate(struct TCP_Server_Info *server) |
| 45 | { |
Jeff Layton | ba48202 | 2013-07-31 13:48:00 -0400 | [diff] [blame] | 46 | int rc; |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 47 | unsigned int size; |
| 48 | |
| 49 | if (server->secmech.sdeschmacsha256 != NULL) |
| 50 | return 0; /* already allocated */ |
| 51 | |
| 52 | server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0); |
| 53 | if (IS_ERR(server->secmech.hmacsha256)) { |
| 54 | cifs_dbg(VFS, "could not allocate crypto hmacsha256\n"); |
Jeff Layton | ba48202 | 2013-07-31 13:48:00 -0400 | [diff] [blame] | 55 | rc = PTR_ERR(server->secmech.hmacsha256); |
| 56 | server->secmech.hmacsha256 = NULL; |
| 57 | return rc; |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | size = sizeof(struct shash_desc) + |
| 61 | crypto_shash_descsize(server->secmech.hmacsha256); |
| 62 | server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL); |
| 63 | if (!server->secmech.sdeschmacsha256) { |
| 64 | crypto_free_shash(server->secmech.hmacsha256); |
| 65 | server->secmech.hmacsha256 = NULL; |
| 66 | return -ENOMEM; |
| 67 | } |
| 68 | server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256; |
| 69 | server->secmech.sdeschmacsha256->shash.flags = 0x0; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int |
| 75 | smb3_crypto_shash_allocate(struct TCP_Server_Info *server) |
| 76 | { |
| 77 | unsigned int size; |
| 78 | int rc; |
| 79 | |
| 80 | if (server->secmech.sdesccmacaes != NULL) |
| 81 | return 0; /* already allocated */ |
| 82 | |
| 83 | rc = smb2_crypto_shash_allocate(server); |
| 84 | if (rc) |
| 85 | return rc; |
| 86 | |
| 87 | server->secmech.cmacaes = crypto_alloc_shash("cmac(aes)", 0, 0); |
| 88 | if (IS_ERR(server->secmech.cmacaes)) { |
| 89 | cifs_dbg(VFS, "could not allocate crypto cmac-aes"); |
| 90 | kfree(server->secmech.sdeschmacsha256); |
| 91 | server->secmech.sdeschmacsha256 = NULL; |
| 92 | crypto_free_shash(server->secmech.hmacsha256); |
| 93 | server->secmech.hmacsha256 = NULL; |
Jeff Layton | ba48202 | 2013-07-31 13:48:00 -0400 | [diff] [blame] | 94 | rc = PTR_ERR(server->secmech.cmacaes); |
| 95 | server->secmech.cmacaes = NULL; |
| 96 | return rc; |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | size = sizeof(struct shash_desc) + |
| 100 | crypto_shash_descsize(server->secmech.cmacaes); |
| 101 | server->secmech.sdesccmacaes = kmalloc(size, GFP_KERNEL); |
| 102 | if (!server->secmech.sdesccmacaes) { |
| 103 | cifs_dbg(VFS, "%s: Can't alloc cmacaes\n", __func__); |
| 104 | kfree(server->secmech.sdeschmacsha256); |
| 105 | server->secmech.sdeschmacsha256 = NULL; |
| 106 | crypto_free_shash(server->secmech.hmacsha256); |
| 107 | crypto_free_shash(server->secmech.cmacaes); |
| 108 | server->secmech.hmacsha256 = NULL; |
| 109 | server->secmech.cmacaes = NULL; |
| 110 | return -ENOMEM; |
| 111 | } |
| 112 | server->secmech.sdesccmacaes->shash.tfm = server->secmech.cmacaes; |
| 113 | server->secmech.sdesccmacaes->shash.flags = 0x0; |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 118 | struct cifs_ses * |
| 119 | smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id) |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 120 | { |
| 121 | struct cifs_ses *ses; |
| 122 | |
| 123 | spin_lock(&cifs_tcp_ses_lock); |
| 124 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 125 | if (ses->Suid != ses_id) |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 126 | continue; |
| 127 | spin_unlock(&cifs_tcp_ses_lock); |
| 128 | return ses; |
| 129 | } |
| 130 | spin_unlock(&cifs_tcp_ses_lock); |
| 131 | |
| 132 | return NULL; |
| 133 | } |
| 134 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 135 | int |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 136 | smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 137 | { |
Al Viro | 16c568e | 2015-11-12 22:46:49 -0500 | [diff] [blame] | 138 | int rc; |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 139 | unsigned char smb2_signature[SMB2_HMACSHA256_SIZE]; |
| 140 | unsigned char *sigptr = smb2_signature; |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 141 | struct kvec *iov = rqst->rq_iov; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 142 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[1].iov_base; |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 143 | struct cifs_ses *ses; |
| 144 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 145 | ses = smb2_find_smb_ses(server, shdr->SessionId); |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 146 | if (!ses) { |
| 147 | cifs_dbg(VFS, "%s: Could not find session\n", __func__); |
| 148 | return 0; |
| 149 | } |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 150 | |
| 151 | memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 152 | memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 153 | |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 154 | rc = smb2_crypto_shash_allocate(server); |
| 155 | if (rc) { |
| 156 | cifs_dbg(VFS, "%s: shah256 alloc failed\n", __func__); |
| 157 | return rc; |
| 158 | } |
| 159 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 160 | rc = crypto_shash_setkey(server->secmech.hmacsha256, |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 161 | ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 162 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 163 | cifs_dbg(VFS, "%s: Could not update with response\n", __func__); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 164 | return rc; |
| 165 | } |
| 166 | |
| 167 | rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash); |
| 168 | if (rc) { |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 169 | cifs_dbg(VFS, "%s: Could not init sha256", __func__); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 170 | return rc; |
| 171 | } |
| 172 | |
Al Viro | 16c568e | 2015-11-12 22:46:49 -0500 | [diff] [blame] | 173 | rc = __cifs_calc_signature(rqst, server, sigptr, |
| 174 | &server->secmech.sdeschmacsha256->shash); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 175 | |
Al Viro | 16c568e | 2015-11-12 22:46:49 -0500 | [diff] [blame] | 176 | if (!rc) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 177 | memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 178 | |
| 179 | return rc; |
| 180 | } |
| 181 | |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 182 | static int generate_key(struct cifs_ses *ses, struct kvec label, |
| 183 | struct kvec context, __u8 *key, unsigned int key_size) |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 184 | { |
| 185 | unsigned char zero = 0x0; |
| 186 | __u8 i[4] = {0, 0, 0, 1}; |
| 187 | __u8 L[4] = {0, 0, 0, 128}; |
| 188 | int rc = 0; |
| 189 | unsigned char prfhash[SMB2_HMACSHA256_SIZE]; |
| 190 | unsigned char *hashptr = prfhash; |
| 191 | |
| 192 | memset(prfhash, 0x0, SMB2_HMACSHA256_SIZE); |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 193 | memset(key, 0x0, key_size); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 194 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 195 | rc = smb3_crypto_shash_allocate(ses->server); |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 196 | if (rc) { |
| 197 | cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
| 198 | goto smb3signkey_ret; |
| 199 | } |
| 200 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 201 | rc = crypto_shash_setkey(ses->server->secmech.hmacsha256, |
| 202 | ses->auth_key.response, SMB2_NTLMV2_SESSKEY_SIZE); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 203 | if (rc) { |
| 204 | cifs_dbg(VFS, "%s: Could not set with session key\n", __func__); |
| 205 | goto smb3signkey_ret; |
| 206 | } |
| 207 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 208 | rc = crypto_shash_init(&ses->server->secmech.sdeschmacsha256->shash); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 209 | if (rc) { |
| 210 | cifs_dbg(VFS, "%s: Could not init sign hmac\n", __func__); |
| 211 | goto smb3signkey_ret; |
| 212 | } |
| 213 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 214 | rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 215 | i, 4); |
| 216 | if (rc) { |
| 217 | cifs_dbg(VFS, "%s: Could not update with n\n", __func__); |
| 218 | goto smb3signkey_ret; |
| 219 | } |
| 220 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 221 | rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 222 | label.iov_base, label.iov_len); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 223 | if (rc) { |
| 224 | cifs_dbg(VFS, "%s: Could not update with label\n", __func__); |
| 225 | goto smb3signkey_ret; |
| 226 | } |
| 227 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 228 | rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 229 | &zero, 1); |
| 230 | if (rc) { |
| 231 | cifs_dbg(VFS, "%s: Could not update with zero\n", __func__); |
| 232 | goto smb3signkey_ret; |
| 233 | } |
| 234 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 235 | rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 236 | context.iov_base, context.iov_len); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 237 | if (rc) { |
| 238 | cifs_dbg(VFS, "%s: Could not update with context\n", __func__); |
| 239 | goto smb3signkey_ret; |
| 240 | } |
| 241 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 242 | rc = crypto_shash_update(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 243 | L, 4); |
| 244 | if (rc) { |
| 245 | cifs_dbg(VFS, "%s: Could not update with L\n", __func__); |
| 246 | goto smb3signkey_ret; |
| 247 | } |
| 248 | |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 249 | rc = crypto_shash_final(&ses->server->secmech.sdeschmacsha256->shash, |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 250 | hashptr); |
| 251 | if (rc) { |
| 252 | cifs_dbg(VFS, "%s: Could not generate sha256 hash\n", __func__); |
| 253 | goto smb3signkey_ret; |
| 254 | } |
| 255 | |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 256 | memcpy(key, hashptr, key_size); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 257 | |
| 258 | smb3signkey_ret: |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 259 | return rc; |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 260 | } |
| 261 | |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 262 | struct derivation { |
| 263 | struct kvec label; |
| 264 | struct kvec context; |
| 265 | }; |
| 266 | |
| 267 | struct derivation_triplet { |
| 268 | struct derivation signing; |
| 269 | struct derivation encryption; |
| 270 | struct derivation decryption; |
| 271 | }; |
| 272 | |
| 273 | static int |
| 274 | generate_smb3signingkey(struct cifs_ses *ses, |
| 275 | const struct derivation_triplet *ptriplet) |
| 276 | { |
| 277 | int rc; |
| 278 | |
| 279 | rc = generate_key(ses, ptriplet->signing.label, |
| 280 | ptriplet->signing.context, ses->smb3signingkey, |
| 281 | SMB3_SIGN_KEY_SIZE); |
| 282 | if (rc) |
| 283 | return rc; |
| 284 | |
| 285 | rc = generate_key(ses, ptriplet->encryption.label, |
| 286 | ptriplet->encryption.context, ses->smb3encryptionkey, |
| 287 | SMB3_SIGN_KEY_SIZE); |
| 288 | if (rc) |
| 289 | return rc; |
| 290 | |
| 291 | return generate_key(ses, ptriplet->decryption.label, |
| 292 | ptriplet->decryption.context, |
| 293 | ses->smb3decryptionkey, SMB3_SIGN_KEY_SIZE); |
| 294 | } |
| 295 | |
| 296 | int |
| 297 | generate_smb30signingkey(struct cifs_ses *ses) |
| 298 | |
| 299 | { |
| 300 | struct derivation_triplet triplet; |
| 301 | struct derivation *d; |
| 302 | |
| 303 | d = &triplet.signing; |
| 304 | d->label.iov_base = "SMB2AESCMAC"; |
| 305 | d->label.iov_len = 12; |
| 306 | d->context.iov_base = "SmbSign"; |
| 307 | d->context.iov_len = 8; |
| 308 | |
| 309 | d = &triplet.encryption; |
| 310 | d->label.iov_base = "SMB2AESCCM"; |
| 311 | d->label.iov_len = 11; |
| 312 | d->context.iov_base = "ServerIn "; |
| 313 | d->context.iov_len = 10; |
| 314 | |
| 315 | d = &triplet.decryption; |
| 316 | d->label.iov_base = "SMB2AESCCM"; |
| 317 | d->label.iov_len = 11; |
| 318 | d->context.iov_base = "ServerOut"; |
| 319 | d->context.iov_len = 10; |
| 320 | |
| 321 | return generate_smb3signingkey(ses, &triplet); |
| 322 | } |
| 323 | |
| 324 | int |
| 325 | generate_smb311signingkey(struct cifs_ses *ses) |
| 326 | |
| 327 | { |
| 328 | struct derivation_triplet triplet; |
| 329 | struct derivation *d; |
| 330 | |
| 331 | d = &triplet.signing; |
| 332 | d->label.iov_base = "SMB2AESCMAC"; |
| 333 | d->label.iov_len = 12; |
| 334 | d->context.iov_base = "SmbSign"; |
| 335 | d->context.iov_len = 8; |
| 336 | |
| 337 | d = &triplet.encryption; |
| 338 | d->label.iov_base = "SMB2AESCCM"; |
| 339 | d->label.iov_len = 11; |
| 340 | d->context.iov_base = "ServerIn "; |
| 341 | d->context.iov_len = 10; |
| 342 | |
| 343 | d = &triplet.decryption; |
| 344 | d->label.iov_base = "SMB2AESCCM"; |
| 345 | d->label.iov_len = 11; |
| 346 | d->context.iov_base = "ServerOut"; |
| 347 | d->context.iov_len = 10; |
| 348 | |
| 349 | return generate_smb3signingkey(ses, &triplet); |
| 350 | } |
| 351 | |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 352 | int |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 353 | smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) |
| 354 | { |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 355 | int rc = 0; |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 356 | unsigned char smb3_signature[SMB2_CMACAES_SIZE]; |
| 357 | unsigned char *sigptr = smb3_signature; |
| 358 | struct kvec *iov = rqst->rq_iov; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 359 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[1].iov_base; |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 360 | struct cifs_ses *ses; |
| 361 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 362 | ses = smb2_find_smb_ses(server, shdr->SessionId); |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 363 | if (!ses) { |
| 364 | cifs_dbg(VFS, "%s: Could not find session\n", __func__); |
| 365 | return 0; |
| 366 | } |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 367 | |
| 368 | memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 369 | memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 370 | |
| 371 | rc = crypto_shash_setkey(server->secmech.cmacaes, |
Shirish Pargaonkar | 32811d2 | 2013-08-29 08:35:11 -0500 | [diff] [blame] | 372 | ses->smb3signingkey, SMB2_CMACAES_SIZE); |
| 373 | |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 374 | if (rc) { |
| 375 | cifs_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__); |
| 376 | return rc; |
| 377 | } |
| 378 | |
Steve French | 95dc8dd | 2013-07-04 10:35:21 -0500 | [diff] [blame] | 379 | /* |
| 380 | * we already allocate sdesccmacaes when we init smb3 signing key, |
| 381 | * so unlike smb2 case we do not have to check here if secmech are |
| 382 | * initialized |
| 383 | */ |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 384 | rc = crypto_shash_init(&server->secmech.sdesccmacaes->shash); |
| 385 | if (rc) { |
| 386 | cifs_dbg(VFS, "%s: Could not init cmac aes\n", __func__); |
| 387 | return rc; |
| 388 | } |
Al Viro | 16c568e | 2015-11-12 22:46:49 -0500 | [diff] [blame] | 389 | |
| 390 | rc = __cifs_calc_signature(rqst, server, sigptr, |
| 391 | &server->secmech.sdesccmacaes->shash); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 392 | |
Al Viro | 16c568e | 2015-11-12 22:46:49 -0500 | [diff] [blame] | 393 | if (!rc) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 394 | memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE); |
Steve French | 429b46f | 2013-06-26 23:45:05 -0500 | [diff] [blame] | 395 | |
| 396 | return rc; |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 397 | } |
| 398 | |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 399 | /* must be called with server->srv_mutex held */ |
| 400 | static int |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 401 | smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 402 | { |
| 403 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 404 | struct smb2_sync_hdr *shdr = |
| 405 | (struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base; |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 406 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 407 | if (!(shdr->Flags & SMB2_FLAGS_SIGNED) || |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 408 | server->tcpStatus == CifsNeedNegotiate) |
| 409 | return rc; |
| 410 | |
| 411 | if (!server->session_estab) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 412 | strncpy(shdr->Signature, "BSRSPYL", 8); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 413 | return rc; |
| 414 | } |
| 415 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 416 | rc = server->ops->calc_signature(rqst, server); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 417 | |
| 418 | return rc; |
| 419 | } |
| 420 | |
| 421 | int |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 422 | smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 423 | { |
| 424 | unsigned int rc; |
| 425 | char server_response_sig[16]; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 426 | struct smb2_sync_hdr *shdr = |
| 427 | (struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base; |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 428 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 429 | if ((shdr->Command == SMB2_NEGOTIATE) || |
| 430 | (shdr->Command == SMB2_SESSION_SETUP) || |
| 431 | (shdr->Command == SMB2_OPLOCK_BREAK) || |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 432 | (!server->session_estab)) |
| 433 | return 0; |
| 434 | |
| 435 | /* |
| 436 | * BB what if signatures are supposed to be on for session but |
| 437 | * server does not send one? BB |
| 438 | */ |
| 439 | |
| 440 | /* Do not need to verify session setups with signature "BSRSPYL " */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 441 | if (memcmp(shdr->Signature, "BSRSPYL ", 8) == 0) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 442 | cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n", |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 443 | shdr->Command); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * Save off the origiginal signature so we can modify the smb and check |
| 447 | * our calculated signature against what the server sent. |
| 448 | */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 449 | memcpy(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 450 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 451 | memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 452 | |
| 453 | mutex_lock(&server->srv_mutex); |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 454 | rc = server->ops->calc_signature(rqst, server); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 455 | mutex_unlock(&server->srv_mutex); |
| 456 | |
| 457 | if (rc) |
| 458 | return rc; |
| 459 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 460 | if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE)) |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 461 | return -EACCES; |
| 462 | else |
| 463 | return 0; |
| 464 | } |
| 465 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 466 | /* |
| 467 | * Set message id for the request. Should be called after wait_for_free_request |
| 468 | * and when srv_mutex is held. |
| 469 | */ |
| 470 | static inline void |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 471 | smb2_seq_num_into_buf(struct TCP_Server_Info *server, |
| 472 | struct smb2_sync_hdr *shdr) |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 473 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 474 | unsigned int i, num = le16_to_cpu(shdr->CreditCharge); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 475 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 476 | shdr->MessageId = get_next_mid64(server); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 477 | /* skip message numbers according to CreditCharge field */ |
| 478 | for (i = 1; i < num; i++) |
| 479 | get_next_mid(server); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static struct mid_q_entry * |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 483 | smb2_mid_entry_alloc(const struct smb2_sync_hdr *shdr, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 484 | struct TCP_Server_Info *server) |
| 485 | { |
| 486 | struct mid_q_entry *temp; |
| 487 | |
| 488 | if (server == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 489 | cifs_dbg(VFS, "Null TCP session in smb2_mid_entry_alloc\n"); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 490 | return NULL; |
| 491 | } |
| 492 | |
| 493 | temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS); |
| 494 | if (temp == NULL) |
| 495 | return temp; |
| 496 | else { |
| 497 | memset(temp, 0, sizeof(struct mid_q_entry)); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 498 | temp->mid = le64_to_cpu(shdr->MessageId); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 499 | temp->pid = current->pid; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 500 | temp->command = shdr->Command; /* Always LE */ |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 501 | temp->when_alloc = jiffies; |
| 502 | temp->server = server; |
| 503 | |
| 504 | /* |
| 505 | * The default is for the mid to be synchronous, so the |
| 506 | * default callback just wakes up the current task. |
| 507 | */ |
| 508 | temp->callback = cifs_wake_up_task; |
| 509 | temp->callback_data = current; |
| 510 | } |
| 511 | |
| 512 | atomic_inc(&midCount); |
| 513 | temp->mid_state = MID_REQUEST_ALLOCATED; |
| 514 | return temp; |
| 515 | } |
| 516 | |
| 517 | static int |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 518 | smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_sync_hdr *shdr, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 519 | struct mid_q_entry **mid) |
| 520 | { |
| 521 | if (ses->server->tcpStatus == CifsExiting) |
| 522 | return -ENOENT; |
| 523 | |
| 524 | if (ses->server->tcpStatus == CifsNeedReconnect) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 525 | cifs_dbg(FYI, "tcp session dead - return to caller to retry\n"); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 526 | return -EAGAIN; |
| 527 | } |
| 528 | |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 529 | if (ses->status == CifsNew) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 530 | if ((shdr->Command != SMB2_SESSION_SETUP) && |
| 531 | (shdr->Command != SMB2_NEGOTIATE)) |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 532 | return -EAGAIN; |
| 533 | /* else ok - we are setting up session */ |
| 534 | } |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 535 | |
| 536 | if (ses->status == CifsExiting) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 537 | if (shdr->Command != SMB2_LOGOFF) |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 538 | return -EAGAIN; |
| 539 | /* else ok - we are shutting down the session */ |
| 540 | } |
| 541 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 542 | *mid = smb2_mid_entry_alloc(shdr, ses->server); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 543 | if (*mid == NULL) |
| 544 | return -ENOMEM; |
| 545 | spin_lock(&GlobalMid_Lock); |
| 546 | list_add_tail(&(*mid)->qhead, &ses->server->pending_mid_q); |
| 547 | spin_unlock(&GlobalMid_Lock); |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | int |
| 552 | smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
| 553 | bool log_error) |
| 554 | { |
| 555 | unsigned int len = get_rfc1002_length(mid->resp_buf); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 556 | struct kvec iov[2]; |
| 557 | struct smb_rqst rqst = { .rq_iov = iov, |
| 558 | .rq_nvec = 2 }; |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 559 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 560 | iov[0].iov_base = (char *)mid->resp_buf; |
| 561 | iov[0].iov_len = 4; |
| 562 | iov[1].iov_base = (char *)mid->resp_buf + 4; |
| 563 | iov[1].iov_len = len; |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 564 | |
| 565 | dump_smb(mid->resp_buf, min_t(u32, 80, len)); |
| 566 | /* convert the length into a more usable form */ |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame^] | 567 | if (len > 24 && server->sign && !mid->decrypted) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 568 | int rc; |
| 569 | |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 570 | rc = smb2_verify_signature(&rqst, server); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 571 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 572 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 573 | rc); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 574 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 575 | |
| 576 | return map_smb2_to_linux_error(mid->resp_buf, log_error); |
| 577 | } |
| 578 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 579 | struct mid_q_entry * |
| 580 | smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 581 | { |
| 582 | int rc; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 583 | struct smb2_sync_hdr *shdr = |
| 584 | (struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base; |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 585 | struct mid_q_entry *mid; |
| 586 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 587 | smb2_seq_num_into_buf(ses->server, shdr); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 588 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 589 | rc = smb2_get_mid_entry(ses, shdr, &mid); |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 590 | if (rc) |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 591 | return ERR_PTR(rc); |
| 592 | rc = smb2_sign_rqst(rqst, ses->server); |
| 593 | if (rc) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 594 | cifs_delete_mid(mid); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 595 | return ERR_PTR(rc); |
| 596 | } |
| 597 | return mid; |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 598 | } |
| 599 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 600 | struct mid_q_entry * |
| 601 | smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 602 | { |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 603 | int rc; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 604 | struct smb2_sync_hdr *shdr = |
| 605 | (struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base; |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 606 | struct mid_q_entry *mid; |
| 607 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 608 | smb2_seq_num_into_buf(server, shdr); |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 609 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 610 | mid = smb2_mid_entry_alloc(shdr, server); |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 611 | if (mid == NULL) |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 612 | return ERR_PTR(-ENOMEM); |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 613 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 614 | rc = smb2_sign_rqst(rqst, server); |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 615 | if (rc) { |
| 616 | DeleteMidQEntry(mid); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 617 | return ERR_PTR(rc); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 620 | return mid; |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 621 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 622 | |
| 623 | int |
| 624 | smb3_crypto_aead_allocate(struct TCP_Server_Info *server) |
| 625 | { |
| 626 | struct crypto_aead *tfm; |
| 627 | |
| 628 | if (!server->secmech.ccmaesencrypt) { |
| 629 | tfm = crypto_alloc_aead("ccm(aes)", 0, 0); |
| 630 | if (IS_ERR(tfm)) { |
| 631 | cifs_dbg(VFS, "%s: Failed to alloc encrypt aead\n", |
| 632 | __func__); |
| 633 | return PTR_ERR(tfm); |
| 634 | } |
| 635 | server->secmech.ccmaesencrypt = tfm; |
| 636 | } |
| 637 | |
| 638 | if (!server->secmech.ccmaesdecrypt) { |
| 639 | tfm = crypto_alloc_aead("ccm(aes)", 0, 0); |
| 640 | if (IS_ERR(tfm)) { |
| 641 | crypto_free_aead(server->secmech.ccmaesencrypt); |
| 642 | server->secmech.ccmaesencrypt = NULL; |
| 643 | cifs_dbg(VFS, "%s: Failed to alloc decrypt aead\n", |
| 644 | __func__); |
| 645 | return PTR_ERR(tfm); |
| 646 | } |
| 647 | server->secmech.ccmaesdecrypt = tfm; |
| 648 | } |
| 649 | |
| 650 | return 0; |
| 651 | } |