Lines Matching +full:tcon +full:- +full:channel

1 // SPDX-License-Identifier: LGPL-2.1
13 /* SMB2 PDU handling routines here - except for leftovers (eg session setup) */
76 int smb3_encryption_required(const struct cifs_tcon *tcon) in smb3_encryption_required() argument
78 if (!tcon || !tcon->ses) in smb3_encryption_required()
80 if ((tcon->ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) || in smb3_encryption_required()
81 (tcon->share_flags & SHI1005_FLAGS_ENCRYPT_DATA)) in smb3_encryption_required()
83 if (tcon->seal && in smb3_encryption_required()
84 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in smb3_encryption_required()
87 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in smb3_encryption_required()
94 const struct cifs_tcon *tcon, in smb2_hdr_assemble() argument
99 shdr->ProtocolId = SMB2_PROTO_NUMBER; in smb2_hdr_assemble()
100 shdr->StructureSize = cpu_to_le16(64); in smb2_hdr_assemble()
101 shdr->Command = smb2_cmd; in smb2_hdr_assemble()
105 if (server->dialect >= SMB30_PROT_ID) { in smb2_hdr_assemble()
108 * if primary channel is not set yet, use default in smb2_hdr_assemble()
109 * channel for chan sequence num in smb2_hdr_assemble()
112 smb3_hdr->ChannelSequence = in smb2_hdr_assemble()
113 cpu_to_le16(server->primary_server->channel_sequence_num); in smb2_hdr_assemble()
115 smb3_hdr->ChannelSequence = in smb2_hdr_assemble()
116 cpu_to_le16(server->channel_sequence_num); in smb2_hdr_assemble()
118 spin_lock(&server->req_lock); in smb2_hdr_assemble()
120 if (server->credits >= server->max_credits) in smb2_hdr_assemble()
121 shdr->CreditRequest = cpu_to_le16(0); in smb2_hdr_assemble()
123 shdr->CreditRequest = cpu_to_le16( in smb2_hdr_assemble()
124 min_t(int, server->max_credits - in smb2_hdr_assemble()
125 server->credits, 10)); in smb2_hdr_assemble()
126 spin_unlock(&server->req_lock); in smb2_hdr_assemble()
128 shdr->CreditRequest = cpu_to_le16(2); in smb2_hdr_assemble()
130 shdr->Id.SyncId.ProcessId = cpu_to_le32((__u16)current->tgid); in smb2_hdr_assemble()
132 if (!tcon) in smb2_hdr_assemble()
136 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */ in smb2_hdr_assemble()
137 if (server && (server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_hdr_assemble()
138 shdr->CreditCharge = cpu_to_le16(1); in smb2_hdr_assemble()
141 shdr->Id.SyncId.TreeId = cpu_to_le32(tcon->tid); in smb2_hdr_assemble()
143 if (tcon->ses) in smb2_hdr_assemble()
144 shdr->SessionId = cpu_to_le64(tcon->ses->Suid); in smb2_hdr_assemble()
156 /* if (tcon->share_flags & SHI1005_FLAGS_DFS) in smb2_hdr_assemble()
157 shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */ in smb2_hdr_assemble()
159 if (server && server->sign && !smb3_encryption_required(tcon)) in smb2_hdr_assemble()
160 shdr->Flags |= SMB2_FLAGS_SIGNED; in smb2_hdr_assemble()
176 "server %s does not support multichannel anymore. Skip secondary channel\n", in cifs_chan_skip_or_disable()
177 ses->server->hostname); in cifs_chan_skip_or_disable()
179 spin_lock(&ses->chan_lock); in cifs_chan_skip_or_disable()
182 spin_unlock(&ses->chan_lock); in cifs_chan_skip_or_disable()
186 ses->chans[chan_index].server = NULL; in cifs_chan_skip_or_disable()
187 server->terminate = true; in cifs_chan_skip_or_disable()
188 spin_unlock(&ses->chan_lock); in cifs_chan_skip_or_disable()
191 * the above reference of server by channel in cifs_chan_skip_or_disable()
201 pserver = server->primary_server; in cifs_chan_skip_or_disable()
204 return -EHOSTDOWN; in cifs_chan_skip_or_disable()
216 smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, in smb2_reconnect() argument
225 * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so in smb2_reconnect()
227 * for those three - in the calling routine. in smb2_reconnect()
229 if (tcon == NULL) in smb2_reconnect()
239 spin_lock(&tcon->tc_lock); in smb2_reconnect()
240 if (tcon->status == TID_EXITING) { in smb2_reconnect()
245 spin_unlock(&tcon->tc_lock); in smb2_reconnect()
248 return -ENODEV; in smb2_reconnect()
251 spin_unlock(&tcon->tc_lock); in smb2_reconnect()
253 ses = tcon->ses; in smb2_reconnect()
255 return -EIO; in smb2_reconnect()
256 spin_lock(&ses->ses_lock); in smb2_reconnect()
257 if (ses->ses_status == SES_EXITING) { in smb2_reconnect()
258 spin_unlock(&ses->ses_lock); in smb2_reconnect()
259 return -EIO; in smb2_reconnect()
261 spin_unlock(&ses->ses_lock); in smb2_reconnect()
262 if (!ses->server || !server) in smb2_reconnect()
263 return -EIO; in smb2_reconnect()
265 spin_lock(&server->srv_lock); in smb2_reconnect()
266 if (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
279 spin_unlock(&server->srv_lock); in smb2_reconnect()
280 return -EAGAIN; in smb2_reconnect()
285 if (server->terminate) { in smb2_reconnect()
286 spin_unlock(&server->srv_lock); in smb2_reconnect()
287 return -EHOSTDOWN; in smb2_reconnect()
289 spin_unlock(&server->srv_lock); in smb2_reconnect()
292 rc = cifs_wait_for_server_reconnect(server, tcon->retry); in smb2_reconnect()
296 spin_lock(&ses->chan_lock); in smb2_reconnect()
297 if (!cifs_chan_needs_reconnect(ses, server) && !tcon->need_reconnect) { in smb2_reconnect()
298 spin_unlock(&ses->chan_lock); in smb2_reconnect()
301 spin_unlock(&ses->chan_lock); in smb2_reconnect()
302 cifs_dbg(FYI, "sess reconnect mask: 0x%lx, tcon reconnect: %d", in smb2_reconnect()
303 tcon->ses->chans_need_reconnect, in smb2_reconnect()
304 tcon->need_reconnect); in smb2_reconnect()
306 mutex_lock(&ses->session_mutex); in smb2_reconnect()
308 * if this is called by delayed work, and the channel has been disabled in smb2_reconnect()
310 * there's a chance that this channel may not exist anymore in smb2_reconnect()
312 spin_lock(&server->srv_lock); in smb2_reconnect()
313 if (server->tcpStatus == CifsExiting) { in smb2_reconnect()
314 spin_unlock(&server->srv_lock); in smb2_reconnect()
315 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
316 rc = -EHOSTDOWN; in smb2_reconnect()
325 if (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
326 spin_unlock(&server->srv_lock); in smb2_reconnect()
327 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
329 if (tcon->retry) in smb2_reconnect()
332 rc = -EHOSTDOWN; in smb2_reconnect()
335 spin_unlock(&server->srv_lock); in smb2_reconnect()
337 nls_codepage = ses->local_nls; in smb2_reconnect()
343 spin_lock(&ses->ses_lock); in smb2_reconnect()
344 spin_lock(&ses->chan_lock); in smb2_reconnect()
346 ses->ses_status == SES_GOOD) { in smb2_reconnect()
347 spin_unlock(&ses->chan_lock); in smb2_reconnect()
348 spin_unlock(&ses->ses_lock); in smb2_reconnect()
350 if (tcon->need_reconnect) in smb2_reconnect()
353 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
356 spin_unlock(&ses->chan_lock); in smb2_reconnect()
357 spin_unlock(&ses->ses_lock); in smb2_reconnect()
363 * and the first channel reconnected, disable all the others. in smb2_reconnect()
365 if (ses->chan_count > 1 && in smb2_reconnect()
366 !(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { in smb2_reconnect()
370 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
376 if ((rc == -EACCES) || (rc == -EKEYEXPIRED) || (rc == -EKEYREVOKED)) { in smb2_reconnect()
383 if (ses->password2) in smb2_reconnect()
384 swap(ses->password2, ses->password); in smb2_reconnect()
387 if ((rc == -EACCES) && !tcon->retry) { in smb2_reconnect()
388 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
389 rc = -EHOSTDOWN; in smb2_reconnect()
392 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
396 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
401 if (!tcon->need_reconnect) { in smb2_reconnect()
402 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
405 cifs_mark_open_files_invalid(tcon); in smb2_reconnect()
406 if (tcon->use_persistent) in smb2_reconnect()
407 tcon->need_reopen_files = true; in smb2_reconnect()
409 rc = cifs_tree_connect(0, tcon, nls_codepage); in smb2_reconnect()
411 cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); in smb2_reconnect()
413 /* If sess reconnected but tcon didn't, something strange ... */ in smb2_reconnect()
414 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
415 cifs_dbg(VFS, "reconnect tcon failed rc = %d\n", rc); in smb2_reconnect()
419 spin_lock(&ses->ses_lock); in smb2_reconnect()
420 if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) { in smb2_reconnect()
421 spin_unlock(&ses->ses_lock); in smb2_reconnect()
422 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
425 ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS; in smb2_reconnect()
426 spin_unlock(&ses->ses_lock); in smb2_reconnect()
429 (server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL) && in smb2_reconnect()
430 server->ops->query_server_interfaces) { in smb2_reconnect()
431 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
437 rc = server->ops->query_server_interfaces(xid, tcon, false); in smb2_reconnect()
440 if (rc == -EOPNOTSUPP && ses->chan_count > 1) { in smb2_reconnect()
455 if (ses->chan_max > ses->chan_count && in smb2_reconnect()
456 ses->iface_count && in smb2_reconnect()
458 if (ses->chan_count == 1) { in smb2_reconnect()
460 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in smb2_reconnect()
467 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
471 spin_lock(&ses->ses_lock); in smb2_reconnect()
472 ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS; in smb2_reconnect()
473 spin_unlock(&ses->ses_lock); in smb2_reconnect()
476 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in smb2_reconnect()
497 rc = -EAGAIN; in smb2_reconnect()
504 fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, in fill_small_buf() argument
519 smb2_hdr_assemble(&spdu->hdr, smb2_command, tcon, server); in fill_small_buf()
520 spdu->StructureSize2 = cpu_to_le16(parmsize); in fill_small_buf()
530 static int __smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, in __smb2_plain_req_init() argument
546 return -ENOMEM; in __smb2_plain_req_init()
549 fill_small_buf(smb2_command, tcon, server, in __smb2_plain_req_init()
553 if (tcon != NULL) { in __smb2_plain_req_init()
555 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]); in __smb2_plain_req_init()
556 cifs_stats_inc(&tcon->num_smbs_sent); in __smb2_plain_req_init()
562 static int smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon, in smb2_plain_req_init() argument
568 rc = smb2_reconnect(smb2_command, tcon, server, false); in smb2_plain_req_init()
572 return __smb2_plain_req_init(smb2_command, tcon, server, request_buf, in smb2_plain_req_init()
576 static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon, in smb2_ioctl_req_init() argument
582 return __smb2_plain_req_init(SMB2_IOCTL, tcon, server, in smb2_ioctl_req_init()
585 return smb2_plain_req_init(SMB2_IOCTL, tcon, server, in smb2_ioctl_req_init()
589 /* For explanation of negotiate contexts see MS-SMB2 section 2.2.3.1 */
594 pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES; in build_preauth_ctxt()
595 pneg_ctxt->DataLength = cpu_to_le16(38); in build_preauth_ctxt()
596 pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1); in build_preauth_ctxt()
597 pneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE); in build_preauth_ctxt()
598 get_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE); in build_preauth_ctxt()
599 pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512; in build_preauth_ctxt()
605 pneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES; in build_compression_ctxt()
606 pneg_ctxt->DataLength = in build_compression_ctxt()
608 - sizeof(struct smb2_neg_context)); in build_compression_ctxt()
609 pneg_ctxt->CompressionAlgorithmCount = cpu_to_le16(3); in build_compression_ctxt()
610 pneg_ctxt->CompressionAlgorithms[0] = SMB3_COMPRESS_LZ77; in build_compression_ctxt()
611 pneg_ctxt->CompressionAlgorithms[1] = SMB3_COMPRESS_LZ77_HUFF; in build_compression_ctxt()
612 pneg_ctxt->CompressionAlgorithms[2] = SMB3_COMPRESS_LZNT1; in build_compression_ctxt()
621 pneg_ctxt->ContextType = SMB2_SIGNING_CAPABILITIES; in build_signing_ctxt()
625 pneg_ctxt->DataLength = cpu_to_le16(ALIGN(sizeof(struct smb2_signing_capabilities) - in build_signing_ctxt()
628 pneg_ctxt->SigningAlgorithmCount = cpu_to_le16(num_algs); in build_signing_ctxt()
629 pneg_ctxt->SigningAlgorithms[0] = cpu_to_le16(SIGNING_ALG_AES_CMAC); in build_signing_ctxt()
640 pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES; in build_encrypt_ctxt()
642 pneg_ctxt->DataLength = cpu_to_le16(4); /* Cipher Count + 1 cipher */ in build_encrypt_ctxt()
643 pneg_ctxt->CipherCount = cpu_to_le16(1); in build_encrypt_ctxt()
644 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
646 pneg_ctxt->DataLength = cpu_to_le16(8); /* Cipher Count + 3 ciphers */ in build_encrypt_ctxt()
647 pneg_ctxt->CipherCount = cpu_to_le16(3); in build_encrypt_ctxt()
648 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
649 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
650 pneg_ctxt->Ciphers[2] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
652 pneg_ctxt->DataLength = cpu_to_le16(6); /* Cipher Count + 2 ciphers */ in build_encrypt_ctxt()
653 pneg_ctxt->CipherCount = cpu_to_le16(2); in build_encrypt_ctxt()
654 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
655 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
664 pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID; in build_netname_ctxt()
667 pneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp)); in build_netname_ctxt()
669 return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8); in build_netname_ctxt()
675 pneg_ctxt->ContextType = SMB2_POSIX_EXTENSIONS_AVAILABLE; in build_posix_ctxt()
676 pneg_ctxt->DataLength = cpu_to_le16(POSIX_CTXT_DATA_LEN); in build_posix_ctxt()
678 pneg_ctxt->Name[0] = 0x93; in build_posix_ctxt()
679 pneg_ctxt->Name[1] = 0xAD; in build_posix_ctxt()
680 pneg_ctxt->Name[2] = 0x25; in build_posix_ctxt()
681 pneg_ctxt->Name[3] = 0x50; in build_posix_ctxt()
682 pneg_ctxt->Name[4] = 0x9C; in build_posix_ctxt()
683 pneg_ctxt->Name[5] = 0xB4; in build_posix_ctxt()
684 pneg_ctxt->Name[6] = 0x11; in build_posix_ctxt()
685 pneg_ctxt->Name[7] = 0xE7; in build_posix_ctxt()
686 pneg_ctxt->Name[8] = 0xB4; in build_posix_ctxt()
687 pneg_ctxt->Name[9] = 0x23; in build_posix_ctxt()
688 pneg_ctxt->Name[10] = 0x83; in build_posix_ctxt()
689 pneg_ctxt->Name[11] = 0xDE; in build_posix_ctxt()
690 pneg_ctxt->Name[12] = 0x96; in build_posix_ctxt()
691 pneg_ctxt->Name[13] = 0x8B; in build_posix_ctxt()
692 pneg_ctxt->Name[14] = 0xCD; in build_posix_ctxt()
693 pneg_ctxt->Name[15] = 0x7C; in build_posix_ctxt()
718 req->NegotiateContextOffset = cpu_to_le32(*total_len); in assemble_neg_contexts()
732 * use the hostname field in the primary channel instead in assemble_neg_contexts()
734 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in assemble_neg_contexts()
736 hostname = pserver->hostname; in assemble_neg_contexts()
752 if (server->compression.requested) { in assemble_neg_contexts()
770 req->NegotiateContextCount = cpu_to_le16(neg_context_count); in assemble_neg_contexts()
774 /* If invalid preauth context warn but use what we requested, SHA-512 */
777 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_preauth_context()
786 } else if (len < MIN_PREAUTH_CTXT_DATA_LEN + le16_to_cpu(ctxt->SaltLength)) { in decode_preauth_context()
790 if (le16_to_cpu(ctxt->HashAlgorithmCount) != 1) in decode_preauth_context()
792 if (ctxt->HashAlgorithms != SMB2_PREAUTH_INTEGRITY_SHA512) in decode_preauth_context()
799 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_compress_ctx()
802 server->compression.enabled = false; in decode_compress_ctx()
814 if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) { in decode_compress_ctx()
819 alg = ctxt->CompressionAlgorithms[0]; in decode_compress_ctx()
827 server->compression.alg = alg; in decode_compress_ctx()
828 server->compression.enabled = true; in decode_compress_ctx()
834 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_encrypt_ctx()
844 return -EINVAL; in decode_encrypt_ctx()
847 if (le16_to_cpu(ctxt->CipherCount) != 1) { in decode_encrypt_ctx()
849 return -EINVAL; in decode_encrypt_ctx()
851 cifs_dbg(FYI, "SMB311 cipher type:%d\n", le16_to_cpu(ctxt->Ciphers[0])); in decode_encrypt_ctx()
853 if (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM) { in decode_encrypt_ctx()
855 return -EOPNOTSUPP; in decode_encrypt_ctx()
857 } else if (ctxt->Ciphers[0] == 0) { in decode_encrypt_ctx()
867 server->cipher_type = 0; in decode_encrypt_ctx()
868 server->capabilities &= ~SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
871 } else if ((ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_CCM) && in decode_encrypt_ctx()
872 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_GCM) && in decode_encrypt_ctx()
873 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM)) { in decode_encrypt_ctx()
876 return -EINVAL; in decode_encrypt_ctx()
878 server->cipher_type = ctxt->Ciphers[0]; in decode_encrypt_ctx()
879 server->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
886 unsigned int len = le16_to_cpu(pctxt->DataLength); in decode_signing_ctx()
897 if (le16_to_cpu(pctxt->SigningAlgorithmCount) != 1) { in decode_signing_ctx()
901 if (le16_to_cpu(pctxt->SigningAlgorithms[0]) > 2) { in decode_signing_ctx()
906 server->signing_negotiated = true; in decode_signing_ctx()
907 server->signing_algorithm = le16_to_cpu(pctxt->SigningAlgorithms[0]); in decode_signing_ctx()
909 server->signing_algorithm); in decode_signing_ctx()
918 unsigned int offset = le32_to_cpu(rsp->NegotiateContextOffset); in smb311_decode_neg_context()
919 unsigned int ctxt_cnt = le16_to_cpu(rsp->NegotiateContextCount); in smb311_decode_neg_context()
926 return -EINVAL; in smb311_decode_neg_context()
929 len_of_ctxts = len_of_smb - offset; in smb311_decode_neg_context()
939 + le16_to_cpu(pctx->DataLength); in smb311_decode_neg_context()
942 * Subsequent negotiate contexts MUST appear at the first 8-byte in smb311_decode_neg_context()
950 if (pctx->ContextType == SMB2_PREAUTH_INTEGRITY_CAPABILITIES) in smb311_decode_neg_context()
953 else if (pctx->ContextType == SMB2_ENCRYPTION_CAPABILITIES) in smb311_decode_neg_context()
956 else if (pctx->ContextType == SMB2_COMPRESSION_CAPABILITIES) in smb311_decode_neg_context()
959 else if (pctx->ContextType == SMB2_POSIX_EXTENSIONS_AVAILABLE) in smb311_decode_neg_context()
960 server->posix_ext_supported = true; in smb311_decode_neg_context()
961 else if (pctx->ContextType == SMB2_SIGNING_CAPABILITIES) in smb311_decode_neg_context()
966 le16_to_cpu(pctx->ContextType)); in smb311_decode_neg_context()
971 len_of_ctxts -= clen; in smb311_decode_neg_context()
986 buf->ccontext.DataOffset = in create_posix_buf()
988 buf->ccontext.DataLength = cpu_to_le32(4); in create_posix_buf()
989 buf->ccontext.NameOffset = in create_posix_buf()
991 buf->ccontext.NameLength = cpu_to_le16(16); in create_posix_buf()
994 buf->Name[0] = 0x93; in create_posix_buf()
995 buf->Name[1] = 0xAD; in create_posix_buf()
996 buf->Name[2] = 0x25; in create_posix_buf()
997 buf->Name[3] = 0x50; in create_posix_buf()
998 buf->Name[4] = 0x9C; in create_posix_buf()
999 buf->Name[5] = 0xB4; in create_posix_buf()
1000 buf->Name[6] = 0x11; in create_posix_buf()
1001 buf->Name[7] = 0xE7; in create_posix_buf()
1002 buf->Name[8] = 0xB4; in create_posix_buf()
1003 buf->Name[9] = 0x23; in create_posix_buf()
1004 buf->Name[10] = 0x83; in create_posix_buf()
1005 buf->Name[11] = 0xDE; in create_posix_buf()
1006 buf->Name[12] = 0x96; in create_posix_buf()
1007 buf->Name[13] = 0x8B; in create_posix_buf()
1008 buf->Name[14] = 0xCD; in create_posix_buf()
1009 buf->Name[15] = 0x7C; in create_posix_buf()
1010 buf->Mode = cpu_to_le32(mode); in create_posix_buf()
1024 return -ENOMEM; in add_posix_context()
1067 return -EIO; in SMB2_negotiate()
1075 req->hdr.SessionId = 0; in SMB2_negotiate()
1077 memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
1078 memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
1080 if (strcmp(server->vals->version_string, in SMB2_negotiate()
1082 req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
1083 req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
1084 req->Dialects[2] = cpu_to_le16(SMB311_PROT_ID); in SMB2_negotiate()
1085 req->DialectCount = cpu_to_le16(3); in SMB2_negotiate()
1087 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
1089 req->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in SMB2_negotiate()
1090 req->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
1091 req->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
1092 req->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in SMB2_negotiate()
1093 req->DialectCount = cpu_to_le16(4); in SMB2_negotiate()
1097 req->Dialects[0] = cpu_to_le16(server->vals->protocol_id); in SMB2_negotiate()
1098 req->DialectCount = cpu_to_le16(1); in SMB2_negotiate()
1103 if (ses->sign) in SMB2_negotiate()
1104 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); in SMB2_negotiate()
1106 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); in SMB2_negotiate()
1108 req->SecurityMode = 0; in SMB2_negotiate()
1110 req->Capabilities = cpu_to_le32(server->vals->req_capabilities); in SMB2_negotiate()
1111 if (ses->chan_max > 1) in SMB2_negotiate()
1112 req->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in SMB2_negotiate()
1115 if (server->vals->protocol_id == SMB20_PROT_ID) in SMB2_negotiate()
1116 memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE); in SMB2_negotiate()
1118 memcpy(req->ClientGUID, server->client_guid, in SMB2_negotiate()
1120 if ((server->vals->protocol_id == SMB311_PROT_ID) || in SMB2_negotiate()
1121 (strcmp(server->vals->version_string, in SMB2_negotiate()
1123 (strcmp(server->vals->version_string, in SMB2_negotiate()
1139 * No tcon so can't do in SMB2_negotiate()
1140 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_negotiate()
1142 if (rc == -EOPNOTSUPP) { in SMB2_negotiate()
1148 rc = -EIO; in SMB2_negotiate()
1149 if (strcmp(server->vals->version_string, in SMB2_negotiate()
1151 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
1155 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
1159 } else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1161 server->ops = &smb311_operations; in SMB2_negotiate()
1162 server->vals = &smb311_values; in SMB2_negotiate()
1164 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
1166 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
1170 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
1172 server->ops = &smb21_operations; in SMB2_negotiate()
1173 server->vals = &smb21_values; in SMB2_negotiate()
1174 } else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1175 server->ops = &smb311_operations; in SMB2_negotiate()
1176 server->vals = &smb311_values; in SMB2_negotiate()
1178 } else if (le16_to_cpu(rsp->DialectRevision) != in SMB2_negotiate()
1179 server->vals->protocol_id) { in SMB2_negotiate()
1182 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
1186 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode); in SMB2_negotiate()
1188 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) in SMB2_negotiate()
1190 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) in SMB2_negotiate()
1192 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) in SMB2_negotiate()
1194 else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID)) in SMB2_negotiate()
1196 else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) in SMB2_negotiate()
1200 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
1205 server->dialect = le16_to_cpu(rsp->DialectRevision); in SMB2_negotiate()
1212 memcpy(server->preauth_sha_hash, ses->preauth_sha_hash, in SMB2_negotiate()
1216 server->negflavor = CIFS_NEGFLAVOR_EXTENDED; in SMB2_negotiate()
1218 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize), in SMB2_negotiate()
1220 server->max_read = le32_to_cpu(rsp->MaxReadSize); in SMB2_negotiate()
1221 server->max_write = le32_to_cpu(rsp->MaxWriteSize); in SMB2_negotiate()
1222 server->sec_mode = le16_to_cpu(rsp->SecurityMode); in SMB2_negotiate()
1223 if ((server->sec_mode & SMB2_SEC_MODE_FLAGS_ALL) != server->sec_mode) in SMB2_negotiate()
1225 server->sec_mode); in SMB2_negotiate()
1226 server->capabilities = le32_to_cpu(rsp->Capabilities); in SMB2_negotiate()
1228 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES; in SMB2_negotiate()
1234 if (server->dialect == SMB30_PROT_ID && (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_negotiate()
1235 server->cipher_type = SMB2_ENCRYPTION_AES128_CCM; in SMB2_negotiate()
1240 * See MS-SMB2 section 2.2.4: if no blob, client picks default which in SMB2_negotiate()
1242 * ses->sectype = RawNTLMSSP; in SMB2_negotiate()
1248 server->sec_ntlmssp = true; in SMB2_negotiate()
1251 rc = cifs_enable_signing(server, ses->sign); in SMB2_negotiate()
1259 rc = -EIO; in SMB2_negotiate()
1262 if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1263 if (rsp->NegotiateContextCount) in SMB2_negotiate()
1270 if (server->cipher_type && !rc) { in SMB2_negotiate()
1275 server->secmech.enc = server->primary_server->secmech.enc; in SMB2_negotiate()
1276 server->secmech.dec = server->primary_server->secmech.dec; in SMB2_negotiate()
1284 int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon) in smb3_validate_negotiate() argument
1291 struct TCP_Server_Info *server = tcon->ses->server; in smb3_validate_negotiate()
1296 if (server->dialect == SMB311_PROT_ID) in smb3_validate_negotiate()
1306 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) in smb3_validate_negotiate()
1309 if (tcon->ses->user_name == NULL) { in smb3_validate_negotiate()
1314 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_NULL) in smb3_validate_negotiate()
1319 return -ENOMEM; in smb3_validate_negotiate()
1321 pneg_inbuf->Capabilities = in smb3_validate_negotiate()
1322 cpu_to_le32(server->vals->req_capabilities); in smb3_validate_negotiate()
1323 if (tcon->ses->chan_max > 1) in smb3_validate_negotiate()
1324 pneg_inbuf->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in smb3_validate_negotiate()
1326 memcpy(pneg_inbuf->Guid, server->client_guid, in smb3_validate_negotiate()
1329 if (tcon->ses->sign) in smb3_validate_negotiate()
1330 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1333 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1336 pneg_inbuf->SecurityMode = 0; in smb3_validate_negotiate()
1339 if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1341 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1342 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1343 pneg_inbuf->Dialects[2] = cpu_to_le16(SMB311_PROT_ID); in smb3_validate_negotiate()
1344 pneg_inbuf->DialectCount = cpu_to_le16(3); in smb3_validate_negotiate()
1346 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1347 (sizeof(pneg_inbuf->Dialects[0])); in smb3_validate_negotiate()
1348 } else if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1350 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in smb3_validate_negotiate()
1351 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1352 pneg_inbuf->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1353 pneg_inbuf->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in smb3_validate_negotiate()
1354 pneg_inbuf->DialectCount = cpu_to_le16(4); in smb3_validate_negotiate()
1359 pneg_inbuf->Dialects[0] = in smb3_validate_negotiate()
1360 cpu_to_le16(server->vals->protocol_id); in smb3_validate_negotiate()
1361 pneg_inbuf->DialectCount = cpu_to_le16(1); in smb3_validate_negotiate()
1363 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1364 sizeof(pneg_inbuf->Dialects[0]) * 3; in smb3_validate_negotiate()
1367 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in smb3_validate_negotiate()
1371 if (rc == -EOPNOTSUPP) { in smb3_validate_negotiate()
1382 rc = -EIO; in smb3_validate_negotiate()
1386 rc = -EIO; in smb3_validate_negotiate()
1397 if (pneg_rsp->Dialect != cpu_to_le16(server->dialect)) in smb3_validate_negotiate()
1400 if (pneg_rsp->SecurityMode != cpu_to_le16(server->sec_mode)) in smb3_validate_negotiate()
1405 if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND | in smb3_validate_negotiate()
1406 SMB2_LARGE_FILES) != server->capabilities) in smb3_validate_negotiate()
1415 cifs_tcon_dbg(VFS, "protocol revalidation - security settings mismatch\n"); in smb3_validate_negotiate()
1433 if (server->sec_ntlmssp && in smb2_select_sectype()
1436 if ((server->sec_kerberos || server->sec_mskerberos) && in smb2_select_sectype()
1469 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_alloc_buffer()
1470 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_alloc_buffer()
1481 spin_lock(&ses->ses_lock); in SMB2_sess_alloc_buffer()
1482 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_alloc_buffer()
1483 spin_unlock(&ses->ses_lock); in SMB2_sess_alloc_buffer()
1486 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_sess_alloc_buffer()
1487 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_sess_alloc_buffer()
1488 req->PreviousSessionId = 0; in SMB2_sess_alloc_buffer()
1489 req->Flags = SMB2_SESSION_REQ_FLAG_BINDING; in SMB2_sess_alloc_buffer()
1490 cifs_dbg(FYI, "Binding to sess id: %llx\n", ses->Suid); in SMB2_sess_alloc_buffer()
1493 req->hdr.SessionId = 0; in SMB2_sess_alloc_buffer()
1498 req->PreviousSessionId = cpu_to_le64(sess_data->previous_session); in SMB2_sess_alloc_buffer()
1499 req->Flags = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1501 sess_data->previous_session); in SMB2_sess_alloc_buffer()
1505 if (server->credits >= server->max_credits) in SMB2_sess_alloc_buffer()
1506 req->hdr.CreditRequest = cpu_to_le16(0); in SMB2_sess_alloc_buffer()
1508 req->hdr.CreditRequest = cpu_to_le16( in SMB2_sess_alloc_buffer()
1509 min_t(int, server->max_credits - in SMB2_sess_alloc_buffer()
1510 server->credits, 130)); in SMB2_sess_alloc_buffer()
1513 if (server->sign) in SMB2_sess_alloc_buffer()
1514 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED; in SMB2_sess_alloc_buffer()
1516 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED; in SMB2_sess_alloc_buffer()
1518 req->SecurityMode = 0; in SMB2_sess_alloc_buffer()
1521 req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); in SMB2_sess_alloc_buffer()
1523 req->Capabilities = 0; in SMB2_sess_alloc_buffer()
1526 req->Channel = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1528 sess_data->iov[0].iov_base = (char *)req; in SMB2_sess_alloc_buffer()
1530 sess_data->iov[0].iov_len = total_len - 1; in SMB2_sess_alloc_buffer()
1535 sess_data->buf0_type = CIFS_SMALL_BUFFER; in SMB2_sess_alloc_buffer()
1543 struct kvec *iov = sess_data->iov; in SMB2_sess_free_buffer()
1546 if (sess_data->buf0_type != CIFS_NO_BUFFER && iov[0].iov_base) in SMB2_sess_free_buffer()
1549 free_rsp_buf(sess_data->buf0_type, iov[0].iov_base); in SMB2_sess_free_buffer()
1550 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_free_buffer()
1558 struct smb2_sess_setup_req *req = sess_data->iov[0].iov_base; in SMB2_sess_sendreceive()
1562 req->SecurityBufferOffset = in SMB2_sess_sendreceive()
1564 req->SecurityBufferLength = cpu_to_le16(sess_data->iov[1].iov_len); in SMB2_sess_sendreceive()
1567 rqst.rq_iov = sess_data->iov; in SMB2_sess_sendreceive()
1571 rc = cifs_send_recv(sess_data->xid, sess_data->ses, in SMB2_sess_sendreceive()
1572 sess_data->server, in SMB2_sess_sendreceive()
1574 &sess_data->buf0_type, in SMB2_sess_sendreceive()
1576 cifs_small_buf_release(sess_data->iov[0].iov_base); in SMB2_sess_sendreceive()
1578 sess_data->ses->expired_pwd = false; in SMB2_sess_sendreceive()
1579 else if ((rc == -EACCES) || (rc == -EKEYEXPIRED) || (rc == -EKEYREVOKED)) { in SMB2_sess_sendreceive()
1580 if (sess_data->ses->expired_pwd == false) in SMB2_sess_sendreceive()
1581 trace_smb3_key_expired(sess_data->server->hostname, in SMB2_sess_sendreceive()
1582 sess_data->ses->user_name, in SMB2_sess_sendreceive()
1583 sess_data->server->conn_id, in SMB2_sess_sendreceive()
1584 &sess_data->server->dstaddr, rc); in SMB2_sess_sendreceive()
1585 sess_data->ses->expired_pwd = true; in SMB2_sess_sendreceive()
1588 memcpy(&sess_data->iov[0], &rsp_iov, sizeof(struct kvec)); in SMB2_sess_sendreceive()
1597 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_establish_session()
1598 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_establish_session()
1601 if (server->ops->generate_signingkey) { in SMB2_sess_establish_session()
1602 rc = server->ops->generate_signingkey(ses, server); in SMB2_sess_establish_session()
1610 if (!server->session_estab) { in SMB2_sess_establish_session()
1611 server->sequence_number = 0x2; in SMB2_sess_establish_session()
1612 server->session_estab = true; in SMB2_sess_establish_session()
1625 struct cifs_ses *ses = sess_data->ses; in SMB2_auth_kerberos()
1626 struct TCP_Server_Info *server = sess_data->server; in SMB2_auth_kerberos()
1639 if (rc == -ENOKEY) in SMB2_auth_kerberos()
1645 msg = spnego_key->payload.data[0]; in SMB2_auth_kerberos()
1650 if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { in SMB2_auth_kerberos()
1652 CIFS_SPNEGO_UPCALL_VERSION, msg->version); in SMB2_auth_kerberos()
1653 rc = -EKEYREJECTED; in SMB2_auth_kerberos()
1657 spin_lock(&ses->ses_lock); in SMB2_auth_kerberos()
1658 is_binding = (ses->ses_status == SES_GOOD); in SMB2_auth_kerberos()
1659 spin_unlock(&ses->ses_lock); in SMB2_auth_kerberos()
1663 kfree_sensitive(ses->auth_key.response); in SMB2_auth_kerberos()
1664 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, in SMB2_auth_kerberos()
1666 if (!ses->auth_key.response) { in SMB2_auth_kerberos()
1668 msg->sesskey_len); in SMB2_auth_kerberos()
1669 rc = -ENOMEM; in SMB2_auth_kerberos()
1672 ses->auth_key.len = msg->sesskey_len; in SMB2_auth_kerberos()
1675 sess_data->iov[1].iov_base = msg->data + msg->sesskey_len; in SMB2_auth_kerberos()
1676 sess_data->iov[1].iov_len = msg->secblob_len; in SMB2_auth_kerberos()
1682 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_auth_kerberos()
1685 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_auth_kerberos()
1686 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_auth_kerberos()
1694 kfree_sensitive(ses->auth_key.response); in SMB2_auth_kerberos()
1695 ses->auth_key.response = NULL; in SMB2_auth_kerberos()
1696 ses->auth_key.len = 0; in SMB2_auth_kerberos()
1699 sess_data->result = rc; in SMB2_auth_kerberos()
1700 sess_data->func = NULL; in SMB2_auth_kerberos()
1708 sess_data->result = -EOPNOTSUPP; in SMB2_auth_kerberos()
1709 sess_data->func = NULL; in SMB2_auth_kerberos()
1720 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_negotiate()
1721 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_auth_rawntlmssp_negotiate()
1732 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL); in SMB2_sess_auth_rawntlmssp_negotiate()
1733 if (!ses->ntlmssp) { in SMB2_sess_auth_rawntlmssp_negotiate()
1734 rc = -ENOMEM; in SMB2_sess_auth_rawntlmssp_negotiate()
1737 ses->ntlmssp->sesskey_per_smbsess = true; in SMB2_sess_auth_rawntlmssp_negotiate()
1745 sess_data->nls_cp); in SMB2_sess_auth_rawntlmssp_negotiate()
1752 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_negotiate()
1755 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_negotiate()
1756 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_negotiate()
1759 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_negotiate()
1762 if (sess_data->buf0_type != CIFS_NO_BUFFER && in SMB2_sess_auth_rawntlmssp_negotiate()
1763 rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) in SMB2_sess_auth_rawntlmssp_negotiate()
1770 le16_to_cpu(rsp->SecurityBufferOffset)) { in SMB2_sess_auth_rawntlmssp_negotiate()
1772 le16_to_cpu(rsp->SecurityBufferOffset)); in SMB2_sess_auth_rawntlmssp_negotiate()
1773 rc = -EIO; in SMB2_sess_auth_rawntlmssp_negotiate()
1776 rc = decode_ntlmssp_challenge(rsp->Buffer, in SMB2_sess_auth_rawntlmssp_negotiate()
1777 le16_to_cpu(rsp->SecurityBufferLength), ses); in SMB2_sess_auth_rawntlmssp_negotiate()
1783 spin_lock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_negotiate()
1784 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_auth_rawntlmssp_negotiate()
1785 spin_unlock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_negotiate()
1789 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_sess_auth_rawntlmssp_negotiate()
1790 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_negotiate()
1797 sess_data->result = 0; in SMB2_sess_auth_rawntlmssp_negotiate()
1798 sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate; in SMB2_sess_auth_rawntlmssp_negotiate()
1802 kfree_sensitive(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_negotiate()
1803 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1804 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_negotiate()
1805 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1812 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_authenticate()
1813 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_auth_rawntlmssp_authenticate()
1825 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1826 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_sess_auth_rawntlmssp_authenticate()
1830 sess_data->nls_cp); in SMB2_sess_auth_rawntlmssp_authenticate()
1839 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_authenticate()
1842 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_authenticate()
1843 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_authenticate()
1849 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1851 spin_lock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_authenticate()
1852 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_auth_rawntlmssp_authenticate()
1853 spin_unlock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_authenticate()
1857 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_sess_auth_rawntlmssp_authenticate()
1858 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_authenticate()
1863 if (ses->server->dialect < SMB30_PROT_ID) { in SMB2_sess_auth_rawntlmssp_authenticate()
1869 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid), in SMB2_sess_auth_rawntlmssp_authenticate()
1870 &ses->Suid); in SMB2_sess_auth_rawntlmssp_authenticate()
1872 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1874 SMB3_SIGN_KEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1880 kfree_sensitive(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_authenticate()
1881 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1882 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_authenticate()
1883 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1890 struct cifs_ses *ses = sess_data->ses; in SMB2_select_sec()
1891 struct TCP_Server_Info *server = sess_data->server; in SMB2_select_sec()
1893 type = smb2_select_sectype(server, ses->sectype); in SMB2_select_sec()
1897 return -EINVAL; in SMB2_select_sec()
1902 sess_data->func = SMB2_auth_kerberos; in SMB2_select_sec()
1905 sess_data->func = SMB2_sess_auth_rawntlmssp_negotiate; in SMB2_select_sec()
1909 return -EOPNOTSUPP; in SMB2_select_sec()
1927 return -EIO; in SMB2_sess_setup()
1932 return -ENOMEM; in SMB2_sess_setup()
1934 sess_data->xid = xid; in SMB2_sess_setup()
1935 sess_data->ses = ses; in SMB2_sess_setup()
1936 sess_data->server = server; in SMB2_sess_setup()
1937 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_setup()
1938 sess_data->nls_cp = (struct nls_table *) nls_cp; in SMB2_sess_setup()
1939 sess_data->previous_session = ses->Suid; in SMB2_sess_setup()
1948 memcpy(ses->preauth_sha_hash, server->preauth_sha_hash, in SMB2_sess_setup()
1951 while (sess_data->func) in SMB2_sess_setup()
1952 sess_data->func(sess_data); in SMB2_sess_setup()
1954 if ((ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) && (ses->sign)) in SMB2_sess_setup()
1956 rc = sess_data->result; in SMB2_sess_setup()
1977 if (ses && (ses->server)) in SMB2_logoff()
1978 server = ses->server; in SMB2_logoff()
1980 return -EIO; in SMB2_logoff()
1983 spin_lock(&ses->chan_lock); in SMB2_logoff()
1985 spin_unlock(&ses->chan_lock); in SMB2_logoff()
1988 spin_unlock(&ses->chan_lock); in SMB2_logoff()
1990 rc = smb2_plain_req_init(SMB2_LOGOFF, NULL, ses->server, in SMB2_logoff()
1995 /* since no tcon, smb2_init can not do this, so do here */ in SMB2_logoff()
1996 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_logoff()
1998 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) in SMB2_logoff()
2000 else if (server->sign) in SMB2_logoff()
2001 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_logoff()
2012 rc = cifs_send_recv(xid, ses, ses->server, in SMB2_logoff()
2016 * No tcon so can't do in SMB2_logoff()
2017 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_logoff()
2024 static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code) in cifs_stats_fail_inc() argument
2026 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]); in cifs_stats_fail_inc()
2032 static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon) in init_copy_chunk_defaults() argument
2034 tcon->max_chunks = 256; in init_copy_chunk_defaults()
2035 tcon->max_bytes_chunk = 1048576; in init_copy_chunk_defaults()
2036 tcon->max_bytes_copy = 16777216; in init_copy_chunk_defaults()
2041 struct cifs_tcon *tcon, const struct nls_table *cp) in SMB2_tcon() argument
2056 cifs_dbg(FYI, "TCON\n"); in SMB2_tcon()
2059 return -EIO; in SMB2_tcon()
2063 return -ENOMEM; in SMB2_tcon()
2068 return -EINVAL; in SMB2_tcon()
2073 tcon->tid = 0; in SMB2_tcon()
2074 atomic_set(&tcon->num_remote_opens, 0); in SMB2_tcon()
2075 rc = smb2_plain_req_init(SMB2_TREE_CONNECT, tcon, server, in SMB2_tcon()
2082 if (smb3_encryption_required(tcon)) in SMB2_tcon()
2087 iov[0].iov_len = total_len - 1; in SMB2_tcon()
2090 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req)); in SMB2_tcon()
2091 req->PathLength = cpu_to_le16(unc_path_len); in SMB2_tcon()
2096 * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 in SMB2_tcon()
2097 * unless it is guest or anonymous user. See MS-SMB2 3.2.5.3.1 in SMB2_tcon()
2100 if ((server->dialect == SMB311_PROT_ID) && in SMB2_tcon()
2101 !smb3_encryption_required(tcon) && in SMB2_tcon()
2102 !(ses->session_flags & in SMB2_tcon()
2104 ((ses->user_name != NULL) || (ses->sectype == Kerberos))) in SMB2_tcon()
2105 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_tcon()
2112 if (server->credits >= server->max_credits) in SMB2_tcon()
2113 req->hdr.CreditRequest = cpu_to_le16(0); in SMB2_tcon()
2115 req->hdr.CreditRequest = cpu_to_le16( in SMB2_tcon()
2116 min_t(int, server->max_credits - in SMB2_tcon()
2117 server->credits, 64)); in SMB2_tcon()
2123 trace_smb3_tcon(xid, tcon->tid, ses->Suid, tree, rc); in SMB2_tcon()
2125 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE); in SMB2_tcon()
2126 tcon->need_reconnect = true; in SMB2_tcon()
2130 switch (rsp->ShareType) { in SMB2_tcon()
2135 tcon->pipe = true; in SMB2_tcon()
2139 tcon->print = true; in SMB2_tcon()
2143 cifs_server_dbg(VFS, "unknown share type %d\n", rsp->ShareType); in SMB2_tcon()
2144 rc = -EOPNOTSUPP; in SMB2_tcon()
2148 tcon->share_flags = le32_to_cpu(rsp->ShareFlags); in SMB2_tcon()
2149 tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */ in SMB2_tcon()
2150 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess); in SMB2_tcon()
2151 tcon->tid = le32_to_cpu(rsp->hdr.Id.SyncId.TreeId); in SMB2_tcon()
2152 strscpy(tcon->tree_name, tree, sizeof(tcon->tree_name)); in SMB2_tcon()
2154 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) && in SMB2_tcon()
2155 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0)) in SMB2_tcon()
2158 if (tcon->seal && in SMB2_tcon()
2159 !(server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_tcon()
2162 init_copy_chunk_defaults(tcon); in SMB2_tcon()
2163 if (server->ops->validate_negotiate) in SMB2_tcon()
2164 rc = server->ops->validate_negotiate(xid, tcon); in SMB2_tcon()
2165 if (rc == 0) /* See MS-SMB2 2.2.10 and 3.2.5.5 */ in SMB2_tcon()
2166 if (tcon->share_flags & SMB2_SHAREFLAG_ISOLATED_TRANSPORT) in SMB2_tcon()
2167 server->nosharesock = true; in SMB2_tcon()
2175 if (rsp && rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) in SMB2_tcon()
2181 SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) in SMB2_tdis() argument
2186 struct cifs_ses *ses = tcon->ses; in SMB2_tdis()
2196 if (!ses || !(ses->server)) in SMB2_tdis()
2197 return -EIO; in SMB2_tdis()
2199 trace_smb3_tdis_enter(xid, tcon->tid, ses->Suid, tcon->tree_name); in SMB2_tdis()
2200 spin_lock(&ses->chan_lock); in SMB2_tdis()
2201 if ((tcon->need_reconnect) || in SMB2_tdis()
2202 (CIFS_ALL_CHANS_NEED_RECONNECT(tcon->ses))) { in SMB2_tdis()
2203 spin_unlock(&ses->chan_lock); in SMB2_tdis()
2206 spin_unlock(&ses->chan_lock); in SMB2_tdis()
2208 invalidate_all_cached_dirs(tcon); in SMB2_tdis()
2210 rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, server, in SMB2_tdis()
2216 if (smb3_encryption_required(tcon)) in SMB2_tdis()
2232 cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE); in SMB2_tdis()
2233 trace_smb3_tdis_err(xid, tcon->tid, ses->Suid, rc); in SMB2_tdis()
2235 trace_smb3_tdis_done(xid, tcon->tid, ses->Suid); in SMB2_tdis()
2250 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_buf()
2252 buf->ccontext.DataLength = cpu_to_le32(16); in create_durable_buf()
2253 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_buf()
2255 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_buf()
2257 buf->Name[0] = 'D'; in create_durable_buf()
2258 buf->Name[1] = 'H'; in create_durable_buf()
2259 buf->Name[2] = 'n'; in create_durable_buf()
2260 buf->Name[3] = 'Q'; in create_durable_buf()
2273 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
2275 buf->ccontext.DataLength = cpu_to_le32(16); in create_reconnect_durable_buf()
2276 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
2278 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_buf()
2279 buf->Data.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_buf()
2280 buf->Data.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_buf()
2282 buf->Name[0] = 'D'; in create_reconnect_durable_buf()
2283 buf->Name[1] = 'H'; in create_reconnect_durable_buf()
2284 buf->Name[2] = 'n'; in create_reconnect_durable_buf()
2285 buf->Name[3] = 'C'; in create_reconnect_durable_buf()
2295 pdisk_id->DiskFileId, pdisk_id->VolumeId); in parse_query_id_ctxt()
2296 buf->IndexNumber = pdisk_id->DiskFileId; in parse_query_id_ctxt()
2304 u8 *beg = (u8 *)cc + le16_to_cpu(cc->DataOffset); in parse_posix_ctxt()
2305 u8 *end = beg + le32_to_cpu(cc->DataLength); in parse_posix_ctxt()
2310 posix->nlink = le32_to_cpu(*(__le32 *)(beg + 0)); in parse_posix_ctxt()
2311 posix->reparse_tag = le32_to_cpu(*(__le32 *)(beg + 4)); in parse_posix_ctxt()
2312 posix->mode = le32_to_cpu(*(__le32 *)(beg + 8)); in parse_posix_ctxt()
2320 memcpy(&posix->owner, sid, sid_len); in parse_posix_ctxt()
2328 memcpy(&posix->group, sid, sid_len); in parse_posix_ctxt()
2331 posix->nlink, posix->mode, posix->reparse_tag); in parse_posix_ctxt()
2341 struct smb2_create_rsp *rsp = rsp_iov->iov_base; in smb2_parse_contexts()
2355 off = le32_to_cpu(rsp->CreateContextsOffset); in smb2_parse_contexts()
2356 rem = le32_to_cpu(rsp->CreateContextsLength); in smb2_parse_contexts()
2357 if (check_add_overflow(off, rem, &len) || len > rsp_iov->iov_len) in smb2_parse_contexts()
2358 return -EINVAL; in smb2_parse_contexts()
2363 buf->IndexNumber = 0; in smb2_parse_contexts()
2366 doff = le16_to_cpu(cc->DataOffset); in smb2_parse_contexts()
2367 dlen = le32_to_cpu(cc->DataLength); in smb2_parse_contexts()
2369 return -EINVAL; in smb2_parse_contexts()
2371 noff = le16_to_cpu(cc->NameOffset); in smb2_parse_contexts()
2372 nlen = le16_to_cpu(cc->NameLength); in smb2_parse_contexts()
2374 return -EINVAL; in smb2_parse_contexts()
2380 *oplock = server->ops->parse_lease_buf(cc, epoch, in smb2_parse_contexts()
2399 off = le32_to_cpu(cc->Next); in smb2_parse_contexts()
2403 return -EINVAL; in smb2_parse_contexts()
2407 if (rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) in smb2_parse_contexts()
2408 *oplock = rsp->OplockLevel; in smb2_parse_contexts()
2421 iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock); in add_lease_context()
2423 return -ENOMEM; in add_lease_context()
2424 iov[num].iov_len = server->vals->create_lease_size; in add_lease_context()
2425 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; in add_lease_context()
2433 struct cifs_fid *pfid = oparms->fid; in create_durable_v2_buf()
2440 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2442 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2)); in create_durable_v2_buf()
2443 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2445 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_v2_buf()
2454 buf->dcontext.Timeout = cpu_to_le32(oparms->tcon->handle_timeout); in create_durable_v2_buf()
2455 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_durable_v2_buf()
2458 if (!oparms->replay) { in create_durable_v2_buf()
2459 generate_random_uuid(buf->dcontext.CreateGuid); in create_durable_v2_buf()
2460 memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16); in create_durable_v2_buf()
2462 memcpy(buf->dcontext.CreateGuid, pfid->create_guid, 16); in create_durable_v2_buf()
2465 buf->Name[0] = 'D'; in create_durable_v2_buf()
2466 buf->Name[1] = 'H'; in create_durable_v2_buf()
2467 buf->Name[2] = '2'; in create_durable_v2_buf()
2468 buf->Name[3] = 'Q'; in create_durable_v2_buf()
2482 buf->ccontext.DataOffset = in create_reconnect_durable_v2_buf()
2485 buf->ccontext.DataLength = in create_reconnect_durable_v2_buf()
2487 buf->ccontext.NameOffset = in create_reconnect_durable_v2_buf()
2490 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_v2_buf()
2492 buf->dcontext.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_v2_buf()
2493 buf->dcontext.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_v2_buf()
2494 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_reconnect_durable_v2_buf()
2495 memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16); in create_reconnect_durable_v2_buf()
2498 buf->Name[0] = 'D'; in create_reconnect_durable_v2_buf()
2499 buf->Name[1] = 'H'; in create_reconnect_durable_v2_buf()
2500 buf->Name[2] = '2'; in create_reconnect_durable_v2_buf()
2501 buf->Name[3] = 'C'; in create_reconnect_durable_v2_buf()
2513 return -ENOMEM; in add_durable_v2_context()
2526 oparms->reconnect = false; in add_durable_reconnect_v2_context()
2528 iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid); in add_durable_reconnect_v2_context()
2530 return -ENOMEM; in add_durable_reconnect_v2_context()
2543 if (oparms->reconnect) in add_durable_context()
2550 if (oparms->reconnect) { in add_durable_context()
2551 iov[num].iov_base = create_reconnect_durable_buf(oparms->fid); in add_durable_context()
2553 oparms->reconnect = false; in add_durable_context()
2557 return -ENOMEM; in add_durable_context()
2563 /* See MS-SMB2 2.2.13.2.7 */
2573 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_twarp_buf()
2575 buf->ccontext.DataLength = cpu_to_le32(8); in create_twarp_buf()
2576 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_twarp_buf()
2578 buf->ccontext.NameLength = cpu_to_le16(4); in create_twarp_buf()
2580 buf->Name[0] = 'T'; in create_twarp_buf()
2581 buf->Name[1] = 'W'; in create_twarp_buf()
2582 buf->Name[2] = 'r'; in create_twarp_buf()
2583 buf->Name[3] = 'p'; in create_twarp_buf()
2584 buf->Timestamp = cpu_to_le64(timewarp); in create_twarp_buf()
2588 /* See MS-SMB2 2.2.13.2.7 */
2596 return -ENOMEM; in add_twarp_context()
2602 /* See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx */
2607 /* Populate the user ownership fields S-1-5-88-1 */ in setup_owner_group_sids()
2608 sids->owner.Revision = 1; in setup_owner_group_sids()
2609 sids->owner.NumAuth = 3; in setup_owner_group_sids()
2610 sids->owner.Authority[5] = 5; in setup_owner_group_sids()
2611 sids->owner.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2612 sids->owner.SubAuthorities[1] = cpu_to_le32(1); in setup_owner_group_sids()
2613 sids->owner.SubAuthorities[2] = cpu_to_le32(current_fsuid().val); in setup_owner_group_sids()
2615 /* Populate the group ownership fields S-1-5-88-2 */ in setup_owner_group_sids()
2616 sids->group.Revision = 1; in setup_owner_group_sids()
2617 sids->group.NumAuth = 3; in setup_owner_group_sids()
2618 sids->group.Authority[5] = 5; in setup_owner_group_sids()
2619 sids->group.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2620 sids->group.SubAuthorities[1] = cpu_to_le32(2); in setup_owner_group_sids()
2621 sids->group.SubAuthorities[2] = cpu_to_le32(current_fsgid().val); in setup_owner_group_sids()
2623 …cifs_dbg(FYI, "owner S-1-5-88-1-%d, group S-1-5-88-2-%d\n", current_fsuid().val, current_fsgid().v… in setup_owner_group_sids()
2626 /* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */
2651 owner_offset = ptr - (__u8 *)&buf->sd; in create_sd_buf()
2652 buf->sd.OffsetOwner = cpu_to_le32(owner_offset); in create_sd_buf()
2654 buf->sd.OffsetGroup = cpu_to_le32(group_offset); in create_sd_buf()
2659 buf->sd.OffsetOwner = 0; in create_sd_buf()
2660 buf->sd.OffsetGroup = 0; in create_sd_buf()
2663 buf->ccontext.DataOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, sd)); in create_sd_buf()
2664 buf->ccontext.NameOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, Name)); in create_sd_buf()
2665 buf->ccontext.NameLength = cpu_to_le16(4); in create_sd_buf()
2667 buf->Name[0] = 'S'; in create_sd_buf()
2668 buf->Name[1] = 'e'; in create_sd_buf()
2669 buf->Name[2] = 'c'; in create_sd_buf()
2670 buf->Name[3] = 'D'; in create_sd_buf()
2671 buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */ in create_sd_buf()
2677 buf->sd.Control = cpu_to_le16(ACL_CONTROL_SR | ACL_CONTROL_DP); in create_sd_buf()
2680 buf->sd.OffsetDacl = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2705 acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */ in create_sd_buf()
2711 buf->ccontext.DataLength = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2712 *len = round_up((unsigned int)(ptr - (__u8 *)buf), 8); in create_sd_buf()
2725 return -ENOMEM; in add_sd_context()
2740 buf->ccontext.DataOffset = cpu_to_le16(0); in create_query_id_buf()
2741 buf->ccontext.DataLength = cpu_to_le32(0); in create_query_id_buf()
2742 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_query_id_buf()
2744 buf->ccontext.NameLength = cpu_to_le16(4); in create_query_id_buf()
2746 buf->Name[0] = 'Q'; in create_query_id_buf()
2747 buf->Name[1] = 'F'; in create_query_id_buf()
2748 buf->Name[2] = 'i'; in create_query_id_buf()
2749 buf->Name[3] = 'd'; in create_query_id_buf()
2753 /* See MS-SMB2 2.2.13.2.9 */
2761 return -ENOMEM; in add_query_id_context()
2770 struct kvec *iov = oparms->ea_cctx; in add_ea_context()
2772 if (iov && iov->iov_base && iov->iov_len) { in add_ea_context()
2791 return -EINVAL; in alloc_path_with_tree_prefix()
2794 treename_len -= 2; in alloc_path_with_tree_prefix()
2802 * final path needs to be 8-byte aligned as specified in in alloc_path_with_tree_prefix()
2803 * MS-SMB2 2.2.13 SMB2 CREATE Request. in alloc_path_with_tree_prefix()
2808 return -ENOMEM; in alloc_path_with_tree_prefix()
2825 umode_t mode, struct cifs_tcon *tcon, in smb311_posix_mkdir() argument
2832 struct cifs_ses *ses = tcon->ses; in smb311_posix_mkdir()
2860 return -ENOMEM; in smb311_posix_mkdir()
2863 rc = -EIO; in smb311_posix_mkdir()
2868 rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, in smb311_posix_mkdir()
2874 if (smb3_encryption_required(tcon)) in smb311_posix_mkdir()
2877 req->ImpersonationLevel = IL_IMPERSONATION; in smb311_posix_mkdir()
2878 req->DesiredAccess = cpu_to_le32(FILE_WRITE_ATTRIBUTES); in smb311_posix_mkdir()
2880 req->FileAttributes = cpu_to_le32(file_attributes); in smb311_posix_mkdir()
2881 req->ShareAccess = FILE_SHARE_ALL_LE; in smb311_posix_mkdir()
2882 req->CreateDisposition = cpu_to_le32(FILE_CREATE); in smb311_posix_mkdir()
2883 req->CreateOptions = cpu_to_le32(CREATE_NOT_FILE); in smb311_posix_mkdir()
2886 /* -1 since last byte is buf[0] which is sent below (path) */ in smb311_posix_mkdir()
2887 iov[0].iov_len = total_len - 1; in smb311_posix_mkdir()
2889 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in smb311_posix_mkdir()
2891 /* [MS-SMB2] 2.2.13 NameOffset: in smb311_posix_mkdir()
2899 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in smb311_posix_mkdir()
2902 req->hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in smb311_posix_mkdir()
2905 tcon->tree_name, utf16_path); in smb311_posix_mkdir()
2909 req->NameLength = cpu_to_le16(name_len * 2); in smb311_posix_mkdir()
2917 req->NameLength = cpu_to_le16(uni_path_len - 2); in smb311_posix_mkdir()
2922 rc = -ENOMEM; in smb311_posix_mkdir()
2936 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_NONE; in smb311_posix_mkdir()
2938 if (tcon->posix_extensions) { in smb311_posix_mkdir()
2943 req->CreateContextsOffset = cpu_to_le32( in smb311_posix_mkdir()
2946 pc_buf = iov[n_iov-1].iov_base; in smb311_posix_mkdir()
2955 trace_smb3_posix_mkdir_enter(xid, tcon->tid, ses->Suid, full_path, CREATE_NOT_FILE, in smb311_posix_mkdir()
2965 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); in smb311_posix_mkdir()
2966 trace_smb3_posix_mkdir_err(xid, tcon->tid, ses->Suid, in smb311_posix_mkdir()
2979 rc = -EIO; in smb311_posix_mkdir()
2984 trace_smb3_posix_mkdir_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid, in smb311_posix_mkdir()
2987 SMB2_close(xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId); in smb311_posix_mkdir()
3000 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb311_posix_mkdir()
3007 SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_open_init() argument
3017 struct kvec *iov = rqst->rq_iov; in SMB2_open_init()
3021 rc = smb2_plain_req_init(SMB2_CREATE, tcon, server, in SMB2_open_init()
3027 /* -1 since last byte is buf[0] which is sent below (path) */ in SMB2_open_init()
3028 iov[0].iov_len = total_len - 1; in SMB2_open_init()
3030 if (oparms->create_options & CREATE_OPTION_READONLY) in SMB2_open_init()
3032 if (oparms->create_options & CREATE_OPTION_SPECIAL) in SMB2_open_init()
3035 req->ImpersonationLevel = IL_IMPERSONATION; in SMB2_open_init()
3036 req->DesiredAccess = cpu_to_le32(oparms->desired_access); in SMB2_open_init()
3038 req->FileAttributes = cpu_to_le32(file_attributes); in SMB2_open_init()
3039 req->ShareAccess = FILE_SHARE_ALL_LE; in SMB2_open_init()
3041 req->CreateDisposition = cpu_to_le32(oparms->disposition); in SMB2_open_init()
3042 req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK); in SMB2_open_init()
3043 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in SMB2_open_init()
3045 /* [MS-SMB2] 2.2.13 NameOffset: in SMB2_open_init()
3053 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in SMB2_open_init()
3056 req->hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in SMB2_open_init()
3059 tcon->tree_name, path); in SMB2_open_init()
3062 req->NameLength = cpu_to_le16(name_len * 2); in SMB2_open_init()
3068 req->NameLength = cpu_to_le16(uni_path_len - 2); in SMB2_open_init()
3072 return -ENOMEM; in SMB2_open_init()
3082 if ((!server->oplocks) || (tcon->no_lease)) in SMB2_open_init()
3085 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) || in SMB2_open_init()
3087 req->RequestedOplockLevel = *oplock; in SMB2_open_init()
3088 else if (!(server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING) && in SMB2_open_init()
3089 (oparms->create_options & CREATE_NOT_FILE)) in SMB2_open_init()
3090 req->RequestedOplockLevel = *oplock; /* no srv lease support */ in SMB2_open_init()
3093 oparms->fid->lease_key, oplock); in SMB2_open_init()
3100 tcon->use_persistent); in SMB2_open_init()
3105 if (tcon->posix_extensions) { in SMB2_open_init()
3106 rc = add_posix_context(iov, &n_iov, oparms->mode); in SMB2_open_init()
3111 if (tcon->snapshot_time) { in SMB2_open_init()
3113 rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time); in SMB2_open_init()
3118 if ((oparms->disposition != FILE_OPEN) && (oparms->cifs_sb)) { in SMB2_open_init()
3122 if ((oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID) && in SMB2_open_init()
3123 (oparms->mode != ACL_NO_MODE)) in SMB2_open_init()
3127 oparms->mode = ACL_NO_MODE; in SMB2_open_init()
3130 if (oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) in SMB2_open_init()
3136 cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode); in SMB2_open_init()
3137 rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner); in SMB2_open_init()
3151 req->CreateContextsOffset = cpu_to_le32( in SMB2_open_init()
3154 req->CreateContextsLength = 0; in SMB2_open_init()
3156 for (unsigned int i = 2; i < (n_iov-1); i++) { in SMB2_open_init()
3158 size_t len = v->iov_len; in SMB2_open_init()
3160 (struct create_context *)v->iov_base; in SMB2_open_init()
3162 cctx->Next = cpu_to_le32(len); in SMB2_open_init()
3163 le32_add_cpu(&req->CreateContextsLength, len); in SMB2_open_init()
3165 le32_add_cpu(&req->CreateContextsLength, in SMB2_open_init()
3166 iov[n_iov-1].iov_len); in SMB2_open_init()
3169 rqst->rq_nvec = n_iov; in SMB2_open_init()
3181 if (rqst && rqst->rq_iov) { in SMB2_open_free()
3182 cifs_small_buf_release(rqst->rq_iov[0].iov_base); in SMB2_open_free()
3183 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_open_free()
3184 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_open_free()
3185 kfree(rqst->rq_iov[i].iov_base); in SMB2_open_free()
3197 struct cifs_tcon *tcon = oparms->tcon; in SMB2_open() local
3198 struct cifs_ses *ses = tcon->ses; in SMB2_open()
3211 oparms->replay = !!(retries); in SMB2_open()
3215 return -EIO; in SMB2_open()
3217 if (smb3_encryption_required(tcon)) in SMB2_open()
3225 rc = SMB2_open_init(tcon, server, in SMB2_open()
3230 trace_smb3_open_enter(xid, tcon->tid, tcon->ses->Suid, oparms->path, in SMB2_open()
3231 oparms->create_options, oparms->desired_access); in SMB2_open()
3242 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); in SMB2_open()
3249 trace_smb3_open_err(xid, tcon->tid, ses->Suid, in SMB2_open()
3250 oparms->create_options, oparms->desired_access, rc); in SMB2_open()
3251 if (rc == -EREMCHG) { in SMB2_open()
3253 tcon->tree_name); in SMB2_open()
3254 tcon->need_reconnect = true; in SMB2_open()
3260 trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid, in SMB2_open()
3261 oparms->create_options, oparms->desired_access); in SMB2_open()
3263 atomic_inc(&tcon->num_remote_opens); in SMB2_open()
3264 oparms->fid->persistent_fid = rsp->PersistentFileId; in SMB2_open()
3265 oparms->fid->volatile_fid = rsp->VolatileFileId; in SMB2_open()
3266 oparms->fid->access = oparms->desired_access; in SMB2_open()
3268 oparms->fid->mid = le64_to_cpu(rsp->hdr.MessageId); in SMB2_open()
3272 buf->CreationTime = rsp->CreationTime; in SMB2_open()
3273 buf->LastAccessTime = rsp->LastAccessTime; in SMB2_open()
3274 buf->LastWriteTime = rsp->LastWriteTime; in SMB2_open()
3275 buf->ChangeTime = rsp->ChangeTime; in SMB2_open()
3276 buf->AllocationSize = rsp->AllocationSize; in SMB2_open()
3277 buf->EndOfFile = rsp->EndofFile; in SMB2_open()
3278 buf->Attributes = rsp->FileAttributes; in SMB2_open()
3279 buf->NumberOfLinks = cpu_to_le32(1); in SMB2_open()
3280 buf->DeletePending = 0; in SMB2_open()
3284 rc = smb2_parse_contexts(server, &rsp_iov, &oparms->fid->epoch, in SMB2_open()
3285 oparms->fid->lease_key, oplock, buf, posix); in SMB2_open()
3291 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_open()
3298 SMB2_ioctl_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_ioctl_init() argument
3305 struct kvec *iov = rqst->rq_iov; in SMB2_ioctl_init()
3310 rc = smb2_ioctl_req_init(opcode, tcon, server, in SMB2_ioctl_init()
3318 if (WARN_ON_ONCE(smb3_encryption_required(tcon) && in SMB2_ioctl_init()
3319 (check_add_overflow(total_len - 1, in SMB2_ioctl_init()
3323 return -EIO; in SMB2_ioctl_init()
3332 return -ENOMEM; in SMB2_ioctl_init()
3336 req->CtlCode = cpu_to_le32(opcode); in SMB2_ioctl_init()
3337 req->PersistentFileId = persistent_fid; in SMB2_ioctl_init()
3338 req->VolatileFileId = volatile_fid; in SMB2_ioctl_init()
3350 req->InputCount = cpu_to_le32(indatalen); in SMB2_ioctl_init()
3352 req->InputOffset = in SMB2_ioctl_init()
3354 rqst->rq_nvec = 2; in SMB2_ioctl_init()
3355 iov[0].iov_len = total_len - 1; in SMB2_ioctl_init()
3359 rqst->rq_nvec = 1; in SMB2_ioctl_init()
3363 req->OutputOffset = 0; in SMB2_ioctl_init()
3364 req->OutputCount = 0; /* MBZ */ in SMB2_ioctl_init()
3381 req->MaxOutputResponse = cpu_to_le32(max_response_size); in SMB2_ioctl_init()
3382 req->hdr.CreditCharge = in SMB2_ioctl_init()
3386 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL); in SMB2_ioctl_init()
3388 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */ in SMB2_ioctl_init()
3390 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_ioctl_init()
3400 if (rqst && rqst->rq_iov) { in SMB2_ioctl_free()
3401 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_ioctl_free()
3402 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_ioctl_free()
3403 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_ioctl_free()
3404 kfree(rqst->rq_iov[i].iov_base); in SMB2_ioctl_free()
3413 SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_ioctl() argument
3429 if (!tcon) in SMB2_ioctl()
3430 return -EIO; in SMB2_ioctl()
3432 ses = tcon->ses; in SMB2_ioctl()
3434 return -EIO; in SMB2_ioctl()
3442 return -EIO; in SMB2_ioctl()
3453 if (smb3_encryption_required(tcon)) in SMB2_ioctl()
3461 rc = SMB2_ioctl_init(tcon, server, in SMB2_ioctl()
3476 trace_smb3_fsctl_err(xid, persistent_fid, tcon->tid, in SMB2_ioctl()
3477 ses->Suid, 0, opcode, rc); in SMB2_ioctl()
3479 if ((rc != 0) && (rc != -EINVAL) && (rc != -E2BIG)) { in SMB2_ioctl()
3480 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3482 } else if (rc == -EINVAL) { in SMB2_ioctl()
3485 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3488 } else if (rc == -E2BIG) { in SMB2_ioctl()
3490 cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE); in SMB2_ioctl()
3505 rc = -EIO; in SMB2_ioctl()
3509 *plen = le32_to_cpu(rsp->OutputCount); in SMB2_ioctl()
3517 rc = -EIO; in SMB2_ioctl()
3521 if (rsp_iov.iov_len - *plen < le32_to_cpu(rsp->OutputOffset)) { in SMB2_ioctl()
3523 le32_to_cpu(rsp->OutputOffset)); in SMB2_ioctl()
3525 rc = -EIO; in SMB2_ioctl()
3529 *out_data = kmemdup((char *)rsp + le32_to_cpu(rsp->OutputOffset), in SMB2_ioctl()
3532 rc = -ENOMEM; in SMB2_ioctl()
3541 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_ioctl()
3552 SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_compression() argument
3562 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_compression()
3574 SMB2_close_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_close_init() argument
3579 struct kvec *iov = rqst->rq_iov; in SMB2_close_init()
3583 rc = smb2_plain_req_init(SMB2_CLOSE, tcon, server, in SMB2_close_init()
3588 req->PersistentFileId = persistent_fid; in SMB2_close_init()
3589 req->VolatileFileId = volatile_fid; in SMB2_close_init()
3591 req->Flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB; in SMB2_close_init()
3593 req->Flags = 0; in SMB2_close_init()
3603 if (rqst && rqst->rq_iov) in SMB2_close_free()
3604 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_close_free()
3608 __SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, in __SMB2_close() argument
3614 struct cifs_ses *ses = tcon->ses; in __SMB2_close()
3633 return -EIO; in __SMB2_close()
3635 if (smb3_encryption_required(tcon)) in __SMB2_close()
3647 trace_smb3_close_enter(xid, persistent_fid, tcon->tid, ses->Suid); in __SMB2_close()
3648 rc = SMB2_close_init(tcon, server, in __SMB2_close()
3662 cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE); in __SMB2_close()
3663 trace_smb3_close_err(xid, persistent_fid, tcon->tid, ses->Suid, in __SMB2_close()
3667 trace_smb3_close_done(xid, persistent_fid, tcon->tid, in __SMB2_close()
3668 ses->Suid); in __SMB2_close()
3670 memcpy(&pbuf->network_open_info, in __SMB2_close()
3671 &rsp->network_open_info, in __SMB2_close()
3672 sizeof(pbuf->network_open_info)); in __SMB2_close()
3673 atomic_dec(&tcon->num_remote_opens); in __SMB2_close()
3684 tmp_rc = smb2_handle_cancelled_close(tcon, persistent_fid, in __SMB2_close()
3692 smb2_should_replay(tcon, &retries, &cur_sleep)) in __SMB2_close()
3699 SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_close() argument
3702 return __SMB2_close(xid, tcon, persistent_fid, volatile_fid, NULL); in SMB2_close()
3709 unsigned int smb_len = iov->iov_len; in smb2_validate_iov()
3710 char *end_of_smb = smb_len + (char *)iov->iov_base; in smb2_validate_iov()
3711 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_iov()
3718 return -EINVAL; in smb2_validate_iov()
3725 return -EINVAL; in smb2_validate_iov()
3730 return -EINVAL; in smb2_validate_iov()
3745 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_and_copy_iov()
3749 return -EINVAL; in smb2_validate_and_copy_iov()
3761 SMB2_query_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_query_info_init() argument
3768 struct kvec *iov = rqst->rq_iov; in SMB2_query_info_init()
3775 return -EINVAL; in SMB2_query_info_init()
3777 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, server, in SMB2_query_info_init()
3782 req->InfoType = info_type; in SMB2_query_info_init()
3783 req->FileInfoClass = info_class; in SMB2_query_info_init()
3784 req->PersistentFileId = persistent_fid; in SMB2_query_info_init()
3785 req->VolatileFileId = volatile_fid; in SMB2_query_info_init()
3786 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_query_info_init()
3788 req->OutputBufferLength = cpu_to_le32(output_len); in SMB2_query_info_init()
3790 req->InputBufferLength = cpu_to_le32(input_len); in SMB2_query_info_init()
3792 req->InputBufferOffset = cpu_to_le16(total_len - 1); in SMB2_query_info_init()
3793 memcpy(req->Buffer, input, input_len); in SMB2_query_info_init()
3805 if (rqst && rqst->rq_iov) in SMB2_query_info_free()
3806 cifs_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_info_free()
3810 query_info(const unsigned int xid, struct cifs_tcon *tcon, in query_info() argument
3821 struct cifs_ses *ses = tcon->ses; in query_info()
3830 return -EIO; in query_info()
3839 return -EIO; in query_info()
3841 if (smb3_encryption_required(tcon)) in query_info()
3849 rc = SMB2_query_info_init(tcon, server, in query_info()
3856 trace_smb3_query_info_enter(xid, persistent_fid, tcon->tid, in query_info()
3857 ses->Suid, info_class, (__u32)info_type); in query_info()
3867 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in query_info()
3868 trace_smb3_query_info_err(xid, persistent_fid, tcon->tid, in query_info()
3869 ses->Suid, info_class, (__u32)info_type, rc); in query_info()
3873 trace_smb3_query_info_done(xid, persistent_fid, tcon->tid, in query_info()
3874 ses->Suid, info_class, (__u32)info_type); in query_info()
3877 *dlen = le32_to_cpu(rsp->OutputBufferLength); in query_info()
3885 rc = -ENOMEM; in query_info()
3892 rc = smb2_validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset), in query_info()
3893 le32_to_cpu(rsp->OutputBufferLength), in query_info()
3906 smb2_should_replay(tcon, &retries, &cur_sleep)) in query_info()
3912 int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_info() argument
3915 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_query_info()
3925 SMB311_posix_query_info(const unsigned int xid, struct cifs_tcon *tcon,
3932 return query_info(xid, tcon, persistent_fid, volatile_fid,
3940 SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_acl() argument
3948 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_query_acl()
3954 SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_get_srv_num() argument
3957 return query_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_get_srv_num()
3966 * See MS-SMB2 2.2.35 and 2.2.36
3971 struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_notify_init() argument
3976 struct kvec *iov = rqst->rq_iov; in SMB2_notify_init()
3980 rc = smb2_plain_req_init(SMB2_CHANGE_NOTIFY, tcon, server, in SMB2_notify_init()
3985 req->PersistentFileId = persistent_fid; in SMB2_notify_init()
3986 req->VolatileFileId = volatile_fid; in SMB2_notify_init()
3987 /* See note 354 of MS-SMB2, 64K max */ in SMB2_notify_init()
3988 req->OutputBufferLength = in SMB2_notify_init()
3989 cpu_to_le32(SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE); in SMB2_notify_init()
3990 req->CompletionFilter = cpu_to_le32(completion_filter); in SMB2_notify_init()
3992 req->Flags = cpu_to_le16(SMB2_WATCH_TREE); in SMB2_notify_init()
3994 req->Flags = 0; in SMB2_notify_init()
4003 SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_change_notify() argument
4008 struct cifs_ses *ses = tcon->ses; in SMB2_change_notify()
4026 return -EIO; in SMB2_change_notify()
4028 if (smb3_encryption_required(tcon)) in SMB2_change_notify()
4039 rc = SMB2_notify_init(xid, &rqst, tcon, server, in SMB2_change_notify()
4045 trace_smb3_notify_enter(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
4055 cifs_stats_fail_inc(tcon, SMB2_CHANGE_NOTIFY_HE); in SMB2_change_notify()
4056 trace_smb3_notify_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
4059 trace_smb3_notify_done(xid, persistent_fid, tcon->tid, in SMB2_change_notify()
4060 ses->Suid, (u8)watch_tree, completion_filter); in SMB2_change_notify()
4068 smb2_validate_iov(le16_to_cpu(smb_rsp->OutputBufferOffset), in SMB2_change_notify()
4069 le32_to_cpu(smb_rsp->OutputBufferLength), &rsp_iov, in SMB2_change_notify()
4072 *out_data = kmemdup((char *)smb_rsp + le16_to_cpu(smb_rsp->OutputBufferOffset), in SMB2_change_notify()
4073 le32_to_cpu(smb_rsp->OutputBufferLength), GFP_KERNEL); in SMB2_change_notify()
4075 rc = -ENOMEM; in SMB2_change_notify()
4078 *plen = le32_to_cpu(smb_rsp->OutputBufferLength); in SMB2_change_notify()
4087 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_change_notify()
4096 * This is a no-op for now. We're not really interested in the reply, but
4097 * rather in the fact that the server sent one and that server->lstrp
4105 struct TCP_Server_Info *server = mid->callback_data; in smb2_echo_callback()
4106 struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; in smb2_echo_callback()
4109 if (mid->mid_state == MID_RESPONSE_RECEIVED in smb2_echo_callback()
4110 || mid->mid_state == MID_RESPONSE_MALFORMED) { in smb2_echo_callback()
4111 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_echo_callback()
4112 credits.instance = server->reconnect_instance; in smb2_echo_callback()
4125 struct cifs_tcon *tcon, *tcon2; in smb2_reconnect_server() local
4134 if (!server->srv_count) { in smb2_reconnect_server()
4138 server->srv_count++; in smb2_reconnect_server()
4141 /* If server is a channel, select the primary channel */ in smb2_reconnect_server()
4142 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in smb2_reconnect_server()
4144 /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ in smb2_reconnect_server()
4145 mutex_lock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4148 if (server->terminate) { in smb2_reconnect_server()
4150 mutex_unlock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4159 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { in smb2_reconnect_server()
4160 spin_lock(&ses->ses_lock); in smb2_reconnect_server()
4161 if (ses->ses_status == SES_EXITING) { in smb2_reconnect_server()
4162 spin_unlock(&ses->ses_lock); in smb2_reconnect_server()
4165 spin_unlock(&ses->ses_lock); in smb2_reconnect_server()
4169 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in smb2_reconnect_server()
4170 if (tcon->need_reconnect || tcon->need_reopen_files) { in smb2_reconnect_server()
4171 tcon->tc_count++; in smb2_reconnect_server()
4172 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in smb2_reconnect_server()
4174 list_add_tail(&tcon->rlist, &tmp_list); in smb2_reconnect_server()
4182 if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) { in smb2_reconnect_server()
4183 list_add_tail(&ses->tcon_ipc->rlist, &tmp_list); in smb2_reconnect_server()
4188 * handle the case where channel needs to reconnect in smb2_reconnect_server()
4189 * binding session, but tcon is healthy (some other channel in smb2_reconnect_server()
4192 spin_lock(&ses->chan_lock); in smb2_reconnect_server()
4194 list_add_tail(&ses->rlist, &tmp_ses_list); in smb2_reconnect_server()
4198 spin_unlock(&ses->chan_lock); in smb2_reconnect_server()
4202 list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { in smb2_reconnect_server()
4203 rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); in smb2_reconnect_server()
4205 cifs_reopen_persistent_handles(tcon); in smb2_reconnect_server()
4208 list_del_init(&tcon->rlist); in smb2_reconnect_server()
4209 if (tcon->ipc) in smb2_reconnect_server()
4210 cifs_put_smb_ses(tcon->ses); in smb2_reconnect_server()
4212 cifs_put_tcon(tcon, netfs_trace_tcon_ref_put_reconnect_server); in smb2_reconnect_server()
4218 /* allocate a dummy tcon struct used for reconnect */ in smb2_reconnect_server()
4219 tcon = tcon_info_alloc(false, netfs_trace_tcon_ref_new_reconnect_server); in smb2_reconnect_server()
4220 if (!tcon) { in smb2_reconnect_server()
4223 list_del_init(&ses->rlist); in smb2_reconnect_server()
4229 tcon->status = TID_GOOD; in smb2_reconnect_server()
4230 tcon->retry = false; in smb2_reconnect_server()
4231 tcon->need_reconnect = false; in smb2_reconnect_server()
4235 tcon->ses = ses; in smb2_reconnect_server()
4236 rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon, server, true); in smb2_reconnect_server()
4239 list_del_init(&ses->rlist); in smb2_reconnect_server()
4242 tconInfoFree(tcon, netfs_trace_tcon_ref_free_reconnect_server); in smb2_reconnect_server()
4247 queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); in smb2_reconnect_server()
4248 mutex_unlock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4264 cifs_dbg(FYI, "In echo request for conn_id %lld\n", server->conn_id); in SMB2_echo()
4266 spin_lock(&server->srv_lock); in SMB2_echo()
4267 if (server->ops->need_neg && in SMB2_echo()
4268 server->ops->need_neg(server)) { in SMB2_echo()
4269 spin_unlock(&server->srv_lock); in SMB2_echo()
4271 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in SMB2_echo()
4274 spin_unlock(&server->srv_lock); in SMB2_echo()
4281 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_echo()
4298 if (rqst && rqst->rq_iov) in SMB2_flush_free()
4299 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_flush_free()
4304 struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_flush_init() argument
4308 struct kvec *iov = rqst->rq_iov; in SMB2_flush_init()
4312 rc = smb2_plain_req_init(SMB2_FLUSH, tcon, server, in SMB2_flush_init()
4317 req->PersistentFileId = persistent_fid; in SMB2_flush_init()
4318 req->VolatileFileId = volatile_fid; in SMB2_flush_init()
4327 SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_flush() argument
4330 struct cifs_ses *ses = tcon->ses; in SMB2_flush()
4346 if (!ses || !(ses->server)) in SMB2_flush()
4347 return -EIO; in SMB2_flush()
4349 if (smb3_encryption_required(tcon)) in SMB2_flush()
4357 rc = SMB2_flush_init(xid, &rqst, tcon, server, in SMB2_flush()
4362 trace_smb3_flush_enter(xid, persistent_fid, tcon->tid, ses->Suid); in SMB2_flush()
4371 cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE); in SMB2_flush()
4372 trace_smb3_flush_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_flush()
4375 trace_smb3_flush_done(xid, persistent_fid, tcon->tid, in SMB2_flush()
4376 ses->Suid); in SMB2_flush()
4383 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_flush()
4392 struct TCP_Server_Info *server = io_parms->server; in smb3_use_rdma_offload()
4393 struct cifs_tcon *tcon = io_parms->tcon; in smb3_use_rdma_offload() local
4396 if (!server || !tcon) in smb3_use_rdma_offload()
4400 if (!server->rdma || !server->smbd_conn) in smb3_use_rdma_offload()
4404 if (server->sign) in smb3_use_rdma_offload()
4408 if (smb3_encryption_required(tcon)) in smb3_use_rdma_offload()
4412 if (io_parms->length < server->smbd_conn->rdma_readwrite_threshold) in smb3_use_rdma_offload()
4428 int rc = -EACCES; in smb2_new_read_req()
4431 struct TCP_Server_Info *server = io_parms->server; in smb2_new_read_req()
4433 rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, server, in smb2_new_read_req()
4439 return -ECONNABORTED; in smb2_new_read_req()
4441 shdr = &req->hdr; in smb2_new_read_req()
4442 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in smb2_new_read_req()
4444 req->PersistentFileId = io_parms->persistent_fid; in smb2_new_read_req()
4445 req->VolatileFileId = io_parms->volatile_fid; in smb2_new_read_req()
4446 req->ReadChannelInfoOffset = 0; /* reserved */ in smb2_new_read_req()
4447 req->ReadChannelInfoLength = 0; /* reserved */ in smb2_new_read_req()
4448 req->Channel = 0; /* reserved */ in smb2_new_read_req()
4449 req->MinimumCount = 0; in smb2_new_read_req()
4450 req->Length = cpu_to_le32(io_parms->length); in smb2_new_read_req()
4451 req->Offset = cpu_to_le64(io_parms->offset); in smb2_new_read_req()
4453 trace_smb3_read_enter(rdata ? rdata->rreq->debug_id : 0, in smb2_new_read_req()
4454 rdata ? rdata->subreq.debug_index : 0, in smb2_new_read_req()
4455 rdata ? rdata->xid : 0, in smb2_new_read_req()
4456 io_parms->persistent_fid, in smb2_new_read_req()
4457 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in smb2_new_read_req()
4458 io_parms->offset, io_parms->length); in smb2_new_read_req()
4466 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_new_read_req()
4468 rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter, in smb2_new_read_req()
4470 if (!rdata->mr) in smb2_new_read_req()
4471 return -EAGAIN; in smb2_new_read_req()
4473 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_new_read_req()
4475 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_new_read_req()
4476 req->ReadChannelInfoOffset = in smb2_new_read_req()
4478 req->ReadChannelInfoLength = in smb2_new_read_req()
4480 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_new_read_req()
4481 v1->offset = cpu_to_le64(rdata->mr->mr->iova); in smb2_new_read_req()
4482 v1->token = cpu_to_le32(rdata->mr->mr->rkey); in smb2_new_read_req()
4483 v1->length = cpu_to_le32(rdata->mr->mr->length); in smb2_new_read_req()
4485 *total_len += sizeof(*v1) - 1; in smb2_new_read_req()
4490 /* next 8-byte aligned request */ in smb2_new_read_req()
4492 shdr->NextCommand = cpu_to_le32(*total_len); in smb2_new_read_req()
4494 shdr->NextCommand = 0; in smb2_new_read_req()
4496 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_new_read_req()
4501 shdr->SessionId = cpu_to_le64(0xFFFFFFFFFFFFFFFF); in smb2_new_read_req()
4502 shdr->Id.SyncId.TreeId = cpu_to_le32(0xFFFFFFFF); in smb2_new_read_req()
4503 req->PersistentFileId = (u64)-1; in smb2_new_read_req()
4504 req->VolatileFileId = (u64)-1; in smb2_new_read_req()
4507 if (remaining_bytes > io_parms->length) in smb2_new_read_req()
4508 req->RemainingBytes = cpu_to_le32(remaining_bytes); in smb2_new_read_req()
4510 req->RemainingBytes = 0; in smb2_new_read_req()
4521 netfs_read_subreq_terminated(&rdata->subreq, rdata->result, false); in smb2_readv_worker()
4527 struct cifs_io_subrequest *rdata = mid->callback_data; in smb2_readv_callback()
4528 struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode); in smb2_readv_callback()
4529 struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_readv_callback() local
4530 struct TCP_Server_Info *server = rdata->server; in smb2_readv_callback()
4532 (struct smb2_hdr *)rdata->iov[0].iov_base; in smb2_readv_callback()
4536 .rreq_debug_id = rdata->rreq->debug_id, in smb2_readv_callback()
4537 .rreq_debug_index = rdata->subreq.debug_index, in smb2_readv_callback()
4539 struct smb_rqst rqst = { .rq_iov = &rdata->iov[1], .rq_nvec = 1 }; in smb2_readv_callback()
4540 unsigned int rreq_debug_id = rdata->rreq->debug_id; in smb2_readv_callback()
4541 unsigned int subreq_debug_index = rdata->subreq.debug_index; in smb2_readv_callback()
4543 if (rdata->got_bytes) { in smb2_readv_callback()
4544 rqst.rq_iter = rdata->subreq.io_iter; in smb2_readv_callback()
4547 WARN_ONCE(rdata->server != mid->server, in smb2_readv_callback()
4549 rdata->server, mid->server); in smb2_readv_callback()
4552 __func__, mid->mid, mid->mid_state, rdata->result, in smb2_readv_callback()
4553 rdata->got_bytes, rdata->subreq.len - rdata->subreq.transferred); in smb2_readv_callback()
4555 switch (mid->mid_state) { in smb2_readv_callback()
4557 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
4558 credits.instance = server->reconnect_instance; in smb2_readv_callback()
4560 if (server->sign && !mid->decrypted) { in smb2_readv_callback()
4563 iov_iter_truncate(&rqst.rq_iter, rdata->got_bytes); in smb2_readv_callback()
4570 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
4571 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
4575 __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); in smb2_readv_callback()
4576 rdata->result = -EAGAIN; in smb2_readv_callback()
4577 if (server->sign && rdata->got_bytes) in smb2_readv_callback()
4579 rdata->got_bytes = 0; in smb2_readv_callback()
4581 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
4582 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
4585 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
4586 credits.instance = server->reconnect_instance; in smb2_readv_callback()
4589 rdata->result = -EIO; in smb2_readv_callback()
4597 if (rdata->mr) { in smb2_readv_callback()
4598 smbd_deregister_mr(rdata->mr); in smb2_readv_callback()
4599 rdata->mr = NULL; in smb2_readv_callback()
4602 if (rdata->result && rdata->result != -ENODATA) { in smb2_readv_callback()
4603 cifs_stats_fail_inc(tcon, SMB2_READ_HE); in smb2_readv_callback()
4604 trace_smb3_read_err(rdata->rreq->debug_id, in smb2_readv_callback()
4605 rdata->subreq.debug_index, in smb2_readv_callback()
4606 rdata->xid, in smb2_readv_callback()
4607 rdata->req->cfile->fid.persistent_fid, in smb2_readv_callback()
4608 tcon->tid, tcon->ses->Suid, in smb2_readv_callback()
4609 rdata->subreq.start + rdata->subreq.transferred, in smb2_readv_callback()
4610 rdata->subreq.len - rdata->subreq.transferred, in smb2_readv_callback()
4611 rdata->result); in smb2_readv_callback()
4613 trace_smb3_read_done(rdata->rreq->debug_id, in smb2_readv_callback()
4614 rdata->subreq.debug_index, in smb2_readv_callback()
4615 rdata->xid, in smb2_readv_callback()
4616 rdata->req->cfile->fid.persistent_fid, in smb2_readv_callback()
4617 tcon->tid, tcon->ses->Suid, in smb2_readv_callback()
4618 rdata->subreq.start + rdata->subreq.transferred, in smb2_readv_callback()
4619 rdata->got_bytes); in smb2_readv_callback()
4621 if (rdata->result == -ENODATA) { in smb2_readv_callback()
4622 __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); in smb2_readv_callback()
4623 rdata->result = 0; in smb2_readv_callback()
4625 size_t trans = rdata->subreq.transferred + rdata->got_bytes; in smb2_readv_callback()
4626 if (trans < rdata->subreq.len && in smb2_readv_callback()
4627 rdata->subreq.start + trans == ictx->remote_i_size) { in smb2_readv_callback()
4628 __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); in smb2_readv_callback()
4629 rdata->result = 0; in smb2_readv_callback()
4632 trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, in smb2_readv_callback()
4633 server->credits, server->in_flight, in smb2_readv_callback()
4635 rdata->credits.value = 0; in smb2_readv_callback()
4636 rdata->subreq.transferred += rdata->got_bytes; in smb2_readv_callback()
4637 trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_progress); in smb2_readv_callback()
4638 INIT_WORK(&rdata->subreq.work, smb2_readv_worker); in smb2_readv_callback()
4639 queue_work(cifsiod_wq, &rdata->subreq.work); in smb2_readv_callback()
4642 server->credits, server->in_flight, in smb2_readv_callback()
4647 /* smb2_async_readv - send an async read, and set up mid to handle result */
4653 struct netfs_io_subrequest *subreq = &rdata->subreq; in smb2_async_readv()
4656 struct smb_rqst rqst = { .rq_iov = rdata->iov, in smb2_async_readv()
4659 struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_async_readv() local
4664 __func__, subreq->start, subreq->len); in smb2_async_readv()
4666 if (!rdata->server) in smb2_async_readv()
4667 rdata->server = cifs_pick_channel(tcon->ses); in smb2_async_readv()
4669 io_parms.tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_async_readv()
4670 io_parms.server = server = rdata->server; in smb2_async_readv()
4671 io_parms.offset = subreq->start + subreq->transferred; in smb2_async_readv()
4672 io_parms.length = subreq->len - subreq->transferred; in smb2_async_readv()
4673 io_parms.persistent_fid = rdata->req->cfile->fid.persistent_fid; in smb2_async_readv()
4674 io_parms.volatile_fid = rdata->req->cfile->fid.volatile_fid; in smb2_async_readv()
4675 io_parms.pid = rdata->req->pid; in smb2_async_readv()
4682 if (smb3_encryption_required(io_parms.tcon)) in smb2_async_readv()
4685 rdata->iov[0].iov_base = buf; in smb2_async_readv()
4686 rdata->iov[0].iov_len = total_len; in smb2_async_readv()
4687 rdata->got_bytes = 0; in smb2_async_readv()
4688 rdata->result = 0; in smb2_async_readv()
4692 if (rdata->credits.value > 0) { in smb2_async_readv()
4693 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(io_parms.length, in smb2_async_readv()
4695 credit_request = le16_to_cpu(shdr->CreditCharge) + 8; in smb2_async_readv()
4696 if (server->credits >= server->max_credits) in smb2_async_readv()
4697 shdr->CreditRequest = cpu_to_le16(0); in smb2_async_readv()
4699 shdr->CreditRequest = cpu_to_le16( in smb2_async_readv()
4700 min_t(int, server->max_credits - in smb2_async_readv()
4701 server->credits, credit_request)); in smb2_async_readv()
4713 &rdata->credits); in smb2_async_readv()
4715 cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); in smb2_async_readv()
4716 trace_smb3_read_err(rdata->rreq->debug_id, in smb2_async_readv()
4717 subreq->debug_index, in smb2_async_readv()
4718 rdata->xid, io_parms.persistent_fid, in smb2_async_readv()
4719 io_parms.tcon->tid, in smb2_async_readv()
4720 io_parms.tcon->ses->Suid, in smb2_async_readv()
4722 subreq->len - subreq->transferred, rc); in smb2_async_readv()
4742 struct cifs_ses *ses = io_parms->tcon->ses; in SMB2_read()
4744 if (!io_parms->server) in SMB2_read()
4745 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_read()
4752 if (smb3_encryption_required(io_parms->tcon)) in SMB2_read()
4762 rc = cifs_send_recv(xid, ses, io_parms->server, in SMB2_read()
4767 if (rc != -ENODATA) { in SMB2_read()
4768 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); in SMB2_read()
4771 req->PersistentFileId, in SMB2_read()
4772 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4773 io_parms->offset, io_parms->length, in SMB2_read()
4777 req->PersistentFileId, io_parms->tcon->tid, in SMB2_read()
4778 ses->Suid, io_parms->offset, 0); in SMB2_read()
4781 return rc == -ENODATA ? 0 : rc; in SMB2_read()
4784 req->PersistentFileId, in SMB2_read()
4785 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4786 io_parms->offset, io_parms->length); in SMB2_read()
4790 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_read()
4792 (*nbytes > io_parms->length)) { in SMB2_read()
4794 *nbytes, io_parms->length); in SMB2_read()
4795 rc = -EIO; in SMB2_read()
4800 memcpy(*buf, (char *)rsp + rsp->DataOffset, *nbytes); in SMB2_read()
4819 struct cifs_io_subrequest *wdata = mid->callback_data; in smb2_writev_callback()
4820 struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink); in smb2_writev_callback() local
4821 struct TCP_Server_Info *server = wdata->server; in smb2_writev_callback()
4822 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; in smb2_writev_callback()
4826 .rreq_debug_id = wdata->rreq->debug_id, in smb2_writev_callback()
4827 .rreq_debug_index = wdata->subreq.debug_index, in smb2_writev_callback()
4829 unsigned int rreq_debug_id = wdata->rreq->debug_id; in smb2_writev_callback()
4830 unsigned int subreq_debug_index = wdata->subreq.debug_index; in smb2_writev_callback()
4834 WARN_ONCE(wdata->server != mid->server, in smb2_writev_callback()
4836 wdata->server, mid->server); in smb2_writev_callback()
4838 switch (mid->mid_state) { in smb2_writev_callback()
4840 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_writev_callback()
4841 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4846 written = le32_to_cpu(rsp->DataLength); in smb2_writev_callback()
4853 if (written > wdata->subreq.len) in smb2_writev_callback()
4856 if (written < wdata->subreq.len) in smb2_writev_callback()
4857 wdata->result = -ENOSPC; in smb2_writev_callback()
4859 wdata->subreq.len = written; in smb2_writev_callback()
4863 result = -EAGAIN; in smb2_writev_callback()
4866 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_writev_callback()
4867 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4870 result = -EIO; in smb2_writev_callback()
4881 if (wdata->mr) { in smb2_writev_callback()
4882 smbd_deregister_mr(wdata->mr); in smb2_writev_callback()
4883 wdata->mr = NULL; in smb2_writev_callback()
4887 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); in smb2_writev_callback()
4888 trace_smb3_write_err(wdata->rreq->debug_id, in smb2_writev_callback()
4889 wdata->subreq.debug_index, in smb2_writev_callback()
4890 wdata->xid, in smb2_writev_callback()
4891 wdata->req->cfile->fid.persistent_fid, in smb2_writev_callback()
4892 tcon->tid, tcon->ses->Suid, wdata->subreq.start, in smb2_writev_callback()
4893 wdata->subreq.len, wdata->result); in smb2_writev_callback()
4894 if (wdata->result == -ENOSPC) in smb2_writev_callback()
4896 tcon->tree_name); in smb2_writev_callback()
4898 trace_smb3_write_done(wdata->rreq->debug_id, in smb2_writev_callback()
4899 wdata->subreq.debug_index, in smb2_writev_callback()
4900 wdata->xid, in smb2_writev_callback()
4901 wdata->req->cfile->fid.persistent_fid, in smb2_writev_callback()
4902 tcon->tid, tcon->ses->Suid, in smb2_writev_callback()
4903 wdata->subreq.start, wdata->subreq.len); in smb2_writev_callback()
4905 trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, wdata->credits.value, in smb2_writev_callback()
4906 server->credits, server->in_flight, in smb2_writev_callback()
4908 wdata->credits.value = 0; in smb2_writev_callback()
4909 trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_progress); in smb2_writev_callback()
4913 server->credits, server->in_flight, in smb2_writev_callback()
4918 /* smb2_async_writev - send an async write, and set up mid to handle result */
4922 int rc = -EACCES, flags = 0; in smb2_async_writev()
4925 struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink); in smb2_async_writev() local
4926 struct TCP_Server_Info *server = wdata->server; in smb2_async_writev()
4929 unsigned int total_len, xid = wdata->xid; in smb2_async_writev()
4939 .tcon = tcon, in smb2_async_writev()
4941 .offset = wdata->subreq.start, in smb2_async_writev()
4942 .length = wdata->subreq.len, in smb2_async_writev()
4943 .persistent_fid = wdata->req->cfile->fid.persistent_fid, in smb2_async_writev()
4944 .volatile_fid = wdata->req->cfile->fid.volatile_fid, in smb2_async_writev()
4945 .pid = wdata->req->pid, in smb2_async_writev()
4949 rc = smb2_plain_req_init(SMB2_WRITE, tcon, server, in smb2_async_writev()
4955 rqst.rq_iter = wdata->subreq.io_iter; in smb2_async_writev()
4957 rqst.rq_iov[0].iov_len = total_len - 1; in smb2_async_writev()
4961 if (smb3_encryption_required(tcon)) in smb2_async_writev()
4965 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in smb2_async_writev()
4967 req->PersistentFileId = io_parms->persistent_fid; in smb2_async_writev()
4968 req->VolatileFileId = io_parms->volatile_fid; in smb2_async_writev()
4969 req->WriteChannelInfoOffset = 0; in smb2_async_writev()
4970 req->WriteChannelInfoLength = 0; in smb2_async_writev()
4971 req->Channel = SMB2_CHANNEL_NONE; in smb2_async_writev()
4972 req->Length = cpu_to_le32(io_parms->length); in smb2_async_writev()
4973 req->Offset = cpu_to_le64(io_parms->offset); in smb2_async_writev()
4974 req->DataOffset = cpu_to_le16( in smb2_async_writev()
4976 req->RemainingBytes = 0; in smb2_async_writev()
4978 trace_smb3_write_enter(wdata->rreq->debug_id, in smb2_async_writev()
4979 wdata->subreq.debug_index, in smb2_async_writev()
4980 wdata->xid, in smb2_async_writev()
4981 io_parms->persistent_fid, in smb2_async_writev()
4982 io_parms->tcon->tid, in smb2_async_writev()
4983 io_parms->tcon->ses->Suid, in smb2_async_writev()
4984 io_parms->offset, in smb2_async_writev()
4985 io_parms->length); in smb2_async_writev()
4994 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_async_writev()
4996 wdata->mr = smbd_register_mr(server->smbd_conn, &wdata->subreq.io_iter, in smb2_async_writev()
4998 if (!wdata->mr) { in smb2_async_writev()
4999 rc = -EAGAIN; in smb2_async_writev()
5003 req->RemainingBytes = req->Length; in smb2_async_writev()
5004 req->Length = 0; in smb2_async_writev()
5005 req->DataOffset = 0; in smb2_async_writev()
5006 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_async_writev()
5008 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_async_writev()
5009 req->WriteChannelInfoOffset = in smb2_async_writev()
5011 req->WriteChannelInfoLength = in smb2_async_writev()
5013 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_async_writev()
5014 v1->offset = cpu_to_le64(wdata->mr->mr->iova); in smb2_async_writev()
5015 v1->token = cpu_to_le32(wdata->mr->mr->rkey); in smb2_async_writev()
5016 v1->length = cpu_to_le32(wdata->mr->mr->length); in smb2_async_writev()
5021 * We keep wdata->subreq.io_iter, in smb2_async_writev()
5028 if (test_bit(NETFS_SREQ_RETRYING, &wdata->subreq.flags)) in smb2_async_writev()
5032 io_parms->offset, io_parms->length, iov_iter_count(&wdata->subreq.io_iter)); in smb2_async_writev()
5034 if (wdata->credits.value > 0) { in smb2_async_writev()
5035 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->subreq.len, in smb2_async_writev()
5037 credit_request = le16_to_cpu(shdr->CreditCharge) + 8; in smb2_async_writev()
5038 if (server->credits >= server->max_credits) in smb2_async_writev()
5039 shdr->CreditRequest = cpu_to_le16(0); in smb2_async_writev()
5041 shdr->CreditRequest = cpu_to_le16( in smb2_async_writev()
5042 min_t(int, server->max_credits - in smb2_async_writev()
5043 server->credits, credit_request)); in smb2_async_writev()
5053 if (((flags & CIFS_TRANSFORM_REQ) != CIFS_TRANSFORM_REQ) && should_compress(tcon, &rqst)) in smb2_async_writev()
5057 wdata, flags, &wdata->credits); in smb2_async_writev()
5060 trace_smb3_write_err(wdata->rreq->debug_id, in smb2_async_writev()
5061 wdata->subreq.debug_index, in smb2_async_writev()
5063 io_parms->persistent_fid, in smb2_async_writev()
5064 io_parms->tcon->tid, in smb2_async_writev()
5065 io_parms->tcon->ses->Suid, in smb2_async_writev()
5066 io_parms->offset, in smb2_async_writev()
5067 io_parms->length, in smb2_async_writev()
5069 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); in smb2_async_writev()
5076 trace_smb3_rw_credits(wdata->rreq->debug_id, in smb2_async_writev()
5077 wdata->subreq.debug_index, in smb2_async_writev()
5078 wdata->credits.value, in smb2_async_writev()
5079 server->credits, server->in_flight, in smb2_async_writev()
5080 -(int)wdata->credits.value, in smb2_async_writev()
5082 add_credits_and_wake_if(wdata->server, &wdata->credits, 0); in smb2_async_writev()
5112 if (!io_parms->server) in SMB2_write()
5113 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_write()
5114 server = io_parms->server; in SMB2_write()
5116 return -ECONNABORTED; in SMB2_write()
5121 rc = smb2_plain_req_init(SMB2_WRITE, io_parms->tcon, server, in SMB2_write()
5126 if (smb3_encryption_required(io_parms->tcon)) in SMB2_write()
5129 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in SMB2_write()
5131 req->PersistentFileId = io_parms->persistent_fid; in SMB2_write()
5132 req->VolatileFileId = io_parms->volatile_fid; in SMB2_write()
5133 req->WriteChannelInfoOffset = 0; in SMB2_write()
5134 req->WriteChannelInfoLength = 0; in SMB2_write()
5135 req->Channel = 0; in SMB2_write()
5136 req->Length = cpu_to_le32(io_parms->length); in SMB2_write()
5137 req->Offset = cpu_to_le64(io_parms->offset); in SMB2_write()
5138 req->DataOffset = cpu_to_le16( in SMB2_write()
5140 req->RemainingBytes = 0; in SMB2_write()
5142 trace_smb3_write_enter(0, 0, xid, io_parms->persistent_fid, in SMB2_write()
5143 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in SMB2_write()
5144 io_parms->offset, io_parms->length); in SMB2_write()
5148 iov[0].iov_len = total_len - 1; in SMB2_write()
5157 rc = cifs_send_recv(xid, io_parms->tcon->ses, server, in SMB2_write()
5164 req->PersistentFileId, in SMB2_write()
5165 io_parms->tcon->tid, in SMB2_write()
5166 io_parms->tcon->ses->Suid, in SMB2_write()
5167 io_parms->offset, io_parms->length, rc); in SMB2_write()
5168 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); in SMB2_write()
5171 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_write()
5173 req->PersistentFileId, in SMB2_write()
5174 io_parms->tcon->tid, in SMB2_write()
5175 io_parms->tcon->ses->Suid, in SMB2_write()
5176 io_parms->offset, *nbytes); in SMB2_write()
5183 smb2_should_replay(io_parms->tcon, &retries, &cur_sleep)) in SMB2_write()
5195 return -1; in posix_info_sid_size()
5199 return -1; in posix_info_sid_size()
5203 return -1; in posix_info_sid_size()
5223 end = beg + le32_to_cpu(p->NextEntryOffset); in posix_info_parse()
5231 return -1; in posix_info_parse()
5238 return -1; in posix_info_parse()
5245 return -1; in posix_info_parse()
5250 return -1; in posix_info_parse()
5253 return -1; in posix_info_parse()
5259 return -1; in posix_info_parse()
5263 out->base = beg; in posix_info_parse()
5264 out->size = total_len; in posix_info_parse()
5265 out->name_len = name_len; in posix_info_parse()
5266 out->name = name; in posix_info_parse()
5267 memcpy(&out->owner, owner_sid, owner_len); in posix_info_parse()
5268 memcpy(&out->group, group_sid, group_len); in posix_info_parse()
5278 return -1; in posix_info_extra_size()
5279 return len - sizeof(struct smb2_posix_info); in posix_info_extra_size()
5311 len = le32_to_cpu(dir_info->FileNameLength); in num_entries()
5325 next_offset = le32_to_cpu(dir_info->NextEntryOffset); in num_entries()
5337 struct cifs_tcon *tcon, in SMB2_query_directory_init() argument
5346 unsigned int output_size = CIFSMaxBufSize - in SMB2_query_directory_init()
5347 MAX_SMB2_CREATE_RESPONSE_SIZE - in SMB2_query_directory_init()
5350 struct kvec *iov = rqst->rq_iov; in SMB2_query_directory_init()
5353 rc = smb2_plain_req_init(SMB2_QUERY_DIRECTORY, tcon, server, in SMB2_query_directory_init()
5360 req->FileInformationClass = FILE_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5363 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5366 req->FileInformationClass = SMB_FIND_FILE_POSIX_INFO; in SMB2_query_directory_init()
5369 req->FileInformationClass = FILE_FULL_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5374 return -EINVAL; in SMB2_query_directory_init()
5377 req->FileIndex = cpu_to_le32(index); in SMB2_query_directory_init()
5378 req->PersistentFileId = persistent_fid; in SMB2_query_directory_init()
5379 req->VolatileFileId = volatile_fid; in SMB2_query_directory_init()
5382 bufptr = req->Buffer; in SMB2_query_directory_init()
5385 req->FileNameOffset = in SMB2_query_directory_init()
5387 req->FileNameLength = cpu_to_le16(len); in SMB2_query_directory_init()
5392 output_size = min_t(unsigned int, output_size, server->maxBuf); in SMB2_query_directory_init()
5394 req->OutputBufferLength = cpu_to_le32(output_size); in SMB2_query_directory_init()
5398 iov[0].iov_len = total_len - 1; in SMB2_query_directory_init()
5400 iov[1].iov_base = (char *)(req->Buffer); in SMB2_query_directory_init()
5403 trace_smb3_query_dir_enter(xid, persistent_fid, tcon->tid, in SMB2_query_directory_init()
5404 tcon->ses->Suid, index, output_size); in SMB2_query_directory_init()
5411 if (rqst && rqst->rq_iov) { in SMB2_query_directory_free()
5412 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_directory_free()
5417 smb2_parse_query_directory(struct cifs_tcon *tcon, in smb2_parse_query_directory() argument
5427 rsp = (struct smb2_query_directory_rsp *)rsp_iov->iov_base; in smb2_parse_query_directory()
5429 switch (srch_inf->info_level) { in smb2_parse_query_directory()
5445 srch_inf->info_level); in smb2_parse_query_directory()
5446 return -EINVAL; in smb2_parse_query_directory()
5449 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_parse_query_directory()
5450 le32_to_cpu(rsp->OutputBufferLength), rsp_iov, in smb2_parse_query_directory()
5457 srch_inf->unicode = true; in smb2_parse_query_directory()
5459 if (srch_inf->ntwrk_buf_start) { in smb2_parse_query_directory()
5460 if (srch_inf->smallBuf) in smb2_parse_query_directory()
5461 cifs_small_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
5463 cifs_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
5465 srch_inf->ntwrk_buf_start = (char *)rsp; in smb2_parse_query_directory()
5466 srch_inf->srch_entries_start = srch_inf->last_entry = in smb2_parse_query_directory()
5467 (char *)rsp + le16_to_cpu(rsp->OutputBufferOffset); in smb2_parse_query_directory()
5468 end_of_smb = rsp_iov->iov_len + (char *)rsp; in smb2_parse_query_directory()
5470 srch_inf->entries_in_buffer = num_entries( in smb2_parse_query_directory()
5471 srch_inf->info_level, in smb2_parse_query_directory()
5472 srch_inf->srch_entries_start, in smb2_parse_query_directory()
5474 &srch_inf->last_entry, in smb2_parse_query_directory()
5477 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; in smb2_parse_query_directory()
5479 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, in smb2_parse_query_directory()
5480 srch_inf->srch_entries_start, srch_inf->last_entry); in smb2_parse_query_directory()
5482 srch_inf->smallBuf = false; in smb2_parse_query_directory()
5484 srch_inf->smallBuf = true; in smb2_parse_query_directory()
5492 SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_query_directory() argument
5502 struct cifs_ses *ses = tcon->ses; in SMB2_query_directory()
5512 if (!ses || !(ses->server)) in SMB2_query_directory()
5513 return -EIO; in SMB2_query_directory()
5515 if (smb3_encryption_required(tcon)) in SMB2_query_directory()
5523 rc = SMB2_query_directory_init(xid, tcon, server, in SMB2_query_directory()
5526 srch_inf->info_level); in SMB2_query_directory()
5538 if (rc == -ENODATA && in SMB2_query_directory()
5539 rsp->hdr.Status == STATUS_NO_MORE_FILES) { in SMB2_query_directory()
5541 tcon->tid, tcon->ses->Suid, index, 0); in SMB2_query_directory()
5542 srch_inf->endOfSearch = true; in SMB2_query_directory()
5545 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5546 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
5547 cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); in SMB2_query_directory()
5552 rc = smb2_parse_query_directory(tcon, &rsp_iov, resp_buftype, in SMB2_query_directory()
5555 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5556 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
5561 trace_smb3_query_dir_done(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5562 tcon->ses->Suid, index, srch_inf->entries_in_buffer); in SMB2_query_directory()
5569 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_query_directory()
5576 SMB2_set_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, in SMB2_set_info_init() argument
5583 struct kvec *iov = rqst->rq_iov; in SMB2_set_info_init()
5587 rc = smb2_plain_req_init(SMB2_SET_INFO, tcon, server, in SMB2_set_info_init()
5592 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(pid); in SMB2_set_info_init()
5593 req->InfoType = info_type; in SMB2_set_info_init()
5594 req->FileInfoClass = info_class; in SMB2_set_info_init()
5595 req->PersistentFileId = persistent_fid; in SMB2_set_info_init()
5596 req->VolatileFileId = volatile_fid; in SMB2_set_info_init()
5597 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_set_info_init()
5599 req->BufferOffset = cpu_to_le16(sizeof(struct smb2_set_info_req)); in SMB2_set_info_init()
5600 req->BufferLength = cpu_to_le32(*size); in SMB2_set_info_init()
5602 memcpy(req->Buffer, *data, *size); in SMB2_set_info_init()
5607 iov[0].iov_len = total_len - 1; in SMB2_set_info_init()
5609 for (i = 1; i < rqst->rq_nvec; i++) { in SMB2_set_info_init()
5610 le32_add_cpu(&req->BufferLength, size[i]); in SMB2_set_info_init()
5621 if (rqst && rqst->rq_iov) in SMB2_set_info_free()
5622 cifs_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_set_info_free()
5626 send_set_info(const unsigned int xid, struct cifs_tcon *tcon, in send_set_info() argument
5637 struct cifs_ses *ses = tcon->ses; in send_set_info()
5648 return -EIO; in send_set_info()
5651 return -EINVAL; in send_set_info()
5653 if (smb3_encryption_required(tcon)) in send_set_info()
5658 return -ENOMEM; in send_set_info()
5664 rc = SMB2_set_info_init(tcon, server, in send_set_info()
5683 cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE); in send_set_info()
5684 trace_smb3_set_info_err(xid, persistent_fid, tcon->tid, in send_set_info()
5685 ses->Suid, info_class, (__u32)info_type, rc); in send_set_info()
5692 smb2_should_replay(tcon, &retries, &cur_sleep)) in send_set_info()
5699 SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, in SMB2_set_eof() argument
5711 trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, new_eof); in SMB2_set_eof()
5713 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_eof()
5719 SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_acl() argument
5723 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_acl()
5724 current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag, in SMB2_set_acl()
5729 SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_set_ea() argument
5733 return send_set_info(xid, tcon, persistent_fid, volatile_fid, in SMB2_set_ea()
5734 current->tgid, FILE_FULL_EA_INFORMATION, SMB2_O_INFO_FILE, in SMB2_set_ea()
5739 SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_oplock_break() argument
5746 struct cifs_ses *ses = tcon->ses; in SMB2_oplock_break()
5761 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, server, in SMB2_oplock_break()
5766 if (smb3_encryption_required(tcon)) in SMB2_oplock_break()
5769 req->VolatileFid = volatile_fid; in SMB2_oplock_break()
5770 req->PersistentFid = persistent_fid; in SMB2_oplock_break()
5771 req->OplockLevel = oplock_level; in SMB2_oplock_break()
5772 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_oplock_break()
5790 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); in SMB2_oplock_break()
5795 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_oplock_break()
5805 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * in smb2_copy_fs_info_to_kstatfs()
5806 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); in smb2_copy_fs_info_to_kstatfs()
5807 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5808 kst->f_bfree = kst->f_bavail = in smb2_copy_fs_info_to_kstatfs()
5809 le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5817 kst->f_bsize = le32_to_cpu(response_data->BlockSize); in copy_posix_fs_info_to_kstatfs()
5818 kst->f_blocks = le64_to_cpu(response_data->TotalBlocks); in copy_posix_fs_info_to_kstatfs()
5819 kst->f_bfree = le64_to_cpu(response_data->BlocksAvail); in copy_posix_fs_info_to_kstatfs()
5820 if (response_data->UserBlocksAvail == cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5821 kst->f_bavail = kst->f_bfree; in copy_posix_fs_info_to_kstatfs()
5823 kst->f_bavail = le64_to_cpu(response_data->UserBlocksAvail); in copy_posix_fs_info_to_kstatfs()
5824 if (response_data->TotalFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5825 kst->f_files = le64_to_cpu(response_data->TotalFileNodes); in copy_posix_fs_info_to_kstatfs()
5826 if (response_data->FreeFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5827 kst->f_ffree = le64_to_cpu(response_data->FreeFileNodes); in copy_posix_fs_info_to_kstatfs()
5833 build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, in build_qfs_info_req() argument
5844 if ((tcon->ses == NULL) || server == NULL) in build_qfs_info_req()
5845 return -EIO; in build_qfs_info_req()
5847 rc = smb2_plain_req_init(SMB2_QUERY_INFO, tcon, server, in build_qfs_info_req()
5852 req->InfoType = SMB2_O_INFO_FILESYSTEM; in build_qfs_info_req()
5853 req->FileInfoClass = level; in build_qfs_info_req()
5854 req->PersistentFileId = persistent_fid; in build_qfs_info_req()
5855 req->VolatileFileId = volatile_fid; in build_qfs_info_req()
5857 req->InputBufferOffset = in build_qfs_info_req()
5859 req->OutputBufferLength = cpu_to_le32( in build_qfs_info_req()
5862 iov->iov_base = (char *)req; in build_qfs_info_req()
5863 iov->iov_len = total_len; in build_qfs_info_req()
5869 cifs_buf_release(iov->iov_base); in free_qfs_info_req()
5873 SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB311_posix_qfs_info() argument
5882 struct cifs_ses *ses = tcon->ses; in SMB311_posix_qfs_info()
5893 rc = build_qfs_info_req(&iov, tcon, server, in SMB311_posix_qfs_info()
5900 if (smb3_encryption_required(tcon)) in SMB311_posix_qfs_info()
5914 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB311_posix_qfs_info()
5920 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB311_posix_qfs_info()
5921 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB311_posix_qfs_info()
5922 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB311_posix_qfs_info()
5931 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB311_posix_qfs_info()
5938 SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_QFS_info() argument
5947 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_info()
5958 rc = build_qfs_info_req(&iov, tcon, server, in SMB2_QFS_info()
5965 if (smb3_encryption_required(tcon)) in SMB2_QFS_info()
5979 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB2_QFS_info()
5985 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB2_QFS_info()
5986 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB2_QFS_info()
5987 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB2_QFS_info()
5996 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_QFS_info()
6003 SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_QFS_attr() argument
6012 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_attr()
6037 return -EINVAL; in SMB2_QFS_attr()
6040 rc = build_qfs_info_req(&iov, tcon, server, in SMB2_QFS_attr()
6046 if (smb3_encryption_required(tcon)) in SMB2_QFS_attr()
6060 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); in SMB2_QFS_attr()
6065 rsp_len = le32_to_cpu(rsp->OutputBufferLength); in SMB2_QFS_attr()
6066 offset = le16_to_cpu(rsp->OutputBufferOffset); in SMB2_QFS_attr()
6072 memcpy(&tcon->fsAttrInfo, offset in SMB2_QFS_attr()
6076 memcpy(&tcon->fsDevInfo, offset in SMB2_QFS_attr()
6081 tcon->ss_flags = le32_to_cpu(ss_info->Flags); in SMB2_QFS_attr()
6082 tcon->perf_sector_size = in SMB2_QFS_attr()
6083 le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf); in SMB2_QFS_attr()
6087 tcon->vol_serial_number = vol_info->VolumeSerialNumber; in SMB2_QFS_attr()
6088 tcon->vol_create_time = vol_info->VolumeCreationTime; in SMB2_QFS_attr()
6095 smb2_should_replay(tcon, &retries, &cur_sleep)) in SMB2_QFS_attr()
6102 smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, in smb2_lockv() argument
6121 server = cifs_pick_channel(tcon->ses); in smb2_lockv()
6125 rc = smb2_plain_req_init(SMB2_LOCK, tcon, server, in smb2_lockv()
6130 if (smb3_encryption_required(tcon)) in smb2_lockv()
6133 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(pid); in smb2_lockv()
6134 req->LockCount = cpu_to_le16(num_lock); in smb2_lockv()
6136 req->PersistentFileId = persist_fid; in smb2_lockv()
6137 req->VolatileFileId = volatile_fid; in smb2_lockv()
6142 iov[0].iov_len = total_len - sizeof(struct smb2_lock_element); in smb2_lockv()
6146 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); in smb2_lockv()
6155 rc = cifs_send_recv(xid, tcon->ses, server, in smb2_lockv()
6161 cifs_stats_fail_inc(tcon, SMB2_LOCK_HE); in smb2_lockv()
6162 trace_smb3_lock_err(xid, persist_fid, tcon->tid, in smb2_lockv()
6163 tcon->ses->Suid, rc); in smb2_lockv()
6167 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb2_lockv()
6174 SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_lock() argument
6187 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock); in SMB2_lock()
6191 SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_lease_break() argument
6197 struct cifs_ses *ses = tcon->ses; in SMB2_lease_break()
6205 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in SMB2_lease_break()
6208 rc = smb2_plain_req_init(SMB2_OPLOCK_BREAK, tcon, server, in SMB2_lease_break()
6213 if (smb3_encryption_required(tcon)) in SMB2_lease_break()
6216 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_lease_break()
6217 req->StructureSize = cpu_to_le16(36); in SMB2_lease_break()
6220 memcpy(req->LeaseKey, lease_key, 16); in SMB2_lease_break()
6221 req->LeaseState = lease_state; in SMB2_lease_break()
6239 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); in SMB2_lease_break()
6240 trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
6241 ses->Suid, *please_key_low, *please_key_high, rc); in SMB2_lease_break()
6244 trace_smb3_lease_done(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
6245 ses->Suid, *please_key_low, *please_key_high); in SMB2_lease_break()