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