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