4 * Copyright (C) International Business Machines Corp., 2009, 2013
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
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/pagemap.h>
37 #include <linux/xattr.h>
41 #include "cifsproto.h"
42 #include "smb2proto.h"
43 #include "cifs_unicode.h"
44 #include "cifs_debug.h"
46 #include "smb2status.h"
49 #include "cifs_spnego.h"
52 * The following table defines the expected "StructureSize" of SMB2 requests
53 * in order by SMB2 command. This is similar to "wct" in SMB/CIFS requests.
55 * Note that commands are defined in smb2pdu.h in le16 but the array below is
56 * indexed by command in host byte order.
58 static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
59 /* SMB2_NEGOTIATE */ 36,
60 /* SMB2_SESSION_SETUP */ 25,
62 /* SMB2_TREE_CONNECT */ 9,
63 /* SMB2_TREE_DISCONNECT */ 4,
73 /* SMB2_QUERY_DIRECTORY */ 33,
74 /* SMB2_CHANGE_NOTIFY */ 32,
75 /* SMB2_QUERY_INFO */ 41,
76 /* SMB2_SET_INFO */ 33,
77 /* SMB2_OPLOCK_BREAK */ 24 /* BB this is 36 for LEASE_BREAK variant */
82 smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
83 const struct cifs_tcon *tcon)
85 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
86 char *temp = (char *)hdr;
87 /* lookup word count ie StructureSize from table */
88 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)];
91 * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of
92 * largest operations (Create)
96 /* Note this is only network field converted to big endian */
97 hdr->smb2_buf_length = cpu_to_be32(parmsize + sizeof(struct smb2_hdr)
98 - 4 /* RFC 1001 length field itself not counted */);
100 hdr->ProtocolId[0] = 0xFE;
101 hdr->ProtocolId[1] = 'S';
102 hdr->ProtocolId[2] = 'M';
103 hdr->ProtocolId[3] = 'B';
104 hdr->StructureSize = cpu_to_le16(64);
105 hdr->Command = smb2_cmd;
106 hdr->CreditRequest = cpu_to_le16(2); /* BB make this dynamic */
107 hdr->ProcessId = cpu_to_le32((__u16)current->tgid);
112 /* GLOBAL_CAP_LARGE_MTU will only be set if dialect > SMB2.02 */
113 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */
114 if ((tcon->ses) && (tcon->ses->server) &&
115 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
116 hdr->CreditCharge = cpu_to_le16(1);
117 /* else CreditCharge MBZ */
119 hdr->TreeId = tcon->tid;
120 /* Uid is not converted */
122 hdr->SessionId = tcon->ses->Suid;
125 * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have
126 * to pass the path on the Open SMB prefixed by \\server\share.
127 * Not sure when we would need to do the augmented path (if ever) and
128 * setting this flag breaks the SMB2 open operation since it is
129 * illegal to send an empty path name (without \\server\share prefix)
130 * when the DFS flag is set in the SMB open header. We could
131 * consider setting the flag on all operations other than open
132 * but it is safer to net set it for now.
134 /* if (tcon->share_flags & SHI1005_FLAGS_DFS)
135 hdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */
137 if (tcon->ses && tcon->ses->server && tcon->ses->server->sign)
138 hdr->Flags |= SMB2_FLAGS_SIGNED;
140 pdu->StructureSize2 = cpu_to_le16(parmsize);
145 smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)
148 struct nls_table *nls_codepage;
149 struct cifs_ses *ses;
150 struct TCP_Server_Info *server;
153 * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so
154 * check for tcp and smb session status done differently
155 * for those three - in the calling routine.
160 if (smb2_command == SMB2_TREE_CONNECT)
163 if (tcon->tidStatus == CifsExiting) {
165 * only tree disconnect, open, and write,
166 * (and ulogoff which does not have tcon)
167 * are allowed as we start force umount.
169 if ((smb2_command != SMB2_WRITE) &&
170 (smb2_command != SMB2_CREATE) &&
171 (smb2_command != SMB2_TREE_DISCONNECT)) {
172 cifs_dbg(FYI, "can not send cmd %d while umounting\n",
177 if ((!tcon->ses) || (tcon->ses->status == CifsExiting) ||
178 (!tcon->ses->server))
182 server = ses->server;
185 * Give demultiplex thread up to 10 seconds to reconnect, should be
186 * greater than cifs socket timeout which is 7 seconds
188 while (server->tcpStatus == CifsNeedReconnect) {
190 * Return to caller for TREE_DISCONNECT and LOGOFF and CLOSE
191 * here since they are implicitly done when session drops.
193 switch (smb2_command) {
195 * BB Should we keep oplock break and add flush to exceptions?
197 case SMB2_TREE_DISCONNECT:
200 case SMB2_OPLOCK_BREAK:
204 wait_event_interruptible_timeout(server->response_q,
205 (server->tcpStatus != CifsNeedReconnect), 10 * HZ);
207 /* are we still trying to reconnect? */
208 if (server->tcpStatus != CifsNeedReconnect)
212 * on "soft" mounts we wait once. Hard mounts keep
213 * retrying until process is killed or server comes
217 cifs_dbg(FYI, "gave up waiting on reconnect in smb_init\n");
222 if (!tcon->ses->need_reconnect && !tcon->need_reconnect)
225 nls_codepage = load_nls_default();
228 * need to prevent multiple threads trying to simultaneously reconnect
229 * the same SMB session
231 mutex_lock(&tcon->ses->session_mutex);
232 rc = cifs_negotiate_protocol(0, tcon->ses);
233 if (!rc && tcon->ses->need_reconnect)
234 rc = cifs_setup_session(0, tcon->ses, nls_codepage);
236 if (rc || !tcon->need_reconnect) {
237 mutex_unlock(&tcon->ses->session_mutex);
241 cifs_mark_open_files_invalid(tcon);
242 rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage);
243 mutex_unlock(&tcon->ses->session_mutex);
244 cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc);
247 atomic_inc(&tconInfoReconnectCount);
250 * Check if handle based operation so we know whether we can continue
251 * or not without returning to caller to reset file handle.
254 * BB Is flush done by server on drop of tcp session? Should we special
255 * case it and skip above?
257 switch (smb2_command) {
263 case SMB2_QUERY_DIRECTORY:
264 case SMB2_CHANGE_NOTIFY:
265 case SMB2_QUERY_INFO:
269 unload_nls(nls_codepage);
274 * Allocate and return pointer to an SMB request hdr, and set basic
275 * SMB information in the SMB header. If the return code is zero, this
276 * function must have filled in request_buf pointer.
279 small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon,
284 rc = smb2_reconnect(smb2_command, tcon);
288 /* BB eventually switch this to SMB2 specific small buf size */
289 *request_buf = cifs_small_buf_get();
290 if (*request_buf == NULL) {
291 /* BB should we add a retry in here if not a writepage? */
295 smb2_hdr_assemble((struct smb2_hdr *) *request_buf, smb2_command, tcon);
298 #ifdef CONFIG_CIFS_STATS2
299 uint16_t com_code = le16_to_cpu(smb2_command);
300 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]);
302 cifs_stats_inc(&tcon->num_smbs_sent);
308 #ifdef CONFIG_CIFS_SMB311
309 /* offset is sizeof smb2_negotiate_req - 4 but rounded up to 8 bytes */
310 #define OFFSET_OF_NEG_CONTEXT 0x68 /* sizeof(struct smb2_negotiate_req) - 4 */
313 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
314 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
317 build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt)
319 pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES;
320 pneg_ctxt->DataLength = cpu_to_le16(38);
321 pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1);
322 pneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE);
323 get_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE);
324 pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512;
328 build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)
330 pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES;
331 pneg_ctxt->DataLength = cpu_to_le16(6);
332 pneg_ctxt->CipherCount = cpu_to_le16(2);
333 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM;
334 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM;
338 assemble_neg_contexts(struct smb2_negotiate_req *req)
341 /* +4 is to account for the RFC1001 len field */
342 char *pneg_ctxt = (char *)req + OFFSET_OF_NEG_CONTEXT + 4;
344 build_preauth_ctxt((struct smb2_preauth_neg_context *)pneg_ctxt);
345 /* Add 2 to size to round to 8 byte boundary */
346 pneg_ctxt += 2 + sizeof(struct smb2_preauth_neg_context);
347 build_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt);
348 req->NegotiateContextOffset = cpu_to_le32(OFFSET_OF_NEG_CONTEXT);
349 req->NegotiateContextCount = cpu_to_le16(2);
350 inc_rfc1001_len(req, 4 + sizeof(struct smb2_preauth_neg_context) + 2
351 + sizeof(struct smb2_encryption_neg_context)); /* calculate hash */
354 static void assemble_neg_contexts(struct smb2_negotiate_req *req)
363 * SMB2 Worker functions follow:
365 * The general structure of the worker functions is:
366 * 1) Call smb2_init (assembles SMB2 header)
367 * 2) Initialize SMB2 command specific fields in fixed length area of SMB
368 * 3) Call smb_sendrcv2 (sends request on socket and waits for response)
369 * 4) Decode SMB2 command specific fields in the fixed length area
370 * 5) Decode variable length data area (if any for this SMB2 command type)
371 * 6) Call free smb buffer
377 SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
379 struct smb2_negotiate_req *req;
380 struct smb2_negotiate_rsp *rsp;
384 struct TCP_Server_Info *server = ses->server;
385 int blob_offset, blob_length;
387 int flags = CIFS_NEG_OP;
389 cifs_dbg(FYI, "Negotiate protocol\n");
392 WARN(1, "%s: server is NULL!\n", __func__);
396 rc = small_smb2_init(SMB2_NEGOTIATE, NULL, (void **) &req);
400 req->hdr.SessionId = 0;
402 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
404 req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */
405 inc_rfc1001_len(req, 2);
407 /* only one of SMB2 signing flags may be set in SMB2 request */
409 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED);
410 else if (global_secflags & CIFSSEC_MAY_SIGN)
411 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED);
413 req->SecurityMode = 0;
415 req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities);
417 /* ClientGUID must be zero for SMB2.02 dialect */
418 if (ses->server->vals->protocol_id == SMB20_PROT_ID)
419 memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE);
421 memcpy(req->ClientGUID, server->client_guid,
422 SMB2_CLIENT_GUID_SIZE);
423 if (ses->server->vals->protocol_id == SMB311_PROT_ID)
424 assemble_neg_contexts(req);
426 iov[0].iov_base = (char *)req;
427 /* 4 for rfc1002 length field */
428 iov[0].iov_len = get_rfc1002_length(req) + 4;
430 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags);
432 rsp = (struct smb2_negotiate_rsp *)iov[0].iov_base;
434 * No tcon so can't do
435 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
440 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode);
442 /* BB we may eventually want to match the negotiated vs. requested
443 dialect, even though we are only requesting one at a time */
444 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID))
445 cifs_dbg(FYI, "negotiated smb2.0 dialect\n");
446 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID))
447 cifs_dbg(FYI, "negotiated smb2.1 dialect\n");
448 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID))
449 cifs_dbg(FYI, "negotiated smb3.0 dialect\n");
450 else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID))
451 cifs_dbg(FYI, "negotiated smb3.02 dialect\n");
452 #ifdef CONFIG_CIFS_SMB311
453 else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID))
454 cifs_dbg(FYI, "negotiated smb3.1.1 dialect\n");
457 cifs_dbg(VFS, "Illegal dialect returned by server 0x%x\n",
458 le16_to_cpu(rsp->DialectRevision));
462 server->dialect = le16_to_cpu(rsp->DialectRevision);
464 /* SMB2 only has an extended negflavor */
465 server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
466 /* set it to the maximum buffer size value we can send with 1 credit */
467 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize),
468 SMB2_MAX_BUFFER_SIZE);
469 server->max_read = le32_to_cpu(rsp->MaxReadSize);
470 server->max_write = le32_to_cpu(rsp->MaxWriteSize);
471 /* BB Do we need to validate the SecurityMode? */
472 server->sec_mode = le16_to_cpu(rsp->SecurityMode);
473 server->capabilities = le32_to_cpu(rsp->Capabilities);
475 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES;
477 security_blob = smb2_get_data_area_len(&blob_offset, &blob_length,
480 * See MS-SMB2 section 2.2.4: if no blob, client picks default which
482 * ses->sectype = RawNTLMSSP;
483 * but for time being this is our only auth choice so doesn't matter.
484 * We just found a server which sets blob length to zero expecting raw.
486 if (blob_length == 0)
487 cifs_dbg(FYI, "missing security blob on negprot\n");
489 rc = cifs_enable_signing(server, ses->sign);
493 rc = decode_negTokenInit(security_blob, blob_length, server);
500 free_rsp_buf(resp_buftype, rsp);
504 int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
507 struct validate_negotiate_info_req vneg_inbuf;
508 struct validate_negotiate_info_rsp *pneg_rsp;
511 cifs_dbg(FYI, "validate negotiate\n");
514 * validation ioctl must be signed, so no point sending this if we
515 * can not sign it. We could eventually change this to selectively
516 * sign just this, the first and only signed request on a connection.
517 * This is good enough for now since a user who wants better security
518 * would also enable signing on the mount. Having validation of
519 * negotiate info for signed connections helps reduce attack vectors
521 if (tcon->ses->server->sign == false)
522 return 0; /* validation requires signing */
524 vneg_inbuf.Capabilities =
525 cpu_to_le32(tcon->ses->server->vals->req_capabilities);
526 memcpy(vneg_inbuf.Guid, tcon->ses->server->client_guid,
527 SMB2_CLIENT_GUID_SIZE);
530 vneg_inbuf.SecurityMode =
531 cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED);
532 else if (global_secflags & CIFSSEC_MAY_SIGN)
533 vneg_inbuf.SecurityMode =
534 cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED);
536 vneg_inbuf.SecurityMode = 0;
538 vneg_inbuf.DialectCount = cpu_to_le16(1);
539 vneg_inbuf.Dialects[0] =
540 cpu_to_le16(tcon->ses->server->vals->protocol_id);
542 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
543 FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */,
544 (char *)&vneg_inbuf, sizeof(struct validate_negotiate_info_req),
545 (char **)&pneg_rsp, &rsplen);
548 cifs_dbg(VFS, "validate protocol negotiate failed: %d\n", rc);
552 if (rsplen != sizeof(struct validate_negotiate_info_rsp)) {
553 cifs_dbg(VFS, "invalid size of protocol negotiate response\n");
557 /* check validate negotiate info response matches what we got earlier */
558 if (pneg_rsp->Dialect !=
559 cpu_to_le16(tcon->ses->server->vals->protocol_id))
562 if (pneg_rsp->SecurityMode != cpu_to_le16(tcon->ses->server->sec_mode))
565 /* do not validate server guid because not saved at negprot time yet */
567 if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND |
568 SMB2_LARGE_FILES) != tcon->ses->server->capabilities)
571 /* validate negotiate successful */
572 cifs_dbg(FYI, "validate negotiate info successful\n");
576 cifs_dbg(VFS, "protocol revalidation - security settings mismatch\n");
581 SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
582 const struct nls_table *nls_cp)
584 struct smb2_sess_setup_req *req;
585 struct smb2_sess_setup_rsp *rsp = NULL;
588 int resp_buftype = CIFS_NO_BUFFER;
589 __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */
590 struct TCP_Server_Info *server = ses->server;
592 struct key *spnego_key = NULL;
593 char *security_blob = NULL;
594 unsigned char *ntlmssp_blob = NULL;
595 bool use_spnego = false; /* else use raw ntlmssp */
597 cifs_dbg(FYI, "Session Setup\n");
600 WARN(1, "%s: server is NULL!\n", __func__);
605 * If we are here due to reconnect, free per-smb session key
606 * in case signing was required.
608 kfree(ses->auth_key.response);
609 ses->auth_key.response = NULL;
612 * If memory allocation is successful, caller of this function
615 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL);
618 ses->ntlmssp->sesskey_per_smbsess = true;
620 /* FIXME: allow for other auth types besides NTLMSSP (e.g. krb5) */
621 if (ses->sectype != Kerberos && ses->sectype != RawNTLMSSP)
622 ses->sectype = RawNTLMSSP;
624 ssetup_ntlmssp_authenticate:
625 if (phase == NtLmChallenge)
626 phase = NtLmAuthenticate; /* if ntlmssp, now final phase */
628 rc = small_smb2_init(SMB2_SESSION_SETUP, NULL, (void **) &req);
632 req->hdr.SessionId = 0; /* First session, not a reauthenticate */
633 req->Flags = 0; /* MBZ */
634 /* to enable echos and oplocks */
635 req->hdr.CreditRequest = cpu_to_le16(3);
637 /* only one of SMB2 signing flags may be set in SMB2 request */
639 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED;
640 else if (global_secflags & CIFSSEC_MAY_SIGN) /* one flag unlike MUST_ */
641 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED;
643 req->SecurityMode = 0;
645 req->Capabilities = 0;
646 req->Channel = 0; /* MBZ */
648 iov[0].iov_base = (char *)req;
649 /* 4 for rfc1002 length field and 1 for pad */
650 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
652 if (ses->sectype == Kerberos) {
653 #ifdef CONFIG_CIFS_UPCALL
654 struct cifs_spnego_msg *msg;
656 spnego_key = cifs_get_spnego_key(ses);
657 if (IS_ERR(spnego_key)) {
658 rc = PTR_ERR(spnego_key);
663 msg = spnego_key->payload.data[0];
665 * check version field to make sure that cifs.upcall is
666 * sending us a response in an expected form
668 if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) {
670 "bad cifs.upcall version. Expected %d got %d",
671 CIFS_SPNEGO_UPCALL_VERSION, msg->version);
675 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
677 if (!ses->auth_key.response) {
679 "Kerberos can't allocate (%u bytes) memory",
684 ses->auth_key.len = msg->sesskey_len;
685 blob_length = msg->secblob_len;
686 iov[1].iov_base = msg->data + msg->sesskey_len;
687 iov[1].iov_len = blob_length;
691 #endif /* CONFIG_CIFS_UPCALL */
692 } else if (phase == NtLmNegotiate) { /* if not krb5 must be ntlmssp */
693 ntlmssp_blob = kmalloc(sizeof(struct _NEGOTIATE_MESSAGE),
695 if (ntlmssp_blob == NULL) {
699 build_ntlmssp_negotiate_blob(ntlmssp_blob, ses);
701 /* blob_length = build_spnego_ntlmssp_blob(
703 sizeof(struct _NEGOTIATE_MESSAGE),
705 /* BB eventually need to add this */
706 cifs_dbg(VFS, "spnego not supported for SMB2 yet\n");
711 blob_length = sizeof(struct _NEGOTIATE_MESSAGE);
712 /* with raw NTLMSSP we don't encapsulate in SPNEGO */
713 security_blob = ntlmssp_blob;
715 iov[1].iov_base = security_blob;
716 iov[1].iov_len = blob_length;
717 } else if (phase == NtLmAuthenticate) {
718 req->hdr.SessionId = ses->Suid;
719 rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses,
722 cifs_dbg(FYI, "build_ntlmssp_auth_blob failed %d\n",
724 goto ssetup_exit; /* BB double check error handling */
727 /* blob_length = build_spnego_ntlmssp_blob(
731 cifs_dbg(VFS, "spnego not supported for SMB2 yet\n");
736 security_blob = ntlmssp_blob;
738 iov[1].iov_base = security_blob;
739 iov[1].iov_len = blob_length;
741 cifs_dbg(VFS, "illegal ntlmssp phase\n");
746 /* Testing shows that buffer offset must be at location of Buffer[0] */
747 req->SecurityBufferOffset =
748 cpu_to_le16(sizeof(struct smb2_sess_setup_req) -
749 1 /* pad */ - 4 /* rfc1001 len */);
750 req->SecurityBufferLength = cpu_to_le16(blob_length);
752 inc_rfc1001_len(req, blob_length - 1 /* pad */);
754 /* BB add code to build os and lm fields */
756 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype,
757 CIFS_LOG_ERROR | CIFS_NEG_OP);
759 kfree(security_blob);
760 rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base;
761 ses->Suid = rsp->hdr.SessionId;
762 if (resp_buftype != CIFS_NO_BUFFER &&
763 rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) {
764 if (phase != NtLmNegotiate) {
765 cifs_dbg(VFS, "Unexpected more processing error\n");
768 if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 !=
769 le16_to_cpu(rsp->SecurityBufferOffset)) {
770 cifs_dbg(VFS, "Invalid security buffer offset %d\n",
771 le16_to_cpu(rsp->SecurityBufferOffset));
776 /* NTLMSSP Negotiate sent now processing challenge (response) */
777 phase = NtLmChallenge; /* process ntlmssp challenge */
778 rc = 0; /* MORE_PROCESSING is not an error here but expected */
779 rc = decode_ntlmssp_challenge(rsp->Buffer,
780 le16_to_cpu(rsp->SecurityBufferLength), ses);
784 * BB eventually add code for SPNEGO decoding of NtlmChallenge blob,
785 * but at least the raw NTLMSSP case works.
788 * No tcon so can't do
789 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
794 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
795 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
796 cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
798 free_rsp_buf(resp_buftype, rsp);
800 /* if ntlmssp, and negotiate succeeded, proceed to authenticate phase */
801 if ((phase == NtLmChallenge) && (rc == 0))
802 goto ssetup_ntlmssp_authenticate;
805 mutex_lock(&server->srv_mutex);
806 if (server->sign && server->ops->generate_signingkey) {
807 rc = server->ops->generate_signingkey(ses);
808 kfree(ses->auth_key.response);
809 ses->auth_key.response = NULL;
812 "SMB3 session key generation failed\n");
813 mutex_unlock(&server->srv_mutex);
817 if (!server->session_estab) {
818 server->sequence_number = 0x2;
819 server->session_estab = true;
821 mutex_unlock(&server->srv_mutex);
823 cifs_dbg(FYI, "SMB2/3 session established successfully\n");
824 spin_lock(&GlobalMid_Lock);
825 ses->status = CifsGood;
826 ses->need_reconnect = false;
827 spin_unlock(&GlobalMid_Lock);
832 kfree(ses->auth_key.response);
833 ses->auth_key.response = NULL;
836 key_invalidate(spnego_key);
845 SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
847 struct smb2_logoff_req *req; /* response is also trivial struct */
849 struct TCP_Server_Info *server;
851 cifs_dbg(FYI, "disconnect session %p\n", ses);
853 if (ses && (ses->server))
854 server = ses->server;
858 /* no need to send SMB logoff if uid already closed due to reconnect */
859 if (ses->need_reconnect)
860 goto smb2_session_already_dead;
862 rc = small_smb2_init(SMB2_LOGOFF, NULL, (void **) &req);
866 /* since no tcon, smb2_init can not do this, so do here */
867 req->hdr.SessionId = ses->Suid;
869 req->hdr.Flags |= SMB2_FLAGS_SIGNED;
871 rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0);
873 * No tcon so can't do
874 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
877 smb2_session_already_dead:
881 static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)
883 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]);
886 #define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */)
888 /* These are similar values to what Windows uses */
889 static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon)
891 tcon->max_chunks = 256;
892 tcon->max_bytes_chunk = 1048576;
893 tcon->max_bytes_copy = 16777216;
897 SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
898 struct cifs_tcon *tcon, const struct nls_table *cp)
900 struct smb2_tree_connect_req *req;
901 struct smb2_tree_connect_rsp *rsp = NULL;
906 struct TCP_Server_Info *server;
907 __le16 *unc_path = NULL;
909 cifs_dbg(FYI, "TCON\n");
911 if ((ses->server) && tree)
912 server = ses->server;
916 if (tcon && tcon->bad_network_name)
919 if ((tcon && tcon->seal) &&
920 ((ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) == 0)) {
921 cifs_dbg(VFS, "encryption requested but no server support");
925 unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL);
926 if (unc_path == NULL)
929 unc_path_len = cifs_strtoUTF16(unc_path, tree, strlen(tree), cp) + 1;
931 if (unc_path_len < 2) {
936 rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req);
943 /* since no tcon, smb2_init can not do this, so do here */
944 req->hdr.SessionId = ses->Suid;
945 /* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED)
946 req->hdr.Flags |= SMB2_FLAGS_SIGNED; */
949 iov[0].iov_base = (char *)req;
950 /* 4 for rfc1002 length field and 1 for pad */
951 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
953 /* Testing shows that buffer offset must be at location of Buffer[0] */
954 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req)
955 - 1 /* pad */ - 4 /* do not count rfc1001 len field */);
956 req->PathLength = cpu_to_le16(unc_path_len - 2);
957 iov[1].iov_base = unc_path;
958 iov[1].iov_len = unc_path_len;
960 inc_rfc1001_len(req, unc_path_len - 1 /* pad */);
962 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0);
963 rsp = (struct smb2_tree_connect_rsp *)iov[0].iov_base;
967 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE);
968 tcon->need_reconnect = true;
970 goto tcon_error_exit;
974 ses->ipc_tid = rsp->hdr.TreeId;
978 if (rsp->ShareType & SMB2_SHARE_TYPE_DISK)
979 cifs_dbg(FYI, "connection to disk share\n");
980 else if (rsp->ShareType & SMB2_SHARE_TYPE_PIPE) {
982 cifs_dbg(FYI, "connection to pipe share\n");
983 } else if (rsp->ShareType & SMB2_SHARE_TYPE_PRINT) {
985 cifs_dbg(FYI, "connection to printer\n");
987 cifs_dbg(VFS, "unknown share type %d\n", rsp->ShareType);
989 goto tcon_error_exit;
992 tcon->share_flags = le32_to_cpu(rsp->ShareFlags);
993 tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */
994 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess);
995 tcon->tidStatus = CifsGood;
996 tcon->need_reconnect = false;
997 tcon->tid = rsp->hdr.TreeId;
998 strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
1000 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
1001 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
1002 cifs_dbg(VFS, "DFS capability contradicts DFS flag\n");
1003 init_copy_chunk_defaults(tcon);
1004 if (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA)
1005 cifs_dbg(VFS, "Encrypted shares not supported");
1006 if (tcon->ses->server->ops->validate_negotiate)
1007 rc = tcon->ses->server->ops->validate_negotiate(xid, tcon);
1009 free_rsp_buf(resp_buftype, rsp);
1014 if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) {
1015 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree);
1017 tcon->bad_network_name = true;
1023 SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)
1025 struct smb2_tree_disconnect_req *req; /* response is trivial */
1027 struct TCP_Server_Info *server;
1028 struct cifs_ses *ses = tcon->ses;
1030 cifs_dbg(FYI, "Tree Disconnect\n");
1032 if (ses && (ses->server))
1033 server = ses->server;
1037 if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))
1040 rc = small_smb2_init(SMB2_TREE_DISCONNECT, tcon, (void **) &req);
1044 rc = SendReceiveNoRsp(xid, ses, (char *)&req->hdr, 0);
1046 cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE);
1052 static struct create_durable *
1053 create_durable_buf(void)
1055 struct create_durable *buf;
1057 buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
1061 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1062 (struct create_durable, Data));
1063 buf->ccontext.DataLength = cpu_to_le32(16);
1064 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1065 (struct create_durable, Name));
1066 buf->ccontext.NameLength = cpu_to_le16(4);
1067 /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DHnQ" */
1075 static struct create_durable *
1076 create_reconnect_durable_buf(struct cifs_fid *fid)
1078 struct create_durable *buf;
1080 buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
1084 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1085 (struct create_durable, Data));
1086 buf->ccontext.DataLength = cpu_to_le32(16);
1087 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1088 (struct create_durable, Name));
1089 buf->ccontext.NameLength = cpu_to_le16(4);
1090 buf->Data.Fid.PersistentFileId = fid->persistent_fid;
1091 buf->Data.Fid.VolatileFileId = fid->volatile_fid;
1092 /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT is "DHnC" */
1101 parse_lease_state(struct TCP_Server_Info *server, struct smb2_create_rsp *rsp,
1102 unsigned int *epoch)
1105 struct create_context *cc;
1107 unsigned int remaining;
1110 data_offset = (char *)rsp + 4 + le32_to_cpu(rsp->CreateContextsOffset);
1111 remaining = le32_to_cpu(rsp->CreateContextsLength);
1112 cc = (struct create_context *)data_offset;
1113 while (remaining >= sizeof(struct create_context)) {
1114 name = le16_to_cpu(cc->NameOffset) + (char *)cc;
1115 if (le16_to_cpu(cc->NameLength) == 4 &&
1116 strncmp(name, "RqLs", 4) == 0)
1117 return server->ops->parse_lease_buf(cc, epoch);
1119 next = le32_to_cpu(cc->Next);
1123 cc = (struct create_context *)((char *)cc + next);
1130 add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,
1131 unsigned int *num_iovec, __u8 *oplock)
1133 struct smb2_create_req *req = iov[0].iov_base;
1134 unsigned int num = *num_iovec;
1136 iov[num].iov_base = server->ops->create_lease_buf(oplock+1, *oplock);
1137 if (iov[num].iov_base == NULL)
1139 iov[num].iov_len = server->vals->create_lease_size;
1140 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
1141 if (!req->CreateContextsOffset)
1142 req->CreateContextsOffset = cpu_to_le32(
1143 sizeof(struct smb2_create_req) - 4 +
1144 iov[num - 1].iov_len);
1145 le32_add_cpu(&req->CreateContextsLength,
1146 server->vals->create_lease_size);
1147 inc_rfc1001_len(&req->hdr, server->vals->create_lease_size);
1148 *num_iovec = num + 1;
1152 static struct create_durable_v2 *
1153 create_durable_v2_buf(struct cifs_fid *pfid)
1155 struct create_durable_v2 *buf;
1157 buf = kzalloc(sizeof(struct create_durable_v2), GFP_KERNEL);
1161 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1162 (struct create_durable_v2, dcontext));
1163 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2));
1164 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1165 (struct create_durable_v2, Name));
1166 buf->ccontext.NameLength = cpu_to_le16(4);
1168 buf->dcontext.Timeout = 0; /* Should this be configurable by workload */
1169 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT);
1170 get_random_bytes(buf->dcontext.CreateGuid, 16);
1171 memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16);
1173 /* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */
1181 static struct create_durable_handle_reconnect_v2 *
1182 create_reconnect_durable_v2_buf(struct cifs_fid *fid)
1184 struct create_durable_handle_reconnect_v2 *buf;
1186 buf = kzalloc(sizeof(struct create_durable_handle_reconnect_v2),
1191 buf->ccontext.DataOffset =
1192 cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2,
1194 buf->ccontext.DataLength =
1195 cpu_to_le32(sizeof(struct durable_reconnect_context_v2));
1196 buf->ccontext.NameOffset =
1197 cpu_to_le16(offsetof(struct create_durable_handle_reconnect_v2,
1199 buf->ccontext.NameLength = cpu_to_le16(4);
1201 buf->dcontext.Fid.PersistentFileId = fid->persistent_fid;
1202 buf->dcontext.Fid.VolatileFileId = fid->volatile_fid;
1203 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT);
1204 memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16);
1206 /* SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 is "DH2C" */
1215 add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,
1216 struct cifs_open_parms *oparms)
1218 struct smb2_create_req *req = iov[0].iov_base;
1219 unsigned int num = *num_iovec;
1221 iov[num].iov_base = create_durable_v2_buf(oparms->fid);
1222 if (iov[num].iov_base == NULL)
1224 iov[num].iov_len = sizeof(struct create_durable_v2);
1225 if (!req->CreateContextsOffset)
1226 req->CreateContextsOffset =
1227 cpu_to_le32(sizeof(struct smb2_create_req) - 4 +
1229 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2));
1230 inc_rfc1001_len(&req->hdr, sizeof(struct create_durable_v2));
1231 *num_iovec = num + 1;
1236 add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
1237 struct cifs_open_parms *oparms)
1239 struct smb2_create_req *req = iov[0].iov_base;
1240 unsigned int num = *num_iovec;
1242 /* indicate that we don't need to relock the file */
1243 oparms->reconnect = false;
1245 iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid);
1246 if (iov[num].iov_base == NULL)
1248 iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2);
1249 if (!req->CreateContextsOffset)
1250 req->CreateContextsOffset =
1251 cpu_to_le32(sizeof(struct smb2_create_req) - 4 +
1253 le32_add_cpu(&req->CreateContextsLength,
1254 sizeof(struct create_durable_handle_reconnect_v2));
1255 inc_rfc1001_len(&req->hdr,
1256 sizeof(struct create_durable_handle_reconnect_v2));
1257 *num_iovec = num + 1;
1262 add_durable_context(struct kvec *iov, unsigned int *num_iovec,
1263 struct cifs_open_parms *oparms, bool use_persistent)
1265 struct smb2_create_req *req = iov[0].iov_base;
1266 unsigned int num = *num_iovec;
1268 if (use_persistent) {
1269 if (oparms->reconnect)
1270 return add_durable_reconnect_v2_context(iov, num_iovec,
1273 return add_durable_v2_context(iov, num_iovec, oparms);
1276 if (oparms->reconnect) {
1277 iov[num].iov_base = create_reconnect_durable_buf(oparms->fid);
1278 /* indicate that we don't need to relock the file */
1279 oparms->reconnect = false;
1281 iov[num].iov_base = create_durable_buf();
1282 if (iov[num].iov_base == NULL)
1284 iov[num].iov_len = sizeof(struct create_durable);
1285 if (!req->CreateContextsOffset)
1286 req->CreateContextsOffset =
1287 cpu_to_le32(sizeof(struct smb2_create_req) - 4 +
1289 le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable));
1290 inc_rfc1001_len(&req->hdr, sizeof(struct create_durable));
1291 *num_iovec = num + 1;
1296 SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
1297 __u8 *oplock, struct smb2_file_all_info *buf,
1298 struct smb2_err_rsp **err_buf)
1300 struct smb2_create_req *req;
1301 struct smb2_create_rsp *rsp;
1302 struct TCP_Server_Info *server;
1303 struct cifs_tcon *tcon = oparms->tcon;
1304 struct cifs_ses *ses = tcon->ses;
1308 __le16 *copy_path = NULL;
1311 unsigned int num_iovecs = 2;
1312 __u32 file_attributes = 0;
1313 char *dhc_buf = NULL, *lc_buf = NULL;
1315 cifs_dbg(FYI, "create/open\n");
1317 if (ses && (ses->server))
1318 server = ses->server;
1322 rc = small_smb2_init(SMB2_CREATE, tcon, (void **) &req);
1326 if (oparms->create_options & CREATE_OPTION_READONLY)
1327 file_attributes |= ATTR_READONLY;
1328 if (oparms->create_options & CREATE_OPTION_SPECIAL)
1329 file_attributes |= ATTR_SYSTEM;
1331 req->ImpersonationLevel = IL_IMPERSONATION;
1332 req->DesiredAccess = cpu_to_le32(oparms->desired_access);
1333 /* File attributes ignored on open (used in create though) */
1334 req->FileAttributes = cpu_to_le32(file_attributes);
1335 req->ShareAccess = FILE_SHARE_ALL_LE;
1336 req->CreateDisposition = cpu_to_le32(oparms->disposition);
1337 req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK);
1338 uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2;
1339 /* do not count rfc1001 len field */
1340 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) - 4);
1342 iov[0].iov_base = (char *)req;
1343 /* 4 for rfc1002 length field */
1344 iov[0].iov_len = get_rfc1002_length(req) + 4;
1346 /* MUST set path len (NameLength) to 0 opening root of share */
1347 req->NameLength = cpu_to_le16(uni_path_len - 2);
1348 /* -1 since last byte is buf[0] which is sent below (path) */
1350 if (uni_path_len % 8 != 0) {
1351 copy_size = uni_path_len / 8 * 8;
1352 if (copy_size < uni_path_len)
1355 copy_path = kzalloc(copy_size, GFP_KERNEL);
1358 memcpy((char *)copy_path, (const char *)path,
1360 uni_path_len = copy_size;
1364 iov[1].iov_len = uni_path_len;
1365 iov[1].iov_base = path;
1366 /* -1 since last byte is buf[0] which was counted in smb2_buf_len */
1367 inc_rfc1001_len(req, uni_path_len - 1);
1369 if (!server->oplocks)
1370 *oplock = SMB2_OPLOCK_LEVEL_NONE;
1372 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) ||
1373 *oplock == SMB2_OPLOCK_LEVEL_NONE)
1374 req->RequestedOplockLevel = *oplock;
1376 rc = add_lease_context(server, iov, &num_iovecs, oplock);
1378 cifs_small_buf_release(req);
1382 lc_buf = iov[num_iovecs-1].iov_base;
1385 if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
1386 /* need to set Next field of lease context if we request it */
1387 if (server->capabilities & SMB2_GLOBAL_CAP_LEASING) {
1388 struct create_context *ccontext =
1389 (struct create_context *)iov[num_iovecs-1].iov_base;
1391 cpu_to_le32(server->vals->create_lease_size);
1394 rc = add_durable_context(iov, &num_iovecs, oparms,
1395 tcon->use_persistent);
1397 cifs_small_buf_release(req);
1402 dhc_buf = iov[num_iovecs-1].iov_base;
1405 rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0);
1406 rsp = (struct smb2_create_rsp *)iov[0].iov_base;
1409 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE);
1411 *err_buf = kmemdup(rsp, get_rfc1002_length(rsp) + 4,
1416 oparms->fid->persistent_fid = rsp->PersistentFileId;
1417 oparms->fid->volatile_fid = rsp->VolatileFileId;
1420 memcpy(buf, &rsp->CreationTime, 32);
1421 buf->AllocationSize = rsp->AllocationSize;
1422 buf->EndOfFile = rsp->EndofFile;
1423 buf->Attributes = rsp->FileAttributes;
1424 buf->NumberOfLinks = cpu_to_le32(1);
1425 buf->DeletePending = 0;
1428 if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
1429 *oplock = parse_lease_state(server, rsp, &oparms->fid->epoch);
1431 *oplock = rsp->OplockLevel;
1436 free_rsp_buf(resp_buftype, rsp);
1441 * SMB2 IOCTL is used for both IOCTLs and FSCTLs
1444 SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1445 u64 volatile_fid, u32 opcode, bool is_fsctl, char *in_data,
1446 u32 indatalen, char **out_data, u32 *plen /* returned data len */)
1448 struct smb2_ioctl_req *req;
1449 struct smb2_ioctl_rsp *rsp;
1450 struct TCP_Server_Info *server;
1451 struct cifs_ses *ses;
1457 cifs_dbg(FYI, "SMB2 IOCTL\n");
1459 if (out_data != NULL)
1462 /* zero out returned data len, in case of error */
1471 if (ses && (ses->server))
1472 server = ses->server;
1476 rc = small_smb2_init(SMB2_IOCTL, tcon, (void **) &req);
1480 req->CtlCode = cpu_to_le32(opcode);
1481 req->PersistentFileId = persistent_fid;
1482 req->VolatileFileId = volatile_fid;
1485 req->InputCount = cpu_to_le32(indatalen);
1486 /* do not set InputOffset if no input data */
1488 cpu_to_le32(offsetof(struct smb2_ioctl_req, Buffer) - 4);
1489 iov[1].iov_base = in_data;
1490 iov[1].iov_len = indatalen;
1495 req->OutputOffset = 0;
1496 req->OutputCount = 0; /* MBZ */
1499 * Could increase MaxOutputResponse, but that would require more
1500 * than one credit. Windows typically sets this smaller, but for some
1501 * ioctls it may be useful to allow server to send more. No point
1502 * limiting what the server can send as long as fits in one credit
1504 req->MaxOutputResponse = cpu_to_le32(0xFF00); /* < 64K uses 1 credit */
1507 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL);
1511 iov[0].iov_base = (char *)req;
1514 * If no input data, the size of ioctl struct in
1515 * protocol spec still includes a 1 byte data buffer,
1516 * but if input data passed to ioctl, we do not
1517 * want to double count this, so we do not send
1518 * the dummy one byte of data in iovec[0] if sending
1519 * input data (in iovec[1]). We also must add 4 bytes
1520 * in first iovec to allow for rfc1002 length field.
1524 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
1525 inc_rfc1001_len(req, indatalen - 1);
1527 iov[0].iov_len = get_rfc1002_length(req) + 4;
1530 rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0);
1531 rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
1533 if ((rc != 0) && (rc != -EINVAL)) {
1534 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
1536 } else if (rc == -EINVAL) {
1537 if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
1538 (opcode != FSCTL_SRV_COPYCHUNK)) {
1539 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
1544 /* check if caller wants to look at return data or just return rc */
1545 if ((plen == NULL) || (out_data == NULL))
1548 *plen = le32_to_cpu(rsp->OutputCount);
1550 /* We check for obvious errors in the output buffer length and offset */
1552 goto ioctl_exit; /* server returned no data */
1553 else if (*plen > 0xFF00) {
1554 cifs_dbg(VFS, "srv returned invalid ioctl length: %d\n", *plen);
1560 if (get_rfc1002_length(rsp) < le32_to_cpu(rsp->OutputOffset) + *plen) {
1561 cifs_dbg(VFS, "Malformed ioctl resp: len %d offset %d\n", *plen,
1562 le32_to_cpu(rsp->OutputOffset));
1568 *out_data = kmalloc(*plen, GFP_KERNEL);
1569 if (*out_data == NULL) {
1574 memcpy(*out_data, rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
1577 free_rsp_buf(resp_buftype, rsp);
1582 * Individual callers to ioctl worker function follow
1586 SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1587 u64 persistent_fid, u64 volatile_fid)
1590 struct compress_ioctl fsctl_input;
1591 char *ret_data = NULL;
1593 fsctl_input.CompressionState =
1594 cpu_to_le16(COMPRESSION_FORMAT_DEFAULT);
1596 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1597 FSCTL_SET_COMPRESSION, true /* is_fsctl */,
1598 (char *)&fsctl_input /* data input */,
1599 2 /* in data len */, &ret_data /* out data */, NULL);
1601 cifs_dbg(FYI, "set compression rc %d\n", rc);
1607 SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
1608 u64 persistent_fid, u64 volatile_fid)
1610 struct smb2_close_req *req;
1611 struct smb2_close_rsp *rsp;
1612 struct TCP_Server_Info *server;
1613 struct cifs_ses *ses = tcon->ses;
1618 cifs_dbg(FYI, "Close\n");
1620 if (ses && (ses->server))
1621 server = ses->server;
1625 rc = small_smb2_init(SMB2_CLOSE, tcon, (void **) &req);
1629 req->PersistentFileId = persistent_fid;
1630 req->VolatileFileId = volatile_fid;
1632 iov[0].iov_base = (char *)req;
1633 /* 4 for rfc1002 length field */
1634 iov[0].iov_len = get_rfc1002_length(req) + 4;
1636 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1637 rsp = (struct smb2_close_rsp *)iov[0].iov_base;
1640 cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE);
1644 /* BB FIXME - decode close response, update inode for caching */
1647 free_rsp_buf(resp_buftype, rsp);
1652 validate_buf(unsigned int offset, unsigned int buffer_length,
1653 struct smb2_hdr *hdr, unsigned int min_buf_size)
1656 unsigned int smb_len = be32_to_cpu(hdr->smb2_buf_length);
1657 char *end_of_smb = smb_len + 4 /* RFC1001 length field */ + (char *)hdr;
1658 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
1659 char *end_of_buf = begin_of_buf + buffer_length;
1662 if (buffer_length < min_buf_size) {
1663 cifs_dbg(VFS, "buffer length %d smaller than minimum size %d\n",
1664 buffer_length, min_buf_size);
1668 /* check if beyond RFC1001 maximum length */
1669 if ((smb_len > 0x7FFFFF) || (buffer_length > 0x7FFFFF)) {
1670 cifs_dbg(VFS, "buffer length %d or smb length %d too large\n",
1671 buffer_length, smb_len);
1675 if ((begin_of_buf > end_of_smb) || (end_of_buf > end_of_smb)) {
1676 cifs_dbg(VFS, "illegal server response, bad offset to data\n");
1684 * If SMB buffer fields are valid, copy into temporary buffer to hold result.
1685 * Caller must free buffer.
1688 validate_and_copy_buf(unsigned int offset, unsigned int buffer_length,
1689 struct smb2_hdr *hdr, unsigned int minbufsize,
1693 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
1699 rc = validate_buf(offset, buffer_length, hdr, minbufsize);
1703 memcpy(data, begin_of_buf, buffer_length);
1709 query_info(const unsigned int xid, struct cifs_tcon *tcon,
1710 u64 persistent_fid, u64 volatile_fid, u8 info_class,
1711 size_t output_len, size_t min_len, void *data)
1713 struct smb2_query_info_req *req;
1714 struct smb2_query_info_rsp *rsp = NULL;
1718 struct TCP_Server_Info *server;
1719 struct cifs_ses *ses = tcon->ses;
1721 cifs_dbg(FYI, "Query Info\n");
1723 if (ses && (ses->server))
1724 server = ses->server;
1728 rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req);
1732 req->InfoType = SMB2_O_INFO_FILE;
1733 req->FileInfoClass = info_class;
1734 req->PersistentFileId = persistent_fid;
1735 req->VolatileFileId = volatile_fid;
1736 /* 4 for rfc1002 length field and 1 for Buffer */
1737 req->InputBufferOffset =
1738 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4);
1739 req->OutputBufferLength = cpu_to_le32(output_len);
1741 iov[0].iov_base = (char *)req;
1742 /* 4 for rfc1002 length field */
1743 iov[0].iov_len = get_rfc1002_length(req) + 4;
1745 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1746 rsp = (struct smb2_query_info_rsp *)iov[0].iov_base;
1749 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
1753 rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset),
1754 le32_to_cpu(rsp->OutputBufferLength),
1755 &rsp->hdr, min_len, data);
1758 free_rsp_buf(resp_buftype, rsp);
1763 SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
1764 u64 persistent_fid, u64 volatile_fid,
1765 struct smb2_file_all_info *data)
1767 return query_info(xid, tcon, persistent_fid, volatile_fid,
1768 FILE_ALL_INFORMATION,
1769 sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
1770 sizeof(struct smb2_file_all_info), data);
1774 SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
1775 u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid)
1777 return query_info(xid, tcon, persistent_fid, volatile_fid,
1778 FILE_INTERNAL_INFORMATION,
1779 sizeof(struct smb2_file_internal_info),
1780 sizeof(struct smb2_file_internal_info), uniqueid);
1784 * This is a no-op for now. We're not really interested in the reply, but
1785 * rather in the fact that the server sent one and that server->lstrp
1788 * FIXME: maybe we should consider checking that the reply matches request?
1791 smb2_echo_callback(struct mid_q_entry *mid)
1793 struct TCP_Server_Info *server = mid->callback_data;
1794 struct smb2_echo_rsp *smb2 = (struct smb2_echo_rsp *)mid->resp_buf;
1795 unsigned int credits_received = 1;
1797 if (mid->mid_state == MID_RESPONSE_RECEIVED)
1798 credits_received = le16_to_cpu(smb2->hdr.CreditRequest);
1800 mutex_lock(&server->srv_mutex);
1801 DeleteMidQEntry(mid);
1802 mutex_unlock(&server->srv_mutex);
1803 add_credits(server, credits_received, CIFS_ECHO_OP);
1807 SMB2_echo(struct TCP_Server_Info *server)
1809 struct smb2_echo_req *req;
1812 struct smb_rqst rqst = { .rq_iov = &iov,
1815 cifs_dbg(FYI, "In echo request\n");
1817 if (server->tcpStatus == CifsNeedNegotiate) {
1818 struct list_head *tmp, *tmp2;
1819 struct cifs_ses *ses;
1820 struct cifs_tcon *tcon;
1822 cifs_dbg(FYI, "Need negotiate, reconnecting tcons\n");
1823 spin_lock(&cifs_tcp_ses_lock);
1824 list_for_each(tmp, &server->smb_ses_list) {
1825 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
1826 list_for_each(tmp2, &ses->tcon_list) {
1827 tcon = list_entry(tmp2, struct cifs_tcon,
1829 /* add check for persistent handle reconnect */
1830 if (tcon && tcon->need_reconnect) {
1831 spin_unlock(&cifs_tcp_ses_lock);
1832 rc = smb2_reconnect(SMB2_ECHO, tcon);
1833 spin_lock(&cifs_tcp_ses_lock);
1837 spin_unlock(&cifs_tcp_ses_lock);
1840 /* if no session, renegotiate failed above */
1841 if (server->tcpStatus == CifsNeedNegotiate)
1844 rc = small_smb2_init(SMB2_ECHO, NULL, (void **)&req);
1848 req->hdr.CreditRequest = cpu_to_le16(1);
1850 iov.iov_base = (char *)req;
1851 /* 4 for rfc1002 length field */
1852 iov.iov_len = get_rfc1002_length(req) + 4;
1854 rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, server,
1857 cifs_dbg(FYI, "Echo request failed: %d\n", rc);
1859 cifs_small_buf_release(req);
1864 SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1867 struct smb2_flush_req *req;
1868 struct TCP_Server_Info *server;
1869 struct cifs_ses *ses = tcon->ses;
1874 cifs_dbg(FYI, "Flush\n");
1876 if (ses && (ses->server))
1877 server = ses->server;
1881 rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req);
1885 req->PersistentFileId = persistent_fid;
1886 req->VolatileFileId = volatile_fid;
1888 iov[0].iov_base = (char *)req;
1889 /* 4 for rfc1002 length field */
1890 iov[0].iov_len = get_rfc1002_length(req) + 4;
1892 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1895 cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE);
1897 free_rsp_buf(resp_buftype, iov[0].iov_base);
1902 * To form a chain of read requests, any read requests after the first should
1903 * have the end_of_chain boolean set to true.
1906 smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
1907 unsigned int remaining_bytes, int request_type)
1910 struct smb2_read_req *req = NULL;
1912 rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req);
1915 if (io_parms->tcon->ses->server == NULL)
1916 return -ECONNABORTED;
1918 req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
1920 req->PersistentFileId = io_parms->persistent_fid;
1921 req->VolatileFileId = io_parms->volatile_fid;
1922 req->ReadChannelInfoOffset = 0; /* reserved */
1923 req->ReadChannelInfoLength = 0; /* reserved */
1924 req->Channel = 0; /* reserved */
1925 req->MinimumCount = 0;
1926 req->Length = cpu_to_le32(io_parms->length);
1927 req->Offset = cpu_to_le64(io_parms->offset);
1929 if (request_type & CHAINED_REQUEST) {
1930 if (!(request_type & END_OF_CHAIN)) {
1931 /* 4 for rfc1002 length field */
1932 req->hdr.NextCommand =
1933 cpu_to_le32(get_rfc1002_length(req) + 4);
1934 } else /* END_OF_CHAIN */
1935 req->hdr.NextCommand = 0;
1936 if (request_type & RELATED_REQUEST) {
1937 req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1939 * Related requests use info from previous read request
1942 req->hdr.SessionId = 0xFFFFFFFF;
1943 req->hdr.TreeId = 0xFFFFFFFF;
1944 req->PersistentFileId = 0xFFFFFFFF;
1945 req->VolatileFileId = 0xFFFFFFFF;
1948 if (remaining_bytes > io_parms->length)
1949 req->RemainingBytes = cpu_to_le32(remaining_bytes);
1951 req->RemainingBytes = 0;
1953 iov[0].iov_base = (char *)req;
1954 /* 4 for rfc1002 length field */
1955 iov[0].iov_len = get_rfc1002_length(req) + 4;
1960 smb2_readv_callback(struct mid_q_entry *mid)
1962 struct cifs_readdata *rdata = mid->callback_data;
1963 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
1964 struct TCP_Server_Info *server = tcon->ses->server;
1965 struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base;
1966 unsigned int credits_received = 1;
1967 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
1969 .rq_pages = rdata->pages,
1970 .rq_npages = rdata->nr_pages,
1971 .rq_pagesz = rdata->pagesz,
1972 .rq_tailsz = rdata->tailsz };
1974 cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n",
1975 __func__, mid->mid, mid->mid_state, rdata->result,
1978 switch (mid->mid_state) {
1979 case MID_RESPONSE_RECEIVED:
1980 credits_received = le16_to_cpu(buf->CreditRequest);
1981 /* result already set, check signature */
1985 rc = smb2_verify_signature(&rqst, server);
1987 cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
1990 /* FIXME: should this be counted toward the initiating task? */
1991 task_io_account_read(rdata->got_bytes);
1992 cifs_stats_bytes_read(tcon, rdata->got_bytes);
1994 case MID_REQUEST_SUBMITTED:
1995 case MID_RETRY_NEEDED:
1996 rdata->result = -EAGAIN;
1997 if (server->sign && rdata->got_bytes)
1998 /* reset bytes number since we can not check a sign */
1999 rdata->got_bytes = 0;
2000 /* FIXME: should this be counted toward the initiating task? */
2001 task_io_account_read(rdata->got_bytes);
2002 cifs_stats_bytes_read(tcon, rdata->got_bytes);
2005 if (rdata->result != -ENODATA)
2006 rdata->result = -EIO;
2010 cifs_stats_fail_inc(tcon, SMB2_READ_HE);
2012 queue_work(cifsiod_wq, &rdata->work);
2013 mutex_lock(&server->srv_mutex);
2014 DeleteMidQEntry(mid);
2015 mutex_unlock(&server->srv_mutex);
2016 add_credits(server, credits_received, 0);
2019 /* smb2_async_readv - send an async write, and set up mid to handle result */
2021 smb2_async_readv(struct cifs_readdata *rdata)
2024 struct smb2_hdr *buf;
2025 struct cifs_io_parms io_parms;
2026 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
2028 struct TCP_Server_Info *server;
2030 cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n",
2031 __func__, rdata->offset, rdata->bytes);
2033 io_parms.tcon = tlink_tcon(rdata->cfile->tlink);
2034 io_parms.offset = rdata->offset;
2035 io_parms.length = rdata->bytes;
2036 io_parms.persistent_fid = rdata->cfile->fid.persistent_fid;
2037 io_parms.volatile_fid = rdata->cfile->fid.volatile_fid;
2038 io_parms.pid = rdata->pid;
2040 server = io_parms.tcon->ses->server;
2042 rc = smb2_new_read_req(&rdata->iov, &io_parms, 0, 0);
2044 if (rc == -EAGAIN && rdata->credits) {
2045 /* credits was reset by reconnect */
2047 /* reduce in_flight value since we won't send the req */
2048 spin_lock(&server->req_lock);
2049 server->in_flight--;
2050 spin_unlock(&server->req_lock);
2055 buf = (struct smb2_hdr *)rdata->iov.iov_base;
2056 /* 4 for rfc1002 length field */
2057 rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4;
2059 if (rdata->credits) {
2060 buf->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
2061 SMB2_MAX_BUFFER_SIZE));
2062 spin_lock(&server->req_lock);
2063 server->credits += rdata->credits -
2064 le16_to_cpu(buf->CreditCharge);
2065 spin_unlock(&server->req_lock);
2066 wake_up(&server->request_q);
2067 flags = CIFS_HAS_CREDITS;
2070 kref_get(&rdata->refcount);
2071 rc = cifs_call_async(io_parms.tcon->ses->server, &rqst,
2072 cifs_readv_receive, smb2_readv_callback,
2075 kref_put(&rdata->refcount, cifs_readdata_release);
2076 cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE);
2079 cifs_small_buf_release(buf);
2084 SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
2085 unsigned int *nbytes, char **buf, int *buf_type)
2087 int resp_buftype, rc = -EACCES;
2088 struct smb2_read_rsp *rsp = NULL;
2092 rc = smb2_new_read_req(iov, io_parms, 0, 0);
2096 rc = SendReceive2(xid, io_parms->tcon->ses, iov, 1,
2097 &resp_buftype, CIFS_LOG_ERROR);
2099 rsp = (struct smb2_read_rsp *)iov[0].iov_base;
2101 if (rsp->hdr.Status == STATUS_END_OF_FILE) {
2102 free_rsp_buf(resp_buftype, iov[0].iov_base);
2107 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE);
2108 cifs_dbg(VFS, "Send error in read = %d\n", rc);
2110 *nbytes = le32_to_cpu(rsp->DataLength);
2111 if ((*nbytes > CIFS_MAX_MSGSIZE) ||
2112 (*nbytes > io_parms->length)) {
2113 cifs_dbg(FYI, "bad length %d for count %d\n",
2114 *nbytes, io_parms->length);
2121 memcpy(*buf, (char *)rsp->hdr.ProtocolId + rsp->DataOffset,
2123 free_rsp_buf(resp_buftype, iov[0].iov_base);
2124 } else if (resp_buftype != CIFS_NO_BUFFER) {
2125 *buf = iov[0].iov_base;
2126 if (resp_buftype == CIFS_SMALL_BUFFER)
2127 *buf_type = CIFS_SMALL_BUFFER;
2128 else if (resp_buftype == CIFS_LARGE_BUFFER)
2129 *buf_type = CIFS_LARGE_BUFFER;
2135 * Check the mid_state and signature on received buffer (if any), and queue the
2136 * workqueue completion task.
2139 smb2_writev_callback(struct mid_q_entry *mid)
2141 struct cifs_writedata *wdata = mid->callback_data;
2142 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2143 struct TCP_Server_Info *server = tcon->ses->server;
2144 unsigned int written;
2145 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf;
2146 unsigned int credits_received = 1;
2148 switch (mid->mid_state) {
2149 case MID_RESPONSE_RECEIVED:
2150 credits_received = le16_to_cpu(rsp->hdr.CreditRequest);
2151 wdata->result = smb2_check_receive(mid, tcon->ses->server, 0);
2152 if (wdata->result != 0)
2155 written = le32_to_cpu(rsp->DataLength);
2157 * Mask off high 16 bits when bytes written as returned
2158 * by the server is greater than bytes requested by the
2159 * client. OS/2 servers are known to set incorrect
2162 if (written > wdata->bytes)
2165 if (written < wdata->bytes)
2166 wdata->result = -ENOSPC;
2168 wdata->bytes = written;
2170 case MID_REQUEST_SUBMITTED:
2171 case MID_RETRY_NEEDED:
2172 wdata->result = -EAGAIN;
2175 wdata->result = -EIO;
2180 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
2182 queue_work(cifsiod_wq, &wdata->work);
2183 mutex_lock(&server->srv_mutex);
2184 DeleteMidQEntry(mid);
2185 mutex_unlock(&server->srv_mutex);
2186 add_credits(tcon->ses->server, credits_received, 0);
2189 /* smb2_async_writev - send an async write, and set up mid to handle result */
2191 smb2_async_writev(struct cifs_writedata *wdata,
2192 void (*release)(struct kref *kref))
2194 int rc = -EACCES, flags = 0;
2195 struct smb2_write_req *req = NULL;
2196 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2197 struct TCP_Server_Info *server = tcon->ses->server;
2199 struct smb_rqst rqst;
2201 rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req);
2203 if (rc == -EAGAIN && wdata->credits) {
2204 /* credits was reset by reconnect */
2206 /* reduce in_flight value since we won't send the req */
2207 spin_lock(&server->req_lock);
2208 server->in_flight--;
2209 spin_unlock(&server->req_lock);
2211 goto async_writev_out;
2214 req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid);
2216 req->PersistentFileId = wdata->cfile->fid.persistent_fid;
2217 req->VolatileFileId = wdata->cfile->fid.volatile_fid;
2218 req->WriteChannelInfoOffset = 0;
2219 req->WriteChannelInfoLength = 0;
2221 req->Offset = cpu_to_le64(wdata->offset);
2222 /* 4 for rfc1002 length field */
2223 req->DataOffset = cpu_to_le16(
2224 offsetof(struct smb2_write_req, Buffer) - 4);
2225 req->RemainingBytes = 0;
2227 /* 4 for rfc1002 length field and 1 for Buffer */
2228 iov.iov_len = get_rfc1002_length(req) + 4 - 1;
2233 rqst.rq_pages = wdata->pages;
2234 rqst.rq_npages = wdata->nr_pages;
2235 rqst.rq_pagesz = wdata->pagesz;
2236 rqst.rq_tailsz = wdata->tailsz;
2238 cifs_dbg(FYI, "async write at %llu %u bytes\n",
2239 wdata->offset, wdata->bytes);
2241 req->Length = cpu_to_le32(wdata->bytes);
2243 inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */);
2245 if (wdata->credits) {
2246 req->hdr.CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
2247 SMB2_MAX_BUFFER_SIZE));
2248 spin_lock(&server->req_lock);
2249 server->credits += wdata->credits -
2250 le16_to_cpu(req->hdr.CreditCharge);
2251 spin_unlock(&server->req_lock);
2252 wake_up(&server->request_q);
2253 flags = CIFS_HAS_CREDITS;
2256 kref_get(&wdata->refcount);
2257 rc = cifs_call_async(server, &rqst, NULL, smb2_writev_callback, wdata,
2261 kref_put(&wdata->refcount, release);
2262 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
2266 cifs_small_buf_release(req);
2271 * SMB2_write function gets iov pointer to kvec array with n_vec as a length.
2272 * The length field from io_parms must be at least 1 and indicates a number of
2273 * elements with data to write that begins with position 1 in iov array. All
2274 * data length is specified by count.
2277 SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
2278 unsigned int *nbytes, struct kvec *iov, int n_vec)
2281 struct smb2_write_req *req = NULL;
2282 struct smb2_write_rsp *rsp = NULL;
2289 rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req);
2293 if (io_parms->tcon->ses->server == NULL)
2294 return -ECONNABORTED;
2296 req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
2298 req->PersistentFileId = io_parms->persistent_fid;
2299 req->VolatileFileId = io_parms->volatile_fid;
2300 req->WriteChannelInfoOffset = 0;
2301 req->WriteChannelInfoLength = 0;
2303 req->Length = cpu_to_le32(io_parms->length);
2304 req->Offset = cpu_to_le64(io_parms->offset);
2305 /* 4 for rfc1002 length field */
2306 req->DataOffset = cpu_to_le16(
2307 offsetof(struct smb2_write_req, Buffer) - 4);
2308 req->RemainingBytes = 0;
2310 iov[0].iov_base = (char *)req;
2311 /* 4 for rfc1002 length field and 1 for Buffer */
2312 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
2314 /* length of entire message including data to be written */
2315 inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */);
2317 rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1,
2319 rsp = (struct smb2_write_rsp *)iov[0].iov_base;
2322 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
2323 cifs_dbg(VFS, "Send error in write = %d\n", rc);
2325 *nbytes = le32_to_cpu(rsp->DataLength);
2327 free_rsp_buf(resp_buftype, rsp);
2332 num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)
2335 unsigned int entrycount = 0;
2336 unsigned int next_offset = 0;
2337 FILE_DIRECTORY_INFO *entryptr;
2339 if (bufstart == NULL)
2342 entryptr = (FILE_DIRECTORY_INFO *)bufstart;
2345 entryptr = (FILE_DIRECTORY_INFO *)
2346 ((char *)entryptr + next_offset);
2348 if ((char *)entryptr + size > end_of_buf) {
2349 cifs_dbg(VFS, "malformed search entry would overflow\n");
2353 len = le32_to_cpu(entryptr->FileNameLength);
2354 if ((char *)entryptr + len + size > end_of_buf) {
2355 cifs_dbg(VFS, "directory entry name would overflow frame end of buf %p\n",
2360 *lastentry = (char *)entryptr;
2363 next_offset = le32_to_cpu(entryptr->NextEntryOffset);
2375 SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
2376 u64 persistent_fid, u64 volatile_fid, int index,
2377 struct cifs_search_info *srch_inf)
2379 struct smb2_query_directory_req *req;
2380 struct smb2_query_directory_rsp *rsp = NULL;
2384 int resp_buftype = CIFS_NO_BUFFER;
2385 unsigned char *bufptr;
2386 struct TCP_Server_Info *server;
2387 struct cifs_ses *ses = tcon->ses;
2388 __le16 asteriks = cpu_to_le16('*');
2390 unsigned int output_size = CIFSMaxBufSize;
2391 size_t info_buf_size;
2393 if (ses && (ses->server))
2394 server = ses->server;
2398 rc = small_smb2_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req);
2402 switch (srch_inf->info_level) {
2403 case SMB_FIND_FILE_DIRECTORY_INFO:
2404 req->FileInformationClass = FILE_DIRECTORY_INFORMATION;
2405 info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1;
2407 case SMB_FIND_FILE_ID_FULL_DIR_INFO:
2408 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION;
2409 info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1;
2412 cifs_dbg(VFS, "info level %u isn't supported\n",
2413 srch_inf->info_level);
2418 req->FileIndex = cpu_to_le32(index);
2419 req->PersistentFileId = persistent_fid;
2420 req->VolatileFileId = volatile_fid;
2423 bufptr = req->Buffer;
2424 memcpy(bufptr, &asteriks, len);
2426 req->FileNameOffset =
2427 cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1 - 4);
2428 req->FileNameLength = cpu_to_le16(len);
2430 * BB could be 30 bytes or so longer if we used SMB2 specific
2431 * buffer lengths, but this is safe and close enough.
2433 output_size = min_t(unsigned int, output_size, server->maxBuf);
2434 output_size = min_t(unsigned int, output_size, 2 << 15);
2435 req->OutputBufferLength = cpu_to_le32(output_size);
2437 iov[0].iov_base = (char *)req;
2438 /* 4 for RFC1001 length and 1 for Buffer */
2439 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
2441 iov[1].iov_base = (char *)(req->Buffer);
2442 iov[1].iov_len = len;
2444 inc_rfc1001_len(req, len - 1 /* Buffer */);
2446 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0);
2447 rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base;
2450 if (rc == -ENODATA && rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2451 srch_inf->endOfSearch = true;
2454 cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE);
2458 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
2459 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
2464 srch_inf->unicode = true;
2466 if (srch_inf->ntwrk_buf_start) {
2467 if (srch_inf->smallBuf)
2468 cifs_small_buf_release(srch_inf->ntwrk_buf_start);
2470 cifs_buf_release(srch_inf->ntwrk_buf_start);
2472 srch_inf->ntwrk_buf_start = (char *)rsp;
2473 srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ +
2474 (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset);
2475 /* 4 for rfc1002 length field */
2476 end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr;
2477 srch_inf->entries_in_buffer =
2478 num_entries(srch_inf->srch_entries_start, end_of_smb,
2479 &srch_inf->last_entry, info_buf_size);
2480 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer;
2481 cifs_dbg(FYI, "num entries %d last_index %lld srch start %p srch end %p\n",
2482 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry,
2483 srch_inf->srch_entries_start, srch_inf->last_entry);
2484 if (resp_buftype == CIFS_LARGE_BUFFER)
2485 srch_inf->smallBuf = false;
2486 else if (resp_buftype == CIFS_SMALL_BUFFER)
2487 srch_inf->smallBuf = true;
2489 cifs_dbg(VFS, "illegal search buffer type\n");
2494 free_rsp_buf(resp_buftype, rsp);
2499 send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
2500 u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class,
2501 unsigned int num, void **data, unsigned int *size)
2503 struct smb2_set_info_req *req;
2504 struct smb2_set_info_rsp *rsp = NULL;
2509 struct TCP_Server_Info *server;
2510 struct cifs_ses *ses = tcon->ses;
2512 if (ses && (ses->server))
2513 server = ses->server;
2520 iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL);
2524 rc = small_smb2_init(SMB2_SET_INFO, tcon, (void **) &req);
2530 req->hdr.ProcessId = cpu_to_le32(pid);
2532 req->InfoType = SMB2_O_INFO_FILE;
2533 req->FileInfoClass = info_class;
2534 req->PersistentFileId = persistent_fid;
2535 req->VolatileFileId = volatile_fid;
2537 /* 4 for RFC1001 length and 1 for Buffer */
2539 cpu_to_le16(sizeof(struct smb2_set_info_req) - 1 - 4);
2540 req->BufferLength = cpu_to_le32(*size);
2542 inc_rfc1001_len(req, *size - 1 /* Buffer */);
2544 memcpy(req->Buffer, *data, *size);
2546 iov[0].iov_base = (char *)req;
2547 /* 4 for RFC1001 length */
2548 iov[0].iov_len = get_rfc1002_length(req) + 4;
2550 for (i = 1; i < num; i++) {
2551 inc_rfc1001_len(req, size[i]);
2552 le32_add_cpu(&req->BufferLength, size[i]);
2553 iov[i].iov_base = (char *)data[i];
2554 iov[i].iov_len = size[i];
2557 rc = SendReceive2(xid, ses, iov, num, &resp_buftype, 0);
2558 rsp = (struct smb2_set_info_rsp *)iov[0].iov_base;
2561 cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE);
2563 free_rsp_buf(resp_buftype, rsp);
2569 SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
2570 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
2572 struct smb2_file_rename_info info;
2574 unsigned int size[2];
2576 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
2578 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
2582 info.ReplaceIfExists = 1; /* 1 = replace existing target with new */
2583 /* 0 = fail if target already exists */
2584 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
2585 info.FileNameLength = cpu_to_le32(len);
2588 size[0] = sizeof(struct smb2_file_rename_info);
2590 data[1] = target_file;
2591 size[1] = len + 2 /* null */;
2593 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
2594 current->tgid, FILE_RENAME_INFORMATION, 2, data,
2601 SMB2_rmdir(const unsigned int xid, struct cifs_tcon *tcon,
2602 u64 persistent_fid, u64 volatile_fid)
2604 __u8 delete_pending = 1;
2608 data = &delete_pending;
2609 size = 1; /* sizeof __u8 */
2611 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2612 current->tgid, FILE_DISPOSITION_INFORMATION, 1, &data,
2617 SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
2618 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
2620 struct smb2_file_link_info info;
2622 unsigned int size[2];
2624 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
2626 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
2630 info.ReplaceIfExists = 0; /* 1 = replace existing link with new */
2631 /* 0 = fail if link already exists */
2632 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
2633 info.FileNameLength = cpu_to_le32(len);
2636 size[0] = sizeof(struct smb2_file_link_info);
2638 data[1] = target_file;
2639 size[1] = len + 2 /* null */;
2641 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
2642 current->tgid, FILE_LINK_INFORMATION, 2, data, size);
2648 SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
2649 u64 volatile_fid, u32 pid, __le64 *eof, bool is_falloc)
2651 struct smb2_file_eof_info info;
2655 info.EndOfFile = *eof;
2658 size = sizeof(struct smb2_file_eof_info);
2661 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2662 pid, FILE_ALLOCATION_INFORMATION, 1, &data, &size);
2664 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2665 pid, FILE_END_OF_FILE_INFORMATION, 1, &data, &size);
2669 SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon,
2670 u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf)
2673 size = sizeof(FILE_BASIC_INFO);
2674 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2675 current->tgid, FILE_BASIC_INFORMATION, 1,
2676 (void **)&buf, &size);
2680 SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
2681 const u64 persistent_fid, const u64 volatile_fid,
2685 struct smb2_oplock_break *req = NULL;
2687 cifs_dbg(FYI, "SMB2_oplock_break\n");
2688 rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req);
2693 req->VolatileFid = volatile_fid;
2694 req->PersistentFid = persistent_fid;
2695 req->OplockLevel = oplock_level;
2696 req->hdr.CreditRequest = cpu_to_le16(1);
2698 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
2699 /* SMB2 buffer freed by function above */
2702 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
2703 cifs_dbg(FYI, "Send error in Oplock Break = %d\n", rc);
2710 copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
2711 struct kstatfs *kst)
2713 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) *
2714 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit);
2715 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits);
2716 kst->f_bfree = le64_to_cpu(pfs_inf->ActualAvailableAllocationUnits);
2717 kst->f_bavail = le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits);
2722 build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level,
2723 int outbuf_len, u64 persistent_fid, u64 volatile_fid)
2726 struct smb2_query_info_req *req;
2728 cifs_dbg(FYI, "Query FSInfo level %d\n", level);
2730 if ((tcon->ses == NULL) || (tcon->ses->server == NULL))
2733 rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req);
2737 req->InfoType = SMB2_O_INFO_FILESYSTEM;
2738 req->FileInfoClass = level;
2739 req->PersistentFileId = persistent_fid;
2740 req->VolatileFileId = volatile_fid;
2741 /* 4 for rfc1002 length field and 1 for pad */
2742 req->InputBufferOffset =
2743 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4);
2744 req->OutputBufferLength = cpu_to_le32(
2745 outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - 4);
2747 iov->iov_base = (char *)req;
2748 /* 4 for rfc1002 length field */
2749 iov->iov_len = get_rfc1002_length(req) + 4;
2754 SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
2755 u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata)
2757 struct smb2_query_info_rsp *rsp = NULL;
2761 struct cifs_ses *ses = tcon->ses;
2762 struct smb2_fs_full_size_info *info = NULL;
2764 rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION,
2765 sizeof(struct smb2_fs_full_size_info),
2766 persistent_fid, volatile_fid);
2770 rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0);
2772 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
2775 rsp = (struct smb2_query_info_rsp *)iov.iov_base;
2777 info = (struct smb2_fs_full_size_info *)(4 /* RFC1001 len */ +
2778 le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr);
2779 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
2780 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
2781 sizeof(struct smb2_fs_full_size_info));
2783 copy_fs_info_to_kstatfs(info, fsdata);
2786 free_rsp_buf(resp_buftype, iov.iov_base);
2791 SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
2792 u64 persistent_fid, u64 volatile_fid, int level)
2794 struct smb2_query_info_rsp *rsp = NULL;
2797 int resp_buftype, max_len, min_len;
2798 struct cifs_ses *ses = tcon->ses;
2799 unsigned int rsp_len, offset;
2801 if (level == FS_DEVICE_INFORMATION) {
2802 max_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
2803 min_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
2804 } else if (level == FS_ATTRIBUTE_INFORMATION) {
2805 max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO);
2806 min_len = MIN_FS_ATTR_INFO_SIZE;
2807 } else if (level == FS_SECTOR_SIZE_INFORMATION) {
2808 max_len = sizeof(struct smb3_fs_ss_info);
2809 min_len = sizeof(struct smb3_fs_ss_info);
2811 cifs_dbg(FYI, "Invalid qfsinfo level %d\n", level);
2815 rc = build_qfs_info_req(&iov, tcon, level, max_len,
2816 persistent_fid, volatile_fid);
2820 rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0);
2822 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
2825 rsp = (struct smb2_query_info_rsp *)iov.iov_base;
2827 rsp_len = le32_to_cpu(rsp->OutputBufferLength);
2828 offset = le16_to_cpu(rsp->OutputBufferOffset);
2829 rc = validate_buf(offset, rsp_len, &rsp->hdr, min_len);
2833 if (level == FS_ATTRIBUTE_INFORMATION)
2834 memcpy(&tcon->fsAttrInfo, 4 /* RFC1001 len */ + offset
2835 + (char *)&rsp->hdr, min_t(unsigned int,
2837 else if (level == FS_DEVICE_INFORMATION)
2838 memcpy(&tcon->fsDevInfo, 4 /* RFC1001 len */ + offset
2839 + (char *)&rsp->hdr, sizeof(FILE_SYSTEM_DEVICE_INFO));
2840 else if (level == FS_SECTOR_SIZE_INFORMATION) {
2841 struct smb3_fs_ss_info *ss_info = (struct smb3_fs_ss_info *)
2842 (4 /* RFC1001 len */ + offset + (char *)&rsp->hdr);
2843 tcon->ss_flags = le32_to_cpu(ss_info->Flags);
2844 tcon->perf_sector_size =
2845 le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf);
2849 free_rsp_buf(resp_buftype, iov.iov_base);
2854 smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
2855 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
2856 const __u32 num_lock, struct smb2_lock_element *buf)
2859 struct smb2_lock_req *req = NULL;
2864 cifs_dbg(FYI, "smb2_lockv num lock %d\n", num_lock);
2866 rc = small_smb2_init(SMB2_LOCK, tcon, (void **) &req);
2870 req->hdr.ProcessId = cpu_to_le32(pid);
2871 req->LockCount = cpu_to_le16(num_lock);
2873 req->PersistentFileId = persist_fid;
2874 req->VolatileFileId = volatile_fid;
2876 count = num_lock * sizeof(struct smb2_lock_element);
2877 inc_rfc1001_len(req, count - sizeof(struct smb2_lock_element));
2879 iov[0].iov_base = (char *)req;
2880 /* 4 for rfc1002 length field and count for all locks */
2881 iov[0].iov_len = get_rfc1002_length(req) + 4 - count;
2882 iov[1].iov_base = (char *)buf;
2883 iov[1].iov_len = count;
2885 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks);
2886 rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP);
2888 cifs_dbg(FYI, "Send error in smb2_lockv = %d\n", rc);
2889 cifs_stats_fail_inc(tcon, SMB2_LOCK_HE);
2896 SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
2897 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
2898 const __u64 length, const __u64 offset, const __u32 lock_flags,
2901 struct smb2_lock_element lock;
2903 lock.Offset = cpu_to_le64(offset);
2904 lock.Length = cpu_to_le64(length);
2905 lock.Flags = cpu_to_le32(lock_flags);
2906 if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK)
2907 lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY);
2909 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock);
2913 SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
2914 __u8 *lease_key, const __le32 lease_state)
2917 struct smb2_lease_ack *req = NULL;
2919 cifs_dbg(FYI, "SMB2_lease_break\n");
2920 rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req);
2925 req->hdr.CreditRequest = cpu_to_le16(1);
2926 req->StructureSize = cpu_to_le16(36);
2927 inc_rfc1001_len(req, 12);
2929 memcpy(req->LeaseKey, lease_key, 16);
2930 req->LeaseState = lease_state;
2932 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
2933 /* SMB2 buffer freed by function above */
2936 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
2937 cifs_dbg(FYI, "Send error in Lease Break = %d\n", rc);