Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/smb2pdu.c |
| 3 | * |
Steve French | 2b80d04 | 2013-06-23 18:43:37 -0500 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2009, 2013 |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 5 | * Etersoft, 2012 |
| 6 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 7 | * Pavel Shilovsky (pshilovsky@samba.org) 2012 |
| 8 | * |
| 9 | * Contains the routines for constructing the SMB2 PDUs themselves |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU Lesser General Public License as published |
| 13 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 19 | * the GNU Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Lesser General Public License |
| 22 | * along with this library; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | /* SMB2 PDU handling routines here - except for leftovers (eg session setup) */ |
| 27 | /* Note that there are handle based routines which must be */ |
| 28 | /* treated slightly differently for reconnection purposes since we never */ |
| 29 | /* want to reuse a stale file handle and only the caller knows the file info */ |
| 30 | |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/vfs.h> |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 34 | #include <linux/task_io_accounting_ops.h> |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
Andrew Lunn | c6e970a | 2017-03-28 23:45:06 +0200 | [diff] [blame] | 36 | #include <linux/uuid.h> |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 37 | #include <linux/pagemap.h> |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 38 | #include <linux/xattr.h> |
| 39 | #include "smb2pdu.h" |
| 40 | #include "cifsglob.h" |
| 41 | #include "cifsacl.h" |
| 42 | #include "cifsproto.h" |
| 43 | #include "smb2proto.h" |
| 44 | #include "cifs_unicode.h" |
| 45 | #include "cifs_debug.h" |
| 46 | #include "ntlmssp.h" |
| 47 | #include "smb2status.h" |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 48 | #include "smb2glob.h" |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 49 | #include "cifspdu.h" |
Steve French | ceb1b0b | 2015-09-24 00:52:37 -0500 | [diff] [blame] | 50 | #include "cifs_spnego.h" |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * The following table defines the expected "StructureSize" of SMB2 requests |
| 54 | * in order by SMB2 command. This is similar to "wct" in SMB/CIFS requests. |
| 55 | * |
| 56 | * Note that commands are defined in smb2pdu.h in le16 but the array below is |
| 57 | * indexed by command in host byte order. |
| 58 | */ |
| 59 | static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = { |
| 60 | /* SMB2_NEGOTIATE */ 36, |
| 61 | /* SMB2_SESSION_SETUP */ 25, |
| 62 | /* SMB2_LOGOFF */ 4, |
| 63 | /* SMB2_TREE_CONNECT */ 9, |
| 64 | /* SMB2_TREE_DISCONNECT */ 4, |
| 65 | /* SMB2_CREATE */ 57, |
| 66 | /* SMB2_CLOSE */ 24, |
| 67 | /* SMB2_FLUSH */ 24, |
| 68 | /* SMB2_READ */ 49, |
| 69 | /* SMB2_WRITE */ 49, |
| 70 | /* SMB2_LOCK */ 48, |
| 71 | /* SMB2_IOCTL */ 57, |
| 72 | /* SMB2_CANCEL */ 4, |
| 73 | /* SMB2_ECHO */ 4, |
| 74 | /* SMB2_QUERY_DIRECTORY */ 33, |
| 75 | /* SMB2_CHANGE_NOTIFY */ 32, |
| 76 | /* SMB2_QUERY_INFO */ 41, |
| 77 | /* SMB2_SET_INFO */ 33, |
| 78 | /* SMB2_OPLOCK_BREAK */ 24 /* BB this is 36 for LEASE_BREAK variant */ |
| 79 | }; |
| 80 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 81 | static int encryption_required(const struct cifs_tcon *tcon) |
| 82 | { |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 83 | if (!tcon) |
| 84 | return 0; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 85 | if ((tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) || |
| 86 | (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA)) |
| 87 | return 1; |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 88 | if (tcon->seal && |
| 89 | (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) |
| 90 | return 1; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 93 | |
| 94 | static void |
Pavel Shilovsky | cb200bd | 2016-10-24 16:59:57 -0700 | [diff] [blame] | 95 | smb2_hdr_assemble(struct smb2_sync_hdr *shdr, __le16 smb2_cmd, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 96 | const struct cifs_tcon *tcon) |
| 97 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 98 | shdr->ProtocolId = SMB2_PROTO_NUMBER; |
| 99 | shdr->StructureSize = cpu_to_le16(64); |
| 100 | shdr->Command = smb2_cmd; |
Ross Lagerwall | 7d414f3 | 2016-09-20 13:37:13 +0100 | [diff] [blame] | 101 | if (tcon && tcon->ses && tcon->ses->server) { |
| 102 | struct TCP_Server_Info *server = tcon->ses->server; |
| 103 | |
| 104 | spin_lock(&server->req_lock); |
| 105 | /* Request up to 2 credits but don't go over the limit. */ |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 106 | if (server->credits >= server->max_credits) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 107 | shdr->CreditRequest = cpu_to_le16(0); |
Ross Lagerwall | 7d414f3 | 2016-09-20 13:37:13 +0100 | [diff] [blame] | 108 | else |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 109 | shdr->CreditRequest = cpu_to_le16( |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 110 | min_t(int, server->max_credits - |
Ross Lagerwall | 7d414f3 | 2016-09-20 13:37:13 +0100 | [diff] [blame] | 111 | server->credits, 2)); |
| 112 | spin_unlock(&server->req_lock); |
| 113 | } else { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 114 | shdr->CreditRequest = cpu_to_le16(2); |
Ross Lagerwall | 7d414f3 | 2016-09-20 13:37:13 +0100 | [diff] [blame] | 115 | } |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 116 | shdr->ProcessId = cpu_to_le32((__u16)current->tgid); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 117 | |
| 118 | if (!tcon) |
| 119 | goto out; |
| 120 | |
Steve French | 2b80d04 | 2013-06-23 18:43:37 -0500 | [diff] [blame] | 121 | /* GLOBAL_CAP_LARGE_MTU will only be set if dialect > SMB2.02 */ |
| 122 | /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */ |
Steve French | 1dc92c4 | 2015-05-20 09:32:21 -0500 | [diff] [blame] | 123 | if ((tcon->ses) && (tcon->ses->server) && |
Steve French | 84ceeb9 | 2013-06-26 17:52:17 -0500 | [diff] [blame] | 124 | (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 125 | shdr->CreditCharge = cpu_to_le16(1); |
Steve French | 2b80d04 | 2013-06-23 18:43:37 -0500 | [diff] [blame] | 126 | /* else CreditCharge MBZ */ |
| 127 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 128 | shdr->TreeId = tcon->tid; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 129 | /* Uid is not converted */ |
| 130 | if (tcon->ses) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 131 | shdr->SessionId = tcon->ses->Suid; |
Steve French | f87ab88 | 2013-06-26 19:14:55 -0500 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have |
| 135 | * to pass the path on the Open SMB prefixed by \\server\share. |
| 136 | * Not sure when we would need to do the augmented path (if ever) and |
| 137 | * setting this flag breaks the SMB2 open operation since it is |
| 138 | * illegal to send an empty path name (without \\server\share prefix) |
| 139 | * when the DFS flag is set in the SMB open header. We could |
| 140 | * consider setting the flag on all operations other than open |
| 141 | * but it is safer to net set it for now. |
| 142 | */ |
| 143 | /* if (tcon->share_flags & SHI1005_FLAGS_DFS) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 144 | shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */ |
Steve French | f87ab88 | 2013-06-26 19:14:55 -0500 | [diff] [blame] | 145 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 146 | if (tcon->ses && tcon->ses->server && tcon->ses->server->sign && |
| 147 | !encryption_required(tcon)) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 148 | shdr->Flags |= SMB2_FLAGS_SIGNED; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 149 | out: |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 150 | return; |
| 151 | } |
| 152 | |
| 153 | static int |
| 154 | smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) |
| 155 | { |
| 156 | int rc = 0; |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 157 | struct nls_table *nls_codepage; |
| 158 | struct cifs_ses *ses; |
| 159 | struct TCP_Server_Info *server; |
| 160 | |
| 161 | /* |
| 162 | * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so |
| 163 | * check for tcp and smb session status done differently |
| 164 | * for those three - in the calling routine. |
| 165 | */ |
| 166 | if (tcon == NULL) |
| 167 | return rc; |
| 168 | |
| 169 | if (smb2_command == SMB2_TREE_CONNECT) |
| 170 | return rc; |
| 171 | |
| 172 | if (tcon->tidStatus == CifsExiting) { |
| 173 | /* |
| 174 | * only tree disconnect, open, and write, |
| 175 | * (and ulogoff which does not have tcon) |
| 176 | * are allowed as we start force umount. |
| 177 | */ |
| 178 | if ((smb2_command != SMB2_WRITE) && |
| 179 | (smb2_command != SMB2_CREATE) && |
| 180 | (smb2_command != SMB2_TREE_DISCONNECT)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 181 | cifs_dbg(FYI, "can not send cmd %d while umounting\n", |
| 182 | smb2_command); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 183 | return -ENODEV; |
| 184 | } |
| 185 | } |
| 186 | if ((!tcon->ses) || (tcon->ses->status == CifsExiting) || |
| 187 | (!tcon->ses->server)) |
| 188 | return -EIO; |
| 189 | |
| 190 | ses = tcon->ses; |
| 191 | server = ses->server; |
| 192 | |
| 193 | /* |
| 194 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 195 | * greater than cifs socket timeout which is 7 seconds |
| 196 | */ |
| 197 | while (server->tcpStatus == CifsNeedReconnect) { |
| 198 | /* |
| 199 | * Return to caller for TREE_DISCONNECT and LOGOFF and CLOSE |
| 200 | * here since they are implicitly done when session drops. |
| 201 | */ |
| 202 | switch (smb2_command) { |
| 203 | /* |
| 204 | * BB Should we keep oplock break and add flush to exceptions? |
| 205 | */ |
| 206 | case SMB2_TREE_DISCONNECT: |
| 207 | case SMB2_CANCEL: |
| 208 | case SMB2_CLOSE: |
| 209 | case SMB2_OPLOCK_BREAK: |
| 210 | return -EAGAIN; |
| 211 | } |
| 212 | |
| 213 | wait_event_interruptible_timeout(server->response_q, |
| 214 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
| 215 | |
| 216 | /* are we still trying to reconnect? */ |
| 217 | if (server->tcpStatus != CifsNeedReconnect) |
| 218 | break; |
| 219 | |
| 220 | /* |
| 221 | * on "soft" mounts we wait once. Hard mounts keep |
| 222 | * retrying until process is killed or server comes |
| 223 | * back on-line |
| 224 | */ |
| 225 | if (!tcon->retry) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 226 | cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n"); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 227 | return -EHOSTDOWN; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (!tcon->ses->need_reconnect && !tcon->need_reconnect) |
| 232 | return rc; |
| 233 | |
| 234 | nls_codepage = load_nls_default(); |
| 235 | |
| 236 | /* |
| 237 | * need to prevent multiple threads trying to simultaneously reconnect |
| 238 | * the same SMB session |
| 239 | */ |
| 240 | mutex_lock(&tcon->ses->session_mutex); |
| 241 | rc = cifs_negotiate_protocol(0, tcon->ses); |
| 242 | if (!rc && tcon->ses->need_reconnect) |
| 243 | rc = cifs_setup_session(0, tcon->ses, nls_codepage); |
| 244 | |
| 245 | if (rc || !tcon->need_reconnect) { |
| 246 | mutex_unlock(&tcon->ses->session_mutex); |
| 247 | goto out; |
| 248 | } |
| 249 | |
| 250 | cifs_mark_open_files_invalid(tcon); |
Pavel Shilovsky | 96a988f | 2016-11-29 11:31:23 -0800 | [diff] [blame] | 251 | if (tcon->use_persistent) |
| 252 | tcon->need_reopen_files = true; |
Steve French | 52ace1e | 2016-09-22 19:23:56 -0500 | [diff] [blame] | 253 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 254 | rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage); |
| 255 | mutex_unlock(&tcon->ses->session_mutex); |
Steve French | 52ace1e | 2016-09-22 19:23:56 -0500 | [diff] [blame] | 256 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 257 | cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 258 | if (rc) |
| 259 | goto out; |
Pavel Shilovsky | 96a988f | 2016-11-29 11:31:23 -0800 | [diff] [blame] | 260 | |
| 261 | if (smb2_command != SMB2_INTERNAL_CMD) |
| 262 | queue_delayed_work(cifsiod_wq, &server->reconnect, 0); |
| 263 | |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 264 | atomic_inc(&tconInfoReconnectCount); |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 265 | out: |
| 266 | /* |
| 267 | * Check if handle based operation so we know whether we can continue |
| 268 | * or not without returning to caller to reset file handle. |
| 269 | */ |
| 270 | /* |
| 271 | * BB Is flush done by server on drop of tcp session? Should we special |
| 272 | * case it and skip above? |
| 273 | */ |
| 274 | switch (smb2_command) { |
| 275 | case SMB2_FLUSH: |
| 276 | case SMB2_READ: |
| 277 | case SMB2_WRITE: |
| 278 | case SMB2_LOCK: |
| 279 | case SMB2_IOCTL: |
| 280 | case SMB2_QUERY_DIRECTORY: |
| 281 | case SMB2_CHANGE_NOTIFY: |
| 282 | case SMB2_QUERY_INFO: |
| 283 | case SMB2_SET_INFO: |
Pavel Shilovsky | 4772c79 | 2016-11-29 11:30:58 -0800 | [diff] [blame] | 284 | rc = -EAGAIN; |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 285 | } |
| 286 | unload_nls(nls_codepage); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 287 | return rc; |
| 288 | } |
| 289 | |
Pavel Shilovsky | cb200bd | 2016-10-24 16:59:57 -0700 | [diff] [blame] | 290 | static void |
| 291 | fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, void *buf, |
| 292 | unsigned int *total_len) |
| 293 | { |
| 294 | struct smb2_sync_pdu *spdu = (struct smb2_sync_pdu *)buf; |
| 295 | /* lookup word count ie StructureSize from table */ |
| 296 | __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_command)]; |
| 297 | |
| 298 | /* |
| 299 | * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of |
| 300 | * largest operations (Create) |
| 301 | */ |
| 302 | memset(buf, 0, 256); |
| 303 | |
| 304 | smb2_hdr_assemble(&spdu->sync_hdr, smb2_command, tcon); |
| 305 | spdu->StructureSize2 = cpu_to_le16(parmsize); |
| 306 | |
| 307 | *total_len = parmsize + sizeof(struct smb2_sync_hdr); |
| 308 | } |
| 309 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 310 | /* init request without RFC1001 length at the beginning */ |
| 311 | static int |
| 312 | smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, |
| 313 | void **request_buf, unsigned int *total_len) |
| 314 | { |
| 315 | int rc; |
| 316 | struct smb2_sync_hdr *shdr; |
| 317 | |
| 318 | rc = smb2_reconnect(smb2_command, tcon); |
| 319 | if (rc) |
| 320 | return rc; |
| 321 | |
| 322 | /* BB eventually switch this to SMB2 specific small buf size */ |
| 323 | *request_buf = cifs_small_buf_get(); |
| 324 | if (*request_buf == NULL) { |
| 325 | /* BB should we add a retry in here if not a writepage? */ |
| 326 | return -ENOMEM; |
| 327 | } |
| 328 | |
| 329 | shdr = (struct smb2_sync_hdr *)(*request_buf); |
| 330 | |
| 331 | fill_small_buf(smb2_command, tcon, shdr, total_len); |
| 332 | |
| 333 | if (tcon != NULL) { |
| 334 | #ifdef CONFIG_CIFS_STATS2 |
| 335 | uint16_t com_code = le16_to_cpu(smb2_command); |
| 336 | |
| 337 | cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]); |
| 338 | #endif |
| 339 | cifs_stats_inc(&tcon->num_smbs_sent); |
| 340 | } |
| 341 | |
| 342 | return rc; |
| 343 | } |
| 344 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 345 | /* |
| 346 | * Allocate and return pointer to an SMB request hdr, and set basic |
| 347 | * SMB information in the SMB header. If the return code is zero, this |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 348 | * function must have filled in request_buf pointer. The returned buffer |
| 349 | * has RFC1001 length at the beginning. |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 350 | */ |
| 351 | static int |
| 352 | small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, |
| 353 | void **request_buf) |
| 354 | { |
Pavel Shilovsky | cb200bd | 2016-10-24 16:59:57 -0700 | [diff] [blame] | 355 | int rc; |
| 356 | unsigned int total_len; |
| 357 | struct smb2_pdu *pdu; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 358 | |
| 359 | rc = smb2_reconnect(smb2_command, tcon); |
| 360 | if (rc) |
| 361 | return rc; |
| 362 | |
| 363 | /* BB eventually switch this to SMB2 specific small buf size */ |
| 364 | *request_buf = cifs_small_buf_get(); |
| 365 | if (*request_buf == NULL) { |
| 366 | /* BB should we add a retry in here if not a writepage? */ |
| 367 | return -ENOMEM; |
| 368 | } |
| 369 | |
Pavel Shilovsky | cb200bd | 2016-10-24 16:59:57 -0700 | [diff] [blame] | 370 | pdu = (struct smb2_pdu *)(*request_buf); |
| 371 | |
| 372 | fill_small_buf(smb2_command, tcon, get_sync_hdr(pdu), &total_len); |
| 373 | |
| 374 | /* Note this is only network field converted to big endian */ |
| 375 | pdu->hdr.smb2_buf_length = cpu_to_be32(total_len); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 376 | |
| 377 | if (tcon != NULL) { |
| 378 | #ifdef CONFIG_CIFS_STATS2 |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 379 | uint16_t com_code = le16_to_cpu(smb2_command); |
| 380 | cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 381 | #endif |
| 382 | cifs_stats_inc(&tcon->num_smbs_sent); |
| 383 | } |
| 384 | |
| 385 | return rc; |
| 386 | } |
| 387 | |
Steve French | ebb3a9d | 2015-06-18 04:49:47 -0500 | [diff] [blame] | 388 | #ifdef CONFIG_CIFS_SMB311 |
| 389 | /* offset is sizeof smb2_negotiate_req - 4 but rounded up to 8 bytes */ |
| 390 | #define OFFSET_OF_NEG_CONTEXT 0x68 /* sizeof(struct smb2_negotiate_req) - 4 */ |
| 391 | |
| 392 | |
| 393 | #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1) |
| 394 | #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2) |
| 395 | |
| 396 | static void |
| 397 | build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt) |
| 398 | { |
| 399 | pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES; |
| 400 | pneg_ctxt->DataLength = cpu_to_le16(38); |
| 401 | pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1); |
| 402 | pneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE); |
| 403 | get_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE); |
| 404 | pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512; |
| 405 | } |
| 406 | |
| 407 | static void |
| 408 | build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt) |
| 409 | { |
| 410 | pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES; |
| 411 | pneg_ctxt->DataLength = cpu_to_le16(6); |
| 412 | pneg_ctxt->CipherCount = cpu_to_le16(2); |
| 413 | pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; |
| 414 | pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM; |
| 415 | } |
| 416 | |
| 417 | static void |
| 418 | assemble_neg_contexts(struct smb2_negotiate_req *req) |
| 419 | { |
| 420 | |
| 421 | /* +4 is to account for the RFC1001 len field */ |
| 422 | char *pneg_ctxt = (char *)req + OFFSET_OF_NEG_CONTEXT + 4; |
| 423 | |
| 424 | build_preauth_ctxt((struct smb2_preauth_neg_context *)pneg_ctxt); |
| 425 | /* Add 2 to size to round to 8 byte boundary */ |
| 426 | pneg_ctxt += 2 + sizeof(struct smb2_preauth_neg_context); |
| 427 | build_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt); |
| 428 | req->NegotiateContextOffset = cpu_to_le32(OFFSET_OF_NEG_CONTEXT); |
| 429 | req->NegotiateContextCount = cpu_to_le16(2); |
| 430 | inc_rfc1001_len(req, 4 + sizeof(struct smb2_preauth_neg_context) + 2 |
| 431 | + sizeof(struct smb2_encryption_neg_context)); /* calculate hash */ |
| 432 | } |
| 433 | #else |
| 434 | static void assemble_neg_contexts(struct smb2_negotiate_req *req) |
| 435 | { |
| 436 | return; |
| 437 | } |
| 438 | #endif /* SMB311 */ |
| 439 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 440 | /* |
| 441 | * |
| 442 | * SMB2 Worker functions follow: |
| 443 | * |
| 444 | * The general structure of the worker functions is: |
| 445 | * 1) Call smb2_init (assembles SMB2 header) |
| 446 | * 2) Initialize SMB2 command specific fields in fixed length area of SMB |
| 447 | * 3) Call smb_sendrcv2 (sends request on socket and waits for response) |
| 448 | * 4) Decode SMB2 command specific fields in the fixed length area |
| 449 | * 5) Decode variable length data area (if any for this SMB2 command type) |
| 450 | * 6) Call free smb buffer |
| 451 | * 7) return |
| 452 | * |
| 453 | */ |
| 454 | |
| 455 | int |
| 456 | SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 457 | { |
| 458 | struct smb2_negotiate_req *req; |
| 459 | struct smb2_negotiate_rsp *rsp; |
| 460 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 461 | struct kvec rsp_iov; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 462 | int rc = 0; |
| 463 | int resp_buftype; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 464 | struct TCP_Server_Info *server = ses->server; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 465 | int blob_offset, blob_length; |
| 466 | char *security_blob; |
| 467 | int flags = CIFS_NEG_OP; |
| 468 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 469 | cifs_dbg(FYI, "Negotiate protocol\n"); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 470 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 471 | if (!server) { |
| 472 | WARN(1, "%s: server is NULL!\n", __func__); |
| 473 | return -EIO; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | rc = small_smb2_init(SMB2_NEGOTIATE, NULL, (void **) &req); |
| 477 | if (rc) |
| 478 | return rc; |
| 479 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 480 | req->hdr.sync_hdr.SessionId = 0; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 481 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 482 | req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 483 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 484 | req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */ |
| 485 | inc_rfc1001_len(req, 2); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 486 | |
| 487 | /* only one of SMB2 signing flags may be set in SMB2 request */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 488 | if (ses->sign) |
Steve French | 9cd2e62 | 2013-06-12 19:59:03 -0500 | [diff] [blame] | 489 | req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 490 | else if (global_secflags & CIFSSEC_MAY_SIGN) |
Steve French | 9cd2e62 | 2013-06-12 19:59:03 -0500 | [diff] [blame] | 491 | req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 492 | else |
| 493 | req->SecurityMode = 0; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 494 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 495 | req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 496 | |
Steve French | 3c5f9be1 | 2014-05-13 13:37:45 -0700 | [diff] [blame] | 497 | /* ClientGUID must be zero for SMB2.02 dialect */ |
| 498 | if (ses->server->vals->protocol_id == SMB20_PROT_ID) |
| 499 | memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE); |
Steve French | ebb3a9d | 2015-06-18 04:49:47 -0500 | [diff] [blame] | 500 | else { |
Steve French | 3c5f9be1 | 2014-05-13 13:37:45 -0700 | [diff] [blame] | 501 | memcpy(req->ClientGUID, server->client_guid, |
| 502 | SMB2_CLIENT_GUID_SIZE); |
Steve French | ebb3a9d | 2015-06-18 04:49:47 -0500 | [diff] [blame] | 503 | if (ses->server->vals->protocol_id == SMB311_PROT_ID) |
| 504 | assemble_neg_contexts(req); |
| 505 | } |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 506 | iov[0].iov_base = (char *)req; |
| 507 | /* 4 for rfc1002 length field */ |
| 508 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 509 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 510 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov); |
| 511 | cifs_small_buf_release(req); |
| 512 | rsp = (struct smb2_negotiate_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 513 | /* |
| 514 | * No tcon so can't do |
| 515 | * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); |
| 516 | */ |
| 517 | if (rc != 0) |
| 518 | goto neg_exit; |
| 519 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 520 | cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 521 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 522 | /* BB we may eventually want to match the negotiated vs. requested |
| 523 | dialect, even though we are only requesting one at a time */ |
| 524 | if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 525 | cifs_dbg(FYI, "negotiated smb2.0 dialect\n"); |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 526 | else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 527 | cifs_dbg(FYI, "negotiated smb2.1 dialect\n"); |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 528 | else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 529 | cifs_dbg(FYI, "negotiated smb3.0 dialect\n"); |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 530 | else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID)) |
| 531 | cifs_dbg(FYI, "negotiated smb3.02 dialect\n"); |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 532 | #ifdef CONFIG_CIFS_SMB311 |
| 533 | else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) |
| 534 | cifs_dbg(FYI, "negotiated smb3.1.1 dialect\n"); |
| 535 | #endif /* SMB311 */ |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 536 | else { |
Steve French | f799d62 | 2015-06-18 05:07:52 -0500 | [diff] [blame] | 537 | cifs_dbg(VFS, "Illegal dialect returned by server 0x%x\n", |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 538 | le16_to_cpu(rsp->DialectRevision)); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 539 | rc = -EIO; |
| 540 | goto neg_exit; |
| 541 | } |
| 542 | server->dialect = le16_to_cpu(rsp->DialectRevision); |
| 543 | |
Jeff Layton | e598d1d8 | 2013-05-26 07:00:59 -0400 | [diff] [blame] | 544 | /* SMB2 only has an extended negflavor */ |
| 545 | server->negflavor = CIFS_NEGFLAVOR_EXTENDED; |
Pavel Shilovsky | 2365c4e | 2014-02-14 13:31:02 +0400 | [diff] [blame] | 546 | /* set it to the maximum buffer size value we can send with 1 credit */ |
| 547 | server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize), |
| 548 | SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 549 | server->max_read = le32_to_cpu(rsp->MaxReadSize); |
| 550 | server->max_write = le32_to_cpu(rsp->MaxWriteSize); |
| 551 | /* BB Do we need to validate the SecurityMode? */ |
| 552 | server->sec_mode = le16_to_cpu(rsp->SecurityMode); |
| 553 | server->capabilities = le32_to_cpu(rsp->Capabilities); |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 554 | /* Internal types */ |
| 555 | server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 556 | |
| 557 | security_blob = smb2_get_data_area_len(&blob_offset, &blob_length, |
| 558 | &rsp->hdr); |
Steve French | 5d875cc | 2013-06-25 15:33:41 -0500 | [diff] [blame] | 559 | /* |
| 560 | * See MS-SMB2 section 2.2.4: if no blob, client picks default which |
| 561 | * for us will be |
| 562 | * ses->sectype = RawNTLMSSP; |
| 563 | * but for time being this is our only auth choice so doesn't matter. |
| 564 | * We just found a server which sets blob length to zero expecting raw. |
| 565 | */ |
Pavel Shilovsky | 67dbea2 | 2017-04-12 13:32:07 -0700 | [diff] [blame] | 566 | if (blob_length == 0) { |
Steve French | 5d875cc | 2013-06-25 15:33:41 -0500 | [diff] [blame] | 567 | cifs_dbg(FYI, "missing security blob on negprot\n"); |
Pavel Shilovsky | 67dbea2 | 2017-04-12 13:32:07 -0700 | [diff] [blame] | 568 | server->sec_ntlmssp = true; |
| 569 | } |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 570 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 571 | rc = cifs_enable_signing(server, ses->sign); |
Jeff Layton | 9ddec56 | 2013-05-26 07:00:58 -0400 | [diff] [blame] | 572 | if (rc) |
| 573 | goto neg_exit; |
Steve French | ceb1b0b | 2015-09-24 00:52:37 -0500 | [diff] [blame] | 574 | if (blob_length) { |
Steve French | ebdd207 | 2014-10-20 12:48:23 -0500 | [diff] [blame] | 575 | rc = decode_negTokenInit(security_blob, blob_length, server); |
Steve French | ceb1b0b | 2015-09-24 00:52:37 -0500 | [diff] [blame] | 576 | if (rc == 1) |
| 577 | rc = 0; |
| 578 | else if (rc == 0) |
| 579 | rc = -EIO; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 580 | } |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 581 | neg_exit: |
| 582 | free_rsp_buf(resp_buftype, rsp); |
| 583 | return rc; |
| 584 | } |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 585 | |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 586 | int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) |
| 587 | { |
| 588 | int rc = 0; |
| 589 | struct validate_negotiate_info_req vneg_inbuf; |
| 590 | struct validate_negotiate_info_rsp *pneg_rsp; |
| 591 | u32 rsplen; |
| 592 | |
| 593 | cifs_dbg(FYI, "validate negotiate\n"); |
| 594 | |
| 595 | /* |
| 596 | * validation ioctl must be signed, so no point sending this if we |
| 597 | * can not sign it. We could eventually change this to selectively |
| 598 | * sign just this, the first and only signed request on a connection. |
| 599 | * This is good enough for now since a user who wants better security |
| 600 | * would also enable signing on the mount. Having validation of |
| 601 | * negotiate info for signed connections helps reduce attack vectors |
| 602 | */ |
| 603 | if (tcon->ses->server->sign == false) |
| 604 | return 0; /* validation requires signing */ |
| 605 | |
| 606 | vneg_inbuf.Capabilities = |
| 607 | cpu_to_le32(tcon->ses->server->vals->req_capabilities); |
Sachin Prabhu | 39552ea | 2014-05-13 00:48:12 +0100 | [diff] [blame] | 608 | memcpy(vneg_inbuf.Guid, tcon->ses->server->client_guid, |
| 609 | SMB2_CLIENT_GUID_SIZE); |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 610 | |
| 611 | if (tcon->ses->sign) |
| 612 | vneg_inbuf.SecurityMode = |
| 613 | cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); |
| 614 | else if (global_secflags & CIFSSEC_MAY_SIGN) |
| 615 | vneg_inbuf.SecurityMode = |
| 616 | cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); |
| 617 | else |
| 618 | vneg_inbuf.SecurityMode = 0; |
| 619 | |
| 620 | vneg_inbuf.DialectCount = cpu_to_le16(1); |
| 621 | vneg_inbuf.Dialects[0] = |
| 622 | cpu_to_le16(tcon->ses->server->vals->protocol_id); |
| 623 | |
| 624 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 625 | FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 626 | false /* use_ipc */, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 627 | (char *)&vneg_inbuf, sizeof(struct validate_negotiate_info_req), |
| 628 | (char **)&pneg_rsp, &rsplen); |
| 629 | |
| 630 | if (rc != 0) { |
| 631 | cifs_dbg(VFS, "validate protocol negotiate failed: %d\n", rc); |
| 632 | return -EIO; |
| 633 | } |
| 634 | |
| 635 | if (rsplen != sizeof(struct validate_negotiate_info_rsp)) { |
Steve French | 7db0a6e | 2017-05-03 21:12:20 -0500 | [diff] [blame] | 636 | cifs_dbg(VFS, "invalid protocol negotiate response size: %d\n", |
| 637 | rsplen); |
| 638 | |
| 639 | /* relax check since Mac returns max bufsize allowed on ioctl */ |
| 640 | if (rsplen > CIFSMaxBufSize) |
| 641 | return -EIO; |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* check validate negotiate info response matches what we got earlier */ |
| 645 | if (pneg_rsp->Dialect != |
| 646 | cpu_to_le16(tcon->ses->server->vals->protocol_id)) |
| 647 | goto vneg_out; |
| 648 | |
| 649 | if (pneg_rsp->SecurityMode != cpu_to_le16(tcon->ses->server->sec_mode)) |
| 650 | goto vneg_out; |
| 651 | |
| 652 | /* do not validate server guid because not saved at negprot time yet */ |
| 653 | |
| 654 | if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND | |
| 655 | SMB2_LARGE_FILES) != tcon->ses->server->capabilities) |
| 656 | goto vneg_out; |
| 657 | |
| 658 | /* validate negotiate successful */ |
| 659 | cifs_dbg(FYI, "validate negotiate info successful\n"); |
| 660 | return 0; |
| 661 | |
| 662 | vneg_out: |
| 663 | cifs_dbg(VFS, "protocol revalidation - security settings mismatch\n"); |
| 664 | return -EIO; |
| 665 | } |
| 666 | |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 667 | enum securityEnum |
| 668 | smb2_select_sectype(struct TCP_Server_Info *server, enum securityEnum requested) |
| 669 | { |
| 670 | switch (requested) { |
| 671 | case Kerberos: |
| 672 | case RawNTLMSSP: |
| 673 | return requested; |
| 674 | case NTLMv2: |
| 675 | return RawNTLMSSP; |
| 676 | case Unspecified: |
| 677 | if (server->sec_ntlmssp && |
| 678 | (global_secflags & CIFSSEC_MAY_NTLMSSP)) |
| 679 | return RawNTLMSSP; |
| 680 | if ((server->sec_kerberos || server->sec_mskerberos) && |
| 681 | (global_secflags & CIFSSEC_MAY_KRB5)) |
| 682 | return Kerberos; |
| 683 | /* Fallthrough */ |
| 684 | default: |
| 685 | return Unspecified; |
| 686 | } |
| 687 | } |
| 688 | |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 689 | struct SMB2_sess_data { |
| 690 | unsigned int xid; |
| 691 | struct cifs_ses *ses; |
| 692 | struct nls_table *nls_cp; |
| 693 | void (*func)(struct SMB2_sess_data *); |
| 694 | int result; |
| 695 | u64 previous_session; |
| 696 | |
| 697 | /* we will send the SMB in three pieces: |
| 698 | * a fixed length beginning part, an optional |
| 699 | * SPNEGO blob (which can be zero length), and a |
| 700 | * last part which will include the strings |
| 701 | * and rest of bcc area. This allows us to avoid |
| 702 | * a large buffer 17K allocation |
| 703 | */ |
| 704 | int buf0_type; |
| 705 | struct kvec iov[2]; |
| 706 | }; |
| 707 | |
| 708 | static int |
| 709 | SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data) |
| 710 | { |
| 711 | int rc; |
| 712 | struct cifs_ses *ses = sess_data->ses; |
| 713 | struct smb2_sess_setup_req *req; |
| 714 | struct TCP_Server_Info *server = ses->server; |
| 715 | |
| 716 | rc = small_smb2_init(SMB2_SESSION_SETUP, NULL, (void **) &req); |
| 717 | if (rc) |
| 718 | return rc; |
| 719 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 720 | /* First session, not a reauthenticate */ |
| 721 | req->hdr.sync_hdr.SessionId = 0; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 722 | |
| 723 | /* if reconnect, we need to send previous sess id, otherwise it is 0 */ |
| 724 | req->PreviousSessionId = sess_data->previous_session; |
| 725 | |
| 726 | req->Flags = 0; /* MBZ */ |
| 727 | /* to enable echos and oplocks */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 728 | req->hdr.sync_hdr.CreditRequest = cpu_to_le16(3); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 729 | |
| 730 | /* only one of SMB2 signing flags may be set in SMB2 request */ |
| 731 | if (server->sign) |
| 732 | req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED; |
| 733 | else if (global_secflags & CIFSSEC_MAY_SIGN) /* one flag unlike MUST_ */ |
| 734 | req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED; |
| 735 | else |
| 736 | req->SecurityMode = 0; |
| 737 | |
| 738 | req->Capabilities = 0; |
| 739 | req->Channel = 0; /* MBZ */ |
| 740 | |
| 741 | sess_data->iov[0].iov_base = (char *)req; |
| 742 | /* 4 for rfc1002 length field and 1 for pad */ |
| 743 | sess_data->iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; |
| 744 | /* |
| 745 | * This variable will be used to clear the buffer |
| 746 | * allocated above in case of any error in the calling function. |
| 747 | */ |
| 748 | sess_data->buf0_type = CIFS_SMALL_BUFFER; |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static void |
| 754 | SMB2_sess_free_buffer(struct SMB2_sess_data *sess_data) |
| 755 | { |
| 756 | free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base); |
| 757 | sess_data->buf0_type = CIFS_NO_BUFFER; |
| 758 | } |
| 759 | |
| 760 | static int |
| 761 | SMB2_sess_sendreceive(struct SMB2_sess_data *sess_data) |
| 762 | { |
| 763 | int rc; |
| 764 | struct smb2_sess_setup_req *req = sess_data->iov[0].iov_base; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 765 | struct kvec rsp_iov = { NULL, 0 }; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 766 | |
| 767 | /* Testing shows that buffer offset must be at location of Buffer[0] */ |
| 768 | req->SecurityBufferOffset = |
| 769 | cpu_to_le16(sizeof(struct smb2_sess_setup_req) - |
| 770 | 1 /* pad */ - 4 /* rfc1001 len */); |
| 771 | req->SecurityBufferLength = cpu_to_le16(sess_data->iov[1].iov_len); |
| 772 | |
| 773 | inc_rfc1001_len(req, sess_data->iov[1].iov_len - 1 /* pad */); |
| 774 | |
| 775 | /* BB add code to build os and lm fields */ |
| 776 | |
| 777 | rc = SendReceive2(sess_data->xid, sess_data->ses, |
| 778 | sess_data->iov, 2, |
| 779 | &sess_data->buf0_type, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 780 | CIFS_LOG_ERROR | CIFS_NEG_OP, &rsp_iov); |
| 781 | cifs_small_buf_release(sess_data->iov[0].iov_base); |
| 782 | memcpy(&sess_data->iov[0], &rsp_iov, sizeof(struct kvec)); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 783 | |
| 784 | return rc; |
| 785 | } |
| 786 | |
| 787 | static int |
| 788 | SMB2_sess_establish_session(struct SMB2_sess_data *sess_data) |
| 789 | { |
| 790 | int rc = 0; |
| 791 | struct cifs_ses *ses = sess_data->ses; |
| 792 | |
| 793 | mutex_lock(&ses->server->srv_mutex); |
Pavel Shilovsky | cabfb36 | 2016-11-07 18:20:50 -0800 | [diff] [blame] | 794 | if (ses->server->ops->generate_signingkey) { |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 795 | rc = ses->server->ops->generate_signingkey(ses); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 796 | if (rc) { |
| 797 | cifs_dbg(FYI, |
| 798 | "SMB3 session key generation failed\n"); |
| 799 | mutex_unlock(&ses->server->srv_mutex); |
Pavel Shilovsky | cabfb36 | 2016-11-07 18:20:50 -0800 | [diff] [blame] | 800 | return rc; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | if (!ses->server->session_estab) { |
| 804 | ses->server->sequence_number = 0x2; |
| 805 | ses->server->session_estab = true; |
| 806 | } |
| 807 | mutex_unlock(&ses->server->srv_mutex); |
| 808 | |
| 809 | cifs_dbg(FYI, "SMB2/3 session established successfully\n"); |
| 810 | spin_lock(&GlobalMid_Lock); |
| 811 | ses->status = CifsGood; |
| 812 | ses->need_reconnect = false; |
| 813 | spin_unlock(&GlobalMid_Lock); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 814 | return rc; |
| 815 | } |
| 816 | |
| 817 | #ifdef CONFIG_CIFS_UPCALL |
| 818 | static void |
| 819 | SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) |
| 820 | { |
| 821 | int rc; |
| 822 | struct cifs_ses *ses = sess_data->ses; |
| 823 | struct cifs_spnego_msg *msg; |
| 824 | struct key *spnego_key = NULL; |
| 825 | struct smb2_sess_setup_rsp *rsp = NULL; |
| 826 | |
| 827 | rc = SMB2_sess_alloc_buffer(sess_data); |
| 828 | if (rc) |
| 829 | goto out; |
| 830 | |
| 831 | spnego_key = cifs_get_spnego_key(ses); |
| 832 | if (IS_ERR(spnego_key)) { |
| 833 | rc = PTR_ERR(spnego_key); |
| 834 | spnego_key = NULL; |
| 835 | goto out; |
| 836 | } |
| 837 | |
| 838 | msg = spnego_key->payload.data[0]; |
| 839 | /* |
| 840 | * check version field to make sure that cifs.upcall is |
| 841 | * sending us a response in an expected form |
| 842 | */ |
| 843 | if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { |
| 844 | cifs_dbg(VFS, |
| 845 | "bad cifs.upcall version. Expected %d got %d", |
| 846 | CIFS_SPNEGO_UPCALL_VERSION, msg->version); |
| 847 | rc = -EKEYREJECTED; |
| 848 | goto out_put_spnego_key; |
| 849 | } |
| 850 | |
| 851 | ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, |
| 852 | GFP_KERNEL); |
| 853 | if (!ses->auth_key.response) { |
| 854 | cifs_dbg(VFS, |
| 855 | "Kerberos can't allocate (%u bytes) memory", |
| 856 | msg->sesskey_len); |
| 857 | rc = -ENOMEM; |
| 858 | goto out_put_spnego_key; |
| 859 | } |
| 860 | ses->auth_key.len = msg->sesskey_len; |
| 861 | |
| 862 | sess_data->iov[1].iov_base = msg->data + msg->sesskey_len; |
| 863 | sess_data->iov[1].iov_len = msg->secblob_len; |
| 864 | |
| 865 | rc = SMB2_sess_sendreceive(sess_data); |
| 866 | if (rc) |
| 867 | goto out_put_spnego_key; |
| 868 | |
| 869 | rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 870 | ses->Suid = rsp->hdr.sync_hdr.SessionId; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 871 | |
| 872 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 873 | |
| 874 | rc = SMB2_sess_establish_session(sess_data); |
| 875 | out_put_spnego_key: |
| 876 | key_invalidate(spnego_key); |
| 877 | key_put(spnego_key); |
| 878 | out: |
| 879 | sess_data->result = rc; |
| 880 | sess_data->func = NULL; |
| 881 | SMB2_sess_free_buffer(sess_data); |
| 882 | } |
| 883 | #else |
| 884 | static void |
| 885 | SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) |
| 886 | { |
| 887 | cifs_dbg(VFS, "Kerberos negotiated but upcall support disabled!\n"); |
| 888 | sess_data->result = -EOPNOTSUPP; |
| 889 | sess_data->func = NULL; |
| 890 | } |
| 891 | #endif |
| 892 | |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 893 | static void |
| 894 | SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data); |
| 895 | |
| 896 | static void |
| 897 | SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data) |
| 898 | { |
| 899 | int rc; |
| 900 | struct cifs_ses *ses = sess_data->ses; |
| 901 | struct smb2_sess_setup_rsp *rsp = NULL; |
| 902 | char *ntlmssp_blob = NULL; |
| 903 | bool use_spnego = false; /* else use raw ntlmssp */ |
| 904 | u16 blob_length = 0; |
| 905 | |
| 906 | /* |
| 907 | * If memory allocation is successful, caller of this function |
| 908 | * frees it. |
| 909 | */ |
| 910 | ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL); |
| 911 | if (!ses->ntlmssp) { |
| 912 | rc = -ENOMEM; |
| 913 | goto out_err; |
| 914 | } |
| 915 | ses->ntlmssp->sesskey_per_smbsess = true; |
| 916 | |
| 917 | rc = SMB2_sess_alloc_buffer(sess_data); |
| 918 | if (rc) |
| 919 | goto out_err; |
| 920 | |
| 921 | ntlmssp_blob = kmalloc(sizeof(struct _NEGOTIATE_MESSAGE), |
| 922 | GFP_KERNEL); |
| 923 | if (ntlmssp_blob == NULL) { |
| 924 | rc = -ENOMEM; |
| 925 | goto out; |
| 926 | } |
| 927 | |
| 928 | build_ntlmssp_negotiate_blob(ntlmssp_blob, ses); |
| 929 | if (use_spnego) { |
| 930 | /* BB eventually need to add this */ |
| 931 | cifs_dbg(VFS, "spnego not supported for SMB2 yet\n"); |
| 932 | rc = -EOPNOTSUPP; |
| 933 | goto out; |
| 934 | } else { |
| 935 | blob_length = sizeof(struct _NEGOTIATE_MESSAGE); |
| 936 | /* with raw NTLMSSP we don't encapsulate in SPNEGO */ |
| 937 | } |
| 938 | sess_data->iov[1].iov_base = ntlmssp_blob; |
| 939 | sess_data->iov[1].iov_len = blob_length; |
| 940 | |
| 941 | rc = SMB2_sess_sendreceive(sess_data); |
| 942 | rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; |
| 943 | |
| 944 | /* If true, rc here is expected and not an error */ |
| 945 | if (sess_data->buf0_type != CIFS_NO_BUFFER && |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 946 | rsp->hdr.sync_hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 947 | rc = 0; |
| 948 | |
| 949 | if (rc) |
| 950 | goto out; |
| 951 | |
| 952 | if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 != |
| 953 | le16_to_cpu(rsp->SecurityBufferOffset)) { |
| 954 | cifs_dbg(VFS, "Invalid security buffer offset %d\n", |
| 955 | le16_to_cpu(rsp->SecurityBufferOffset)); |
| 956 | rc = -EIO; |
| 957 | goto out; |
| 958 | } |
| 959 | rc = decode_ntlmssp_challenge(rsp->Buffer, |
| 960 | le16_to_cpu(rsp->SecurityBufferLength), ses); |
| 961 | if (rc) |
| 962 | goto out; |
| 963 | |
| 964 | cifs_dbg(FYI, "rawntlmssp session setup challenge phase\n"); |
| 965 | |
| 966 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 967 | ses->Suid = rsp->hdr.sync_hdr.SessionId; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 968 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 969 | |
| 970 | out: |
| 971 | kfree(ntlmssp_blob); |
| 972 | SMB2_sess_free_buffer(sess_data); |
| 973 | if (!rc) { |
| 974 | sess_data->result = 0; |
| 975 | sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate; |
| 976 | return; |
| 977 | } |
| 978 | out_err: |
| 979 | kfree(ses->ntlmssp); |
| 980 | ses->ntlmssp = NULL; |
| 981 | sess_data->result = rc; |
| 982 | sess_data->func = NULL; |
| 983 | } |
| 984 | |
| 985 | static void |
| 986 | SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data) |
| 987 | { |
| 988 | int rc; |
| 989 | struct cifs_ses *ses = sess_data->ses; |
| 990 | struct smb2_sess_setup_req *req; |
| 991 | struct smb2_sess_setup_rsp *rsp = NULL; |
| 992 | unsigned char *ntlmssp_blob = NULL; |
| 993 | bool use_spnego = false; /* else use raw ntlmssp */ |
| 994 | u16 blob_length = 0; |
| 995 | |
| 996 | rc = SMB2_sess_alloc_buffer(sess_data); |
| 997 | if (rc) |
| 998 | goto out; |
| 999 | |
| 1000 | req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1001 | req->hdr.sync_hdr.SessionId = ses->Suid; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1002 | |
| 1003 | rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses, |
| 1004 | sess_data->nls_cp); |
| 1005 | if (rc) { |
| 1006 | cifs_dbg(FYI, "build_ntlmssp_auth_blob failed %d\n", rc); |
| 1007 | goto out; |
| 1008 | } |
| 1009 | |
| 1010 | if (use_spnego) { |
| 1011 | /* BB eventually need to add this */ |
| 1012 | cifs_dbg(VFS, "spnego not supported for SMB2 yet\n"); |
| 1013 | rc = -EOPNOTSUPP; |
| 1014 | goto out; |
| 1015 | } |
| 1016 | sess_data->iov[1].iov_base = ntlmssp_blob; |
| 1017 | sess_data->iov[1].iov_len = blob_length; |
| 1018 | |
| 1019 | rc = SMB2_sess_sendreceive(sess_data); |
| 1020 | if (rc) |
| 1021 | goto out; |
| 1022 | |
| 1023 | rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; |
| 1024 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1025 | ses->Suid = rsp->hdr.sync_hdr.SessionId; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1026 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1027 | |
| 1028 | rc = SMB2_sess_establish_session(sess_data); |
| 1029 | out: |
| 1030 | kfree(ntlmssp_blob); |
| 1031 | SMB2_sess_free_buffer(sess_data); |
| 1032 | kfree(ses->ntlmssp); |
| 1033 | ses->ntlmssp = NULL; |
| 1034 | sess_data->result = rc; |
| 1035 | sess_data->func = NULL; |
| 1036 | } |
| 1037 | |
| 1038 | static int |
| 1039 | SMB2_select_sec(struct cifs_ses *ses, struct SMB2_sess_data *sess_data) |
| 1040 | { |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 1041 | int type; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1042 | |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 1043 | type = smb2_select_sectype(ses->server, ses->sectype); |
| 1044 | cifs_dbg(FYI, "sess setup type %d\n", type); |
| 1045 | if (type == Unspecified) { |
| 1046 | cifs_dbg(VFS, |
| 1047 | "Unable to select appropriate authentication method!"); |
| 1048 | return -EINVAL; |
| 1049 | } |
| 1050 | |
| 1051 | switch (type) { |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1052 | case Kerberos: |
| 1053 | sess_data->func = SMB2_auth_kerberos; |
| 1054 | break; |
| 1055 | case RawNTLMSSP: |
| 1056 | sess_data->func = SMB2_sess_auth_rawntlmssp_negotiate; |
| 1057 | break; |
| 1058 | default: |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 1059 | cifs_dbg(VFS, "secType %d not supported!\n", type); |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1060 | return -EOPNOTSUPP; |
| 1061 | } |
| 1062 | |
| 1063 | return 0; |
| 1064 | } |
| 1065 | |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1066 | int |
| 1067 | SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses, |
| 1068 | const struct nls_table *nls_cp) |
| 1069 | { |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1070 | int rc = 0; |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 1071 | struct TCP_Server_Info *server = ses->server; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1072 | struct SMB2_sess_data *sess_data; |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1073 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1074 | cifs_dbg(FYI, "Session Setup\n"); |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1075 | |
Jeff Layton | 3534b85 | 2013-05-24 07:41:01 -0400 | [diff] [blame] | 1076 | if (!server) { |
| 1077 | WARN(1, "%s: server is NULL!\n", __func__); |
| 1078 | return -EIO; |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1079 | } |
| 1080 | |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1081 | sess_data = kzalloc(sizeof(struct SMB2_sess_data), GFP_KERNEL); |
| 1082 | if (!sess_data) |
| 1083 | return -ENOMEM; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1084 | |
| 1085 | rc = SMB2_select_sec(ses, sess_data); |
| 1086 | if (rc) |
| 1087 | goto out; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1088 | sess_data->xid = xid; |
| 1089 | sess_data->ses = ses; |
| 1090 | sess_data->buf0_type = CIFS_NO_BUFFER; |
| 1091 | sess_data->nls_cp = (struct nls_table *) nls_cp; |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1092 | |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1093 | while (sess_data->func) |
| 1094 | sess_data->func(sess_data); |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1095 | |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1096 | rc = sess_data->result; |
Sachin Prabhu | 166cea4 | 2016-10-07 19:11:22 +0100 | [diff] [blame] | 1097 | out: |
Sachin Prabhu | 3baf1a7 | 2016-10-07 19:11:21 +0100 | [diff] [blame] | 1098 | kfree(sess_data); |
| 1099 | return rc; |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | int |
| 1103 | SMB2_logoff(const unsigned int xid, struct cifs_ses *ses) |
| 1104 | { |
| 1105 | struct smb2_logoff_req *req; /* response is also trivial struct */ |
| 1106 | int rc = 0; |
| 1107 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1108 | int flags = 0; |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1109 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1110 | cifs_dbg(FYI, "disconnect session %p\n", ses); |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1111 | |
| 1112 | if (ses && (ses->server)) |
| 1113 | server = ses->server; |
| 1114 | else |
| 1115 | return -EIO; |
| 1116 | |
Shirish Pargaonkar | eb4c7df | 2013-10-03 05:44:45 -0500 | [diff] [blame] | 1117 | /* no need to send SMB logoff if uid already closed due to reconnect */ |
| 1118 | if (ses->need_reconnect) |
| 1119 | goto smb2_session_already_dead; |
| 1120 | |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1121 | rc = small_smb2_init(SMB2_LOGOFF, NULL, (void **) &req); |
| 1122 | if (rc) |
| 1123 | return rc; |
| 1124 | |
| 1125 | /* since no tcon, smb2_init can not do this, so do here */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1126 | req->hdr.sync_hdr.SessionId = ses->Suid; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1127 | |
| 1128 | if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) |
| 1129 | flags |= CIFS_TRANSFORM_REQ; |
| 1130 | else if (server->sign) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1131 | req->hdr.sync_hdr.Flags |= SMB2_FLAGS_SIGNED; |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1132 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1133 | rc = SendReceiveNoRsp(xid, ses, (char *) req, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1134 | cifs_small_buf_release(req); |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1135 | /* |
| 1136 | * No tcon so can't do |
| 1137 | * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); |
| 1138 | */ |
Shirish Pargaonkar | eb4c7df | 2013-10-03 05:44:45 -0500 | [diff] [blame] | 1139 | |
| 1140 | smb2_session_already_dead: |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 1141 | return rc; |
| 1142 | } |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1143 | |
| 1144 | static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code) |
| 1145 | { |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1146 | cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | #define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */) |
| 1150 | |
Steve French | de9f68d | 2013-11-15 11:26:24 -0600 | [diff] [blame] | 1151 | /* These are similar values to what Windows uses */ |
| 1152 | static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon) |
| 1153 | { |
| 1154 | tcon->max_chunks = 256; |
| 1155 | tcon->max_bytes_chunk = 1048576; |
| 1156 | tcon->max_bytes_copy = 16777216; |
| 1157 | } |
| 1158 | |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1159 | int |
| 1160 | SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, |
| 1161 | struct cifs_tcon *tcon, const struct nls_table *cp) |
| 1162 | { |
| 1163 | struct smb2_tree_connect_req *req; |
| 1164 | struct smb2_tree_connect_rsp *rsp = NULL; |
| 1165 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1166 | struct kvec rsp_iov; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1167 | int rc = 0; |
| 1168 | int resp_buftype; |
| 1169 | int unc_path_len; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1170 | __le16 *unc_path = NULL; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1171 | int flags = 0; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1172 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1173 | cifs_dbg(FYI, "TCON\n"); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1174 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 1175 | if (!(ses->server) || !tree) |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1176 | return -EIO; |
| 1177 | |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1178 | unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL); |
| 1179 | if (unc_path == NULL) |
| 1180 | return -ENOMEM; |
| 1181 | |
| 1182 | unc_path_len = cifs_strtoUTF16(unc_path, tree, strlen(tree), cp) + 1; |
| 1183 | unc_path_len *= 2; |
| 1184 | if (unc_path_len < 2) { |
| 1185 | kfree(unc_path); |
| 1186 | return -EINVAL; |
| 1187 | } |
| 1188 | |
Jan-Marek Glogowski | 806a28e | 2017-02-20 12:25:58 +0100 | [diff] [blame] | 1189 | /* SMB2 TREE_CONNECT request must be called with TreeId == 0 */ |
| 1190 | if (tcon) |
| 1191 | tcon->tid = 0; |
| 1192 | |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1193 | rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req); |
| 1194 | if (rc) { |
| 1195 | kfree(unc_path); |
| 1196 | return rc; |
| 1197 | } |
| 1198 | |
| 1199 | if (tcon == NULL) { |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 1200 | if ((ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)) |
| 1201 | flags |= CIFS_TRANSFORM_REQ; |
| 1202 | |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1203 | /* since no tcon, smb2_init can not do this, so do here */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1204 | req->hdr.sync_hdr.SessionId = ses->Suid; |
Aurelien Aptel | b9043cc | 2017-02-13 16:19:04 +0100 | [diff] [blame] | 1205 | if (ses->server->sign) |
| 1206 | req->hdr.sync_hdr.Flags |= SMB2_FLAGS_SIGNED; |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 1207 | } else if (encryption_required(tcon)) |
| 1208 | flags |= CIFS_TRANSFORM_REQ; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1209 | |
| 1210 | iov[0].iov_base = (char *)req; |
| 1211 | /* 4 for rfc1002 length field and 1 for pad */ |
| 1212 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; |
| 1213 | |
| 1214 | /* Testing shows that buffer offset must be at location of Buffer[0] */ |
| 1215 | req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req) |
| 1216 | - 1 /* pad */ - 4 /* do not count rfc1001 len field */); |
| 1217 | req->PathLength = cpu_to_le16(unc_path_len - 2); |
| 1218 | iov[1].iov_base = unc_path; |
| 1219 | iov[1].iov_len = unc_path_len; |
| 1220 | |
| 1221 | inc_rfc1001_len(req, unc_path_len - 1 /* pad */); |
| 1222 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1223 | rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1224 | cifs_small_buf_release(req); |
| 1225 | rsp = (struct smb2_tree_connect_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1226 | |
| 1227 | if (rc != 0) { |
| 1228 | if (tcon) { |
| 1229 | cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE); |
| 1230 | tcon->need_reconnect = true; |
| 1231 | } |
| 1232 | goto tcon_error_exit; |
| 1233 | } |
| 1234 | |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1235 | if (tcon == NULL) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1236 | ses->ipc_tid = rsp->hdr.sync_hdr.TreeId; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1237 | goto tcon_exit; |
| 1238 | } |
| 1239 | |
Christophe JAILLET | cd12300 | 2017-05-12 17:59:32 +0200 | [diff] [blame] | 1240 | switch (rsp->ShareType) { |
| 1241 | case SMB2_SHARE_TYPE_DISK: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1242 | cifs_dbg(FYI, "connection to disk share\n"); |
Christophe JAILLET | cd12300 | 2017-05-12 17:59:32 +0200 | [diff] [blame] | 1243 | break; |
| 1244 | case SMB2_SHARE_TYPE_PIPE: |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1245 | tcon->ipc = true; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1246 | cifs_dbg(FYI, "connection to pipe share\n"); |
Christophe JAILLET | cd12300 | 2017-05-12 17:59:32 +0200 | [diff] [blame] | 1247 | break; |
| 1248 | case SMB2_SHARE_TYPE_PRINT: |
| 1249 | tcon->ipc = true; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1250 | cifs_dbg(FYI, "connection to printer\n"); |
Christophe JAILLET | cd12300 | 2017-05-12 17:59:32 +0200 | [diff] [blame] | 1251 | break; |
| 1252 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1253 | cifs_dbg(VFS, "unknown share type %d\n", rsp->ShareType); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1254 | rc = -EOPNOTSUPP; |
| 1255 | goto tcon_error_exit; |
| 1256 | } |
| 1257 | |
| 1258 | tcon->share_flags = le32_to_cpu(rsp->ShareFlags); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1259 | tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */ |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1260 | tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess); |
| 1261 | tcon->tidStatus = CifsGood; |
| 1262 | tcon->need_reconnect = false; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1263 | tcon->tid = rsp->hdr.sync_hdr.TreeId; |
Zhao Hongjiang | 46b51d0 | 2013-06-24 01:57:47 -0500 | [diff] [blame] | 1264 | strlcpy(tcon->treeName, tree, sizeof(tcon->treeName)); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1265 | |
| 1266 | if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) && |
| 1267 | ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0)) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1268 | cifs_dbg(VFS, "DFS capability contradicts DFS flag\n"); |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 1269 | |
| 1270 | if (tcon->seal && |
| 1271 | !(tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) |
| 1272 | cifs_dbg(VFS, "Encryption is requested but not supported\n"); |
| 1273 | |
Steve French | de9f68d | 2013-11-15 11:26:24 -0600 | [diff] [blame] | 1274 | init_copy_chunk_defaults(tcon); |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 1275 | if (tcon->ses->server->ops->validate_negotiate) |
| 1276 | rc = tcon->ses->server->ops->validate_negotiate(xid, tcon); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1277 | tcon_exit: |
| 1278 | free_rsp_buf(resp_buftype, rsp); |
| 1279 | kfree(unc_path); |
| 1280 | return rc; |
| 1281 | |
| 1282 | tcon_error_exit: |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1283 | if (rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1284 | cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1285 | } |
| 1286 | goto tcon_exit; |
| 1287 | } |
| 1288 | |
| 1289 | int |
| 1290 | SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) |
| 1291 | { |
| 1292 | struct smb2_tree_disconnect_req *req; /* response is trivial */ |
| 1293 | int rc = 0; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1294 | struct cifs_ses *ses = tcon->ses; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1295 | int flags = 0; |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1296 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1297 | cifs_dbg(FYI, "Tree Disconnect\n"); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1298 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 1299 | if (!ses || !(ses->server)) |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1300 | return -EIO; |
| 1301 | |
| 1302 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
| 1303 | return 0; |
| 1304 | |
| 1305 | rc = small_smb2_init(SMB2_TREE_DISCONNECT, tcon, (void **) &req); |
| 1306 | if (rc) |
| 1307 | return rc; |
| 1308 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1309 | if (encryption_required(tcon)) |
| 1310 | flags |= CIFS_TRANSFORM_REQ; |
| 1311 | |
| 1312 | rc = SendReceiveNoRsp(xid, ses, (char *)req, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1313 | cifs_small_buf_release(req); |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 1314 | if (rc) |
| 1315 | cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE); |
| 1316 | |
| 1317 | return rc; |
| 1318 | } |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1319 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1320 | |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1321 | static struct create_durable * |
| 1322 | create_durable_buf(void) |
| 1323 | { |
| 1324 | struct create_durable *buf; |
| 1325 | |
| 1326 | buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL); |
| 1327 | if (!buf) |
| 1328 | return NULL; |
| 1329 | |
| 1330 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1331 | (struct create_durable, Data)); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1332 | buf->ccontext.DataLength = cpu_to_le32(16); |
| 1333 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1334 | (struct create_durable, Name)); |
| 1335 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1336 | /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DHnQ" */ |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1337 | buf->Name[0] = 'D'; |
| 1338 | buf->Name[1] = 'H'; |
| 1339 | buf->Name[2] = 'n'; |
| 1340 | buf->Name[3] = 'Q'; |
| 1341 | return buf; |
| 1342 | } |
| 1343 | |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1344 | static struct create_durable * |
| 1345 | create_reconnect_durable_buf(struct cifs_fid *fid) |
| 1346 | { |
| 1347 | struct create_durable *buf; |
| 1348 | |
| 1349 | buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL); |
| 1350 | if (!buf) |
| 1351 | return NULL; |
| 1352 | |
| 1353 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1354 | (struct create_durable, Data)); |
| 1355 | buf->ccontext.DataLength = cpu_to_le32(16); |
| 1356 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1357 | (struct create_durable, Name)); |
| 1358 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 1359 | buf->Data.Fid.PersistentFileId = fid->persistent_fid; |
| 1360 | buf->Data.Fid.VolatileFileId = fid->volatile_fid; |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1361 | /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT is "DHnC" */ |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1362 | buf->Name[0] = 'D'; |
| 1363 | buf->Name[1] = 'H'; |
| 1364 | buf->Name[2] = 'n'; |
| 1365 | buf->Name[3] = 'C'; |
| 1366 | return buf; |
| 1367 | } |
| 1368 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1369 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1370 | parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp, |
| 1371 | unsigned int *epoch) |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1372 | { |
| 1373 | char *data_offset; |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1374 | struct create_context *cc; |
Justin Maggard | deb7def | 2016-02-09 15:52:08 -0800 | [diff] [blame] | 1375 | unsigned int next; |
| 1376 | unsigned int remaining; |
Pavel Shilovsky | fd55439 | 2013-07-09 19:44:56 +0400 | [diff] [blame] | 1377 | char *name; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1378 | |
Pavel Shilovsky | fd55439 | 2013-07-09 19:44:56 +0400 | [diff] [blame] | 1379 | data_offset = (char *)rsp + 4 + le32_to_cpu(rsp->CreateContextsOffset); |
Justin Maggard | deb7def | 2016-02-09 15:52:08 -0800 | [diff] [blame] | 1380 | remaining = le32_to_cpu(rsp->CreateContextsLength); |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1381 | cc = (struct create_context *)data_offset; |
Justin Maggard | deb7def | 2016-02-09 15:52:08 -0800 | [diff] [blame] | 1382 | while (remaining >= sizeof(struct create_context)) { |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1383 | name = le16_to_cpu(cc->NameOffset) + (char *)cc; |
Justin Maggard | deb7def | 2016-02-09 15:52:08 -0800 | [diff] [blame] | 1384 | if (le16_to_cpu(cc->NameLength) == 4 && |
| 1385 | strncmp(name, "RqLs", 4) == 0) |
| 1386 | return server->ops->parse_lease_buf(cc, epoch); |
| 1387 | |
| 1388 | next = le32_to_cpu(cc->Next); |
| 1389 | if (!next) |
| 1390 | break; |
| 1391 | remaining -= next; |
| 1392 | cc = (struct create_context *)((char *)cc + next); |
| 1393 | } |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1394 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 1395 | return 0; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1398 | static int |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1399 | add_lease_context(struct TCP_Server_Info *server, struct kvec *iov, |
| 1400 | unsigned int *num_iovec, __u8 *oplock) |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1401 | { |
| 1402 | struct smb2_create_req *req = iov[0].iov_base; |
| 1403 | unsigned int num = *num_iovec; |
| 1404 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1405 | iov[num].iov_base = server->ops->create_lease_buf(oplock+1, *oplock); |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1406 | if (iov[num].iov_base == NULL) |
| 1407 | return -ENOMEM; |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1408 | iov[num].iov_len = server->vals->create_lease_size; |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1409 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; |
| 1410 | if (!req->CreateContextsOffset) |
| 1411 | req->CreateContextsOffset = cpu_to_le32( |
| 1412 | sizeof(struct smb2_create_req) - 4 + |
| 1413 | iov[num - 1].iov_len); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1414 | le32_add_cpu(&req->CreateContextsLength, |
| 1415 | server->vals->create_lease_size); |
| 1416 | inc_rfc1001_len(&req->hdr, server->vals->create_lease_size); |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1417 | *num_iovec = num + 1; |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1421 | static struct create_durable_v2 * |
| 1422 | create_durable_v2_buf(struct cifs_fid *pfid) |
| 1423 | { |
| 1424 | struct create_durable_v2 *buf; |
| 1425 | |
| 1426 | buf = kzalloc(sizeof(struct create_durable_v2), GFP_KERNEL); |
| 1427 | if (!buf) |
| 1428 | return NULL; |
| 1429 | |
| 1430 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1431 | (struct create_durable_v2, dcontext)); |
| 1432 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2)); |
| 1433 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1434 | (struct create_durable_v2, Name)); |
| 1435 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 1436 | |
| 1437 | buf->dcontext.Timeout = 0; /* Should this be configurable by workload */ |
| 1438 | buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 1439 | generate_random_uuid(buf->dcontext.CreateGuid); |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1440 | memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16); |
| 1441 | |
| 1442 | /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ |
| 1443 | buf->Name[0] = 'D'; |
| 1444 | buf->Name[1] = 'H'; |
| 1445 | buf->Name[2] = '2'; |
| 1446 | buf->Name[3] = 'Q'; |
| 1447 | return buf; |
| 1448 | } |
| 1449 | |
| 1450 | static struct create_durable_handle_reconnect_v2 * |
| 1451 | create_reconnect_durable_v2_buf(struct cifs_fid *fid) |
| 1452 | { |
| 1453 | struct create_durable_handle_reconnect_v2 *buf; |
| 1454 | |
| 1455 | buf = kzalloc(sizeof(struct create_durable_handle_reconnect_v2), |
| 1456 | GFP_KERNEL); |
| 1457 | if (!buf) |
| 1458 | return NULL; |
| 1459 | |
| 1460 | buf->ccontext.DataOffset = |
| 1461 | cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2, |
| 1462 | dcontext)); |
| 1463 | buf->ccontext.DataLength = |
| 1464 | cpu_to_le32(sizeof(struct durable_reconnect_context_v2)); |
| 1465 | buf->ccontext.NameOffset = |
| 1466 | cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2, |
| 1467 | Name)); |
| 1468 | buf->ccontext.NameLength = cpu_to_le16(4); |
| 1469 | |
| 1470 | buf->dcontext.Fid.PersistentFileId = fid->persistent_fid; |
| 1471 | buf->dcontext.Fid.VolatileFileId = fid->volatile_fid; |
| 1472 | buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); |
| 1473 | memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16); |
| 1474 | |
| 1475 | /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 is "DH2C" */ |
| 1476 | buf->Name[0] = 'D'; |
| 1477 | buf->Name[1] = 'H'; |
| 1478 | buf->Name[2] = '2'; |
| 1479 | buf->Name[3] = 'C'; |
| 1480 | return buf; |
| 1481 | } |
| 1482 | |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1483 | static int |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1484 | add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec, |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1485 | struct cifs_open_parms *oparms) |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1486 | { |
| 1487 | struct smb2_create_req *req = iov[0].iov_base; |
| 1488 | unsigned int num = *num_iovec; |
| 1489 | |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1490 | iov[num].iov_base = create_durable_v2_buf(oparms->fid); |
| 1491 | if (iov[num].iov_base == NULL) |
| 1492 | return -ENOMEM; |
| 1493 | iov[num].iov_len = sizeof(struct create_durable_v2); |
| 1494 | if (!req->CreateContextsOffset) |
| 1495 | req->CreateContextsOffset = |
| 1496 | cpu_to_le32(sizeof(struct smb2_create_req) - 4 + |
| 1497 | iov[1].iov_len); |
| 1498 | le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2)); |
| 1499 | inc_rfc1001_len(&req->hdr, sizeof(struct create_durable_v2)); |
| 1500 | *num_iovec = num + 1; |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | static int |
| 1505 | add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec, |
| 1506 | struct cifs_open_parms *oparms) |
| 1507 | { |
| 1508 | struct smb2_create_req *req = iov[0].iov_base; |
| 1509 | unsigned int num = *num_iovec; |
| 1510 | |
| 1511 | /* indicate that we don't need to relock the file */ |
| 1512 | oparms->reconnect = false; |
| 1513 | |
| 1514 | iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid); |
| 1515 | if (iov[num].iov_base == NULL) |
| 1516 | return -ENOMEM; |
| 1517 | iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2); |
| 1518 | if (!req->CreateContextsOffset) |
| 1519 | req->CreateContextsOffset = |
| 1520 | cpu_to_le32(sizeof(struct smb2_create_req) - 4 + |
| 1521 | iov[1].iov_len); |
| 1522 | le32_add_cpu(&req->CreateContextsLength, |
| 1523 | sizeof(struct create_durable_handle_reconnect_v2)); |
| 1524 | inc_rfc1001_len(&req->hdr, |
| 1525 | sizeof(struct create_durable_handle_reconnect_v2)); |
| 1526 | *num_iovec = num + 1; |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static int |
| 1531 | add_durable_context(struct kvec *iov, unsigned int *num_iovec, |
| 1532 | struct cifs_open_parms *oparms, bool use_persistent) |
| 1533 | { |
| 1534 | struct smb2_create_req *req = iov[0].iov_base; |
| 1535 | unsigned int num = *num_iovec; |
| 1536 | |
| 1537 | if (use_persistent) { |
| 1538 | if (oparms->reconnect) |
| 1539 | return add_durable_reconnect_v2_context(iov, num_iovec, |
| 1540 | oparms); |
| 1541 | else |
| 1542 | return add_durable_v2_context(iov, num_iovec, oparms); |
| 1543 | } |
| 1544 | |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1545 | if (oparms->reconnect) { |
| 1546 | iov[num].iov_base = create_reconnect_durable_buf(oparms->fid); |
| 1547 | /* indicate that we don't need to relock the file */ |
| 1548 | oparms->reconnect = false; |
| 1549 | } else |
| 1550 | iov[num].iov_base = create_durable_buf(); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1551 | if (iov[num].iov_base == NULL) |
| 1552 | return -ENOMEM; |
| 1553 | iov[num].iov_len = sizeof(struct create_durable); |
| 1554 | if (!req->CreateContextsOffset) |
| 1555 | req->CreateContextsOffset = |
| 1556 | cpu_to_le32(sizeof(struct smb2_create_req) - 4 + |
| 1557 | iov[1].iov_len); |
Wei Yongjun | 31f92e9 | 2013-08-26 14:34:46 +0800 | [diff] [blame] | 1558 | le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable)); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1559 | inc_rfc1001_len(&req->hdr, sizeof(struct create_durable)); |
| 1560 | *num_iovec = num + 1; |
| 1561 | return 0; |
| 1562 | } |
| 1563 | |
Aurelien Aptel | f071292 | 2017-02-22 14:47:17 +0100 | [diff] [blame] | 1564 | static int |
| 1565 | alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len, |
| 1566 | const char *treename, const __le16 *path) |
| 1567 | { |
| 1568 | int treename_len, path_len; |
| 1569 | struct nls_table *cp; |
| 1570 | const __le16 sep[] = {cpu_to_le16('\\'), cpu_to_le16(0x0000)}; |
| 1571 | |
| 1572 | /* |
| 1573 | * skip leading "\\" |
| 1574 | */ |
| 1575 | treename_len = strlen(treename); |
| 1576 | if (treename_len < 2 || !(treename[0] == '\\' && treename[1] == '\\')) |
| 1577 | return -EINVAL; |
| 1578 | |
| 1579 | treename += 2; |
| 1580 | treename_len -= 2; |
| 1581 | |
| 1582 | path_len = UniStrnlen((wchar_t *)path, PATH_MAX); |
| 1583 | |
| 1584 | /* |
| 1585 | * make room for one path separator between the treename and |
| 1586 | * path |
| 1587 | */ |
| 1588 | *out_len = treename_len + 1 + path_len; |
| 1589 | |
| 1590 | /* |
| 1591 | * final path needs to be null-terminated UTF16 with a |
| 1592 | * size aligned to 8 |
| 1593 | */ |
| 1594 | |
| 1595 | *out_size = roundup((*out_len+1)*2, 8); |
| 1596 | *out_path = kzalloc(*out_size, GFP_KERNEL); |
| 1597 | if (!*out_path) |
| 1598 | return -ENOMEM; |
| 1599 | |
| 1600 | cp = load_nls_default(); |
| 1601 | cifs_strtoUTF16(*out_path, treename, treename_len, cp); |
| 1602 | UniStrcat(*out_path, sep); |
| 1603 | UniStrcat(*out_path, path); |
| 1604 | unload_nls(cp); |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1609 | int |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1610 | SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1611 | __u8 *oplock, struct smb2_file_all_info *buf, |
| 1612 | struct smb2_err_rsp **err_buf) |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1613 | { |
| 1614 | struct smb2_create_req *req; |
| 1615 | struct smb2_create_rsp *rsp; |
| 1616 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1617 | struct cifs_tcon *tcon = oparms->tcon; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1618 | struct cifs_ses *ses = tcon->ses; |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1619 | struct kvec iov[4]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1620 | struct kvec rsp_iov; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1621 | int resp_buftype; |
| 1622 | int uni_path_len; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1623 | __le16 *copy_path = NULL; |
| 1624 | int copy_size; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1625 | int rc = 0; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1626 | unsigned int n_iov = 2; |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 1627 | __u32 file_attributes = 0; |
Pavel Shilovsky | 663a9621 | 2014-05-24 16:42:02 +0400 | [diff] [blame] | 1628 | char *dhc_buf = NULL, *lc_buf = NULL; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1629 | int flags = 0; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1630 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1631 | cifs_dbg(FYI, "create/open\n"); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1632 | |
| 1633 | if (ses && (ses->server)) |
| 1634 | server = ses->server; |
| 1635 | else |
| 1636 | return -EIO; |
| 1637 | |
| 1638 | rc = small_smb2_init(SMB2_CREATE, tcon, (void **) &req); |
| 1639 | if (rc) |
| 1640 | return rc; |
| 1641 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1642 | if (encryption_required(tcon)) |
| 1643 | flags |= CIFS_TRANSFORM_REQ; |
| 1644 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1645 | if (oparms->create_options & CREATE_OPTION_READONLY) |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 1646 | file_attributes |= ATTR_READONLY; |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1647 | if (oparms->create_options & CREATE_OPTION_SPECIAL) |
| 1648 | file_attributes |= ATTR_SYSTEM; |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 1649 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1650 | req->ImpersonationLevel = IL_IMPERSONATION; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1651 | req->DesiredAccess = cpu_to_le32(oparms->desired_access); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1652 | /* File attributes ignored on open (used in create though) */ |
| 1653 | req->FileAttributes = cpu_to_le32(file_attributes); |
| 1654 | req->ShareAccess = FILE_SHARE_ALL_LE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1655 | req->CreateDisposition = cpu_to_le32(oparms->disposition); |
| 1656 | req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1657 | |
| 1658 | iov[0].iov_base = (char *)req; |
| 1659 | /* 4 for rfc1002 length field */ |
| 1660 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
Pavel Shilovsky | 59aa371 | 2013-07-04 19:41:24 +0400 | [diff] [blame] | 1661 | /* -1 since last byte is buf[0] which is sent below (path) */ |
| 1662 | iov[0].iov_len--; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1663 | |
Aurelien Aptel | f071292 | 2017-02-22 14:47:17 +0100 | [diff] [blame] | 1664 | req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) - 4); |
| 1665 | |
| 1666 | /* [MS-SMB2] 2.2.13 NameOffset: |
| 1667 | * If SMB2_FLAGS_DFS_OPERATIONS is set in the Flags field of |
| 1668 | * the SMB2 header, the file name includes a prefix that will |
| 1669 | * be processed during DFS name normalization as specified in |
| 1670 | * section 3.3.5.9. Otherwise, the file name is relative to |
| 1671 | * the share that is identified by the TreeId in the SMB2 |
| 1672 | * header. |
| 1673 | */ |
| 1674 | if (tcon->share_flags & SHI1005_FLAGS_DFS) { |
| 1675 | int name_len; |
| 1676 | |
| 1677 | req->hdr.sync_hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; |
| 1678 | rc = alloc_path_with_tree_prefix(©_path, ©_size, |
| 1679 | &name_len, |
| 1680 | tcon->treeName, path); |
| 1681 | if (rc) |
| 1682 | return rc; |
| 1683 | req->NameLength = cpu_to_le16(name_len * 2); |
Pavel Shilovsky | 59aa371 | 2013-07-04 19:41:24 +0400 | [diff] [blame] | 1684 | uni_path_len = copy_size; |
| 1685 | path = copy_path; |
Aurelien Aptel | f071292 | 2017-02-22 14:47:17 +0100 | [diff] [blame] | 1686 | } else { |
| 1687 | uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; |
| 1688 | /* MUST set path len (NameLength) to 0 opening root of share */ |
| 1689 | req->NameLength = cpu_to_le16(uni_path_len - 2); |
| 1690 | if (uni_path_len % 8 != 0) { |
| 1691 | copy_size = roundup(uni_path_len, 8); |
| 1692 | copy_path = kzalloc(copy_size, GFP_KERNEL); |
| 1693 | if (!copy_path) |
| 1694 | return -ENOMEM; |
| 1695 | memcpy((char *)copy_path, (const char *)path, |
| 1696 | uni_path_len); |
| 1697 | uni_path_len = copy_size; |
| 1698 | path = copy_path; |
| 1699 | } |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1700 | } |
| 1701 | |
Pavel Shilovsky | 59aa371 | 2013-07-04 19:41:24 +0400 | [diff] [blame] | 1702 | iov[1].iov_len = uni_path_len; |
| 1703 | iov[1].iov_base = path; |
| 1704 | /* -1 since last byte is buf[0] which was counted in smb2_buf_len */ |
| 1705 | inc_rfc1001_len(req, uni_path_len - 1); |
| 1706 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1707 | if (!server->oplocks) |
| 1708 | *oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1709 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1710 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) || |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1711 | *oplock == SMB2_OPLOCK_LEVEL_NONE) |
| 1712 | req->RequestedOplockLevel = *oplock; |
| 1713 | else { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1714 | rc = add_lease_context(server, iov, &n_iov, oplock); |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1715 | if (rc) { |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1716 | cifs_small_buf_release(req); |
| 1717 | kfree(copy_path); |
Pavel Shilovsky | d22cbfe | 2013-07-04 19:10:00 +0400 | [diff] [blame] | 1718 | return rc; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1719 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1720 | lc_buf = iov[n_iov-1].iov_base; |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1723 | if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
| 1724 | /* need to set Next field of lease context if we request it */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1725 | if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) { |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1726 | struct create_context *ccontext = |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1727 | (struct create_context *)iov[n_iov-1].iov_base; |
Steve French | 1c46943 | 2013-07-10 12:50:57 -0500 | [diff] [blame] | 1728 | ccontext->Next = |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1729 | cpu_to_le32(server->vals->create_lease_size); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1730 | } |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1731 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1732 | rc = add_durable_context(iov, &n_iov, oparms, |
Steve French | b56eae4 | 2015-11-03 09:26:27 -0600 | [diff] [blame] | 1733 | tcon->use_persistent); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1734 | if (rc) { |
| 1735 | cifs_small_buf_release(req); |
| 1736 | kfree(copy_path); |
Pavel Shilovsky | 663a9621 | 2014-05-24 16:42:02 +0400 | [diff] [blame] | 1737 | kfree(lc_buf); |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1738 | return rc; |
| 1739 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1740 | dhc_buf = iov[n_iov-1].iov_base; |
Pavel Shilovsky | 63eb3de | 2013-07-04 18:41:09 +0400 | [diff] [blame] | 1741 | } |
| 1742 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1743 | rc = SendReceive2(xid, ses, iov, n_iov, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1744 | cifs_small_buf_release(req); |
| 1745 | rsp = (struct smb2_create_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1746 | |
| 1747 | if (rc != 0) { |
| 1748 | cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1749 | if (err_buf) |
| 1750 | *err_buf = kmemdup(rsp, get_rfc1002_length(rsp) + 4, |
| 1751 | GFP_KERNEL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1752 | goto creat_exit; |
| 1753 | } |
| 1754 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1755 | oparms->fid->persistent_fid = rsp->PersistentFileId; |
| 1756 | oparms->fid->volatile_fid = rsp->VolatileFileId; |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1757 | |
| 1758 | if (buf) { |
| 1759 | memcpy(buf, &rsp->CreationTime, 32); |
| 1760 | buf->AllocationSize = rsp->AllocationSize; |
| 1761 | buf->EndOfFile = rsp->EndofFile; |
| 1762 | buf->Attributes = rsp->FileAttributes; |
| 1763 | buf->NumberOfLinks = cpu_to_le32(1); |
| 1764 | buf->DeletePending = 0; |
| 1765 | } |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1766 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1767 | if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1768 | *oplock = parse_lease_state(server, rsp, &oparms->fid->epoch); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1769 | else |
| 1770 | *oplock = rsp->OplockLevel; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1771 | creat_exit: |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1772 | kfree(copy_path); |
Pavel Shilovsky | 663a9621 | 2014-05-24 16:42:02 +0400 | [diff] [blame] | 1773 | kfree(lc_buf); |
| 1774 | kfree(dhc_buf); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1775 | free_rsp_buf(resp_buftype, rsp); |
| 1776 | return rc; |
| 1777 | } |
| 1778 | |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1779 | /* |
| 1780 | * SMB2 IOCTL is used for both IOCTLs and FSCTLs |
| 1781 | */ |
| 1782 | int |
| 1783 | SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1784 | u64 volatile_fid, u32 opcode, bool is_fsctl, bool use_ipc, |
| 1785 | char *in_data, u32 indatalen, |
| 1786 | char **out_data, u32 *plen /* returned data len */) |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1787 | { |
| 1788 | struct smb2_ioctl_req *req; |
| 1789 | struct smb2_ioctl_rsp *rsp; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1790 | struct smb2_sync_hdr *shdr; |
Steve French | 8e35310 | 2015-03-26 19:47:02 -0500 | [diff] [blame] | 1791 | struct cifs_ses *ses; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1792 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1793 | struct kvec rsp_iov; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1794 | int resp_buftype; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1795 | int n_iov; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1796 | int rc = 0; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1797 | int flags = 0; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1798 | |
| 1799 | cifs_dbg(FYI, "SMB2 IOCTL\n"); |
| 1800 | |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1801 | if (out_data != NULL) |
| 1802 | *out_data = NULL; |
| 1803 | |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1804 | /* zero out returned data len, in case of error */ |
| 1805 | if (plen) |
| 1806 | *plen = 0; |
| 1807 | |
Steve French | 8e35310 | 2015-03-26 19:47:02 -0500 | [diff] [blame] | 1808 | if (tcon) |
| 1809 | ses = tcon->ses; |
| 1810 | else |
| 1811 | return -EIO; |
| 1812 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 1813 | if (!ses || !(ses->server)) |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1814 | return -EIO; |
| 1815 | |
| 1816 | rc = small_smb2_init(SMB2_IOCTL, tcon, (void **) &req); |
| 1817 | if (rc) |
| 1818 | return rc; |
| 1819 | |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1820 | if (use_ipc) { |
| 1821 | if (ses->ipc_tid == 0) { |
| 1822 | cifs_small_buf_release(req); |
| 1823 | return -ENOTCONN; |
| 1824 | } |
| 1825 | |
| 1826 | cifs_dbg(FYI, "replacing tid 0x%x with IPC tid 0x%x\n", |
| 1827 | req->hdr.sync_hdr.TreeId, ses->ipc_tid); |
| 1828 | req->hdr.sync_hdr.TreeId = ses->ipc_tid; |
| 1829 | } |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1830 | if (encryption_required(tcon)) |
| 1831 | flags |= CIFS_TRANSFORM_REQ; |
| 1832 | |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1833 | req->CtlCode = cpu_to_le32(opcode); |
| 1834 | req->PersistentFileId = persistent_fid; |
| 1835 | req->VolatileFileId = volatile_fid; |
| 1836 | |
| 1837 | if (indatalen) { |
| 1838 | req->InputCount = cpu_to_le32(indatalen); |
| 1839 | /* do not set InputOffset if no input data */ |
| 1840 | req->InputOffset = |
| 1841 | cpu_to_le32(offsetof(struct smb2_ioctl_req, Buffer) - 4); |
| 1842 | iov[1].iov_base = in_data; |
| 1843 | iov[1].iov_len = indatalen; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1844 | n_iov = 2; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1845 | } else |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1846 | n_iov = 1; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1847 | |
| 1848 | req->OutputOffset = 0; |
| 1849 | req->OutputCount = 0; /* MBZ */ |
| 1850 | |
| 1851 | /* |
| 1852 | * Could increase MaxOutputResponse, but that would require more |
| 1853 | * than one credit. Windows typically sets this smaller, but for some |
| 1854 | * ioctls it may be useful to allow server to send more. No point |
| 1855 | * limiting what the server can send as long as fits in one credit |
Steve French | 7db0a6e | 2017-05-03 21:12:20 -0500 | [diff] [blame] | 1856 | * Unfortunately - we can not handle more than CIFS_MAX_MSG_SIZE |
| 1857 | * (by default, note that it can be overridden to make max larger) |
| 1858 | * in responses (except for read responses which can be bigger. |
| 1859 | * We may want to bump this limit up |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1860 | */ |
Steve French | 7db0a6e | 2017-05-03 21:12:20 -0500 | [diff] [blame] | 1861 | req->MaxOutputResponse = cpu_to_le32(CIFSMaxBufSize); |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1862 | |
| 1863 | if (is_fsctl) |
| 1864 | req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL); |
| 1865 | else |
| 1866 | req->Flags = 0; |
| 1867 | |
| 1868 | iov[0].iov_base = (char *)req; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1869 | |
Steve French | 7ff8d45 | 2013-10-14 00:44:19 -0500 | [diff] [blame] | 1870 | /* |
| 1871 | * If no input data, the size of ioctl struct in |
| 1872 | * protocol spec still includes a 1 byte data buffer, |
| 1873 | * but if input data passed to ioctl, we do not |
| 1874 | * want to double count this, so we do not send |
| 1875 | * the dummy one byte of data in iovec[0] if sending |
| 1876 | * input data (in iovec[1]). We also must add 4 bytes |
| 1877 | * in first iovec to allow for rfc1002 length field. |
| 1878 | */ |
| 1879 | |
| 1880 | if (indatalen) { |
| 1881 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; |
| 1882 | inc_rfc1001_len(req, indatalen - 1); |
| 1883 | } else |
| 1884 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 1885 | |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1886 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1887 | rc = SendReceive2(xid, ses, iov, n_iov, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1888 | cifs_small_buf_release(req); |
| 1889 | rsp = (struct smb2_ioctl_rsp *)rsp_iov.iov_base; |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1890 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1891 | if ((rc != 0) && (rc != -EINVAL)) { |
Steve French | 8e35310 | 2015-03-26 19:47:02 -0500 | [diff] [blame] | 1892 | cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1893 | goto ioctl_exit; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1894 | } else if (rc == -EINVAL) { |
| 1895 | if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) && |
| 1896 | (opcode != FSCTL_SRV_COPYCHUNK)) { |
Steve French | 8e35310 | 2015-03-26 19:47:02 -0500 | [diff] [blame] | 1897 | cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1898 | goto ioctl_exit; |
| 1899 | } |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /* check if caller wants to look at return data or just return rc */ |
| 1903 | if ((plen == NULL) || (out_data == NULL)) |
| 1904 | goto ioctl_exit; |
| 1905 | |
| 1906 | *plen = le32_to_cpu(rsp->OutputCount); |
| 1907 | |
| 1908 | /* We check for obvious errors in the output buffer length and offset */ |
| 1909 | if (*plen == 0) |
| 1910 | goto ioctl_exit; /* server returned no data */ |
| 1911 | else if (*plen > 0xFF00) { |
| 1912 | cifs_dbg(VFS, "srv returned invalid ioctl length: %d\n", *plen); |
| 1913 | *plen = 0; |
| 1914 | rc = -EIO; |
| 1915 | goto ioctl_exit; |
| 1916 | } |
| 1917 | |
| 1918 | if (get_rfc1002_length(rsp) < le32_to_cpu(rsp->OutputOffset) + *plen) { |
| 1919 | cifs_dbg(VFS, "Malformed ioctl resp: len %d offset %d\n", *plen, |
| 1920 | le32_to_cpu(rsp->OutputOffset)); |
| 1921 | *plen = 0; |
| 1922 | rc = -EIO; |
| 1923 | goto ioctl_exit; |
| 1924 | } |
| 1925 | |
| 1926 | *out_data = kmalloc(*plen, GFP_KERNEL); |
| 1927 | if (*out_data == NULL) { |
| 1928 | rc = -ENOMEM; |
| 1929 | goto ioctl_exit; |
| 1930 | } |
| 1931 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1932 | shdr = get_sync_hdr(rsp); |
| 1933 | memcpy(*out_data, (char *)shdr + le32_to_cpu(rsp->OutputOffset), *plen); |
Steve French | 4a72daf | 2013-06-25 00:20:49 -0500 | [diff] [blame] | 1934 | ioctl_exit: |
| 1935 | free_rsp_buf(resp_buftype, rsp); |
| 1936 | return rc; |
| 1937 | } |
| 1938 | |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1939 | /* |
| 1940 | * Individual callers to ioctl worker function follow |
| 1941 | */ |
| 1942 | |
| 1943 | int |
| 1944 | SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 1945 | u64 persistent_fid, u64 volatile_fid) |
| 1946 | { |
| 1947 | int rc; |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1948 | struct compress_ioctl fsctl_input; |
| 1949 | char *ret_data = NULL; |
| 1950 | |
| 1951 | fsctl_input.CompressionState = |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 1952 | cpu_to_le16(COMPRESSION_FORMAT_DEFAULT); |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1953 | |
| 1954 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 1955 | FSCTL_SET_COMPRESSION, true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1956 | false /* use_ipc */, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1957 | (char *)&fsctl_input /* data input */, |
| 1958 | 2 /* in data len */, &ret_data /* out data */, NULL); |
| 1959 | |
| 1960 | cifs_dbg(FYI, "set compression rc %d\n", rc); |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1961 | |
| 1962 | return rc; |
| 1963 | } |
| 1964 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1965 | int |
| 1966 | SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, |
| 1967 | u64 persistent_fid, u64 volatile_fid) |
| 1968 | { |
| 1969 | struct smb2_close_req *req; |
| 1970 | struct smb2_close_rsp *rsp; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1971 | struct cifs_ses *ses = tcon->ses; |
| 1972 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1973 | struct kvec rsp_iov; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1974 | int resp_buftype; |
| 1975 | int rc = 0; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1976 | int flags = 0; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1977 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1978 | cifs_dbg(FYI, "Close\n"); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1979 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 1980 | if (!ses || !(ses->server)) |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1981 | return -EIO; |
| 1982 | |
| 1983 | rc = small_smb2_init(SMB2_CLOSE, tcon, (void **) &req); |
| 1984 | if (rc) |
| 1985 | return rc; |
| 1986 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1987 | if (encryption_required(tcon)) |
| 1988 | flags |= CIFS_TRANSFORM_REQ; |
| 1989 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1990 | req->PersistentFileId = persistent_fid; |
| 1991 | req->VolatileFileId = volatile_fid; |
| 1992 | |
| 1993 | iov[0].iov_base = (char *)req; |
| 1994 | /* 4 for rfc1002 length field */ |
| 1995 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 1996 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 1997 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 1998 | cifs_small_buf_release(req); |
| 1999 | rsp = (struct smb2_close_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 2000 | |
| 2001 | if (rc != 0) { |
Namjae Jeon | d4a029d | 2014-08-20 19:39:59 +0900 | [diff] [blame] | 2002 | cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 2003 | goto close_exit; |
| 2004 | } |
| 2005 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 2006 | /* BB FIXME - decode close response, update inode for caching */ |
| 2007 | |
| 2008 | close_exit: |
| 2009 | free_rsp_buf(resp_buftype, rsp); |
| 2010 | return rc; |
| 2011 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2012 | |
| 2013 | static int |
| 2014 | validate_buf(unsigned int offset, unsigned int buffer_length, |
| 2015 | struct smb2_hdr *hdr, unsigned int min_buf_size) |
| 2016 | |
| 2017 | { |
| 2018 | unsigned int smb_len = be32_to_cpu(hdr->smb2_buf_length); |
| 2019 | char *end_of_smb = smb_len + 4 /* RFC1001 length field */ + (char *)hdr; |
| 2020 | char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr; |
| 2021 | char *end_of_buf = begin_of_buf + buffer_length; |
| 2022 | |
| 2023 | |
| 2024 | if (buffer_length < min_buf_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2025 | cifs_dbg(VFS, "buffer length %d smaller than minimum size %d\n", |
| 2026 | buffer_length, min_buf_size); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2027 | return -EINVAL; |
| 2028 | } |
| 2029 | |
| 2030 | /* check if beyond RFC1001 maximum length */ |
| 2031 | if ((smb_len > 0x7FFFFF) || (buffer_length > 0x7FFFFF)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2032 | cifs_dbg(VFS, "buffer length %d or smb length %d too large\n", |
| 2033 | buffer_length, smb_len); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2034 | return -EINVAL; |
| 2035 | } |
| 2036 | |
| 2037 | if ((begin_of_buf > end_of_smb) || (end_of_buf > end_of_smb)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2038 | cifs_dbg(VFS, "illegal server response, bad offset to data\n"); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2039 | return -EINVAL; |
| 2040 | } |
| 2041 | |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | /* |
| 2046 | * If SMB buffer fields are valid, copy into temporary buffer to hold result. |
| 2047 | * Caller must free buffer. |
| 2048 | */ |
| 2049 | static int |
| 2050 | validate_and_copy_buf(unsigned int offset, unsigned int buffer_length, |
| 2051 | struct smb2_hdr *hdr, unsigned int minbufsize, |
| 2052 | char *data) |
| 2053 | |
| 2054 | { |
| 2055 | char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr; |
| 2056 | int rc; |
| 2057 | |
| 2058 | if (!data) |
| 2059 | return -EINVAL; |
| 2060 | |
| 2061 | rc = validate_buf(offset, buffer_length, hdr, minbufsize); |
| 2062 | if (rc) |
| 2063 | return rc; |
| 2064 | |
| 2065 | memcpy(data, begin_of_buf, buffer_length); |
| 2066 | |
| 2067 | return 0; |
| 2068 | } |
| 2069 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2070 | static int |
| 2071 | query_info(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2072 | u64 persistent_fid, u64 volatile_fid, u8 info_class, u8 info_type, |
| 2073 | u32 additional_info, size_t output_len, size_t min_len, void **data, |
| 2074 | u32 *dlen) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2075 | { |
| 2076 | struct smb2_query_info_req *req; |
| 2077 | struct smb2_query_info_rsp *rsp = NULL; |
| 2078 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2079 | struct kvec rsp_iov; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2080 | int rc = 0; |
| 2081 | int resp_buftype; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2082 | struct cifs_ses *ses = tcon->ses; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2083 | int flags = 0; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2084 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2085 | cifs_dbg(FYI, "Query Info\n"); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2086 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 2087 | if (!ses || !(ses->server)) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2088 | return -EIO; |
| 2089 | |
| 2090 | rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req); |
| 2091 | if (rc) |
| 2092 | return rc; |
| 2093 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2094 | if (encryption_required(tcon)) |
| 2095 | flags |= CIFS_TRANSFORM_REQ; |
| 2096 | |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2097 | req->InfoType = info_type; |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2098 | req->FileInfoClass = info_class; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2099 | req->PersistentFileId = persistent_fid; |
| 2100 | req->VolatileFileId = volatile_fid; |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2101 | req->AdditionalInformation = cpu_to_le32(additional_info); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2102 | /* 4 for rfc1002 length field and 1 for Buffer */ |
| 2103 | req->InputBufferOffset = |
| 2104 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2105 | req->OutputBufferLength = cpu_to_le32(output_len); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2106 | |
| 2107 | iov[0].iov_base = (char *)req; |
| 2108 | /* 4 for rfc1002 length field */ |
| 2109 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 2110 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2111 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2112 | cifs_small_buf_release(req); |
| 2113 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2114 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2115 | if (rc) { |
| 2116 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); |
| 2117 | goto qinf_exit; |
| 2118 | } |
| 2119 | |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2120 | if (dlen) { |
| 2121 | *dlen = le32_to_cpu(rsp->OutputBufferLength); |
| 2122 | if (!*data) { |
| 2123 | *data = kmalloc(*dlen, GFP_KERNEL); |
| 2124 | if (!*data) { |
| 2125 | cifs_dbg(VFS, |
| 2126 | "Error %d allocating memory for acl\n", |
| 2127 | rc); |
| 2128 | *dlen = 0; |
| 2129 | goto qinf_exit; |
| 2130 | } |
| 2131 | } |
| 2132 | } |
| 2133 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2134 | rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset), |
| 2135 | le32_to_cpu(rsp->OutputBufferLength), |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2136 | &rsp->hdr, min_len, *data); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2137 | |
| 2138 | qinf_exit: |
| 2139 | free_rsp_buf(resp_buftype, rsp); |
| 2140 | return rc; |
| 2141 | } |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2142 | |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2143 | int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 2144 | u64 persistent_fid, u64 volatile_fid, struct smb2_file_all_info *data) |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2145 | { |
| 2146 | return query_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2147 | FILE_ALL_INFORMATION, SMB2_O_INFO_FILE, 0, |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 2148 | sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2149 | sizeof(struct smb2_file_all_info), (void **)&data, |
| 2150 | NULL); |
| 2151 | } |
| 2152 | |
| 2153 | int |
| 2154 | SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon, |
| 2155 | u64 persistent_fid, u64 volatile_fid, |
| 2156 | void **data, u32 *plen) |
| 2157 | { |
| 2158 | __u32 additional_info = OWNER_SECINFO | GROUP_SECINFO | DACL_SECINFO; |
| 2159 | *plen = 0; |
| 2160 | |
| 2161 | return query_info(xid, tcon, persistent_fid, volatile_fid, |
| 2162 | 0, SMB2_O_INFO_SECURITY, additional_info, |
| 2163 | SMB2_MAX_BUFFER_SIZE, |
| 2164 | sizeof(struct smb2_file_all_info), data, plen); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | int |
| 2168 | SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, |
| 2169 | u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid) |
| 2170 | { |
| 2171 | return query_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2172 | FILE_INTERNAL_INFORMATION, SMB2_O_INFO_FILE, 0, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2173 | sizeof(struct smb2_file_internal_info), |
Shirish Pargaonkar | 42c493c | 2017-06-22 22:51:31 -0500 | [diff] [blame] | 2174 | sizeof(struct smb2_file_internal_info), |
| 2175 | (void **)&uniqueid, NULL); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2178 | /* |
| 2179 | * This is a no-op for now. We're not really interested in the reply, but |
| 2180 | * rather in the fact that the server sent one and that server->lstrp |
| 2181 | * gets updated. |
| 2182 | * |
| 2183 | * FIXME: maybe we should consider checking that the reply matches request? |
| 2184 | */ |
| 2185 | static void |
| 2186 | smb2_echo_callback(struct mid_q_entry *mid) |
| 2187 | { |
| 2188 | struct TCP_Server_Info *server = mid->callback_data; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2189 | struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2190 | unsigned int credits_received = 1; |
| 2191 | |
| 2192 | if (mid->mid_state == MID_RESPONSE_RECEIVED) |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2193 | credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest); |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2194 | |
| 2195 | DeleteMidQEntry(mid); |
| 2196 | add_credits(server, credits_received, CIFS_ECHO_OP); |
| 2197 | } |
| 2198 | |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2199 | void smb2_reconnect_server(struct work_struct *work) |
| 2200 | { |
| 2201 | struct TCP_Server_Info *server = container_of(work, |
| 2202 | struct TCP_Server_Info, reconnect.work); |
| 2203 | struct cifs_ses *ses; |
| 2204 | struct cifs_tcon *tcon, *tcon2; |
| 2205 | struct list_head tmp_list; |
| 2206 | int tcon_exist = false; |
Germano Percossi | 18ea431 | 2017-04-07 12:29:36 +0100 | [diff] [blame] | 2207 | int rc; |
| 2208 | int resched = false; |
| 2209 | |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2210 | |
| 2211 | /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ |
| 2212 | mutex_lock(&server->reconnect_mutex); |
| 2213 | |
| 2214 | INIT_LIST_HEAD(&tmp_list); |
| 2215 | cifs_dbg(FYI, "Need negotiate, reconnecting tcons\n"); |
| 2216 | |
| 2217 | spin_lock(&cifs_tcp_ses_lock); |
| 2218 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 2219 | list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { |
Pavel Shilovsky | 96a988f | 2016-11-29 11:31:23 -0800 | [diff] [blame] | 2220 | if (tcon->need_reconnect || tcon->need_reopen_files) { |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2221 | tcon->tc_count++; |
| 2222 | list_add_tail(&tcon->rlist, &tmp_list); |
| 2223 | tcon_exist = true; |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | /* |
| 2228 | * Get the reference to server struct to be sure that the last call of |
| 2229 | * cifs_put_tcon() in the loop below won't release the server pointer. |
| 2230 | */ |
| 2231 | if (tcon_exist) |
| 2232 | server->srv_count++; |
| 2233 | |
| 2234 | spin_unlock(&cifs_tcp_ses_lock); |
| 2235 | |
| 2236 | list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { |
Germano Percossi | 18ea431 | 2017-04-07 12:29:36 +0100 | [diff] [blame] | 2237 | rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon); |
| 2238 | if (!rc) |
Pavel Shilovsky | 96a988f | 2016-11-29 11:31:23 -0800 | [diff] [blame] | 2239 | cifs_reopen_persistent_handles(tcon); |
Germano Percossi | 18ea431 | 2017-04-07 12:29:36 +0100 | [diff] [blame] | 2240 | else |
| 2241 | resched = true; |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2242 | list_del_init(&tcon->rlist); |
| 2243 | cifs_put_tcon(tcon); |
| 2244 | } |
| 2245 | |
| 2246 | cifs_dbg(FYI, "Reconnecting tcons finished\n"); |
Germano Percossi | 18ea431 | 2017-04-07 12:29:36 +0100 | [diff] [blame] | 2247 | if (resched) |
| 2248 | queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2249 | mutex_unlock(&server->reconnect_mutex); |
| 2250 | |
| 2251 | /* now we can safely release srv struct */ |
| 2252 | if (tcon_exist) |
| 2253 | cifs_put_tcp_session(server, 1); |
| 2254 | } |
| 2255 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2256 | int |
| 2257 | SMB2_echo(struct TCP_Server_Info *server) |
| 2258 | { |
| 2259 | struct smb2_echo_req *req; |
| 2260 | int rc = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2261 | struct kvec iov[2]; |
| 2262 | struct smb_rqst rqst = { .rq_iov = iov, |
| 2263 | .rq_nvec = 2 }; |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2264 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2265 | cifs_dbg(FYI, "In echo request\n"); |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2266 | |
Steve French | 4fcd181 | 2016-06-22 20:12:05 -0500 | [diff] [blame] | 2267 | if (server->tcpStatus == CifsNeedNegotiate) { |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2268 | /* No need to send echo on newly established connections */ |
| 2269 | queue_delayed_work(cifsiod_wq, &server->reconnect, 0); |
| 2270 | return rc; |
Steve French | 4fcd181 | 2016-06-22 20:12:05 -0500 | [diff] [blame] | 2271 | } |
| 2272 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2273 | rc = small_smb2_init(SMB2_ECHO, NULL, (void **)&req); |
| 2274 | if (rc) |
| 2275 | return rc; |
| 2276 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2277 | req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1); |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2278 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2279 | /* 4 for rfc1002 length field */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2280 | iov[0].iov_len = 4; |
| 2281 | iov[0].iov_base = (char *)req; |
| 2282 | iov[1].iov_len = get_rfc1002_length(req); |
| 2283 | iov[1].iov_base = (char *)req + 4; |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2284 | |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 2285 | rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, NULL, |
| 2286 | server, CIFS_ECHO_OP); |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2287 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2288 | cifs_dbg(FYI, "Echo request failed: %d\n", rc); |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2289 | |
| 2290 | cifs_small_buf_release(req); |
| 2291 | return rc; |
| 2292 | } |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2293 | |
| 2294 | int |
| 2295 | SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, |
| 2296 | u64 volatile_fid) |
| 2297 | { |
| 2298 | struct smb2_flush_req *req; |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2299 | struct cifs_ses *ses = tcon->ses; |
| 2300 | struct kvec iov[1]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2301 | struct kvec rsp_iov; |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2302 | int resp_buftype; |
| 2303 | int rc = 0; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2304 | int flags = 0; |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2305 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2306 | cifs_dbg(FYI, "Flush\n"); |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2307 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 2308 | if (!ses || !(ses->server)) |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2309 | return -EIO; |
| 2310 | |
| 2311 | rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req); |
| 2312 | if (rc) |
| 2313 | return rc; |
| 2314 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2315 | if (encryption_required(tcon)) |
| 2316 | flags |= CIFS_TRANSFORM_REQ; |
| 2317 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2318 | req->PersistentFileId = persistent_fid; |
| 2319 | req->VolatileFileId = volatile_fid; |
| 2320 | |
| 2321 | iov[0].iov_base = (char *)req; |
| 2322 | /* 4 for rfc1002 length field */ |
| 2323 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 2324 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2325 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2326 | cifs_small_buf_release(req); |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2327 | |
Steve French | dfebe40 | 2015-03-27 01:00:06 -0500 | [diff] [blame] | 2328 | if (rc != 0) |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2329 | cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE); |
| 2330 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2331 | free_rsp_buf(resp_buftype, rsp_iov.iov_base); |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2332 | return rc; |
| 2333 | } |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2334 | |
| 2335 | /* |
| 2336 | * To form a chain of read requests, any read requests after the first should |
| 2337 | * have the end_of_chain boolean set to true. |
| 2338 | */ |
| 2339 | static int |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2340 | smb2_new_read_req(void **buf, unsigned int *total_len, |
| 2341 | struct cifs_io_parms *io_parms, unsigned int remaining_bytes, |
| 2342 | int request_type) |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2343 | { |
| 2344 | int rc = -EACCES; |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2345 | struct smb2_read_plain_req *req = NULL; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2346 | struct smb2_sync_hdr *shdr; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2347 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2348 | rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, (void **) &req, |
| 2349 | total_len); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2350 | if (rc) |
| 2351 | return rc; |
| 2352 | if (io_parms->tcon->ses->server == NULL) |
| 2353 | return -ECONNABORTED; |
| 2354 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2355 | shdr = &req->sync_hdr; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2356 | shdr->ProcessId = cpu_to_le32(io_parms->pid); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2357 | |
| 2358 | req->PersistentFileId = io_parms->persistent_fid; |
| 2359 | req->VolatileFileId = io_parms->volatile_fid; |
| 2360 | req->ReadChannelInfoOffset = 0; /* reserved */ |
| 2361 | req->ReadChannelInfoLength = 0; /* reserved */ |
| 2362 | req->Channel = 0; /* reserved */ |
| 2363 | req->MinimumCount = 0; |
| 2364 | req->Length = cpu_to_le32(io_parms->length); |
| 2365 | req->Offset = cpu_to_le64(io_parms->offset); |
| 2366 | |
| 2367 | if (request_type & CHAINED_REQUEST) { |
| 2368 | if (!(request_type & END_OF_CHAIN)) { |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2369 | /* next 8-byte aligned request */ |
| 2370 | *total_len = DIV_ROUND_UP(*total_len, 8) * 8; |
| 2371 | shdr->NextCommand = cpu_to_le32(*total_len); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2372 | } else /* END_OF_CHAIN */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2373 | shdr->NextCommand = 0; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2374 | if (request_type & RELATED_REQUEST) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2375 | shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2376 | /* |
| 2377 | * Related requests use info from previous read request |
| 2378 | * in chain. |
| 2379 | */ |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2380 | shdr->SessionId = 0xFFFFFFFF; |
| 2381 | shdr->TreeId = 0xFFFFFFFF; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2382 | req->PersistentFileId = 0xFFFFFFFF; |
| 2383 | req->VolatileFileId = 0xFFFFFFFF; |
| 2384 | } |
| 2385 | } |
| 2386 | if (remaining_bytes > io_parms->length) |
| 2387 | req->RemainingBytes = cpu_to_le32(remaining_bytes); |
| 2388 | else |
| 2389 | req->RemainingBytes = 0; |
| 2390 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2391 | *buf = req; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2392 | return rc; |
| 2393 | } |
| 2394 | |
| 2395 | static void |
| 2396 | smb2_readv_callback(struct mid_q_entry *mid) |
| 2397 | { |
| 2398 | struct cifs_readdata *rdata = mid->callback_data; |
| 2399 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
| 2400 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2401 | struct smb2_sync_hdr *shdr = |
| 2402 | (struct smb2_sync_hdr *)rdata->iov[1].iov_base; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2403 | unsigned int credits_received = 1; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2404 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 2405 | .rq_nvec = 2, |
Jeff Layton | 8321fec | 2012-09-19 06:22:32 -0700 | [diff] [blame] | 2406 | .rq_pages = rdata->pages, |
| 2407 | .rq_npages = rdata->nr_pages, |
| 2408 | .rq_pagesz = rdata->pagesz, |
| 2409 | .rq_tailsz = rdata->tailsz }; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2410 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2411 | cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", |
| 2412 | __func__, mid->mid, mid->mid_state, rdata->result, |
| 2413 | rdata->bytes); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2414 | |
| 2415 | switch (mid->mid_state) { |
| 2416 | case MID_RESPONSE_RECEIVED: |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2417 | credits_received = le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2418 | /* result already set, check signature */ |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2419 | if (server->sign && !mid->decrypted) { |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2420 | int rc; |
| 2421 | |
Jeff Layton | 0b688cf | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2422 | rc = smb2_verify_signature(&rqst, server); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2423 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2424 | cifs_dbg(VFS, "SMB signature verification returned error = %d\n", |
| 2425 | rc); |
Pavel Shilovsky | 3c1bf7e | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2426 | } |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2427 | /* FIXME: should this be counted toward the initiating task? */ |
Pavel Shilovsky | 34a54d6 | 2014-07-10 10:03:29 +0400 | [diff] [blame] | 2428 | task_io_account_read(rdata->got_bytes); |
| 2429 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2430 | break; |
| 2431 | case MID_REQUEST_SUBMITTED: |
| 2432 | case MID_RETRY_NEEDED: |
| 2433 | rdata->result = -EAGAIN; |
Pavel Shilovsky | d913ed1 | 2014-07-10 11:31:48 +0400 | [diff] [blame] | 2434 | if (server->sign && rdata->got_bytes) |
| 2435 | /* reset bytes number since we can not check a sign */ |
| 2436 | rdata->got_bytes = 0; |
| 2437 | /* FIXME: should this be counted toward the initiating task? */ |
| 2438 | task_io_account_read(rdata->got_bytes); |
| 2439 | cifs_stats_bytes_read(tcon, rdata->got_bytes); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2440 | break; |
| 2441 | default: |
| 2442 | if (rdata->result != -ENODATA) |
| 2443 | rdata->result = -EIO; |
| 2444 | } |
| 2445 | |
| 2446 | if (rdata->result) |
| 2447 | cifs_stats_fail_inc(tcon, SMB2_READ_HE); |
| 2448 | |
| 2449 | queue_work(cifsiod_wq, &rdata->work); |
| 2450 | DeleteMidQEntry(mid); |
| 2451 | add_credits(server, credits_received, 0); |
| 2452 | } |
| 2453 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2454 | /* smb2_async_readv - send an async read, and set up mid to handle result */ |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2455 | int |
| 2456 | smb2_async_readv(struct cifs_readdata *rdata) |
| 2457 | { |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2458 | int rc, flags = 0; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2459 | char *buf; |
| 2460 | struct smb2_sync_hdr *shdr; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2461 | struct cifs_io_parms io_parms; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2462 | struct smb_rqst rqst = { .rq_iov = rdata->iov, |
| 2463 | .rq_nvec = 2 }; |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2464 | struct TCP_Server_Info *server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2465 | unsigned int total_len; |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2466 | __be32 req_len; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2467 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2468 | cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n", |
| 2469 | __func__, rdata->offset, rdata->bytes); |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2470 | |
| 2471 | io_parms.tcon = tlink_tcon(rdata->cfile->tlink); |
| 2472 | io_parms.offset = rdata->offset; |
| 2473 | io_parms.length = rdata->bytes; |
| 2474 | io_parms.persistent_fid = rdata->cfile->fid.persistent_fid; |
| 2475 | io_parms.volatile_fid = rdata->cfile->fid.volatile_fid; |
| 2476 | io_parms.pid = rdata->pid; |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2477 | |
| 2478 | server = io_parms.tcon->ses->server; |
| 2479 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2480 | rc = smb2_new_read_req((void **) &buf, &total_len, &io_parms, 0, 0); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2481 | if (rc) { |
| 2482 | if (rc == -EAGAIN && rdata->credits) { |
| 2483 | /* credits was reset by reconnect */ |
| 2484 | rdata->credits = 0; |
| 2485 | /* reduce in_flight value since we won't send the req */ |
| 2486 | spin_lock(&server->req_lock); |
| 2487 | server->in_flight--; |
| 2488 | spin_unlock(&server->req_lock); |
| 2489 | } |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2490 | return rc; |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2491 | } |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2492 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2493 | if (encryption_required(io_parms.tcon)) |
| 2494 | flags |= CIFS_TRANSFORM_REQ; |
| 2495 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2496 | req_len = cpu_to_be32(total_len); |
| 2497 | |
| 2498 | rdata->iov[0].iov_base = &req_len; |
| 2499 | rdata->iov[0].iov_len = sizeof(__be32); |
| 2500 | rdata->iov[1].iov_base = buf; |
| 2501 | rdata->iov[1].iov_len = total_len; |
| 2502 | |
| 2503 | shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2504 | |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2505 | if (rdata->credits) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2506 | shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2507 | SMB2_MAX_BUFFER_SIZE)); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2508 | shdr->CreditRequest = shdr->CreditCharge; |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2509 | spin_lock(&server->req_lock); |
| 2510 | server->credits += rdata->credits - |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2511 | le16_to_cpu(shdr->CreditCharge); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2512 | spin_unlock(&server->req_lock); |
| 2513 | wake_up(&server->request_q); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2514 | flags |= CIFS_HAS_CREDITS; |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2517 | kref_get(&rdata->refcount); |
Jeff Layton | fec344e | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2518 | rc = cifs_call_async(io_parms.tcon->ses->server, &rqst, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2519 | cifs_readv_receive, smb2_readv_callback, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2520 | smb3_handle_read_data, rdata, flags); |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2521 | if (rc) { |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2522 | kref_put(&rdata->refcount, cifs_readdata_release); |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2523 | cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); |
| 2524 | } |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2525 | |
| 2526 | cifs_small_buf_release(buf); |
| 2527 | return rc; |
| 2528 | } |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2529 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2530 | int |
| 2531 | SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 2532 | unsigned int *nbytes, char **buf, int *buf_type) |
| 2533 | { |
| 2534 | int resp_buftype, rc = -EACCES; |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2535 | struct smb2_read_plain_req *req = NULL; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2536 | struct smb2_read_rsp *rsp = NULL; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2537 | struct smb2_sync_hdr *shdr; |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2538 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2539 | struct kvec rsp_iov; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2540 | unsigned int total_len; |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2541 | __be32 req_len; |
| 2542 | struct smb_rqst rqst = { .rq_iov = iov, |
| 2543 | .rq_nvec = 2 }; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2544 | int flags = CIFS_LOG_ERROR; |
| 2545 | struct cifs_ses *ses = io_parms->tcon->ses; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2546 | |
| 2547 | *nbytes = 0; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2548 | rc = smb2_new_read_req((void **)&req, &total_len, io_parms, 0, 0); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2549 | if (rc) |
| 2550 | return rc; |
| 2551 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2552 | if (encryption_required(io_parms->tcon)) |
| 2553 | flags |= CIFS_TRANSFORM_REQ; |
| 2554 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2555 | req_len = cpu_to_be32(total_len); |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2556 | |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2557 | iov[0].iov_base = &req_len; |
| 2558 | iov[0].iov_len = sizeof(__be32); |
| 2559 | iov[1].iov_base = req; |
| 2560 | iov[1].iov_len = total_len; |
| 2561 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2562 | rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | b8f57ee | 2016-11-23 15:31:54 -0800 | [diff] [blame] | 2563 | cifs_small_buf_release(req); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2564 | |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2565 | rsp = (struct smb2_read_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2566 | shdr = get_sync_hdr(rsp); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2567 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2568 | if (shdr->Status == STATUS_END_OF_FILE) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2569 | free_rsp_buf(resp_buftype, rsp_iov.iov_base); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2570 | return 0; |
| 2571 | } |
| 2572 | |
| 2573 | if (rc) { |
| 2574 | cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2575 | cifs_dbg(VFS, "Send error in read = %d\n", rc); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2576 | } else { |
| 2577 | *nbytes = le32_to_cpu(rsp->DataLength); |
| 2578 | if ((*nbytes > CIFS_MAX_MSGSIZE) || |
| 2579 | (*nbytes > io_parms->length)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2580 | cifs_dbg(FYI, "bad length %d for count %d\n", |
| 2581 | *nbytes, io_parms->length); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2582 | rc = -EIO; |
| 2583 | *nbytes = 0; |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | if (*buf) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2588 | memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2589 | free_rsp_buf(resp_buftype, rsp_iov.iov_base); |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2590 | } else if (resp_buftype != CIFS_NO_BUFFER) { |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2591 | *buf = rsp_iov.iov_base; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2592 | if (resp_buftype == CIFS_SMALL_BUFFER) |
| 2593 | *buf_type = CIFS_SMALL_BUFFER; |
| 2594 | else if (resp_buftype == CIFS_LARGE_BUFFER) |
| 2595 | *buf_type = CIFS_LARGE_BUFFER; |
| 2596 | } |
| 2597 | return rc; |
| 2598 | } |
| 2599 | |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2600 | /* |
| 2601 | * Check the mid_state and signature on received buffer (if any), and queue the |
| 2602 | * workqueue completion task. |
| 2603 | */ |
| 2604 | static void |
| 2605 | smb2_writev_callback(struct mid_q_entry *mid) |
| 2606 | { |
| 2607 | struct cifs_writedata *wdata = mid->callback_data; |
| 2608 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
| 2609 | unsigned int written; |
| 2610 | struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; |
| 2611 | unsigned int credits_received = 1; |
| 2612 | |
| 2613 | switch (mid->mid_state) { |
| 2614 | case MID_RESPONSE_RECEIVED: |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2615 | credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest); |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2616 | wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); |
| 2617 | if (wdata->result != 0) |
| 2618 | break; |
| 2619 | |
| 2620 | written = le32_to_cpu(rsp->DataLength); |
| 2621 | /* |
| 2622 | * Mask off high 16 bits when bytes written as returned |
| 2623 | * by the server is greater than bytes requested by the |
| 2624 | * client. OS/2 servers are known to set incorrect |
| 2625 | * CountHigh values. |
| 2626 | */ |
| 2627 | if (written > wdata->bytes) |
| 2628 | written &= 0xFFFF; |
| 2629 | |
| 2630 | if (written < wdata->bytes) |
| 2631 | wdata->result = -ENOSPC; |
| 2632 | else |
| 2633 | wdata->bytes = written; |
| 2634 | break; |
| 2635 | case MID_REQUEST_SUBMITTED: |
| 2636 | case MID_RETRY_NEEDED: |
| 2637 | wdata->result = -EAGAIN; |
| 2638 | break; |
| 2639 | default: |
| 2640 | wdata->result = -EIO; |
| 2641 | break; |
| 2642 | } |
| 2643 | |
| 2644 | if (wdata->result) |
| 2645 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); |
| 2646 | |
| 2647 | queue_work(cifsiod_wq, &wdata->work); |
| 2648 | DeleteMidQEntry(mid); |
| 2649 | add_credits(tcon->ses->server, credits_received, 0); |
| 2650 | } |
| 2651 | |
| 2652 | /* smb2_async_writev - send an async write, and set up mid to handle result */ |
| 2653 | int |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2654 | smb2_async_writev(struct cifs_writedata *wdata, |
| 2655 | void (*release)(struct kref *kref)) |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2656 | { |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2657 | int rc = -EACCES, flags = 0; |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2658 | struct smb2_write_req *req = NULL; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2659 | struct smb2_sync_hdr *shdr; |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2660 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2661 | struct TCP_Server_Info *server = tcon->ses->server; |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2662 | struct kvec iov[2]; |
| 2663 | struct smb_rqst rqst = { }; |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2664 | |
| 2665 | rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2666 | if (rc) { |
| 2667 | if (rc == -EAGAIN && wdata->credits) { |
| 2668 | /* credits was reset by reconnect */ |
| 2669 | wdata->credits = 0; |
| 2670 | /* reduce in_flight value since we won't send the req */ |
| 2671 | spin_lock(&server->req_lock); |
| 2672 | server->in_flight--; |
| 2673 | spin_unlock(&server->req_lock); |
| 2674 | } |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2675 | goto async_writev_out; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2676 | } |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2677 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2678 | if (encryption_required(tcon)) |
| 2679 | flags |= CIFS_TRANSFORM_REQ; |
| 2680 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2681 | shdr = get_sync_hdr(req); |
| 2682 | shdr->ProcessId = cpu_to_le32(wdata->cfile->pid); |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2683 | |
| 2684 | req->PersistentFileId = wdata->cfile->fid.persistent_fid; |
| 2685 | req->VolatileFileId = wdata->cfile->fid.volatile_fid; |
| 2686 | req->WriteChannelInfoOffset = 0; |
| 2687 | req->WriteChannelInfoLength = 0; |
| 2688 | req->Channel = 0; |
| 2689 | req->Offset = cpu_to_le64(wdata->offset); |
| 2690 | /* 4 for rfc1002 length field */ |
| 2691 | req->DataOffset = cpu_to_le16( |
| 2692 | offsetof(struct smb2_write_req, Buffer) - 4); |
| 2693 | req->RemainingBytes = 0; |
| 2694 | |
| 2695 | /* 4 for rfc1002 length field and 1 for Buffer */ |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2696 | iov[0].iov_len = 4; |
| 2697 | iov[0].iov_base = req; |
| 2698 | iov[1].iov_len = get_rfc1002_length(req) - 1; |
| 2699 | iov[1].iov_base = (char *)req + 4; |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2700 | |
Pavel Shilovsky | 738f9de | 2016-11-23 15:14:57 -0800 | [diff] [blame] | 2701 | rqst.rq_iov = iov; |
| 2702 | rqst.rq_nvec = 2; |
Jeff Layton | eddb079 | 2012-09-18 16:20:35 -0700 | [diff] [blame] | 2703 | rqst.rq_pages = wdata->pages; |
| 2704 | rqst.rq_npages = wdata->nr_pages; |
| 2705 | rqst.rq_pagesz = wdata->pagesz; |
| 2706 | rqst.rq_tailsz = wdata->tailsz; |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2707 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2708 | cifs_dbg(FYI, "async write at %llu %u bytes\n", |
| 2709 | wdata->offset, wdata->bytes); |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2710 | |
| 2711 | req->Length = cpu_to_le32(wdata->bytes); |
| 2712 | |
| 2713 | inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */); |
| 2714 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2715 | if (wdata->credits) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2716 | shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2717 | SMB2_MAX_BUFFER_SIZE)); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2718 | shdr->CreditRequest = shdr->CreditCharge; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2719 | spin_lock(&server->req_lock); |
| 2720 | server->credits += wdata->credits - |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2721 | le16_to_cpu(shdr->CreditCharge); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2722 | spin_unlock(&server->req_lock); |
| 2723 | wake_up(&server->request_q); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2724 | flags |= CIFS_HAS_CREDITS; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2725 | } |
| 2726 | |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2727 | kref_get(&wdata->refcount); |
Pavel Shilovsky | 9b7c18a | 2016-11-16 14:06:17 -0800 | [diff] [blame] | 2728 | rc = cifs_call_async(server, &rqst, NULL, smb2_writev_callback, NULL, |
| 2729 | wdata, flags); |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2730 | |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2731 | if (rc) { |
Steve French | 4a5c80d | 2014-02-07 20:45:12 -0600 | [diff] [blame] | 2732 | kref_put(&wdata->refcount, release); |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2733 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); |
| 2734 | } |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2735 | |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2736 | async_writev_out: |
| 2737 | cifs_small_buf_release(req); |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2738 | return rc; |
| 2739 | } |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2740 | |
| 2741 | /* |
| 2742 | * SMB2_write function gets iov pointer to kvec array with n_vec as a length. |
| 2743 | * The length field from io_parms must be at least 1 and indicates a number of |
| 2744 | * elements with data to write that begins with position 1 in iov array. All |
| 2745 | * data length is specified by count. |
| 2746 | */ |
| 2747 | int |
| 2748 | SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, |
| 2749 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
| 2750 | { |
| 2751 | int rc = 0; |
| 2752 | struct smb2_write_req *req = NULL; |
| 2753 | struct smb2_write_rsp *rsp = NULL; |
| 2754 | int resp_buftype; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2755 | struct kvec rsp_iov; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2756 | int flags = 0; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2757 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2758 | *nbytes = 0; |
| 2759 | |
| 2760 | if (n_vec < 1) |
| 2761 | return rc; |
| 2762 | |
| 2763 | rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req); |
| 2764 | if (rc) |
| 2765 | return rc; |
| 2766 | |
| 2767 | if (io_parms->tcon->ses->server == NULL) |
| 2768 | return -ECONNABORTED; |
| 2769 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2770 | if (encryption_required(io_parms->tcon)) |
| 2771 | flags |= CIFS_TRANSFORM_REQ; |
| 2772 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2773 | req->hdr.sync_hdr.ProcessId = cpu_to_le32(io_parms->pid); |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2774 | |
| 2775 | req->PersistentFileId = io_parms->persistent_fid; |
| 2776 | req->VolatileFileId = io_parms->volatile_fid; |
| 2777 | req->WriteChannelInfoOffset = 0; |
| 2778 | req->WriteChannelInfoLength = 0; |
| 2779 | req->Channel = 0; |
| 2780 | req->Length = cpu_to_le32(io_parms->length); |
| 2781 | req->Offset = cpu_to_le64(io_parms->offset); |
| 2782 | /* 4 for rfc1002 length field */ |
| 2783 | req->DataOffset = cpu_to_le16( |
| 2784 | offsetof(struct smb2_write_req, Buffer) - 4); |
| 2785 | req->RemainingBytes = 0; |
| 2786 | |
| 2787 | iov[0].iov_base = (char *)req; |
| 2788 | /* 4 for rfc1002 length field and 1 for Buffer */ |
| 2789 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; |
| 2790 | |
| 2791 | /* length of entire message including data to be written */ |
| 2792 | inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */); |
| 2793 | |
| 2794 | rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1, |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2795 | &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2796 | cifs_small_buf_release(req); |
| 2797 | rsp = (struct smb2_write_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2798 | |
| 2799 | if (rc) { |
| 2800 | cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2801 | cifs_dbg(VFS, "Send error in write = %d\n", rc); |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2802 | } else |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2803 | *nbytes = le32_to_cpu(rsp->DataLength); |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2804 | |
| 2805 | free_rsp_buf(resp_buftype, rsp); |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2806 | return rc; |
| 2807 | } |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2808 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2809 | static unsigned int |
| 2810 | num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size) |
| 2811 | { |
| 2812 | int len; |
| 2813 | unsigned int entrycount = 0; |
| 2814 | unsigned int next_offset = 0; |
| 2815 | FILE_DIRECTORY_INFO *entryptr; |
| 2816 | |
| 2817 | if (bufstart == NULL) |
| 2818 | return 0; |
| 2819 | |
| 2820 | entryptr = (FILE_DIRECTORY_INFO *)bufstart; |
| 2821 | |
| 2822 | while (1) { |
| 2823 | entryptr = (FILE_DIRECTORY_INFO *) |
| 2824 | ((char *)entryptr + next_offset); |
| 2825 | |
| 2826 | if ((char *)entryptr + size > end_of_buf) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2827 | cifs_dbg(VFS, "malformed search entry would overflow\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2828 | break; |
| 2829 | } |
| 2830 | |
| 2831 | len = le32_to_cpu(entryptr->FileNameLength); |
| 2832 | if ((char *)entryptr + len + size > end_of_buf) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2833 | cifs_dbg(VFS, "directory entry name would overflow frame end of buf %p\n", |
| 2834 | end_of_buf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2835 | break; |
| 2836 | } |
| 2837 | |
| 2838 | *lastentry = (char *)entryptr; |
| 2839 | entrycount++; |
| 2840 | |
| 2841 | next_offset = le32_to_cpu(entryptr->NextEntryOffset); |
| 2842 | if (!next_offset) |
| 2843 | break; |
| 2844 | } |
| 2845 | |
| 2846 | return entrycount; |
| 2847 | } |
| 2848 | |
| 2849 | /* |
| 2850 | * Readdir/FindFirst |
| 2851 | */ |
| 2852 | int |
| 2853 | SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, |
| 2854 | u64 persistent_fid, u64 volatile_fid, int index, |
| 2855 | struct cifs_search_info *srch_inf) |
| 2856 | { |
| 2857 | struct smb2_query_directory_req *req; |
| 2858 | struct smb2_query_directory_rsp *rsp = NULL; |
| 2859 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2860 | struct kvec rsp_iov; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2861 | int rc = 0; |
| 2862 | int len; |
Steve French | 75fdfc8 | 2015-03-25 18:51:57 -0500 | [diff] [blame] | 2863 | int resp_buftype = CIFS_NO_BUFFER; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2864 | unsigned char *bufptr; |
| 2865 | struct TCP_Server_Info *server; |
| 2866 | struct cifs_ses *ses = tcon->ses; |
| 2867 | __le16 asteriks = cpu_to_le16('*'); |
| 2868 | char *end_of_smb; |
| 2869 | unsigned int output_size = CIFSMaxBufSize; |
| 2870 | size_t info_buf_size; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2871 | int flags = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2872 | |
| 2873 | if (ses && (ses->server)) |
| 2874 | server = ses->server; |
| 2875 | else |
| 2876 | return -EIO; |
| 2877 | |
| 2878 | rc = small_smb2_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req); |
| 2879 | if (rc) |
| 2880 | return rc; |
| 2881 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2882 | if (encryption_required(tcon)) |
| 2883 | flags |= CIFS_TRANSFORM_REQ; |
| 2884 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2885 | switch (srch_inf->info_level) { |
| 2886 | case SMB_FIND_FILE_DIRECTORY_INFO: |
| 2887 | req->FileInformationClass = FILE_DIRECTORY_INFORMATION; |
| 2888 | info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1; |
| 2889 | break; |
| 2890 | case SMB_FIND_FILE_ID_FULL_DIR_INFO: |
| 2891 | req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; |
| 2892 | info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1; |
| 2893 | break; |
| 2894 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2895 | cifs_dbg(VFS, "info level %u isn't supported\n", |
| 2896 | srch_inf->info_level); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2897 | rc = -EINVAL; |
| 2898 | goto qdir_exit; |
| 2899 | } |
| 2900 | |
| 2901 | req->FileIndex = cpu_to_le32(index); |
| 2902 | req->PersistentFileId = persistent_fid; |
| 2903 | req->VolatileFileId = volatile_fid; |
| 2904 | |
| 2905 | len = 0x2; |
| 2906 | bufptr = req->Buffer; |
| 2907 | memcpy(bufptr, &asteriks, len); |
| 2908 | |
| 2909 | req->FileNameOffset = |
| 2910 | cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1 - 4); |
| 2911 | req->FileNameLength = cpu_to_le16(len); |
| 2912 | /* |
| 2913 | * BB could be 30 bytes or so longer if we used SMB2 specific |
| 2914 | * buffer lengths, but this is safe and close enough. |
| 2915 | */ |
| 2916 | output_size = min_t(unsigned int, output_size, server->maxBuf); |
| 2917 | output_size = min_t(unsigned int, output_size, 2 << 15); |
| 2918 | req->OutputBufferLength = cpu_to_le32(output_size); |
| 2919 | |
| 2920 | iov[0].iov_base = (char *)req; |
| 2921 | /* 4 for RFC1001 length and 1 for Buffer */ |
| 2922 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; |
| 2923 | |
| 2924 | iov[1].iov_base = (char *)(req->Buffer); |
| 2925 | iov[1].iov_len = len; |
| 2926 | |
| 2927 | inc_rfc1001_len(req, len - 1 /* Buffer */); |
| 2928 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2929 | rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2930 | cifs_small_buf_release(req); |
| 2931 | rsp = (struct smb2_query_directory_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | e5d0488 | 2012-09-19 16:03:26 +0400 | [diff] [blame] | 2932 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2933 | if (rc) { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2934 | if (rc == -ENODATA && |
| 2935 | rsp->hdr.sync_hdr.Status == STATUS_NO_MORE_FILES) { |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2936 | srch_inf->endOfSearch = true; |
| 2937 | rc = 0; |
| 2938 | } |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2939 | cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); |
| 2940 | goto qdir_exit; |
| 2941 | } |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2942 | |
| 2943 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), |
| 2944 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, |
| 2945 | info_buf_size); |
| 2946 | if (rc) |
| 2947 | goto qdir_exit; |
| 2948 | |
| 2949 | srch_inf->unicode = true; |
| 2950 | |
| 2951 | if (srch_inf->ntwrk_buf_start) { |
| 2952 | if (srch_inf->smallBuf) |
| 2953 | cifs_small_buf_release(srch_inf->ntwrk_buf_start); |
| 2954 | else |
| 2955 | cifs_buf_release(srch_inf->ntwrk_buf_start); |
| 2956 | } |
| 2957 | srch_inf->ntwrk_buf_start = (char *)rsp; |
| 2958 | srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ + |
| 2959 | (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset); |
| 2960 | /* 4 for rfc1002 length field */ |
| 2961 | end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr; |
| 2962 | srch_inf->entries_in_buffer = |
| 2963 | num_entries(srch_inf->srch_entries_start, end_of_smb, |
| 2964 | &srch_inf->last_entry, info_buf_size); |
| 2965 | srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2966 | cifs_dbg(FYI, "num entries %d last_index %lld srch start %p srch end %p\n", |
| 2967 | srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, |
| 2968 | srch_inf->srch_entries_start, srch_inf->last_entry); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2969 | if (resp_buftype == CIFS_LARGE_BUFFER) |
| 2970 | srch_inf->smallBuf = false; |
| 2971 | else if (resp_buftype == CIFS_SMALL_BUFFER) |
| 2972 | srch_inf->smallBuf = true; |
| 2973 | else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2974 | cifs_dbg(VFS, "illegal search buffer type\n"); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2975 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2976 | return rc; |
| 2977 | |
| 2978 | qdir_exit: |
| 2979 | free_rsp_buf(resp_buftype, rsp); |
| 2980 | return rc; |
| 2981 | } |
| 2982 | |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2983 | static int |
| 2984 | send_set_info(const unsigned int xid, struct cifs_tcon *tcon, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 2985 | u64 persistent_fid, u64 volatile_fid, u32 pid, u8 info_class, |
| 2986 | u8 info_type, u32 additional_info, unsigned int num, |
| 2987 | void **data, unsigned int *size) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2988 | { |
| 2989 | struct smb2_set_info_req *req; |
| 2990 | struct smb2_set_info_rsp *rsp = NULL; |
| 2991 | struct kvec *iov; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 2992 | struct kvec rsp_iov; |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2993 | int rc = 0; |
| 2994 | int resp_buftype; |
| 2995 | unsigned int i; |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2996 | struct cifs_ses *ses = tcon->ses; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 2997 | int flags = 0; |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2998 | |
Christos Gkekas | 68a6afa | 2017-07-09 11:45:04 +0100 | [diff] [blame] | 2999 | if (!ses || !(ses->server)) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3000 | return -EIO; |
| 3001 | |
| 3002 | if (!num) |
| 3003 | return -EINVAL; |
| 3004 | |
| 3005 | iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL); |
| 3006 | if (!iov) |
| 3007 | return -ENOMEM; |
| 3008 | |
| 3009 | rc = small_smb2_init(SMB2_SET_INFO, tcon, (void **) &req); |
| 3010 | if (rc) { |
| 3011 | kfree(iov); |
| 3012 | return rc; |
| 3013 | } |
| 3014 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3015 | if (encryption_required(tcon)) |
| 3016 | flags |= CIFS_TRANSFORM_REQ; |
| 3017 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 3018 | req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3019 | |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3020 | req->InfoType = info_type; |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3021 | req->FileInfoClass = info_class; |
| 3022 | req->PersistentFileId = persistent_fid; |
| 3023 | req->VolatileFileId = volatile_fid; |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3024 | req->AdditionalInformation = cpu_to_le32(additional_info); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3025 | |
| 3026 | /* 4 for RFC1001 length and 1 for Buffer */ |
| 3027 | req->BufferOffset = |
| 3028 | cpu_to_le16(sizeof(struct smb2_set_info_req) - 1 - 4); |
| 3029 | req->BufferLength = cpu_to_le32(*size); |
| 3030 | |
| 3031 | inc_rfc1001_len(req, *size - 1 /* Buffer */); |
| 3032 | |
| 3033 | memcpy(req->Buffer, *data, *size); |
| 3034 | |
| 3035 | iov[0].iov_base = (char *)req; |
| 3036 | /* 4 for RFC1001 length */ |
| 3037 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
| 3038 | |
| 3039 | for (i = 1; i < num; i++) { |
| 3040 | inc_rfc1001_len(req, size[i]); |
| 3041 | le32_add_cpu(&req->BufferLength, size[i]); |
| 3042 | iov[i].iov_base = (char *)data[i]; |
| 3043 | iov[i].iov_len = size[i]; |
| 3044 | } |
| 3045 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3046 | rc = SendReceive2(xid, ses, iov, num, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3047 | cifs_small_buf_release(req); |
| 3048 | rsp = (struct smb2_set_info_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3049 | |
Steve French | 7d3fb24 | 2013-11-18 09:56:28 -0600 | [diff] [blame] | 3050 | if (rc != 0) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3051 | cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE); |
Steve French | 7d3fb24 | 2013-11-18 09:56:28 -0600 | [diff] [blame] | 3052 | |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3053 | free_rsp_buf(resp_buftype, rsp); |
| 3054 | kfree(iov); |
| 3055 | return rc; |
| 3056 | } |
| 3057 | |
| 3058 | int |
| 3059 | SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, |
| 3060 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) |
| 3061 | { |
| 3062 | struct smb2_file_rename_info info; |
| 3063 | void **data; |
| 3064 | unsigned int size[2]; |
| 3065 | int rc; |
| 3066 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); |
| 3067 | |
| 3068 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); |
| 3069 | if (!data) |
| 3070 | return -ENOMEM; |
| 3071 | |
| 3072 | info.ReplaceIfExists = 1; /* 1 = replace existing target with new */ |
| 3073 | /* 0 = fail if target already exists */ |
| 3074 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ |
| 3075 | info.FileNameLength = cpu_to_le32(len); |
| 3076 | |
| 3077 | data[0] = &info; |
| 3078 | size[0] = sizeof(struct smb2_file_rename_info); |
| 3079 | |
| 3080 | data[1] = target_file; |
| 3081 | size[1] = len + 2 /* null */; |
| 3082 | |
| 3083 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3084 | current->tgid, FILE_RENAME_INFORMATION, SMB2_O_INFO_FILE, |
| 3085 | 0, 2, data, size); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3086 | kfree(data); |
| 3087 | return rc; |
| 3088 | } |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3089 | |
| 3090 | int |
Steve French | 897fba1 | 2016-05-12 21:20:36 -0500 | [diff] [blame] | 3091 | SMB2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, |
| 3092 | u64 persistent_fid, u64 volatile_fid) |
| 3093 | { |
| 3094 | __u8 delete_pending = 1; |
| 3095 | void *data; |
| 3096 | unsigned int size; |
| 3097 | |
| 3098 | data = &delete_pending; |
| 3099 | size = 1; /* sizeof __u8 */ |
| 3100 | |
| 3101 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3102 | current->tgid, FILE_DISPOSITION_INFORMATION, SMB2_O_INFO_FILE, |
| 3103 | 0, 1, &data, &size); |
Steve French | 897fba1 | 2016-05-12 21:20:36 -0500 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | int |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3107 | SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 3108 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) |
| 3109 | { |
| 3110 | struct smb2_file_link_info info; |
| 3111 | void **data; |
| 3112 | unsigned int size[2]; |
| 3113 | int rc; |
| 3114 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); |
| 3115 | |
| 3116 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); |
| 3117 | if (!data) |
| 3118 | return -ENOMEM; |
| 3119 | |
| 3120 | info.ReplaceIfExists = 0; /* 1 = replace existing link with new */ |
| 3121 | /* 0 = fail if link already exists */ |
| 3122 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ |
| 3123 | info.FileNameLength = cpu_to_le32(len); |
| 3124 | |
| 3125 | data[0] = &info; |
| 3126 | size[0] = sizeof(struct smb2_file_link_info); |
| 3127 | |
| 3128 | data[1] = target_file; |
| 3129 | size[1] = len + 2 /* null */; |
| 3130 | |
| 3131 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3132 | current->tgid, FILE_LINK_INFORMATION, SMB2_O_INFO_FILE, |
| 3133 | 0, 2, data, size); |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3134 | kfree(data); |
| 3135 | return rc; |
| 3136 | } |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3137 | |
| 3138 | int |
| 3139 | SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 3140 | u64 volatile_fid, u32 pid, __le64 *eof, bool is_falloc) |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3141 | { |
| 3142 | struct smb2_file_eof_info info; |
| 3143 | void *data; |
| 3144 | unsigned int size; |
| 3145 | |
| 3146 | info.EndOfFile = *eof; |
| 3147 | |
| 3148 | data = &info; |
| 3149 | size = sizeof(struct smb2_file_eof_info); |
| 3150 | |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 3151 | if (is_falloc) |
| 3152 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3153 | pid, FILE_ALLOCATION_INFORMATION, SMB2_O_INFO_FILE, |
| 3154 | 0, 1, &data, &size); |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 3155 | else |
| 3156 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3157 | pid, FILE_END_OF_FILE_INFORMATION, SMB2_O_INFO_FILE, |
| 3158 | 0, 1, &data, &size); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3159 | } |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3160 | |
| 3161 | int |
| 3162 | SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 3163 | u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf) |
| 3164 | { |
| 3165 | unsigned int size; |
| 3166 | size = sizeof(FILE_BASIC_INFO); |
| 3167 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, |
Shirish Pargaonkar | dac9534 | 2017-06-28 22:37:00 -0500 | [diff] [blame] | 3168 | current->tgid, FILE_BASIC_INFORMATION, SMB2_O_INFO_FILE, |
| 3169 | 0, 1, (void **)&buf, &size); |
| 3170 | } |
| 3171 | |
| 3172 | int |
| 3173 | SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon, |
| 3174 | u64 persistent_fid, u64 volatile_fid, |
| 3175 | struct cifs_ntsd *pnntsd, int pacllen, int aclflag) |
| 3176 | { |
| 3177 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, |
| 3178 | current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag, |
| 3179 | 1, (void **)&pnntsd, &pacllen); |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3180 | } |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3181 | |
| 3182 | int |
| 3183 | SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, |
| 3184 | const u64 persistent_fid, const u64 volatile_fid, |
| 3185 | __u8 oplock_level) |
| 3186 | { |
| 3187 | int rc; |
| 3188 | struct smb2_oplock_break *req = NULL; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3189 | int flags = CIFS_OBREAK_OP; |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3190 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3191 | cifs_dbg(FYI, "SMB2_oplock_break\n"); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3192 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3193 | if (rc) |
| 3194 | return rc; |
| 3195 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3196 | if (encryption_required(tcon)) |
| 3197 | flags |= CIFS_TRANSFORM_REQ; |
| 3198 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3199 | req->VolatileFid = volatile_fid; |
| 3200 | req->PersistentFid = persistent_fid; |
| 3201 | req->OplockLevel = oplock_level; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 3202 | req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3203 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3204 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3205 | cifs_small_buf_release(req); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3206 | |
| 3207 | if (rc) { |
| 3208 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3209 | cifs_dbg(FYI, "Send error in Oplock Break = %d\n", rc); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | return rc; |
| 3213 | } |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3214 | |
| 3215 | static void |
| 3216 | copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf, |
| 3217 | struct kstatfs *kst) |
| 3218 | { |
| 3219 | kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * |
| 3220 | le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); |
| 3221 | kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); |
| 3222 | kst->f_bfree = le64_to_cpu(pfs_inf->ActualAvailableAllocationUnits); |
| 3223 | kst->f_bavail = le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); |
| 3224 | return; |
| 3225 | } |
| 3226 | |
| 3227 | static int |
| 3228 | build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level, |
| 3229 | int outbuf_len, u64 persistent_fid, u64 volatile_fid) |
| 3230 | { |
| 3231 | int rc; |
| 3232 | struct smb2_query_info_req *req; |
| 3233 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3234 | cifs_dbg(FYI, "Query FSInfo level %d\n", level); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3235 | |
| 3236 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 3237 | return -EIO; |
| 3238 | |
| 3239 | rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req); |
| 3240 | if (rc) |
| 3241 | return rc; |
| 3242 | |
| 3243 | req->InfoType = SMB2_O_INFO_FILESYSTEM; |
| 3244 | req->FileInfoClass = level; |
| 3245 | req->PersistentFileId = persistent_fid; |
| 3246 | req->VolatileFileId = volatile_fid; |
| 3247 | /* 4 for rfc1002 length field and 1 for pad */ |
| 3248 | req->InputBufferOffset = |
| 3249 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); |
| 3250 | req->OutputBufferLength = cpu_to_le32( |
| 3251 | outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - 4); |
| 3252 | |
| 3253 | iov->iov_base = (char *)req; |
| 3254 | /* 4 for rfc1002 length field */ |
| 3255 | iov->iov_len = get_rfc1002_length(req) + 4; |
| 3256 | return 0; |
| 3257 | } |
| 3258 | |
| 3259 | int |
| 3260 | SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 3261 | u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata) |
| 3262 | { |
| 3263 | struct smb2_query_info_rsp *rsp = NULL; |
| 3264 | struct kvec iov; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3265 | struct kvec rsp_iov; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3266 | int rc = 0; |
| 3267 | int resp_buftype; |
| 3268 | struct cifs_ses *ses = tcon->ses; |
| 3269 | struct smb2_fs_full_size_info *info = NULL; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3270 | int flags = 0; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3271 | |
| 3272 | rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION, |
| 3273 | sizeof(struct smb2_fs_full_size_info), |
| 3274 | persistent_fid, volatile_fid); |
| 3275 | if (rc) |
| 3276 | return rc; |
| 3277 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3278 | if (encryption_required(tcon)) |
| 3279 | flags |= CIFS_TRANSFORM_REQ; |
| 3280 | |
| 3281 | rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3282 | cifs_small_buf_release(iov.iov_base); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3283 | if (rc) { |
| 3284 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3285 | goto qfsinf_exit; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3286 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3287 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3288 | |
| 3289 | info = (struct smb2_fs_full_size_info *)(4 /* RFC1001 len */ + |
| 3290 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr); |
| 3291 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), |
| 3292 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, |
| 3293 | sizeof(struct smb2_fs_full_size_info)); |
| 3294 | if (!rc) |
| 3295 | copy_fs_info_to_kstatfs(info, fsdata); |
| 3296 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3297 | qfsinf_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3298 | free_rsp_buf(resp_buftype, rsp_iov.iov_base); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3299 | return rc; |
| 3300 | } |
| 3301 | |
| 3302 | int |
| 3303 | SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon, |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3304 | u64 persistent_fid, u64 volatile_fid, int level) |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3305 | { |
| 3306 | struct smb2_query_info_rsp *rsp = NULL; |
| 3307 | struct kvec iov; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3308 | struct kvec rsp_iov; |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3309 | int rc = 0; |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3310 | int resp_buftype, max_len, min_len; |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3311 | struct cifs_ses *ses = tcon->ses; |
| 3312 | unsigned int rsp_len, offset; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3313 | int flags = 0; |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3314 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3315 | if (level == FS_DEVICE_INFORMATION) { |
| 3316 | max_len = sizeof(FILE_SYSTEM_DEVICE_INFO); |
| 3317 | min_len = sizeof(FILE_SYSTEM_DEVICE_INFO); |
| 3318 | } else if (level == FS_ATTRIBUTE_INFORMATION) { |
| 3319 | max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO); |
| 3320 | min_len = MIN_FS_ATTR_INFO_SIZE; |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 3321 | } else if (level == FS_SECTOR_SIZE_INFORMATION) { |
| 3322 | max_len = sizeof(struct smb3_fs_ss_info); |
| 3323 | min_len = sizeof(struct smb3_fs_ss_info); |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3324 | } else { |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 3325 | cifs_dbg(FYI, "Invalid qfsinfo level %d\n", level); |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3326 | return -EINVAL; |
| 3327 | } |
| 3328 | |
| 3329 | rc = build_qfs_info_req(&iov, tcon, level, max_len, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3330 | persistent_fid, volatile_fid); |
| 3331 | if (rc) |
| 3332 | return rc; |
| 3333 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3334 | if (encryption_required(tcon)) |
| 3335 | flags |= CIFS_TRANSFORM_REQ; |
| 3336 | |
| 3337 | rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, flags, &rsp_iov); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3338 | cifs_small_buf_release(iov.iov_base); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3339 | if (rc) { |
| 3340 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); |
| 3341 | goto qfsattr_exit; |
| 3342 | } |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3343 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3344 | |
| 3345 | rsp_len = le32_to_cpu(rsp->OutputBufferLength); |
| 3346 | offset = le16_to_cpu(rsp->OutputBufferOffset); |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3347 | rc = validate_buf(offset, rsp_len, &rsp->hdr, min_len); |
| 3348 | if (rc) |
| 3349 | goto qfsattr_exit; |
| 3350 | |
| 3351 | if (level == FS_ATTRIBUTE_INFORMATION) |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3352 | memcpy(&tcon->fsAttrInfo, 4 /* RFC1001 len */ + offset |
| 3353 | + (char *)&rsp->hdr, min_t(unsigned int, |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 3354 | rsp_len, max_len)); |
| 3355 | else if (level == FS_DEVICE_INFORMATION) |
| 3356 | memcpy(&tcon->fsDevInfo, 4 /* RFC1001 len */ + offset |
| 3357 | + (char *)&rsp->hdr, sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 3358 | else if (level == FS_SECTOR_SIZE_INFORMATION) { |
| 3359 | struct smb3_fs_ss_info *ss_info = (struct smb3_fs_ss_info *) |
| 3360 | (4 /* RFC1001 len */ + offset + (char *)&rsp->hdr); |
| 3361 | tcon->ss_flags = le32_to_cpu(ss_info->Flags); |
| 3362 | tcon->perf_sector_size = |
| 3363 | le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf); |
| 3364 | } |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3365 | |
| 3366 | qfsattr_exit: |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3367 | free_rsp_buf(resp_buftype, rsp_iov.iov_base); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3368 | return rc; |
| 3369 | } |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3370 | |
| 3371 | int |
| 3372 | smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, |
| 3373 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, |
| 3374 | const __u32 num_lock, struct smb2_lock_element *buf) |
| 3375 | { |
| 3376 | int rc = 0; |
| 3377 | struct smb2_lock_req *req = NULL; |
| 3378 | struct kvec iov[2]; |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3379 | struct kvec rsp_iov; |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3380 | int resp_buf_type; |
| 3381 | unsigned int count; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3382 | int flags = CIFS_NO_RESP; |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3383 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3384 | cifs_dbg(FYI, "smb2_lockv num lock %d\n", num_lock); |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3385 | |
| 3386 | rc = small_smb2_init(SMB2_LOCK, tcon, (void **) &req); |
| 3387 | if (rc) |
| 3388 | return rc; |
| 3389 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3390 | if (encryption_required(tcon)) |
| 3391 | flags |= CIFS_TRANSFORM_REQ; |
| 3392 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 3393 | req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid); |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3394 | req->LockCount = cpu_to_le16(num_lock); |
| 3395 | |
| 3396 | req->PersistentFileId = persist_fid; |
| 3397 | req->VolatileFileId = volatile_fid; |
| 3398 | |
| 3399 | count = num_lock * sizeof(struct smb2_lock_element); |
| 3400 | inc_rfc1001_len(req, count - sizeof(struct smb2_lock_element)); |
| 3401 | |
| 3402 | iov[0].iov_base = (char *)req; |
| 3403 | /* 4 for rfc1002 length field and count for all locks */ |
| 3404 | iov[0].iov_len = get_rfc1002_length(req) + 4 - count; |
| 3405 | iov[1].iov_base = (char *)buf; |
| 3406 | iov[1].iov_len = count; |
| 3407 | |
| 3408 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3409 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, flags, |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3410 | &rsp_iov); |
| 3411 | cifs_small_buf_release(req); |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3412 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3413 | cifs_dbg(FYI, "Send error in smb2_lockv = %d\n", rc); |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3414 | cifs_stats_fail_inc(tcon, SMB2_LOCK_HE); |
| 3415 | } |
| 3416 | |
| 3417 | return rc; |
| 3418 | } |
| 3419 | |
| 3420 | int |
| 3421 | SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, |
| 3422 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, |
| 3423 | const __u64 length, const __u64 offset, const __u32 lock_flags, |
| 3424 | const bool wait) |
| 3425 | { |
| 3426 | struct smb2_lock_element lock; |
| 3427 | |
| 3428 | lock.Offset = cpu_to_le64(offset); |
| 3429 | lock.Length = cpu_to_le64(length); |
| 3430 | lock.Flags = cpu_to_le32(lock_flags); |
| 3431 | if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK) |
| 3432 | lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY); |
| 3433 | |
| 3434 | return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock); |
| 3435 | } |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3436 | |
| 3437 | int |
| 3438 | SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, |
| 3439 | __u8 *lease_key, const __le32 lease_state) |
| 3440 | { |
| 3441 | int rc; |
| 3442 | struct smb2_lease_ack *req = NULL; |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3443 | int flags = CIFS_OBREAK_OP; |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3444 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3445 | cifs_dbg(FYI, "SMB2_lease_break\n"); |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3446 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3447 | if (rc) |
| 3448 | return rc; |
| 3449 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3450 | if (encryption_required(tcon)) |
| 3451 | flags |= CIFS_TRANSFORM_REQ; |
| 3452 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 3453 | req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1); |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3454 | req->StructureSize = cpu_to_le16(36); |
| 3455 | inc_rfc1001_len(req, 12); |
| 3456 | |
| 3457 | memcpy(req->LeaseKey, lease_key, 16); |
| 3458 | req->LeaseState = lease_state; |
| 3459 | |
Pavel Shilovsky | 7fb8986 | 2016-10-31 13:49:30 -0700 | [diff] [blame] | 3460 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, flags); |
Pavel Shilovsky | da502f7 | 2016-10-25 11:38:47 -0700 | [diff] [blame] | 3461 | cifs_small_buf_release(req); |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3462 | |
| 3463 | if (rc) { |
| 3464 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3465 | cifs_dbg(FYI, "Send error in Lease Break = %d\n", rc); |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | return rc; |
| 3469 | } |