4 * Copyright (C) International Business Machines Corp., 2009, 2013
9 * Contains the routines for constructing the SMB2 PDUs themselves
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.
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.
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
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 */
32 #include <linux/kernel.h>
33 #include <linux/vfs.h>
34 #include <linux/task_io_accounting_ops.h>
35 #include <linux/uaccess.h>
36 #include <linux/uuid.h>
37 #include <linux/pagemap.h>
38 #include <linux/xattr.h>
42 #include "cifsproto.h"
43 #include "smb2proto.h"
44 #include "cifs_unicode.h"
45 #include "cifs_debug.h"
47 #include "smb2status.h"
50 #include "cifs_spnego.h"
51 #include "smbdirect.h"
54 * The following table defines the expected "StructureSize" of SMB2 requests
55 * in order by SMB2 command. This is similar to "wct" in SMB/CIFS requests.
57 * Note that commands are defined in smb2pdu.h in le16 but the array below is
58 * indexed by command in host byte order.
60 static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
61 /* SMB2_NEGOTIATE */ 36,
62 /* SMB2_SESSION_SETUP */ 25,
64 /* SMB2_TREE_CONNECT */ 9,
65 /* SMB2_TREE_DISCONNECT */ 4,
75 /* SMB2_QUERY_DIRECTORY */ 33,
76 /* SMB2_CHANGE_NOTIFY */ 32,
77 /* SMB2_QUERY_INFO */ 41,
78 /* SMB2_SET_INFO */ 33,
79 /* SMB2_OPLOCK_BREAK */ 24 /* BB this is 36 for LEASE_BREAK variant */
82 static int encryption_required(const struct cifs_tcon *tcon)
86 if ((tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) ||
87 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA))
90 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION))
96 smb2_hdr_assemble(struct smb2_sync_hdr *shdr, __le16 smb2_cmd,
97 const struct cifs_tcon *tcon)
99 shdr->ProtocolId = SMB2_PROTO_NUMBER;
100 shdr->StructureSize = cpu_to_le16(64);
101 shdr->Command = smb2_cmd;
102 if (tcon && tcon->ses && tcon->ses->server) {
103 struct TCP_Server_Info *server = tcon->ses->server;
105 spin_lock(&server->req_lock);
106 /* Request up to 2 credits but don't go over the limit. */
107 if (server->credits >= server->max_credits)
108 shdr->CreditRequest = cpu_to_le16(0);
110 shdr->CreditRequest = cpu_to_le16(
111 min_t(int, server->max_credits -
112 server->credits, 2));
113 spin_unlock(&server->req_lock);
115 shdr->CreditRequest = cpu_to_le16(2);
117 shdr->ProcessId = cpu_to_le32((__u16)current->tgid);
122 /* GLOBAL_CAP_LARGE_MTU will only be set if dialect > SMB2.02 */
123 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */
124 if ((tcon->ses) && (tcon->ses->server) &&
125 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
126 shdr->CreditCharge = cpu_to_le16(1);
127 /* else CreditCharge MBZ */
129 shdr->TreeId = tcon->tid;
130 /* Uid is not converted */
132 shdr->SessionId = tcon->ses->Suid;
135 * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have
136 * to pass the path on the Open SMB prefixed by \\server\share.
137 * Not sure when we would need to do the augmented path (if ever) and
138 * setting this flag breaks the SMB2 open operation since it is
139 * illegal to send an empty path name (without \\server\share prefix)
140 * when the DFS flag is set in the SMB open header. We could
141 * consider setting the flag on all operations other than open
142 * but it is safer to net set it for now.
144 /* if (tcon->share_flags & SHI1005_FLAGS_DFS)
145 shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */
147 if (tcon->ses && tcon->ses->server && tcon->ses->server->sign &&
148 !encryption_required(tcon))
149 shdr->Flags |= SMB2_FLAGS_SIGNED;
155 smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)
158 struct nls_table *nls_codepage;
159 struct cifs_ses *ses;
160 struct TCP_Server_Info *server;
163 * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so
164 * check for tcp and smb session status done differently
165 * for those three - in the calling routine.
170 if (smb2_command == SMB2_TREE_CONNECT)
173 if (tcon->tidStatus == CifsExiting) {
175 * only tree disconnect, open, and write,
176 * (and ulogoff which does not have tcon)
177 * are allowed as we start force umount.
179 if ((smb2_command != SMB2_WRITE) &&
180 (smb2_command != SMB2_CREATE) &&
181 (smb2_command != SMB2_TREE_DISCONNECT)) {
182 cifs_dbg(FYI, "can not send cmd %d while umounting\n",
187 if ((!tcon->ses) || (tcon->ses->status == CifsExiting) ||
188 (!tcon->ses->server))
192 server = ses->server;
195 * Give demultiplex thread up to 10 seconds to reconnect, should be
196 * greater than cifs socket timeout which is 7 seconds
198 while (server->tcpStatus == CifsNeedReconnect) {
200 * Return to caller for TREE_DISCONNECT and LOGOFF and CLOSE
201 * here since they are implicitly done when session drops.
203 switch (smb2_command) {
205 * BB Should we keep oplock break and add flush to exceptions?
207 case SMB2_TREE_DISCONNECT:
210 case SMB2_OPLOCK_BREAK:
214 wait_event_interruptible_timeout(server->response_q,
215 (server->tcpStatus != CifsNeedReconnect), 10 * HZ);
217 /* are we still trying to reconnect? */
218 if (server->tcpStatus != CifsNeedReconnect)
222 * on "soft" mounts we wait once. Hard mounts keep
223 * retrying until process is killed or server comes
227 cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n");
232 if (!tcon->ses->need_reconnect && !tcon->need_reconnect)
235 nls_codepage = load_nls_default();
238 * need to prevent multiple threads trying to simultaneously reconnect
239 * the same SMB session
241 mutex_lock(&tcon->ses->session_mutex);
244 * Recheck after acquire mutex. If another thread is negotiating
245 * and the server never sends an answer the socket will be closed
246 * and tcpStatus set to reconnect.
248 if (server->tcpStatus == CifsNeedReconnect) {
250 mutex_unlock(&tcon->ses->session_mutex);
254 rc = cifs_negotiate_protocol(0, tcon->ses);
255 if (!rc && tcon->ses->need_reconnect)
256 rc = cifs_setup_session(0, tcon->ses, nls_codepage);
258 if (rc || !tcon->need_reconnect) {
259 mutex_unlock(&tcon->ses->session_mutex);
263 cifs_mark_open_files_invalid(tcon);
264 if (tcon->use_persistent)
265 tcon->need_reopen_files = true;
267 rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage);
268 mutex_unlock(&tcon->ses->session_mutex);
270 cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc);
274 if (smb2_command != SMB2_INTERNAL_CMD)
275 queue_delayed_work(cifsiod_wq, &server->reconnect, 0);
277 atomic_inc(&tconInfoReconnectCount);
280 * Check if handle based operation so we know whether we can continue
281 * or not without returning to caller to reset file handle.
284 * BB Is flush done by server on drop of tcp session? Should we special
285 * case it and skip above?
287 switch (smb2_command) {
293 case SMB2_QUERY_DIRECTORY:
294 case SMB2_CHANGE_NOTIFY:
295 case SMB2_QUERY_INFO:
299 unload_nls(nls_codepage);
304 fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, void *buf,
305 unsigned int *total_len)
307 struct smb2_sync_pdu *spdu = (struct smb2_sync_pdu *)buf;
308 /* lookup word count ie StructureSize from table */
309 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_command)];
312 * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of
313 * largest operations (Create)
317 smb2_hdr_assemble(&spdu->sync_hdr, smb2_command, tcon);
318 spdu->StructureSize2 = cpu_to_le16(parmsize);
320 *total_len = parmsize + sizeof(struct smb2_sync_hdr);
324 * Allocate and return pointer to an SMB request hdr, and set basic
325 * SMB information in the SMB header. If the return code is zero, this
326 * function must have filled in request_buf pointer.
329 smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon,
330 void **request_buf, unsigned int *total_len)
334 rc = smb2_reconnect(smb2_command, tcon);
338 /* BB eventually switch this to SMB2 specific small buf size */
339 *request_buf = cifs_small_buf_get();
340 if (*request_buf == NULL) {
341 /* BB should we add a retry in here if not a writepage? */
345 fill_small_buf(smb2_command, tcon,
346 (struct smb2_sync_hdr *)(*request_buf),
350 #ifdef CONFIG_CIFS_STATS2
351 uint16_t com_code = le16_to_cpu(smb2_command);
352 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]);
354 cifs_stats_inc(&tcon->num_smbs_sent);
360 #ifdef CONFIG_CIFS_SMB311
361 /* offset is sizeof smb2_negotiate_req but rounded up to 8 bytes */
362 #define OFFSET_OF_NEG_CONTEXT 0x68 /* sizeof(struct smb2_negotiate_req) */
365 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
366 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
369 build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt)
371 pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES;
372 pneg_ctxt->DataLength = cpu_to_le16(38);
373 pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1);
374 pneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE);
375 get_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE);
376 pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512;
380 build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)
382 pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES;
383 pneg_ctxt->DataLength = cpu_to_le16(6);
384 pneg_ctxt->CipherCount = cpu_to_le16(2);
385 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM;
386 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM;
390 assemble_neg_contexts(struct smb2_negotiate_req *req,
391 unsigned int *total_len)
393 char *pneg_ctxt = (char *)req + OFFSET_OF_NEG_CONTEXT;
395 build_preauth_ctxt((struct smb2_preauth_neg_context *)pneg_ctxt);
396 /* Add 2 to size to round to 8 byte boundary */
398 pneg_ctxt += 2 + sizeof(struct smb2_preauth_neg_context);
399 build_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt);
400 req->NegotiateContextOffset = cpu_to_le32(OFFSET_OF_NEG_CONTEXT);
401 req->NegotiateContextCount = cpu_to_le16(2);
403 *total_len += 4 + sizeof(struct smb2_preauth_neg_context)
404 + sizeof(struct smb2_encryption_neg_context);
407 static void assemble_neg_contexts(struct smb2_negotiate_req *req,
408 unsigned int *total_len)
416 * SMB2 Worker functions follow:
418 * The general structure of the worker functions is:
419 * 1) Call smb2_init (assembles SMB2 header)
420 * 2) Initialize SMB2 command specific fields in fixed length area of SMB
421 * 3) Call smb_sendrcv2 (sends request on socket and waits for response)
422 * 4) Decode SMB2 command specific fields in the fixed length area
423 * 5) Decode variable length data area (if any for this SMB2 command type)
424 * 6) Call free smb buffer
430 SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
432 struct smb2_negotiate_req *req;
433 struct smb2_negotiate_rsp *rsp;
438 struct TCP_Server_Info *server = ses->server;
439 int blob_offset, blob_length;
441 int flags = CIFS_NEG_OP;
442 unsigned int total_len;
444 cifs_dbg(FYI, "Negotiate protocol\n");
447 WARN(1, "%s: server is NULL!\n", __func__);
451 rc = smb2_plain_req_init(SMB2_NEGOTIATE, NULL, (void **) &req, &total_len);
455 req->sync_hdr.SessionId = 0;
456 #ifdef CONFIG_CIFS_SMB311
457 memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
458 memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
461 if (strcmp(ses->server->vals->version_string,
462 SMB3ANY_VERSION_STRING) == 0) {
463 req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID);
464 req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID);
465 req->DialectCount = cpu_to_le16(2);
467 } else if (strcmp(ses->server->vals->version_string,
468 SMBDEFAULT_VERSION_STRING) == 0) {
469 req->Dialects[0] = cpu_to_le16(SMB21_PROT_ID);
470 req->Dialects[1] = cpu_to_le16(SMB30_PROT_ID);
471 req->Dialects[2] = cpu_to_le16(SMB302_PROT_ID);
472 req->DialectCount = cpu_to_le16(3);
475 /* otherwise send specific dialect */
476 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
477 req->DialectCount = cpu_to_le16(1);
481 /* only one of SMB2 signing flags may be set in SMB2 request */
483 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED);
484 else if (global_secflags & CIFSSEC_MAY_SIGN)
485 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED);
487 req->SecurityMode = 0;
489 req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities);
491 /* ClientGUID must be zero for SMB2.02 dialect */
492 if (ses->server->vals->protocol_id == SMB20_PROT_ID)
493 memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE);
495 memcpy(req->ClientGUID, server->client_guid,
496 SMB2_CLIENT_GUID_SIZE);
497 if (ses->server->vals->protocol_id == SMB311_PROT_ID)
498 assemble_neg_contexts(req, &total_len);
500 iov[0].iov_base = (char *)req;
501 iov[0].iov_len = total_len;
503 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
504 cifs_small_buf_release(req);
505 rsp = (struct smb2_negotiate_rsp *)rsp_iov.iov_base;
507 * No tcon so can't do
508 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
510 if (rc == -EOPNOTSUPP) {
511 cifs_dbg(VFS, "Dialect not supported by server. Consider "
512 "specifying vers=1.0 or vers=2.0 on mount for accessing"
518 if (strcmp(ses->server->vals->version_string,
519 SMB3ANY_VERSION_STRING) == 0) {
520 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) {
522 "SMB2 dialect returned but not requested\n");
524 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) {
526 "SMB2.1 dialect returned but not requested\n");
529 } else if (strcmp(ses->server->vals->version_string,
530 SMBDEFAULT_VERSION_STRING) == 0) {
531 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) {
533 "SMB2 dialect returned but not requested\n");
535 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) {
536 /* ops set to 3.0 by default for default so update */
537 ses->server->ops = &smb21_operations;
539 } else if (le16_to_cpu(rsp->DialectRevision) !=
540 ses->server->vals->protocol_id) {
541 /* if requested single dialect ensure returned dialect matched */
542 cifs_dbg(VFS, "Illegal 0x%x dialect returned: not requested\n",
543 le16_to_cpu(rsp->DialectRevision));
547 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode);
549 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID))
550 cifs_dbg(FYI, "negotiated smb2.0 dialect\n");
551 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID))
552 cifs_dbg(FYI, "negotiated smb2.1 dialect\n");
553 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID))
554 cifs_dbg(FYI, "negotiated smb3.0 dialect\n");
555 else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID))
556 cifs_dbg(FYI, "negotiated smb3.02 dialect\n");
557 #ifdef CONFIG_CIFS_SMB311
558 else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID))
559 cifs_dbg(FYI, "negotiated smb3.1.1 dialect\n");
562 cifs_dbg(VFS, "Illegal dialect returned by server 0x%x\n",
563 le16_to_cpu(rsp->DialectRevision));
567 server->dialect = le16_to_cpu(rsp->DialectRevision);
569 /* BB: add check that dialect was valid given dialect(s) we asked for */
571 #ifdef CONFIG_CIFS_SMB311
573 * Keep a copy of the hash after negprot. This hash will be
574 * the starting hash value for all sessions made from this
577 memcpy(server->preauth_sha_hash, ses->preauth_sha_hash,
578 SMB2_PREAUTH_HASH_SIZE);
580 /* SMB2 only has an extended negflavor */
581 server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
582 /* set it to the maximum buffer size value we can send with 1 credit */
583 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize),
584 SMB2_MAX_BUFFER_SIZE);
585 server->max_read = le32_to_cpu(rsp->MaxReadSize);
586 server->max_write = le32_to_cpu(rsp->MaxWriteSize);
587 server->sec_mode = le16_to_cpu(rsp->SecurityMode);
588 if ((server->sec_mode & SMB2_SEC_MODE_FLAGS_ALL) != server->sec_mode)
589 cifs_dbg(FYI, "Server returned unexpected security mode 0x%x\n",
591 server->capabilities = le32_to_cpu(rsp->Capabilities);
593 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES;
595 security_blob = smb2_get_data_area_len(&blob_offset, &blob_length,
598 * See MS-SMB2 section 2.2.4: if no blob, client picks default which
600 * ses->sectype = RawNTLMSSP;
601 * but for time being this is our only auth choice so doesn't matter.
602 * We just found a server which sets blob length to zero expecting raw.
604 if (blob_length == 0) {
605 cifs_dbg(FYI, "missing security blob on negprot\n");
606 server->sec_ntlmssp = true;
609 rc = cifs_enable_signing(server, ses->sign);
613 rc = decode_negTokenInit(security_blob, blob_length, server);
620 free_rsp_buf(resp_buftype, rsp);
624 int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
627 struct validate_negotiate_info_req vneg_inbuf;
628 struct validate_negotiate_info_rsp *pneg_rsp = NULL;
630 u32 inbuflen; /* max of 4 dialects */
632 cifs_dbg(FYI, "validate negotiate\n");
634 #ifdef CONFIG_CIFS_SMB_DIRECT
635 if (tcon->ses->server->rdma)
639 /* In SMB3.11 preauth integrity supersedes validate negotiate */
640 if (tcon->ses->server->dialect == SMB311_PROT_ID)
644 * validation ioctl must be signed, so no point sending this if we
645 * can not sign it (ie are not known user). Even if signing is not
646 * required (enabled but not negotiated), in those cases we selectively
647 * sign just this, the first and only signed request on a connection.
648 * Having validation of negotiate info helps reduce attack vectors.
650 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST)
651 return 0; /* validation requires signing */
653 if (tcon->ses->user_name == NULL) {
654 cifs_dbg(FYI, "Can't validate negotiate: null user mount\n");
655 return 0; /* validation requires signing */
658 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_NULL)
659 cifs_dbg(VFS, "Unexpected null user (anonymous) auth flag sent by server\n");
661 vneg_inbuf.Capabilities =
662 cpu_to_le32(tcon->ses->server->vals->req_capabilities);
663 memcpy(vneg_inbuf.Guid, tcon->ses->server->client_guid,
664 SMB2_CLIENT_GUID_SIZE);
667 vneg_inbuf.SecurityMode =
668 cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED);
669 else if (global_secflags & CIFSSEC_MAY_SIGN)
670 vneg_inbuf.SecurityMode =
671 cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED);
673 vneg_inbuf.SecurityMode = 0;
676 if (strcmp(tcon->ses->server->vals->version_string,
677 SMB3ANY_VERSION_STRING) == 0) {
678 vneg_inbuf.Dialects[0] = cpu_to_le16(SMB30_PROT_ID);
679 vneg_inbuf.Dialects[1] = cpu_to_le16(SMB302_PROT_ID);
680 vneg_inbuf.DialectCount = cpu_to_le16(2);
681 /* structure is big enough for 3 dialects, sending only 2 */
682 inbuflen = sizeof(struct validate_negotiate_info_req) - 2;
683 } else if (strcmp(tcon->ses->server->vals->version_string,
684 SMBDEFAULT_VERSION_STRING) == 0) {
685 vneg_inbuf.Dialects[0] = cpu_to_le16(SMB21_PROT_ID);
686 vneg_inbuf.Dialects[1] = cpu_to_le16(SMB30_PROT_ID);
687 vneg_inbuf.Dialects[2] = cpu_to_le16(SMB302_PROT_ID);
688 vneg_inbuf.DialectCount = cpu_to_le16(3);
689 /* structure is big enough for 3 dialects */
690 inbuflen = sizeof(struct validate_negotiate_info_req);
692 /* otherwise specific dialect was requested */
693 vneg_inbuf.Dialects[0] =
694 cpu_to_le16(tcon->ses->server->vals->protocol_id);
695 vneg_inbuf.DialectCount = cpu_to_le16(1);
696 /* structure is big enough for 3 dialects, sending only 1 */
697 inbuflen = sizeof(struct validate_negotiate_info_req) - 4;
700 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
701 FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */,
702 (char *)&vneg_inbuf, sizeof(struct validate_negotiate_info_req),
703 (char **)&pneg_rsp, &rsplen);
706 cifs_dbg(VFS, "validate protocol negotiate failed: %d\n", rc);
710 if (rsplen != sizeof(struct validate_negotiate_info_rsp)) {
711 cifs_dbg(VFS, "invalid protocol negotiate response size: %d\n",
714 /* relax check since Mac returns max bufsize allowed on ioctl */
715 if ((rsplen > CIFSMaxBufSize)
716 || (rsplen < sizeof(struct validate_negotiate_info_rsp)))
720 /* check validate negotiate info response matches what we got earlier */
721 if (pneg_rsp->Dialect != cpu_to_le16(tcon->ses->server->dialect))
724 if (pneg_rsp->SecurityMode != cpu_to_le16(tcon->ses->server->sec_mode))
727 /* do not validate server guid because not saved at negprot time yet */
729 if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND |
730 SMB2_LARGE_FILES) != tcon->ses->server->capabilities)
733 /* validate negotiate successful */
734 cifs_dbg(FYI, "validate negotiate info successful\n");
739 cifs_dbg(VFS, "protocol revalidation - security settings mismatch\n");
746 smb2_select_sectype(struct TCP_Server_Info *server, enum securityEnum requested)
755 if (server->sec_ntlmssp &&
756 (global_secflags & CIFSSEC_MAY_NTLMSSP))
758 if ((server->sec_kerberos || server->sec_mskerberos) &&
759 (global_secflags & CIFSSEC_MAY_KRB5))
767 struct SMB2_sess_data {
769 struct cifs_ses *ses;
770 struct nls_table *nls_cp;
771 void (*func)(struct SMB2_sess_data *);
773 u64 previous_session;
775 /* we will send the SMB in three pieces:
776 * a fixed length beginning part, an optional
777 * SPNEGO blob (which can be zero length), and a
778 * last part which will include the strings
779 * and rest of bcc area. This allows us to avoid
780 * a large buffer 17K allocation
787 SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
790 struct cifs_ses *ses = sess_data->ses;
791 struct smb2_sess_setup_req *req;
792 struct TCP_Server_Info *server = ses->server;
793 unsigned int total_len;
795 rc = smb2_plain_req_init(SMB2_SESSION_SETUP, NULL, (void **) &req,
800 /* First session, not a reauthenticate */
801 req->sync_hdr.SessionId = 0;
803 /* if reconnect, we need to send previous sess id, otherwise it is 0 */
804 req->PreviousSessionId = sess_data->previous_session;
806 req->Flags = 0; /* MBZ */
807 /* to enable echos and oplocks */
808 req->sync_hdr.CreditRequest = cpu_to_le16(3);
810 /* only one of SMB2 signing flags may be set in SMB2 request */
812 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED;
813 else if (global_secflags & CIFSSEC_MAY_SIGN) /* one flag unlike MUST_ */
814 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED;
816 req->SecurityMode = 0;
818 req->Capabilities = 0;
819 req->Channel = 0; /* MBZ */
821 sess_data->iov[0].iov_base = (char *)req;
823 sess_data->iov[0].iov_len = total_len - 1;
825 * This variable will be used to clear the buffer
826 * allocated above in case of any error in the calling function.
828 sess_data->buf0_type = CIFS_SMALL_BUFFER;
834 SMB2_sess_free_buffer(struct SMB2_sess_data *sess_data)
836 free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base);
837 sess_data->buf0_type = CIFS_NO_BUFFER;
841 SMB2_sess_sendreceive(struct SMB2_sess_data *sess_data)
844 struct smb2_sess_setup_req *req = sess_data->iov[0].iov_base;
845 struct kvec rsp_iov = { NULL, 0 };
847 /* Testing shows that buffer offset must be at location of Buffer[0] */
848 req->SecurityBufferOffset =
849 cpu_to_le16(sizeof(struct smb2_sess_setup_req) - 1 /* pad */);
850 req->SecurityBufferLength = cpu_to_le16(sess_data->iov[1].iov_len);
852 /* BB add code to build os and lm fields */
854 rc = smb2_send_recv(sess_data->xid, sess_data->ses,
856 &sess_data->buf0_type,
857 CIFS_LOG_ERROR | CIFS_NEG_OP, &rsp_iov);
858 cifs_small_buf_release(sess_data->iov[0].iov_base);
859 memcpy(&sess_data->iov[0], &rsp_iov, sizeof(struct kvec));
865 SMB2_sess_establish_session(struct SMB2_sess_data *sess_data)
868 struct cifs_ses *ses = sess_data->ses;
870 mutex_lock(&ses->server->srv_mutex);
871 if (ses->server->ops->generate_signingkey) {
872 rc = ses->server->ops->generate_signingkey(ses);
875 "SMB3 session key generation failed\n");
876 mutex_unlock(&ses->server->srv_mutex);
880 if (!ses->server->session_estab) {
881 ses->server->sequence_number = 0x2;
882 ses->server->session_estab = true;
884 mutex_unlock(&ses->server->srv_mutex);
886 cifs_dbg(FYI, "SMB2/3 session established successfully\n");
887 spin_lock(&GlobalMid_Lock);
888 ses->status = CifsGood;
889 ses->need_reconnect = false;
890 spin_unlock(&GlobalMid_Lock);
894 #ifdef CONFIG_CIFS_UPCALL
896 SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
899 struct cifs_ses *ses = sess_data->ses;
900 struct cifs_spnego_msg *msg;
901 struct key *spnego_key = NULL;
902 struct smb2_sess_setup_rsp *rsp = NULL;
904 rc = SMB2_sess_alloc_buffer(sess_data);
908 spnego_key = cifs_get_spnego_key(ses);
909 if (IS_ERR(spnego_key)) {
910 rc = PTR_ERR(spnego_key);
915 msg = spnego_key->payload.data[0];
917 * check version field to make sure that cifs.upcall is
918 * sending us a response in an expected form
920 if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) {
922 "bad cifs.upcall version. Expected %d got %d",
923 CIFS_SPNEGO_UPCALL_VERSION, msg->version);
925 goto out_put_spnego_key;
928 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
930 if (!ses->auth_key.response) {
932 "Kerberos can't allocate (%u bytes) memory",
935 goto out_put_spnego_key;
937 ses->auth_key.len = msg->sesskey_len;
939 sess_data->iov[1].iov_base = msg->data + msg->sesskey_len;
940 sess_data->iov[1].iov_len = msg->secblob_len;
942 rc = SMB2_sess_sendreceive(sess_data);
944 goto out_put_spnego_key;
946 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
947 ses->Suid = rsp->hdr.sync_hdr.SessionId;
949 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
951 rc = SMB2_sess_establish_session(sess_data);
953 key_invalidate(spnego_key);
956 sess_data->result = rc;
957 sess_data->func = NULL;
958 SMB2_sess_free_buffer(sess_data);
962 SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
964 cifs_dbg(VFS, "Kerberos negotiated but upcall support disabled!\n");
965 sess_data->result = -EOPNOTSUPP;
966 sess_data->func = NULL;
971 SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data);
974 SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
977 struct cifs_ses *ses = sess_data->ses;
978 struct smb2_sess_setup_rsp *rsp = NULL;
979 char *ntlmssp_blob = NULL;
980 bool use_spnego = false; /* else use raw ntlmssp */
984 * If memory allocation is successful, caller of this function
987 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL);
992 ses->ntlmssp->sesskey_per_smbsess = true;
994 rc = SMB2_sess_alloc_buffer(sess_data);
998 ntlmssp_blob = kmalloc(sizeof(struct _NEGOTIATE_MESSAGE),
1000 if (ntlmssp_blob == NULL) {
1005 build_ntlmssp_negotiate_blob(ntlmssp_blob, ses);
1007 /* BB eventually need to add this */
1008 cifs_dbg(VFS, "spnego not supported for SMB2 yet\n");
1012 blob_length = sizeof(struct _NEGOTIATE_MESSAGE);
1013 /* with raw NTLMSSP we don't encapsulate in SPNEGO */
1015 sess_data->iov[1].iov_base = ntlmssp_blob;
1016 sess_data->iov[1].iov_len = blob_length;
1018 rc = SMB2_sess_sendreceive(sess_data);
1019 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
1021 /* If true, rc here is expected and not an error */
1022 if (sess_data->buf0_type != CIFS_NO_BUFFER &&
1023 rsp->hdr.sync_hdr.Status == STATUS_MORE_PROCESSING_REQUIRED)
1029 if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 !=
1030 le16_to_cpu(rsp->SecurityBufferOffset)) {
1031 cifs_dbg(VFS, "Invalid security buffer offset %d\n",
1032 le16_to_cpu(rsp->SecurityBufferOffset));
1036 rc = decode_ntlmssp_challenge(rsp->Buffer,
1037 le16_to_cpu(rsp->SecurityBufferLength), ses);
1041 cifs_dbg(FYI, "rawntlmssp session setup challenge phase\n");
1044 ses->Suid = rsp->hdr.sync_hdr.SessionId;
1045 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
1048 kfree(ntlmssp_blob);
1049 SMB2_sess_free_buffer(sess_data);
1051 sess_data->result = 0;
1052 sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate;
1056 kfree(ses->ntlmssp);
1057 ses->ntlmssp = NULL;
1058 sess_data->result = rc;
1059 sess_data->func = NULL;
1063 SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
1066 struct cifs_ses *ses = sess_data->ses;
1067 struct smb2_sess_setup_req *req;
1068 struct smb2_sess_setup_rsp *rsp = NULL;
1069 unsigned char *ntlmssp_blob = NULL;
1070 bool use_spnego = false; /* else use raw ntlmssp */
1071 u16 blob_length = 0;
1073 rc = SMB2_sess_alloc_buffer(sess_data);
1077 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base;
1078 req->sync_hdr.SessionId = ses->Suid;
1080 rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses,
1083 cifs_dbg(FYI, "build_ntlmssp_auth_blob failed %d\n", rc);
1088 /* BB eventually need to add this */
1089 cifs_dbg(VFS, "spnego not supported for SMB2 yet\n");
1093 sess_data->iov[1].iov_base = ntlmssp_blob;
1094 sess_data->iov[1].iov_len = blob_length;
1096 rc = SMB2_sess_sendreceive(sess_data);
1100 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
1102 ses->Suid = rsp->hdr.sync_hdr.SessionId;
1103 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
1105 rc = SMB2_sess_establish_session(sess_data);
1107 kfree(ntlmssp_blob);
1108 SMB2_sess_free_buffer(sess_data);
1109 kfree(ses->ntlmssp);
1110 ses->ntlmssp = NULL;
1111 sess_data->result = rc;
1112 sess_data->func = NULL;
1116 SMB2_select_sec(struct cifs_ses *ses, struct SMB2_sess_data *sess_data)
1120 type = smb2_select_sectype(ses->server, ses->sectype);
1121 cifs_dbg(FYI, "sess setup type %d\n", type);
1122 if (type == Unspecified) {
1124 "Unable to select appropriate authentication method!");
1130 sess_data->func = SMB2_auth_kerberos;
1133 sess_data->func = SMB2_sess_auth_rawntlmssp_negotiate;
1136 cifs_dbg(VFS, "secType %d not supported!\n", type);
1144 SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
1145 const struct nls_table *nls_cp)
1148 struct TCP_Server_Info *server = ses->server;
1149 struct SMB2_sess_data *sess_data;
1151 cifs_dbg(FYI, "Session Setup\n");
1154 WARN(1, "%s: server is NULL!\n", __func__);
1158 sess_data = kzalloc(sizeof(struct SMB2_sess_data), GFP_KERNEL);
1162 rc = SMB2_select_sec(ses, sess_data);
1165 sess_data->xid = xid;
1166 sess_data->ses = ses;
1167 sess_data->buf0_type = CIFS_NO_BUFFER;
1168 sess_data->nls_cp = (struct nls_table *) nls_cp;
1170 #ifdef CONFIG_CIFS_SMB311
1172 * Initialize the session hash with the server one.
1174 memcpy(ses->preauth_sha_hash, ses->server->preauth_sha_hash,
1175 SMB2_PREAUTH_HASH_SIZE);
1178 while (sess_data->func)
1179 sess_data->func(sess_data);
1181 if ((ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) && (ses->sign))
1182 cifs_dbg(VFS, "signing requested but authenticated as guest\n");
1183 rc = sess_data->result;
1190 SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
1192 struct smb2_logoff_req *req; /* response is also trivial struct */
1194 struct TCP_Server_Info *server;
1196 unsigned int total_len;
1198 struct kvec rsp_iov;
1201 cifs_dbg(FYI, "disconnect session %p\n", ses);
1203 if (ses && (ses->server))
1204 server = ses->server;
1208 /* no need to send SMB logoff if uid already closed due to reconnect */
1209 if (ses->need_reconnect)
1210 goto smb2_session_already_dead;
1212 rc = smb2_plain_req_init(SMB2_LOGOFF, NULL, (void **) &req, &total_len);
1216 /* since no tcon, smb2_init can not do this, so do here */
1217 req->sync_hdr.SessionId = ses->Suid;
1219 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
1220 flags |= CIFS_TRANSFORM_REQ;
1221 else if (server->sign)
1222 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
1224 flags |= CIFS_NO_RESP;
1226 iov[0].iov_base = (char *)req;
1227 iov[0].iov_len = total_len;
1229 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov);
1230 cifs_small_buf_release(req);
1232 * No tcon so can't do
1233 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
1236 smb2_session_already_dead:
1240 static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)
1242 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]);
1245 #define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */)
1247 /* These are similar values to what Windows uses */
1248 static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon)
1250 tcon->max_chunks = 256;
1251 tcon->max_bytes_chunk = 1048576;
1252 tcon->max_bytes_copy = 16777216;
1256 SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
1257 struct cifs_tcon *tcon, const struct nls_table *cp)
1259 struct smb2_tree_connect_req *req;
1260 struct smb2_tree_connect_rsp *rsp = NULL;
1262 struct kvec rsp_iov = { NULL, 0 };
1266 __le16 *unc_path = NULL;
1268 unsigned int total_len;
1270 cifs_dbg(FYI, "TCON\n");
1272 if (!(ses->server) || !tree)
1275 unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL);
1276 if (unc_path == NULL)
1279 unc_path_len = cifs_strtoUTF16(unc_path, tree, strlen(tree), cp) + 1;
1281 if (unc_path_len < 2) {
1286 /* SMB2 TREE_CONNECT request must be called with TreeId == 0 */
1289 rc = smb2_plain_req_init(SMB2_TREE_CONNECT, tcon, (void **) &req,
1296 if (encryption_required(tcon))
1297 flags |= CIFS_TRANSFORM_REQ;
1299 iov[0].iov_base = (char *)req;
1301 iov[0].iov_len = total_len - 1;
1303 /* Testing shows that buffer offset must be at location of Buffer[0] */
1304 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req)
1306 req->PathLength = cpu_to_le16(unc_path_len - 2);
1307 iov[1].iov_base = unc_path;
1308 iov[1].iov_len = unc_path_len;
1310 /* 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 */
1311 if ((ses->server->dialect == SMB311_PROT_ID) &&
1312 !encryption_required(tcon))
1313 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
1315 rc = smb2_send_recv(xid, ses, iov, 2, &resp_buftype, flags, &rsp_iov);
1316 cifs_small_buf_release(req);
1317 rsp = (struct smb2_tree_connect_rsp *)rsp_iov.iov_base;
1321 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE);
1322 tcon->need_reconnect = true;
1324 goto tcon_error_exit;
1327 switch (rsp->ShareType) {
1328 case SMB2_SHARE_TYPE_DISK:
1329 cifs_dbg(FYI, "connection to disk share\n");
1331 case SMB2_SHARE_TYPE_PIPE:
1333 cifs_dbg(FYI, "connection to pipe share\n");
1335 case SMB2_SHARE_TYPE_PRINT:
1337 cifs_dbg(FYI, "connection to printer\n");
1340 cifs_dbg(VFS, "unknown share type %d\n", rsp->ShareType);
1342 goto tcon_error_exit;
1345 tcon->share_flags = le32_to_cpu(rsp->ShareFlags);
1346 tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */
1347 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess);
1348 tcon->tidStatus = CifsGood;
1349 tcon->need_reconnect = false;
1350 tcon->tid = rsp->hdr.sync_hdr.TreeId;
1351 strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
1353 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
1354 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
1355 cifs_dbg(VFS, "DFS capability contradicts DFS flag\n");
1358 !(tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION))
1359 cifs_dbg(VFS, "Encryption is requested but not supported\n");
1361 init_copy_chunk_defaults(tcon);
1362 if (tcon->ses->server->ops->validate_negotiate)
1363 rc = tcon->ses->server->ops->validate_negotiate(xid, tcon);
1365 free_rsp_buf(resp_buftype, rsp);
1370 if (rsp && rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) {
1371 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree);
1377 SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)
1379 struct smb2_tree_disconnect_req *req; /* response is trivial */
1381 struct cifs_ses *ses = tcon->ses;
1383 unsigned int total_len;
1385 struct kvec rsp_iov;
1388 cifs_dbg(FYI, "Tree Disconnect\n");
1390 if (!ses || !(ses->server))
1393 if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))
1396 rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, (void **) &req,
1401 if (encryption_required(tcon))
1402 flags |= CIFS_TRANSFORM_REQ;
1404 flags |= CIFS_NO_RESP;
1406 iov[0].iov_base = (char *)req;
1407 iov[0].iov_len = total_len;
1409 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov);
1410 cifs_small_buf_release(req);
1412 cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE);
1418 static struct create_durable *
1419 create_durable_buf(void)
1421 struct create_durable *buf;
1423 buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
1427 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1428 (struct create_durable, Data));
1429 buf->ccontext.DataLength = cpu_to_le32(16);
1430 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1431 (struct create_durable, Name));
1432 buf->ccontext.NameLength = cpu_to_le16(4);
1433 /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DHnQ" */
1441 static struct create_durable *
1442 create_reconnect_durable_buf(struct cifs_fid *fid)
1444 struct create_durable *buf;
1446 buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
1450 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1451 (struct create_durable, Data));
1452 buf->ccontext.DataLength = cpu_to_le32(16);
1453 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1454 (struct create_durable, Name));
1455 buf->ccontext.NameLength = cpu_to_le16(4);
1456 buf->Data.Fid.PersistentFileId = fid->persistent_fid;
1457 buf->Data.Fid.VolatileFileId = fid->volatile_fid;
1458 /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT is "DHnC" */
1467 parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp,
1468 unsigned int *epoch)
1471 struct create_context *cc;
1473 unsigned int remaining;
1476 data_offset = (char *)rsp + server->vals->header_preamble_size + le32_to_cpu(rsp->CreateContextsOffset);
1477 remaining = le32_to_cpu(rsp->CreateContextsLength);
1478 cc = (struct create_context *)data_offset;
1479 while (remaining >= sizeof(struct create_context)) {
1480 name = le16_to_cpu(cc->NameOffset) + (char *)cc;
1481 if (le16_to_cpu(cc->NameLength) == 4 &&
1482 strncmp(name, "RqLs", 4) == 0)
1483 return server->ops->parse_lease_buf(cc, epoch);
1485 next = le32_to_cpu(cc->Next);
1489 cc = (struct create_context *)((char *)cc + next);
1496 add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,
1497 unsigned int *num_iovec, __u8 *oplock)
1499 struct smb2_create_req *req = iov[0].iov_base;
1500 unsigned int num = *num_iovec;
1502 iov[num].iov_base = server->ops->create_lease_buf(oplock+1, *oplock);
1503 if (iov[num].iov_base == NULL)
1505 iov[num].iov_len = server->vals->create_lease_size;
1506 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
1507 if (!req->CreateContextsOffset)
1508 req->CreateContextsOffset = cpu_to_le32(
1509 sizeof(struct smb2_create_req) +
1510 iov[num - 1].iov_len);
1511 le32_add_cpu(&req->CreateContextsLength,
1512 server->vals->create_lease_size);
1513 *num_iovec = num + 1;
1517 static struct create_durable_v2 *
1518 create_durable_v2_buf(struct cifs_fid *pfid)
1520 struct create_durable_v2 *buf;
1522 buf = kzalloc(sizeof(struct create_durable_v2), GFP_KERNEL);
1526 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1527 (struct create_durable_v2, dcontext));
1528 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2));
1529 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1530 (struct create_durable_v2, Name));
1531 buf->ccontext.NameLength = cpu_to_le16(4);
1533 buf->dcontext.Timeout = 0; /* Should this be configurable by workload */
1534 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT);
1535 generate_random_uuid(buf->dcontext.CreateGuid);
1536 memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16);
1538 /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */
1546 static struct create_durable_handle_reconnect_v2 *
1547 create_reconnect_durable_v2_buf(struct cifs_fid *fid)
1549 struct create_durable_handle_reconnect_v2 *buf;
1551 buf = kzalloc(sizeof(struct create_durable_handle_reconnect_v2),
1556 buf->ccontext.DataOffset =
1557 cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2,
1559 buf->ccontext.DataLength =
1560 cpu_to_le32(sizeof(struct durable_reconnect_context_v2));
1561 buf->ccontext.NameOffset =
1562 cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2,
1564 buf->ccontext.NameLength = cpu_to_le16(4);
1566 buf->dcontext.Fid.PersistentFileId = fid->persistent_fid;
1567 buf->dcontext.Fid.VolatileFileId = fid->volatile_fid;
1568 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT);
1569 memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16);
1571 /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 is "DH2C" */
1580 add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,
1581 struct cifs_open_parms *oparms)
1583 struct smb2_create_req *req = iov[0].iov_base;
1584 unsigned int num = *num_iovec;
1586 iov[num].iov_base = create_durable_v2_buf(oparms->fid);
1587 if (iov[num].iov_base == NULL)
1589 iov[num].iov_len = sizeof(struct create_durable_v2);
1590 if (!req->CreateContextsOffset)
1591 req->CreateContextsOffset =
1592 cpu_to_le32(sizeof(struct smb2_create_req) +
1594 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2));
1595 *num_iovec = num + 1;
1600 add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
1601 struct cifs_open_parms *oparms)
1603 struct smb2_create_req *req = iov[0].iov_base;
1604 unsigned int num = *num_iovec;
1606 /* indicate that we don't need to relock the file */
1607 oparms->reconnect = false;
1609 iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid);
1610 if (iov[num].iov_base == NULL)
1612 iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2);
1613 if (!req->CreateContextsOffset)
1614 req->CreateContextsOffset =
1615 cpu_to_le32(sizeof(struct smb2_create_req) +
1617 le32_add_cpu(&req->CreateContextsLength,
1618 sizeof(struct create_durable_handle_reconnect_v2));
1619 *num_iovec = num + 1;
1624 add_durable_context(struct kvec *iov, unsigned int *num_iovec,
1625 struct cifs_open_parms *oparms, bool use_persistent)
1627 struct smb2_create_req *req = iov[0].iov_base;
1628 unsigned int num = *num_iovec;
1630 if (use_persistent) {
1631 if (oparms->reconnect)
1632 return add_durable_reconnect_v2_context(iov, num_iovec,
1635 return add_durable_v2_context(iov, num_iovec, oparms);
1638 if (oparms->reconnect) {
1639 iov[num].iov_base = create_reconnect_durable_buf(oparms->fid);
1640 /* indicate that we don't need to relock the file */
1641 oparms->reconnect = false;
1643 iov[num].iov_base = create_durable_buf();
1644 if (iov[num].iov_base == NULL)
1646 iov[num].iov_len = sizeof(struct create_durable);
1647 if (!req->CreateContextsOffset)
1648 req->CreateContextsOffset =
1649 cpu_to_le32(sizeof(struct smb2_create_req) +
1651 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable));
1652 *num_iovec = num + 1;
1657 alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len,
1658 const char *treename, const __le16 *path)
1660 int treename_len, path_len;
1661 struct nls_table *cp;
1662 const __le16 sep[] = {cpu_to_le16('\\'), cpu_to_le16(0x0000)};
1667 treename_len = strlen(treename);
1668 if (treename_len < 2 || !(treename[0] == '\\' && treename[1] == '\\'))
1674 path_len = UniStrnlen((wchar_t *)path, PATH_MAX);
1677 * make room for one path separator between the treename and
1680 *out_len = treename_len + 1 + path_len;
1683 * final path needs to be null-terminated UTF16 with a
1687 *out_size = roundup((*out_len+1)*2, 8);
1688 *out_path = kzalloc(*out_size, GFP_KERNEL);
1692 cp = load_nls_default();
1693 cifs_strtoUTF16(*out_path, treename, treename_len, cp);
1694 UniStrcat(*out_path, sep);
1695 UniStrcat(*out_path, path);
1702 SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
1703 __u8 *oplock, struct smb2_file_all_info *buf,
1704 struct smb2_err_rsp **err_buf)
1706 struct smb2_create_req *req;
1707 struct smb2_create_rsp *rsp;
1708 struct TCP_Server_Info *server;
1709 struct cifs_tcon *tcon = oparms->tcon;
1710 struct cifs_ses *ses = tcon->ses;
1712 struct kvec rsp_iov = {NULL, 0};
1715 __le16 *copy_path = NULL;
1718 unsigned int n_iov = 2;
1719 __u32 file_attributes = 0;
1720 char *dhc_buf = NULL, *lc_buf = NULL;
1722 unsigned int total_len;
1724 cifs_dbg(FYI, "create/open\n");
1726 if (ses && (ses->server))
1727 server = ses->server;
1731 rc = smb2_plain_req_init(SMB2_CREATE, tcon, (void **) &req, &total_len);
1736 if (encryption_required(tcon))
1737 flags |= CIFS_TRANSFORM_REQ;
1739 if (oparms->create_options & CREATE_OPTION_READONLY)
1740 file_attributes |= ATTR_READONLY;
1741 if (oparms->create_options & CREATE_OPTION_SPECIAL)
1742 file_attributes |= ATTR_SYSTEM;
1744 req->ImpersonationLevel = IL_IMPERSONATION;
1745 req->DesiredAccess = cpu_to_le32(oparms->desired_access);
1746 /* File attributes ignored on open (used in create though) */
1747 req->FileAttributes = cpu_to_le32(file_attributes);
1748 req->ShareAccess = FILE_SHARE_ALL_LE;
1749 req->CreateDisposition = cpu_to_le32(oparms->disposition);
1750 req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK);
1752 iov[0].iov_base = (char *)req;
1753 /* -1 since last byte is buf[0] which is sent below (path) */
1754 iov[0].iov_len = total_len - 1;
1756 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req));
1758 /* [MS-SMB2] 2.2.13 NameOffset:
1759 * If SMB2_FLAGS_DFS_OPERATIONS is set in the Flags field of
1760 * the SMB2 header, the file name includes a prefix that will
1761 * be processed during DFS name normalization as specified in
1762 * section 3.3.5.9. Otherwise, the file name is relative to
1763 * the share that is identified by the TreeId in the SMB2
1766 if (tcon->share_flags & SHI1005_FLAGS_DFS) {
1769 req->sync_hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS;
1770 rc = alloc_path_with_tree_prefix(©_path, ©_size,
1772 tcon->treeName, path);
1774 cifs_small_buf_release(req);
1777 req->NameLength = cpu_to_le16(name_len * 2);
1778 uni_path_len = copy_size;
1781 uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2;
1782 /* MUST set path len (NameLength) to 0 opening root of share */
1783 req->NameLength = cpu_to_le16(uni_path_len - 2);
1784 if (uni_path_len % 8 != 0) {
1785 copy_size = roundup(uni_path_len, 8);
1786 copy_path = kzalloc(copy_size, GFP_KERNEL);
1788 cifs_small_buf_release(req);
1791 memcpy((char *)copy_path, (const char *)path,
1793 uni_path_len = copy_size;
1798 iov[1].iov_len = uni_path_len;
1799 iov[1].iov_base = path;
1801 if (!server->oplocks)
1802 *oplock = SMB2_OPLOCK_LEVEL_NONE;
1804 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) ||
1805 *oplock == SMB2_OPLOCK_LEVEL_NONE)
1806 req->RequestedOplockLevel = *oplock;
1808 rc = add_lease_context(server, iov, &n_iov, oplock);
1810 cifs_small_buf_release(req);
1814 lc_buf = iov[n_iov-1].iov_base;
1817 if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
1818 /* need to set Next field of lease context if we request it */
1819 if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) {
1820 struct create_context *ccontext =
1821 (struct create_context *)iov[n_iov-1].iov_base;
1823 cpu_to_le32(server->vals->create_lease_size);
1826 rc = add_durable_context(iov, &n_iov, oparms,
1827 tcon->use_persistent);
1829 cifs_small_buf_release(req);
1834 dhc_buf = iov[n_iov-1].iov_base;
1837 rc = smb2_send_recv(xid, ses, iov, n_iov, &resp_buftype, flags,
1839 cifs_small_buf_release(req);
1840 rsp = (struct smb2_create_rsp *)rsp_iov.iov_base;
1843 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE);
1845 *err_buf = kmemdup(rsp, get_rfc1002_length(rsp) + 4,
1850 oparms->fid->persistent_fid = rsp->PersistentFileId;
1851 oparms->fid->volatile_fid = rsp->VolatileFileId;
1854 memcpy(buf, &rsp->CreationTime, 32);
1855 buf->AllocationSize = rsp->AllocationSize;
1856 buf->EndOfFile = rsp->EndofFile;
1857 buf->Attributes = rsp->FileAttributes;
1858 buf->NumberOfLinks = cpu_to_le32(1);
1859 buf->DeletePending = 0;
1862 if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
1863 *oplock = parse_lease_state(server, rsp, &oparms->fid->epoch);
1865 *oplock = rsp->OplockLevel;
1870 free_rsp_buf(resp_buftype, rsp);
1875 * SMB2 IOCTL is used for both IOCTLs and FSCTLs
1878 SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1879 u64 volatile_fid, u32 opcode, bool is_fsctl,
1880 char *in_data, u32 indatalen,
1881 char **out_data, u32 *plen /* returned data len */)
1883 struct smb2_ioctl_req *req;
1884 struct smb2_ioctl_rsp *rsp;
1885 struct smb2_sync_hdr *shdr;
1886 struct cifs_ses *ses;
1888 struct kvec rsp_iov;
1893 unsigned int total_len;
1895 cifs_dbg(FYI, "SMB2 IOCTL\n");
1897 if (out_data != NULL)
1900 /* zero out returned data len, in case of error */
1909 if (!ses || !(ses->server))
1912 rc = smb2_plain_req_init(SMB2_IOCTL, tcon, (void **) &req, &total_len);
1916 if (encryption_required(tcon))
1917 flags |= CIFS_TRANSFORM_REQ;
1919 req->CtlCode = cpu_to_le32(opcode);
1920 req->PersistentFileId = persistent_fid;
1921 req->VolatileFileId = volatile_fid;
1924 req->InputCount = cpu_to_le32(indatalen);
1925 /* do not set InputOffset if no input data */
1927 cpu_to_le32(offsetof(struct smb2_ioctl_req, Buffer));
1928 iov[1].iov_base = in_data;
1929 iov[1].iov_len = indatalen;
1934 req->OutputOffset = 0;
1935 req->OutputCount = 0; /* MBZ */
1938 * Could increase MaxOutputResponse, but that would require more
1939 * than one credit. Windows typically sets this smaller, but for some
1940 * ioctls it may be useful to allow server to send more. No point
1941 * limiting what the server can send as long as fits in one credit
1942 * Unfortunately - we can not handle more than CIFS_MAX_MSG_SIZE
1943 * (by default, note that it can be overridden to make max larger)
1944 * in responses (except for read responses which can be bigger.
1945 * We may want to bump this limit up
1947 req->MaxOutputResponse = cpu_to_le32(CIFSMaxBufSize);
1950 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL);
1954 iov[0].iov_base = (char *)req;
1957 * If no input data, the size of ioctl struct in
1958 * protocol spec still includes a 1 byte data buffer,
1959 * but if input data passed to ioctl, we do not
1960 * want to double count this, so we do not send
1961 * the dummy one byte of data in iovec[0] if sending
1962 * input data (in iovec[1]).
1966 iov[0].iov_len = total_len - 1;
1968 iov[0].iov_len = total_len;
1970 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */
1971 if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO)
1972 req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
1974 rc = smb2_send_recv(xid, ses, iov, n_iov, &resp_buftype, flags,
1976 cifs_small_buf_release(req);
1977 rsp = (struct smb2_ioctl_rsp *)rsp_iov.iov_base;
1979 if ((rc != 0) && (rc != -EINVAL)) {
1980 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
1982 } else if (rc == -EINVAL) {
1983 if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
1984 (opcode != FSCTL_SRV_COPYCHUNK)) {
1985 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
1990 /* check if caller wants to look at return data or just return rc */
1991 if ((plen == NULL) || (out_data == NULL))
1994 *plen = le32_to_cpu(rsp->OutputCount);
1996 /* We check for obvious errors in the output buffer length and offset */
1998 goto ioctl_exit; /* server returned no data */
1999 else if (*plen > 0xFF00) {
2000 cifs_dbg(VFS, "srv returned invalid ioctl length: %d\n", *plen);
2006 if (get_rfc1002_length(rsp) < le32_to_cpu(rsp->OutputOffset) + *plen) {
2007 cifs_dbg(VFS, "Malformed ioctl resp: len %d offset %d\n", *plen,
2008 le32_to_cpu(rsp->OutputOffset));
2014 *out_data = kmalloc(*plen, GFP_KERNEL);
2015 if (*out_data == NULL) {
2020 shdr = get_sync_hdr(rsp);
2021 memcpy(*out_data, (char *)shdr + le32_to_cpu(rsp->OutputOffset), *plen);
2023 free_rsp_buf(resp_buftype, rsp);
2028 * Individual callers to ioctl worker function follow
2032 SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2033 u64 persistent_fid, u64 volatile_fid)
2036 struct compress_ioctl fsctl_input;
2037 char *ret_data = NULL;
2039 fsctl_input.CompressionState =
2040 cpu_to_le16(COMPRESSION_FORMAT_DEFAULT);
2042 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
2043 FSCTL_SET_COMPRESSION, true /* is_fsctl */,
2044 (char *)&fsctl_input /* data input */,
2045 2 /* in data len */, &ret_data /* out data */, NULL);
2047 cifs_dbg(FYI, "set compression rc %d\n", rc);
2053 SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
2054 u64 persistent_fid, u64 volatile_fid)
2056 struct smb2_close_req *req;
2057 struct smb2_close_rsp *rsp;
2058 struct cifs_ses *ses = tcon->ses;
2060 struct kvec rsp_iov;
2064 unsigned int total_len;
2066 cifs_dbg(FYI, "Close\n");
2068 if (!ses || !(ses->server))
2071 rc = smb2_plain_req_init(SMB2_CLOSE, tcon, (void **) &req, &total_len);
2075 if (encryption_required(tcon))
2076 flags |= CIFS_TRANSFORM_REQ;
2078 req->PersistentFileId = persistent_fid;
2079 req->VolatileFileId = volatile_fid;
2081 iov[0].iov_base = (char *)req;
2082 iov[0].iov_len = total_len;
2084 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
2085 cifs_small_buf_release(req);
2086 rsp = (struct smb2_close_rsp *)rsp_iov.iov_base;
2089 cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE);
2093 /* BB FIXME - decode close response, update inode for caching */
2096 free_rsp_buf(resp_buftype, rsp);
2101 validate_buf(unsigned int offset, unsigned int buffer_length,
2102 struct smb2_hdr *hdr, unsigned int min_buf_size)
2105 unsigned int smb_len = be32_to_cpu(hdr->smb2_buf_length);
2106 char *end_of_smb = smb_len + 4 /* RFC1001 length field */ + (char *)hdr;
2107 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
2108 char *end_of_buf = begin_of_buf + buffer_length;
2111 if (buffer_length < min_buf_size) {
2112 cifs_dbg(VFS, "buffer length %d smaller than minimum size %d\n",
2113 buffer_length, min_buf_size);
2117 /* check if beyond RFC1001 maximum length */
2118 if ((smb_len > 0x7FFFFF) || (buffer_length > 0x7FFFFF)) {
2119 cifs_dbg(VFS, "buffer length %d or smb length %d too large\n",
2120 buffer_length, smb_len);
2124 if ((begin_of_buf > end_of_smb) || (end_of_buf > end_of_smb)) {
2125 cifs_dbg(VFS, "illegal server response, bad offset to data\n");
2133 * If SMB buffer fields are valid, copy into temporary buffer to hold result.
2134 * Caller must free buffer.
2137 validate_and_copy_buf(unsigned int offset, unsigned int buffer_length,
2138 struct smb2_hdr *hdr, unsigned int minbufsize,
2142 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
2148 rc = validate_buf(offset, buffer_length, hdr, minbufsize);
2152 memcpy(data, begin_of_buf, buffer_length);
2158 query_info(const unsigned int xid, struct cifs_tcon *tcon,
2159 u64 persistent_fid, u64 volatile_fid, u8 info_class, u8 info_type,
2160 u32 additional_info, size_t output_len, size_t min_len, void **data,
2163 struct smb2_query_info_req *req;
2164 struct smb2_query_info_rsp *rsp = NULL;
2166 struct kvec rsp_iov;
2169 struct cifs_ses *ses = tcon->ses;
2171 unsigned int total_len;
2173 cifs_dbg(FYI, "Query Info\n");
2175 if (!ses || !(ses->server))
2178 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, (void **) &req,
2183 if (encryption_required(tcon))
2184 flags |= CIFS_TRANSFORM_REQ;
2186 req->InfoType = info_type;
2187 req->FileInfoClass = info_class;
2188 req->PersistentFileId = persistent_fid;
2189 req->VolatileFileId = volatile_fid;
2190 req->AdditionalInformation = cpu_to_le32(additional_info);
2193 * We do not use the input buffer (do not send extra byte)
2195 req->InputBufferOffset = 0;
2197 req->OutputBufferLength = cpu_to_le32(output_len);
2199 iov[0].iov_base = (char *)req;
2201 iov[0].iov_len = total_len - 1;
2203 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
2204 cifs_small_buf_release(req);
2205 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2208 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
2213 *dlen = le32_to_cpu(rsp->OutputBufferLength);
2215 *data = kmalloc(*dlen, GFP_KERNEL);
2218 "Error %d allocating memory for acl\n",
2226 rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset),
2227 le32_to_cpu(rsp->OutputBufferLength),
2228 &rsp->hdr, min_len, *data);
2231 free_rsp_buf(resp_buftype, rsp);
2235 int SMB2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
2236 u64 persistent_fid, u64 volatile_fid,
2237 int ea_buf_size, struct smb2_file_full_ea_info *data)
2239 return query_info(xid, tcon, persistent_fid, volatile_fid,
2240 FILE_FULL_EA_INFORMATION, SMB2_O_INFO_FILE, 0,
2242 sizeof(struct smb2_file_full_ea_info),
2247 int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
2248 u64 persistent_fid, u64 volatile_fid, struct smb2_file_all_info *data)
2250 return query_info(xid, tcon, persistent_fid, volatile_fid,
2251 FILE_ALL_INFORMATION, SMB2_O_INFO_FILE, 0,
2252 sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
2253 sizeof(struct smb2_file_all_info), (void **)&data,
2258 SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon,
2259 u64 persistent_fid, u64 volatile_fid,
2260 void **data, u32 *plen)
2262 __u32 additional_info = OWNER_SECINFO | GROUP_SECINFO | DACL_SECINFO;
2265 return query_info(xid, tcon, persistent_fid, volatile_fid,
2266 0, SMB2_O_INFO_SECURITY, additional_info,
2267 SMB2_MAX_BUFFER_SIZE,
2268 sizeof(struct smb2_file_all_info), data, plen);
2272 SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
2273 u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid)
2275 return query_info(xid, tcon, persistent_fid, volatile_fid,
2276 FILE_INTERNAL_INFORMATION, SMB2_O_INFO_FILE, 0,
2277 sizeof(struct smb2_file_internal_info),
2278 sizeof(struct smb2_file_internal_info),
2279 (void **)&uniqueid, NULL);
2283 * This is a no-op for now. We're not really interested in the reply, but
2284 * rather in the fact that the server sent one and that server->lstrp
2287 * FIXME: maybe we should consider checking that the reply matches request?
2290 smb2_echo_callback(struct mid_q_entry *mid)
2292 struct TCP_Server_Info *server = mid->callback_data;
2293 struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf;
2294 unsigned int credits_received = 1;
2296 if (mid->mid_state == MID_RESPONSE_RECEIVED)
2297 credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
2299 DeleteMidQEntry(mid);
2300 add_credits(server, credits_received, CIFS_ECHO_OP);
2303 void smb2_reconnect_server(struct work_struct *work)
2305 struct TCP_Server_Info *server = container_of(work,
2306 struct TCP_Server_Info, reconnect.work);
2307 struct cifs_ses *ses;
2308 struct cifs_tcon *tcon, *tcon2;
2309 struct list_head tmp_list;
2310 int tcon_exist = false;
2312 int resched = false;
2315 /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */
2316 mutex_lock(&server->reconnect_mutex);
2318 INIT_LIST_HEAD(&tmp_list);
2319 cifs_dbg(FYI, "Need negotiate, reconnecting tcons\n");
2321 spin_lock(&cifs_tcp_ses_lock);
2322 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2323 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2324 if (tcon->need_reconnect || tcon->need_reopen_files) {
2326 list_add_tail(&tcon->rlist, &tmp_list);
2330 if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) {
2331 list_add_tail(&ses->tcon_ipc->rlist, &tmp_list);
2336 * Get the reference to server struct to be sure that the last call of
2337 * cifs_put_tcon() in the loop below won't release the server pointer.
2340 server->srv_count++;
2342 spin_unlock(&cifs_tcp_ses_lock);
2344 list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) {
2345 rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon);
2347 cifs_reopen_persistent_handles(tcon);
2350 list_del_init(&tcon->rlist);
2351 cifs_put_tcon(tcon);
2354 cifs_dbg(FYI, "Reconnecting tcons finished\n");
2356 queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ);
2357 mutex_unlock(&server->reconnect_mutex);
2359 /* now we can safely release srv struct */
2361 cifs_put_tcp_session(server, 1);
2365 SMB2_echo(struct TCP_Server_Info *server)
2367 struct smb2_echo_req *req;
2370 struct smb_rqst rqst = { .rq_iov = iov,
2372 unsigned int total_len;
2373 __be32 rfc1002_marker;
2375 cifs_dbg(FYI, "In echo request\n");
2377 if (server->tcpStatus == CifsNeedNegotiate) {
2378 /* No need to send echo on newly established connections */
2379 queue_delayed_work(cifsiod_wq, &server->reconnect, 0);
2383 rc = smb2_plain_req_init(SMB2_ECHO, NULL, (void **)&req, &total_len);
2387 req->sync_hdr.CreditRequest = cpu_to_le16(1);
2390 rfc1002_marker = cpu_to_be32(total_len);
2391 iov[0].iov_base = &rfc1002_marker;
2392 iov[1].iov_len = total_len;
2393 iov[1].iov_base = (char *)req;
2395 rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, NULL,
2396 server, CIFS_ECHO_OP);
2398 cifs_dbg(FYI, "Echo request failed: %d\n", rc);
2400 cifs_small_buf_release(req);
2405 SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
2408 struct smb2_flush_req *req;
2409 struct cifs_ses *ses = tcon->ses;
2411 struct kvec rsp_iov;
2415 unsigned int total_len;
2417 cifs_dbg(FYI, "Flush\n");
2419 if (!ses || !(ses->server))
2422 rc = smb2_plain_req_init(SMB2_FLUSH, tcon, (void **) &req, &total_len);
2426 if (encryption_required(tcon))
2427 flags |= CIFS_TRANSFORM_REQ;
2429 req->PersistentFileId = persistent_fid;
2430 req->VolatileFileId = volatile_fid;
2432 iov[0].iov_base = (char *)req;
2433 iov[0].iov_len = total_len;
2435 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
2436 cifs_small_buf_release(req);
2439 cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE);
2441 free_rsp_buf(resp_buftype, rsp_iov.iov_base);
2446 * To form a chain of read requests, any read requests after the first should
2447 * have the end_of_chain boolean set to true.
2450 smb2_new_read_req(void **buf, unsigned int *total_len,
2451 struct cifs_io_parms *io_parms, struct cifs_readdata *rdata,
2452 unsigned int remaining_bytes, int request_type)
2455 struct smb2_read_plain_req *req = NULL;
2456 struct smb2_sync_hdr *shdr;
2457 struct TCP_Server_Info *server;
2459 rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, (void **) &req,
2464 server = io_parms->tcon->ses->server;
2466 return -ECONNABORTED;
2468 shdr = &req->sync_hdr;
2469 shdr->ProcessId = cpu_to_le32(io_parms->pid);
2471 req->PersistentFileId = io_parms->persistent_fid;
2472 req->VolatileFileId = io_parms->volatile_fid;
2473 req->ReadChannelInfoOffset = 0; /* reserved */
2474 req->ReadChannelInfoLength = 0; /* reserved */
2475 req->Channel = 0; /* reserved */
2476 req->MinimumCount = 0;
2477 req->Length = cpu_to_le32(io_parms->length);
2478 req->Offset = cpu_to_le64(io_parms->offset);
2479 #ifdef CONFIG_CIFS_SMB_DIRECT
2481 * If we want to do a RDMA write, fill in and append
2482 * smbd_buffer_descriptor_v1 to the end of read request
2484 if (server->rdma && rdata &&
2485 rdata->bytes >= server->smbd_conn->rdma_readwrite_threshold) {
2487 struct smbd_buffer_descriptor_v1 *v1;
2488 bool need_invalidate =
2489 io_parms->tcon->ses->server->dialect == SMB30_PROT_ID;
2491 rdata->mr = smbd_register_mr(
2492 server->smbd_conn, rdata->pages,
2493 rdata->nr_pages, rdata->tailsz,
2494 true, need_invalidate);
2498 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE;
2499 if (need_invalidate)
2500 req->Channel = SMB2_CHANNEL_RDMA_V1;
2501 req->ReadChannelInfoOffset =
2502 cpu_to_le16(offsetof(struct smb2_read_plain_req, Buffer));
2503 req->ReadChannelInfoLength =
2504 cpu_to_le16(sizeof(struct smbd_buffer_descriptor_v1));
2505 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0];
2506 v1->offset = cpu_to_le64(rdata->mr->mr->iova);
2507 v1->token = cpu_to_le32(rdata->mr->mr->rkey);
2508 v1->length = cpu_to_le32(rdata->mr->mr->length);
2510 *total_len += sizeof(*v1) - 1;
2513 if (request_type & CHAINED_REQUEST) {
2514 if (!(request_type & END_OF_CHAIN)) {
2515 /* next 8-byte aligned request */
2516 *total_len = DIV_ROUND_UP(*total_len, 8) * 8;
2517 shdr->NextCommand = cpu_to_le32(*total_len);
2518 } else /* END_OF_CHAIN */
2519 shdr->NextCommand = 0;
2520 if (request_type & RELATED_REQUEST) {
2521 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2523 * Related requests use info from previous read request
2526 shdr->SessionId = 0xFFFFFFFF;
2527 shdr->TreeId = 0xFFFFFFFF;
2528 req->PersistentFileId = 0xFFFFFFFF;
2529 req->VolatileFileId = 0xFFFFFFFF;
2532 if (remaining_bytes > io_parms->length)
2533 req->RemainingBytes = cpu_to_le32(remaining_bytes);
2535 req->RemainingBytes = 0;
2542 smb2_readv_callback(struct mid_q_entry *mid)
2544 struct cifs_readdata *rdata = mid->callback_data;
2545 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
2546 struct TCP_Server_Info *server = tcon->ses->server;
2547 struct smb2_sync_hdr *shdr =
2548 (struct smb2_sync_hdr *)rdata->iov[1].iov_base;
2549 unsigned int credits_received = 1;
2550 struct smb_rqst rqst = { .rq_iov = rdata->iov,
2552 .rq_pages = rdata->pages,
2553 .rq_npages = rdata->nr_pages,
2554 .rq_pagesz = rdata->pagesz,
2555 .rq_tailsz = rdata->tailsz };
2557 cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n",
2558 __func__, mid->mid, mid->mid_state, rdata->result,
2561 switch (mid->mid_state) {
2562 case MID_RESPONSE_RECEIVED:
2563 credits_received = le16_to_cpu(shdr->CreditRequest);
2564 /* result already set, check signature */
2565 if (server->sign && !mid->decrypted) {
2568 rc = smb2_verify_signature(&rqst, server);
2570 cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
2573 /* FIXME: should this be counted toward the initiating task? */
2574 task_io_account_read(rdata->got_bytes);
2575 cifs_stats_bytes_read(tcon, rdata->got_bytes);
2577 case MID_REQUEST_SUBMITTED:
2578 case MID_RETRY_NEEDED:
2579 rdata->result = -EAGAIN;
2580 if (server->sign && rdata->got_bytes)
2581 /* reset bytes number since we can not check a sign */
2582 rdata->got_bytes = 0;
2583 /* FIXME: should this be counted toward the initiating task? */
2584 task_io_account_read(rdata->got_bytes);
2585 cifs_stats_bytes_read(tcon, rdata->got_bytes);
2588 if (rdata->result != -ENODATA)
2589 rdata->result = -EIO;
2591 #ifdef CONFIG_CIFS_SMB_DIRECT
2593 * If this rdata has a memmory registered, the MR can be freed
2594 * MR needs to be freed as soon as I/O finishes to prevent deadlock
2595 * because they have limited number and are used for future I/Os
2598 smbd_deregister_mr(rdata->mr);
2603 cifs_stats_fail_inc(tcon, SMB2_READ_HE);
2605 queue_work(cifsiod_wq, &rdata->work);
2606 DeleteMidQEntry(mid);
2607 add_credits(server, credits_received, 0);
2610 /* smb2_async_readv - send an async read, and set up mid to handle result */
2612 smb2_async_readv(struct cifs_readdata *rdata)
2616 struct smb2_sync_hdr *shdr;
2617 struct cifs_io_parms io_parms;
2618 struct smb_rqst rqst = { .rq_iov = rdata->iov,
2620 struct TCP_Server_Info *server;
2621 unsigned int total_len;
2624 cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n",
2625 __func__, rdata->offset, rdata->bytes);
2627 io_parms.tcon = tlink_tcon(rdata->cfile->tlink);
2628 io_parms.offset = rdata->offset;
2629 io_parms.length = rdata->bytes;
2630 io_parms.persistent_fid = rdata->cfile->fid.persistent_fid;
2631 io_parms.volatile_fid = rdata->cfile->fid.volatile_fid;
2632 io_parms.pid = rdata->pid;
2634 server = io_parms.tcon->ses->server;
2636 rc = smb2_new_read_req(
2637 (void **) &buf, &total_len, &io_parms, rdata, 0, 0);
2639 if (rc == -EAGAIN && rdata->credits) {
2640 /* credits was reset by reconnect */
2642 /* reduce in_flight value since we won't send the req */
2643 spin_lock(&server->req_lock);
2644 server->in_flight--;
2645 spin_unlock(&server->req_lock);
2650 if (encryption_required(io_parms.tcon))
2651 flags |= CIFS_TRANSFORM_REQ;
2653 req_len = cpu_to_be32(total_len);
2655 rdata->iov[0].iov_base = &req_len;
2656 rdata->iov[0].iov_len = sizeof(__be32);
2657 rdata->iov[1].iov_base = buf;
2658 rdata->iov[1].iov_len = total_len;
2660 shdr = (struct smb2_sync_hdr *)buf;
2662 if (rdata->credits) {
2663 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
2664 SMB2_MAX_BUFFER_SIZE));
2665 shdr->CreditRequest = shdr->CreditCharge;
2666 spin_lock(&server->req_lock);
2667 server->credits += rdata->credits -
2668 le16_to_cpu(shdr->CreditCharge);
2669 spin_unlock(&server->req_lock);
2670 wake_up(&server->request_q);
2671 flags |= CIFS_HAS_CREDITS;
2674 kref_get(&rdata->refcount);
2675 rc = cifs_call_async(io_parms.tcon->ses->server, &rqst,
2676 cifs_readv_receive, smb2_readv_callback,
2677 smb3_handle_read_data, rdata, flags);
2679 kref_put(&rdata->refcount, cifs_readdata_release);
2680 cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE);
2683 cifs_small_buf_release(buf);
2688 SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
2689 unsigned int *nbytes, char **buf, int *buf_type)
2691 int resp_buftype, rc = -EACCES;
2692 struct smb2_read_plain_req *req = NULL;
2693 struct smb2_read_rsp *rsp = NULL;
2694 struct smb2_sync_hdr *shdr;
2696 struct kvec rsp_iov;
2697 unsigned int total_len;
2698 int flags = CIFS_LOG_ERROR;
2699 struct cifs_ses *ses = io_parms->tcon->ses;
2702 rc = smb2_new_read_req((void **)&req, &total_len, io_parms, NULL, 0, 0);
2706 if (encryption_required(io_parms->tcon))
2707 flags |= CIFS_TRANSFORM_REQ;
2709 iov[0].iov_base = (char *)req;
2710 iov[0].iov_len = total_len;
2712 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
2713 cifs_small_buf_release(req);
2715 rsp = (struct smb2_read_rsp *)rsp_iov.iov_base;
2718 if (rc != -ENODATA) {
2719 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE);
2720 cifs_dbg(VFS, "Send error in read = %d\n", rc);
2722 free_rsp_buf(resp_buftype, rsp_iov.iov_base);
2723 return rc == -ENODATA ? 0 : rc;
2726 *nbytes = le32_to_cpu(rsp->DataLength);
2727 if ((*nbytes > CIFS_MAX_MSGSIZE) ||
2728 (*nbytes > io_parms->length)) {
2729 cifs_dbg(FYI, "bad length %d for count %d\n",
2730 *nbytes, io_parms->length);
2735 shdr = get_sync_hdr(rsp);
2738 memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes);
2739 free_rsp_buf(resp_buftype, rsp_iov.iov_base);
2740 } else if (resp_buftype != CIFS_NO_BUFFER) {
2741 *buf = rsp_iov.iov_base;
2742 if (resp_buftype == CIFS_SMALL_BUFFER)
2743 *buf_type = CIFS_SMALL_BUFFER;
2744 else if (resp_buftype == CIFS_LARGE_BUFFER)
2745 *buf_type = CIFS_LARGE_BUFFER;
2751 * Check the mid_state and signature on received buffer (if any), and queue the
2752 * workqueue completion task.
2755 smb2_writev_callback(struct mid_q_entry *mid)
2757 struct cifs_writedata *wdata = mid->callback_data;
2758 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2759 unsigned int written;
2760 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf;
2761 unsigned int credits_received = 1;
2763 switch (mid->mid_state) {
2764 case MID_RESPONSE_RECEIVED:
2765 credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
2766 wdata->result = smb2_check_receive(mid, tcon->ses->server, 0);
2767 if (wdata->result != 0)
2770 written = le32_to_cpu(rsp->DataLength);
2772 * Mask off high 16 bits when bytes written as returned
2773 * by the server is greater than bytes requested by the
2774 * client. OS/2 servers are known to set incorrect
2777 if (written > wdata->bytes)
2780 if (written < wdata->bytes)
2781 wdata->result = -ENOSPC;
2783 wdata->bytes = written;
2785 case MID_REQUEST_SUBMITTED:
2786 case MID_RETRY_NEEDED:
2787 wdata->result = -EAGAIN;
2790 wdata->result = -EIO;
2793 #ifdef CONFIG_CIFS_SMB_DIRECT
2795 * If this wdata has a memory registered, the MR can be freed
2796 * The number of MRs available is limited, it's important to recover
2797 * used MR as soon as I/O is finished. Hold MR longer in the later
2798 * I/O process can possibly result in I/O deadlock due to lack of MR
2799 * to send request on I/O retry
2802 smbd_deregister_mr(wdata->mr);
2807 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
2809 queue_work(cifsiod_wq, &wdata->work);
2810 DeleteMidQEntry(mid);
2811 add_credits(tcon->ses->server, credits_received, 0);
2814 /* smb2_async_writev - send an async write, and set up mid to handle result */
2816 smb2_async_writev(struct cifs_writedata *wdata,
2817 void (*release)(struct kref *kref))
2819 int rc = -EACCES, flags = 0;
2820 struct smb2_write_req *req = NULL;
2821 struct smb2_sync_hdr *shdr;
2822 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2823 struct TCP_Server_Info *server = tcon->ses->server;
2825 struct smb_rqst rqst = { };
2826 unsigned int total_len;
2827 __be32 rfc1002_marker;
2829 rc = smb2_plain_req_init(SMB2_WRITE, tcon, (void **) &req, &total_len);
2831 if (rc == -EAGAIN && wdata->credits) {
2832 /* credits was reset by reconnect */
2834 /* reduce in_flight value since we won't send the req */
2835 spin_lock(&server->req_lock);
2836 server->in_flight--;
2837 spin_unlock(&server->req_lock);
2839 goto async_writev_out;
2842 if (encryption_required(tcon))
2843 flags |= CIFS_TRANSFORM_REQ;
2845 shdr = (struct smb2_sync_hdr *)req;
2846 shdr->ProcessId = cpu_to_le32(wdata->cfile->pid);
2848 req->PersistentFileId = wdata->cfile->fid.persistent_fid;
2849 req->VolatileFileId = wdata->cfile->fid.volatile_fid;
2850 req->WriteChannelInfoOffset = 0;
2851 req->WriteChannelInfoLength = 0;
2853 req->Offset = cpu_to_le64(wdata->offset);
2854 req->DataOffset = cpu_to_le16(
2855 offsetof(struct smb2_write_req, Buffer));
2856 req->RemainingBytes = 0;
2857 #ifdef CONFIG_CIFS_SMB_DIRECT
2859 * If we want to do a server RDMA read, fill in and append
2860 * smbd_buffer_descriptor_v1 to the end of write request
2862 if (server->rdma && wdata->bytes >=
2863 server->smbd_conn->rdma_readwrite_threshold) {
2865 struct smbd_buffer_descriptor_v1 *v1;
2866 bool need_invalidate = server->dialect == SMB30_PROT_ID;
2868 wdata->mr = smbd_register_mr(
2869 server->smbd_conn, wdata->pages,
2870 wdata->nr_pages, wdata->tailsz,
2871 false, need_invalidate);
2874 goto async_writev_out;
2877 req->DataOffset = 0;
2878 req->RemainingBytes =
2879 cpu_to_le32((wdata->nr_pages-1)*PAGE_SIZE + wdata->tailsz);
2880 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE;
2881 if (need_invalidate)
2882 req->Channel = SMB2_CHANNEL_RDMA_V1;
2883 req->WriteChannelInfoOffset =
2884 cpu_to_le16(offsetof(struct smb2_write_req, Buffer));
2885 req->WriteChannelInfoLength =
2886 cpu_to_le16(sizeof(struct smbd_buffer_descriptor_v1));
2887 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0];
2888 v1->offset = cpu_to_le64(wdata->mr->mr->iova);
2889 v1->token = cpu_to_le32(wdata->mr->mr->rkey);
2890 v1->length = cpu_to_le32(wdata->mr->mr->length);
2893 /* 4 for rfc1002 length field and 1 for Buffer */
2895 rfc1002_marker = cpu_to_be32(total_len - 1 + wdata->bytes);
2896 iov[0].iov_base = &rfc1002_marker;
2897 iov[1].iov_len = total_len - 1;
2898 iov[1].iov_base = (char *)req;
2902 rqst.rq_pages = wdata->pages;
2903 rqst.rq_npages = wdata->nr_pages;
2904 rqst.rq_pagesz = wdata->pagesz;
2905 rqst.rq_tailsz = wdata->tailsz;
2906 #ifdef CONFIG_CIFS_SMB_DIRECT
2908 iov[1].iov_len += sizeof(struct smbd_buffer_descriptor_v1);
2912 cifs_dbg(FYI, "async write at %llu %u bytes\n",
2913 wdata->offset, wdata->bytes);
2915 #ifdef CONFIG_CIFS_SMB_DIRECT
2916 /* For RDMA read, I/O size is in RemainingBytes not in Length */
2918 req->Length = cpu_to_le32(wdata->bytes);
2920 req->Length = cpu_to_le32(wdata->bytes);
2923 if (wdata->credits) {
2924 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
2925 SMB2_MAX_BUFFER_SIZE));
2926 shdr->CreditRequest = shdr->CreditCharge;
2927 spin_lock(&server->req_lock);
2928 server->credits += wdata->credits -
2929 le16_to_cpu(shdr->CreditCharge);
2930 spin_unlock(&server->req_lock);
2931 wake_up(&server->request_q);
2932 flags |= CIFS_HAS_CREDITS;
2935 kref_get(&wdata->refcount);
2936 rc = cifs_call_async(server, &rqst, NULL, smb2_writev_callback, NULL,
2940 kref_put(&wdata->refcount, release);
2941 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
2945 cifs_small_buf_release(req);
2950 * SMB2_write function gets iov pointer to kvec array with n_vec as a length.
2951 * The length field from io_parms must be at least 1 and indicates a number of
2952 * elements with data to write that begins with position 1 in iov array. All
2953 * data length is specified by count.
2956 SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
2957 unsigned int *nbytes, struct kvec *iov, int n_vec)
2960 struct smb2_write_req *req = NULL;
2961 struct smb2_write_rsp *rsp = NULL;
2963 struct kvec rsp_iov;
2965 unsigned int total_len;
2972 rc = smb2_plain_req_init(SMB2_WRITE, io_parms->tcon, (void **) &req,
2977 if (io_parms->tcon->ses->server == NULL)
2978 return -ECONNABORTED;
2980 if (encryption_required(io_parms->tcon))
2981 flags |= CIFS_TRANSFORM_REQ;
2983 req->sync_hdr.ProcessId = cpu_to_le32(io_parms->pid);
2985 req->PersistentFileId = io_parms->persistent_fid;
2986 req->VolatileFileId = io_parms->volatile_fid;
2987 req->WriteChannelInfoOffset = 0;
2988 req->WriteChannelInfoLength = 0;
2990 req->Length = cpu_to_le32(io_parms->length);
2991 req->Offset = cpu_to_le64(io_parms->offset);
2992 req->DataOffset = cpu_to_le16(
2993 offsetof(struct smb2_write_req, Buffer));
2994 req->RemainingBytes = 0;
2996 iov[0].iov_base = (char *)req;
2998 iov[0].iov_len = total_len - 1;
3000 rc = smb2_send_recv(xid, io_parms->tcon->ses, iov, n_vec + 1,
3001 &resp_buftype, flags, &rsp_iov);
3002 cifs_small_buf_release(req);
3003 rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
3006 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
3007 cifs_dbg(VFS, "Send error in write = %d\n", rc);
3009 *nbytes = le32_to_cpu(rsp->DataLength);
3011 free_rsp_buf(resp_buftype, rsp);
3016 num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)
3019 unsigned int entrycount = 0;
3020 unsigned int next_offset = 0;
3021 FILE_DIRECTORY_INFO *entryptr;
3023 if (bufstart == NULL)
3026 entryptr = (FILE_DIRECTORY_INFO *)bufstart;
3029 entryptr = (FILE_DIRECTORY_INFO *)
3030 ((char *)entryptr + next_offset);
3032 if ((char *)entryptr + size > end_of_buf) {
3033 cifs_dbg(VFS, "malformed search entry would overflow\n");
3037 len = le32_to_cpu(entryptr->FileNameLength);
3038 if ((char *)entryptr + len + size > end_of_buf) {
3039 cifs_dbg(VFS, "directory entry name would overflow frame end of buf %p\n",
3044 *lastentry = (char *)entryptr;
3047 next_offset = le32_to_cpu(entryptr->NextEntryOffset);
3059 SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
3060 u64 persistent_fid, u64 volatile_fid, int index,
3061 struct cifs_search_info *srch_inf)
3063 struct smb2_query_directory_req *req;
3064 struct smb2_query_directory_rsp *rsp = NULL;
3066 struct kvec rsp_iov;
3069 int resp_buftype = CIFS_NO_BUFFER;
3070 unsigned char *bufptr;
3071 struct TCP_Server_Info *server;
3072 struct cifs_ses *ses = tcon->ses;
3073 __le16 asteriks = cpu_to_le16('*');
3075 unsigned int output_size = CIFSMaxBufSize;
3076 size_t info_buf_size;
3078 unsigned int total_len;
3080 if (ses && (ses->server))
3081 server = ses->server;
3085 rc = smb2_plain_req_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req,
3090 if (encryption_required(tcon))
3091 flags |= CIFS_TRANSFORM_REQ;
3093 switch (srch_inf->info_level) {
3094 case SMB_FIND_FILE_DIRECTORY_INFO:
3095 req->FileInformationClass = FILE_DIRECTORY_INFORMATION;
3096 info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1;
3098 case SMB_FIND_FILE_ID_FULL_DIR_INFO:
3099 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION;
3100 info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1;
3103 cifs_dbg(VFS, "info level %u isn't supported\n",
3104 srch_inf->info_level);
3109 req->FileIndex = cpu_to_le32(index);
3110 req->PersistentFileId = persistent_fid;
3111 req->VolatileFileId = volatile_fid;
3114 bufptr = req->Buffer;
3115 memcpy(bufptr, &asteriks, len);
3117 req->FileNameOffset =
3118 cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1);
3119 req->FileNameLength = cpu_to_le16(len);
3121 * BB could be 30 bytes or so longer if we used SMB2 specific
3122 * buffer lengths, but this is safe and close enough.
3124 output_size = min_t(unsigned int, output_size, server->maxBuf);
3125 output_size = min_t(unsigned int, output_size, 2 << 15);
3126 req->OutputBufferLength = cpu_to_le32(output_size);
3128 iov[0].iov_base = (char *)req;
3130 iov[0].iov_len = total_len - 1;
3132 iov[1].iov_base = (char *)(req->Buffer);
3133 iov[1].iov_len = len;
3135 rc = smb2_send_recv(xid, ses, iov, 2, &resp_buftype, flags, &rsp_iov);
3136 cifs_small_buf_release(req);
3137 rsp = (struct smb2_query_directory_rsp *)rsp_iov.iov_base;
3140 if (rc == -ENODATA &&
3141 rsp->hdr.sync_hdr.Status == STATUS_NO_MORE_FILES) {
3142 srch_inf->endOfSearch = true;
3145 cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE);
3149 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
3150 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
3155 srch_inf->unicode = true;
3157 if (srch_inf->ntwrk_buf_start) {
3158 if (srch_inf->smallBuf)
3159 cifs_small_buf_release(srch_inf->ntwrk_buf_start);
3161 cifs_buf_release(srch_inf->ntwrk_buf_start);
3163 srch_inf->ntwrk_buf_start = (char *)rsp;
3164 srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ +
3165 (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset);
3166 /* 4 for rfc1002 length field */
3167 end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr;
3168 srch_inf->entries_in_buffer =
3169 num_entries(srch_inf->srch_entries_start, end_of_smb,
3170 &srch_inf->last_entry, info_buf_size);
3171 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer;
3172 cifs_dbg(FYI, "num entries %d last_index %lld srch start %p srch end %p\n",
3173 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry,
3174 srch_inf->srch_entries_start, srch_inf->last_entry);
3175 if (resp_buftype == CIFS_LARGE_BUFFER)
3176 srch_inf->smallBuf = false;
3177 else if (resp_buftype == CIFS_SMALL_BUFFER)
3178 srch_inf->smallBuf = true;
3180 cifs_dbg(VFS, "illegal search buffer type\n");
3185 free_rsp_buf(resp_buftype, rsp);
3190 send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
3191 u64 persistent_fid, u64 volatile_fid, u32 pid, u8 info_class,
3192 u8 info_type, u32 additional_info, unsigned int num,
3193 void **data, unsigned int *size)
3195 struct smb2_set_info_req *req;
3196 struct smb2_set_info_rsp *rsp = NULL;
3198 struct kvec rsp_iov;
3202 struct cifs_ses *ses = tcon->ses;
3204 unsigned int total_len;
3206 if (!ses || !(ses->server))
3212 iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL);
3216 rc = smb2_plain_req_init(SMB2_SET_INFO, tcon, (void **) &req, &total_len);
3222 if (encryption_required(tcon))
3223 flags |= CIFS_TRANSFORM_REQ;
3225 req->sync_hdr.ProcessId = cpu_to_le32(pid);
3227 req->InfoType = info_type;
3228 req->FileInfoClass = info_class;
3229 req->PersistentFileId = persistent_fid;
3230 req->VolatileFileId = volatile_fid;
3231 req->AdditionalInformation = cpu_to_le32(additional_info);
3234 cpu_to_le16(sizeof(struct smb2_set_info_req) - 1);
3235 req->BufferLength = cpu_to_le32(*size);
3237 memcpy(req->Buffer, *data, *size);
3240 iov[0].iov_base = (char *)req;
3242 iov[0].iov_len = total_len - 1;
3244 for (i = 1; i < num; i++) {
3245 le32_add_cpu(&req->BufferLength, size[i]);
3246 iov[i].iov_base = (char *)data[i];
3247 iov[i].iov_len = size[i];
3250 rc = smb2_send_recv(xid, ses, iov, num, &resp_buftype, flags,
3252 cifs_small_buf_release(req);
3253 rsp = (struct smb2_set_info_rsp *)rsp_iov.iov_base;
3256 cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE);
3258 free_rsp_buf(resp_buftype, rsp);
3264 SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
3265 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
3267 struct smb2_file_rename_info info;
3269 unsigned int size[2];
3271 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
3273 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
3277 info.ReplaceIfExists = 1; /* 1 = replace existing target with new */
3278 /* 0 = fail if target already exists */
3279 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
3280 info.FileNameLength = cpu_to_le32(len);
3283 size[0] = sizeof(struct smb2_file_rename_info);
3285 data[1] = target_file;
3286 size[1] = len + 2 /* null */;
3288 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
3289 current->tgid, FILE_RENAME_INFORMATION, SMB2_O_INFO_FILE,
3296 SMB2_rmdir(const unsigned int xid, struct cifs_tcon *tcon,
3297 u64 persistent_fid, u64 volatile_fid)
3299 __u8 delete_pending = 1;
3303 data = &delete_pending;
3304 size = 1; /* sizeof __u8 */
3306 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3307 current->tgid, FILE_DISPOSITION_INFORMATION, SMB2_O_INFO_FILE,
3308 0, 1, &data, &size);
3312 SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
3313 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
3315 struct smb2_file_link_info info;
3317 unsigned int size[2];
3319 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
3321 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
3325 info.ReplaceIfExists = 0; /* 1 = replace existing link with new */
3326 /* 0 = fail if link already exists */
3327 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
3328 info.FileNameLength = cpu_to_le32(len);
3331 size[0] = sizeof(struct smb2_file_link_info);
3333 data[1] = target_file;
3334 size[1] = len + 2 /* null */;
3336 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
3337 current->tgid, FILE_LINK_INFORMATION, SMB2_O_INFO_FILE,
3344 SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
3345 u64 volatile_fid, u32 pid, __le64 *eof, bool is_falloc)
3347 struct smb2_file_eof_info info;
3351 info.EndOfFile = *eof;
3354 size = sizeof(struct smb2_file_eof_info);
3357 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3358 pid, FILE_ALLOCATION_INFORMATION, SMB2_O_INFO_FILE,
3359 0, 1, &data, &size);
3361 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3362 pid, FILE_END_OF_FILE_INFORMATION, SMB2_O_INFO_FILE,
3363 0, 1, &data, &size);
3367 SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon,
3368 u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf)
3371 size = sizeof(FILE_BASIC_INFO);
3372 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3373 current->tgid, FILE_BASIC_INFORMATION, SMB2_O_INFO_FILE,
3374 0, 1, (void **)&buf, &size);
3378 SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
3379 u64 persistent_fid, u64 volatile_fid,
3380 struct cifs_ntsd *pnntsd, int pacllen, int aclflag)
3382 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3383 current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag,
3384 1, (void **)&pnntsd, &pacllen);
3388 SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
3389 u64 persistent_fid, u64 volatile_fid,
3390 struct smb2_file_full_ea_info *buf, int len)
3392 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
3393 current->tgid, FILE_FULL_EA_INFORMATION, SMB2_O_INFO_FILE,
3394 0, 1, (void **)&buf, &len);
3398 SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
3399 const u64 persistent_fid, const u64 volatile_fid,
3403 struct smb2_oplock_break_req *req = NULL;
3404 struct cifs_ses *ses = tcon->ses;
3405 int flags = CIFS_OBREAK_OP;
3406 unsigned int total_len;
3408 struct kvec rsp_iov;
3411 cifs_dbg(FYI, "SMB2_oplock_break\n");
3412 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req,
3417 if (encryption_required(tcon))
3418 flags |= CIFS_TRANSFORM_REQ;
3420 req->VolatileFid = volatile_fid;
3421 req->PersistentFid = persistent_fid;
3422 req->OplockLevel = oplock_level;
3423 req->sync_hdr.CreditRequest = cpu_to_le16(1);
3425 flags |= CIFS_NO_RESP;
3427 iov[0].iov_base = (char *)req;
3428 iov[0].iov_len = total_len;
3430 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov);
3431 cifs_small_buf_release(req);
3434 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
3435 cifs_dbg(FYI, "Send error in Oplock Break = %d\n", rc);
3442 copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
3443 struct kstatfs *kst)
3445 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) *
3446 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit);
3447 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits);
3448 kst->f_bfree = kst->f_bavail =
3449 le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits);
3454 build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level,
3455 int outbuf_len, u64 persistent_fid, u64 volatile_fid)
3457 struct TCP_Server_Info *server = tcon->ses->server;
3459 struct smb2_query_info_req *req;
3460 unsigned int total_len;
3462 cifs_dbg(FYI, "Query FSInfo level %d\n", level);
3464 if ((tcon->ses == NULL) || (tcon->ses->server == NULL))
3467 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, (void **) &req,
3472 req->InfoType = SMB2_O_INFO_FILESYSTEM;
3473 req->FileInfoClass = level;
3474 req->PersistentFileId = persistent_fid;
3475 req->VolatileFileId = volatile_fid;
3477 req->InputBufferOffset =
3478 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1);
3479 req->OutputBufferLength = cpu_to_le32(
3480 outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - server->vals->header_preamble_size);
3482 iov->iov_base = (char *)req;
3483 iov->iov_len = total_len;
3488 SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
3489 u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata)
3491 struct smb2_query_info_rsp *rsp = NULL;
3493 struct kvec rsp_iov;
3496 struct cifs_ses *ses = tcon->ses;
3497 struct TCP_Server_Info *server = ses->server;
3498 struct smb2_fs_full_size_info *info = NULL;
3501 rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION,
3502 sizeof(struct smb2_fs_full_size_info),
3503 persistent_fid, volatile_fid);
3507 if (encryption_required(tcon))
3508 flags |= CIFS_TRANSFORM_REQ;
3510 rc = smb2_send_recv(xid, ses, &iov, 1, &resp_buftype, flags, &rsp_iov);
3511 cifs_small_buf_release(iov.iov_base);
3513 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
3516 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
3518 info = (struct smb2_fs_full_size_info *)(server->vals->header_preamble_size +
3519 le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr);
3520 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
3521 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
3522 sizeof(struct smb2_fs_full_size_info));
3524 copy_fs_info_to_kstatfs(info, fsdata);
3527 free_rsp_buf(resp_buftype, rsp_iov.iov_base);
3532 SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
3533 u64 persistent_fid, u64 volatile_fid, int level)
3535 struct smb2_query_info_rsp *rsp = NULL;
3537 struct kvec rsp_iov;
3539 int resp_buftype, max_len, min_len;
3540 struct cifs_ses *ses = tcon->ses;
3541 struct TCP_Server_Info *server = ses->server;
3542 unsigned int rsp_len, offset;
3545 if (level == FS_DEVICE_INFORMATION) {
3546 max_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
3547 min_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
3548 } else if (level == FS_ATTRIBUTE_INFORMATION) {
3549 max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO);
3550 min_len = MIN_FS_ATTR_INFO_SIZE;
3551 } else if (level == FS_SECTOR_SIZE_INFORMATION) {
3552 max_len = sizeof(struct smb3_fs_ss_info);
3553 min_len = sizeof(struct smb3_fs_ss_info);
3555 cifs_dbg(FYI, "Invalid qfsinfo level %d\n", level);
3559 rc = build_qfs_info_req(&iov, tcon, level, max_len,
3560 persistent_fid, volatile_fid);
3564 if (encryption_required(tcon))
3565 flags |= CIFS_TRANSFORM_REQ;
3567 rc = smb2_send_recv(xid, ses, &iov, 1, &resp_buftype, flags, &rsp_iov);
3568 cifs_small_buf_release(iov.iov_base);
3570 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
3573 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
3575 rsp_len = le32_to_cpu(rsp->OutputBufferLength);
3576 offset = le16_to_cpu(rsp->OutputBufferOffset);
3577 rc = validate_buf(offset, rsp_len, &rsp->hdr, min_len);
3581 if (level == FS_ATTRIBUTE_INFORMATION)
3582 memcpy(&tcon->fsAttrInfo, server->vals->header_preamble_size + offset
3583 + (char *)&rsp->hdr, min_t(unsigned int,
3585 else if (level == FS_DEVICE_INFORMATION)
3586 memcpy(&tcon->fsDevInfo, server->vals->header_preamble_size + offset
3587 + (char *)&rsp->hdr, sizeof(FILE_SYSTEM_DEVICE_INFO));
3588 else if (level == FS_SECTOR_SIZE_INFORMATION) {
3589 struct smb3_fs_ss_info *ss_info = (struct smb3_fs_ss_info *)
3590 (server->vals->header_preamble_size + offset + (char *)&rsp->hdr);
3591 tcon->ss_flags = le32_to_cpu(ss_info->Flags);
3592 tcon->perf_sector_size =
3593 le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf);
3597 free_rsp_buf(resp_buftype, rsp_iov.iov_base);
3602 smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
3603 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
3604 const __u32 num_lock, struct smb2_lock_element *buf)
3607 struct smb2_lock_req *req = NULL;
3609 struct kvec rsp_iov;
3612 int flags = CIFS_NO_RESP;
3613 unsigned int total_len;
3615 cifs_dbg(FYI, "smb2_lockv num lock %d\n", num_lock);
3617 rc = smb2_plain_req_init(SMB2_LOCK, tcon, (void **) &req, &total_len);
3621 if (encryption_required(tcon))
3622 flags |= CIFS_TRANSFORM_REQ;
3624 req->sync_hdr.ProcessId = cpu_to_le32(pid);
3625 req->LockCount = cpu_to_le16(num_lock);
3627 req->PersistentFileId = persist_fid;
3628 req->VolatileFileId = volatile_fid;
3630 count = num_lock * sizeof(struct smb2_lock_element);
3632 iov[0].iov_base = (char *)req;
3633 iov[0].iov_len = total_len - sizeof(struct smb2_lock_element);
3634 iov[1].iov_base = (char *)buf;
3635 iov[1].iov_len = count;
3637 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks);
3638 rc = smb2_send_recv(xid, tcon->ses, iov, 2, &resp_buf_type, flags,
3640 cifs_small_buf_release(req);
3642 cifs_dbg(FYI, "Send error in smb2_lockv = %d\n", rc);
3643 cifs_stats_fail_inc(tcon, SMB2_LOCK_HE);
3650 SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
3651 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
3652 const __u64 length, const __u64 offset, const __u32 lock_flags,
3655 struct smb2_lock_element lock;
3657 lock.Offset = cpu_to_le64(offset);
3658 lock.Length = cpu_to_le64(length);
3659 lock.Flags = cpu_to_le32(lock_flags);
3660 if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK)
3661 lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY);
3663 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock);
3667 SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
3668 __u8 *lease_key, const __le32 lease_state)
3671 struct smb2_lease_ack *req = NULL;
3672 struct cifs_ses *ses = tcon->ses;
3673 int flags = CIFS_OBREAK_OP;
3674 unsigned int total_len;
3676 struct kvec rsp_iov;
3679 cifs_dbg(FYI, "SMB2_lease_break\n");
3680 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req,
3685 if (encryption_required(tcon))
3686 flags |= CIFS_TRANSFORM_REQ;
3688 req->sync_hdr.CreditRequest = cpu_to_le16(1);
3689 req->StructureSize = cpu_to_le16(36);
3692 memcpy(req->LeaseKey, lease_key, 16);
3693 req->LeaseState = lease_state;
3695 flags |= CIFS_NO_RESP;
3697 iov[0].iov_base = (char *)req;
3698 iov[0].iov_len = total_len;
3700 rc = smb2_send_recv(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov);
3701 cifs_small_buf_release(req);
3704 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
3705 cifs_dbg(FYI, "Send error in Lease Break = %d\n", rc);