Lines Matching +full:touch +full:- +full:hold +full:- +full:ms
1 // SPDX-License-Identifier: LGPL-2.1
13 /* SMB2 PDU handling routines here - except for leftovers (eg session setup) */
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()
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()
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()
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()
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()
201 pserver = server->primary_server; in cifs_chan_skip_or_disable()
204 return -EHOSTDOWN; in cifs_chan_skip_or_disable()
226 * for those three - in the calling routine. in smb2_reconnect()
234 spin_lock(&tcon->tc_lock); in smb2_reconnect()
235 if (tcon->status == TID_EXITING) { in smb2_reconnect()
240 spin_unlock(&tcon->tc_lock); in smb2_reconnect()
243 return -ENODEV; in smb2_reconnect()
246 spin_unlock(&tcon->tc_lock); in smb2_reconnect()
248 ses = tcon->ses; in smb2_reconnect()
250 return -EIO; in smb2_reconnect()
251 spin_lock(&ses->ses_lock); in smb2_reconnect()
252 if (ses->ses_status == SES_EXITING) { in smb2_reconnect()
253 spin_unlock(&ses->ses_lock); in smb2_reconnect()
254 return -EIO; in smb2_reconnect()
256 spin_unlock(&ses->ses_lock); in smb2_reconnect()
257 if (!ses->server || !server) in smb2_reconnect()
258 return -EIO; in smb2_reconnect()
260 spin_lock(&server->srv_lock); in smb2_reconnect()
261 if (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
274 spin_unlock(&server->srv_lock); in smb2_reconnect()
275 return -EAGAIN; in smb2_reconnect()
280 if (server->terminate) { in smb2_reconnect()
281 spin_unlock(&server->srv_lock); in smb2_reconnect()
282 return -EHOSTDOWN; in smb2_reconnect()
284 spin_unlock(&server->srv_lock); in smb2_reconnect()
287 rc = cifs_wait_for_server_reconnect(server, tcon->retry); in smb2_reconnect()
291 spin_lock(&ses->chan_lock); in smb2_reconnect()
292 if (!cifs_chan_needs_reconnect(ses, server) && !tcon->need_reconnect) { in smb2_reconnect()
293 spin_unlock(&ses->chan_lock); in smb2_reconnect()
296 spin_unlock(&ses->chan_lock); in smb2_reconnect()
298 tcon->ses->chans_need_reconnect, in smb2_reconnect()
299 tcon->need_reconnect); in smb2_reconnect()
301 mutex_lock(&ses->session_mutex); in smb2_reconnect()
307 spin_lock(&server->srv_lock); in smb2_reconnect()
308 if (server->tcpStatus == CifsExiting) { in smb2_reconnect()
309 spin_unlock(&server->srv_lock); in smb2_reconnect()
310 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
311 rc = -EHOSTDOWN; in smb2_reconnect()
320 if (server->tcpStatus == CifsNeedReconnect) { in smb2_reconnect()
321 spin_unlock(&server->srv_lock); in smb2_reconnect()
322 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
324 if (tcon->retry) in smb2_reconnect()
327 rc = -EHOSTDOWN; in smb2_reconnect()
330 spin_unlock(&server->srv_lock); in smb2_reconnect()
336 spin_lock(&ses->ses_lock); in smb2_reconnect()
337 spin_lock(&ses->chan_lock); in smb2_reconnect()
339 ses->ses_status == SES_GOOD) { in smb2_reconnect()
340 spin_unlock(&ses->chan_lock); in smb2_reconnect()
341 spin_unlock(&ses->ses_lock); in smb2_reconnect()
343 if (tcon->need_reconnect) in smb2_reconnect()
346 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
349 spin_unlock(&ses->chan_lock); in smb2_reconnect()
350 spin_unlock(&ses->ses_lock); in smb2_reconnect()
358 if (ses->chan_count > 1 && in smb2_reconnect()
359 !(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { in smb2_reconnect()
363 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
368 rc = cifs_setup_session(0, ses, server, ses->local_nls); in smb2_reconnect()
369 if ((rc == -EACCES) || (rc == -EKEYEXPIRED) || (rc == -EKEYREVOKED)) { in smb2_reconnect()
376 if (ses->password2) in smb2_reconnect()
377 swap(ses->password2, ses->password); in smb2_reconnect()
380 if ((rc == -EACCES) && !tcon->retry) { in smb2_reconnect()
381 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
382 rc = -EHOSTDOWN; in smb2_reconnect()
385 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
389 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
394 if (!tcon->need_reconnect) { in smb2_reconnect()
395 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
399 if (tcon->use_persistent) in smb2_reconnect()
400 tcon->need_reopen_files = true; in smb2_reconnect()
407 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
412 spin_lock(&ses->ses_lock); in smb2_reconnect()
413 if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) { in smb2_reconnect()
414 spin_unlock(&ses->ses_lock); in smb2_reconnect()
415 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
418 ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS; in smb2_reconnect()
419 spin_unlock(&ses->ses_lock); in smb2_reconnect()
422 (server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL) && in smb2_reconnect()
423 server->ops->query_server_interfaces) { in smb2_reconnect()
424 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
430 rc = server->ops->query_server_interfaces(xid, tcon, false); in smb2_reconnect()
433 if (rc == -EOPNOTSUPP && ses->chan_count > 1) { in smb2_reconnect()
448 if (ses->chan_max > ses->chan_count && in smb2_reconnect()
449 ses->iface_count && in smb2_reconnect()
451 if (ses->chan_count == 1) { in smb2_reconnect()
453 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in smb2_reconnect()
460 mutex_unlock(&ses->session_mutex); in smb2_reconnect()
464 spin_lock(&ses->ses_lock); in smb2_reconnect()
465 ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS; in smb2_reconnect()
466 spin_unlock(&ses->ses_lock); in smb2_reconnect()
469 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in smb2_reconnect()
491 rc = -EAGAIN; in smb2_reconnect()
513 smb2_hdr_assemble(&spdu->hdr, smb2_command, tcon, server); in fill_small_buf()
514 spdu->StructureSize2 = cpu_to_le16(parmsize); in fill_small_buf()
540 return -ENOMEM; in __smb2_plain_req_init()
549 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]); in __smb2_plain_req_init()
550 cifs_stats_inc(&tcon->num_smbs_sent); in __smb2_plain_req_init()
583 /* For explanation of negotiate contexts see MS-SMB2 section 2.2.3.1 */
588 pneg_ctxt->ContextType = SMB2_PREAUTH_INTEGRITY_CAPABILITIES; in build_preauth_ctxt()
589 pneg_ctxt->DataLength = cpu_to_le16(38); in build_preauth_ctxt()
590 pneg_ctxt->HashAlgorithmCount = cpu_to_le16(1); in build_preauth_ctxt()
591 pneg_ctxt->SaltLength = cpu_to_le16(SMB311_SALT_SIZE); in build_preauth_ctxt()
592 get_random_bytes(pneg_ctxt->Salt, SMB311_SALT_SIZE); in build_preauth_ctxt()
593 pneg_ctxt->HashAlgorithms = SMB2_PREAUTH_INTEGRITY_SHA512; in build_preauth_ctxt()
599 pneg_ctxt->ContextType = SMB2_COMPRESSION_CAPABILITIES; in build_compression_ctxt()
600 pneg_ctxt->DataLength = in build_compression_ctxt()
602 - sizeof(struct smb2_neg_context)); in build_compression_ctxt()
603 pneg_ctxt->CompressionAlgorithmCount = cpu_to_le16(3); in build_compression_ctxt()
604 pneg_ctxt->CompressionAlgorithms[0] = SMB3_COMPRESS_LZ77; in build_compression_ctxt()
605 pneg_ctxt->CompressionAlgorithms[1] = SMB3_COMPRESS_LZ77_HUFF; in build_compression_ctxt()
606 pneg_ctxt->CompressionAlgorithms[2] = SMB3_COMPRESS_LZNT1; in build_compression_ctxt()
615 pneg_ctxt->ContextType = SMB2_SIGNING_CAPABILITIES; in build_signing_ctxt()
619 pneg_ctxt->DataLength = cpu_to_le16(ALIGN(sizeof(struct smb2_signing_capabilities) - in build_signing_ctxt()
622 pneg_ctxt->SigningAlgorithmCount = cpu_to_le16(num_algs); in build_signing_ctxt()
623 pneg_ctxt->SigningAlgorithms[0] = cpu_to_le16(SIGNING_ALG_AES_CMAC); in build_signing_ctxt()
634 pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES; in build_encrypt_ctxt()
636 pneg_ctxt->DataLength = cpu_to_le16(4); /* Cipher Count + 1 cipher */ in build_encrypt_ctxt()
637 pneg_ctxt->CipherCount = cpu_to_le16(1); in build_encrypt_ctxt()
638 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
640 pneg_ctxt->DataLength = cpu_to_le16(8); /* Cipher Count + 3 ciphers */ in build_encrypt_ctxt()
641 pneg_ctxt->CipherCount = cpu_to_le16(3); in build_encrypt_ctxt()
642 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
643 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES256_GCM; in build_encrypt_ctxt()
644 pneg_ctxt->Ciphers[2] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
646 pneg_ctxt->DataLength = cpu_to_le16(6); /* Cipher Count + 2 ciphers */ in build_encrypt_ctxt()
647 pneg_ctxt->CipherCount = cpu_to_le16(2); in build_encrypt_ctxt()
648 pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; in build_encrypt_ctxt()
649 pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM; in build_encrypt_ctxt()
658 pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID; in build_netname_ctxt()
661 pneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp)); in build_netname_ctxt()
663 return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8); in build_netname_ctxt()
669 pneg_ctxt->ContextType = SMB2_POSIX_EXTENSIONS_AVAILABLE; in build_posix_ctxt()
670 pneg_ctxt->DataLength = cpu_to_le16(POSIX_CTXT_DATA_LEN); in build_posix_ctxt()
672 pneg_ctxt->Name[0] = 0x93; in build_posix_ctxt()
673 pneg_ctxt->Name[1] = 0xAD; in build_posix_ctxt()
674 pneg_ctxt->Name[2] = 0x25; in build_posix_ctxt()
675 pneg_ctxt->Name[3] = 0x50; in build_posix_ctxt()
676 pneg_ctxt->Name[4] = 0x9C; in build_posix_ctxt()
677 pneg_ctxt->Name[5] = 0xB4; in build_posix_ctxt()
678 pneg_ctxt->Name[6] = 0x11; in build_posix_ctxt()
679 pneg_ctxt->Name[7] = 0xE7; in build_posix_ctxt()
680 pneg_ctxt->Name[8] = 0xB4; in build_posix_ctxt()
681 pneg_ctxt->Name[9] = 0x23; in build_posix_ctxt()
682 pneg_ctxt->Name[10] = 0x83; in build_posix_ctxt()
683 pneg_ctxt->Name[11] = 0xDE; in build_posix_ctxt()
684 pneg_ctxt->Name[12] = 0x96; in build_posix_ctxt()
685 pneg_ctxt->Name[13] = 0x8B; in build_posix_ctxt()
686 pneg_ctxt->Name[14] = 0xCD; in build_posix_ctxt()
687 pneg_ctxt->Name[15] = 0x7C; in build_posix_ctxt()
712 req->NegotiateContextOffset = cpu_to_le32(*total_len); in assemble_neg_contexts()
728 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in assemble_neg_contexts()
730 hostname = pserver->hostname; in assemble_neg_contexts()
746 if (server->compression.requested) { in assemble_neg_contexts()
764 req->NegotiateContextCount = cpu_to_le16(neg_context_count); in assemble_neg_contexts()
768 /* If invalid preauth context warn but use what we requested, SHA-512 */
771 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_preauth_context()
780 } else if (len < MIN_PREAUTH_CTXT_DATA_LEN + le16_to_cpu(ctxt->SaltLength)) { in decode_preauth_context()
784 if (le16_to_cpu(ctxt->HashAlgorithmCount) != 1) in decode_preauth_context()
786 if (ctxt->HashAlgorithms != SMB2_PREAUTH_INTEGRITY_SHA512) in decode_preauth_context()
793 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_compress_ctx()
796 server->compression.enabled = false; in decode_compress_ctx()
808 if (le16_to_cpu(ctxt->CompressionAlgorithmCount) != 1) { in decode_compress_ctx()
813 alg = ctxt->CompressionAlgorithms[0]; in decode_compress_ctx()
821 server->compression.alg = alg; in decode_compress_ctx()
822 server->compression.enabled = true; in decode_compress_ctx()
828 unsigned int len = le16_to_cpu(ctxt->DataLength); in decode_encrypt_ctx()
838 return -EINVAL; in decode_encrypt_ctx()
841 if (le16_to_cpu(ctxt->CipherCount) != 1) { in decode_encrypt_ctx()
843 return -EINVAL; in decode_encrypt_ctx()
845 cifs_dbg(FYI, "SMB311 cipher type:%d\n", le16_to_cpu(ctxt->Ciphers[0])); in decode_encrypt_ctx()
847 if (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM) { in decode_encrypt_ctx()
849 return -EOPNOTSUPP; in decode_encrypt_ctx()
851 } else if (ctxt->Ciphers[0] == 0) { in decode_encrypt_ctx()
861 server->cipher_type = 0; in decode_encrypt_ctx()
862 server->capabilities &= ~SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
865 } else if ((ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_CCM) && in decode_encrypt_ctx()
866 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_GCM) && in decode_encrypt_ctx()
867 (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM)) { in decode_encrypt_ctx()
870 return -EINVAL; in decode_encrypt_ctx()
872 server->cipher_type = ctxt->Ciphers[0]; in decode_encrypt_ctx()
873 server->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION; in decode_encrypt_ctx()
880 unsigned int len = le16_to_cpu(pctxt->DataLength); in decode_signing_ctx()
891 if (le16_to_cpu(pctxt->SigningAlgorithmCount) != 1) { in decode_signing_ctx()
895 if (le16_to_cpu(pctxt->SigningAlgorithms[0]) > 2) { in decode_signing_ctx()
900 server->signing_negotiated = true; in decode_signing_ctx()
901 server->signing_algorithm = le16_to_cpu(pctxt->SigningAlgorithms[0]); in decode_signing_ctx()
903 server->signing_algorithm); in decode_signing_ctx()
912 unsigned int offset = le32_to_cpu(rsp->NegotiateContextOffset); in smb311_decode_neg_context()
913 unsigned int ctxt_cnt = le16_to_cpu(rsp->NegotiateContextCount); in smb311_decode_neg_context()
920 return -EINVAL; in smb311_decode_neg_context()
923 len_of_ctxts = len_of_smb - offset; in smb311_decode_neg_context()
933 + le16_to_cpu(pctx->DataLength); in smb311_decode_neg_context()
936 * Subsequent negotiate contexts MUST appear at the first 8-byte in smb311_decode_neg_context()
944 if (pctx->ContextType == SMB2_PREAUTH_INTEGRITY_CAPABILITIES) in smb311_decode_neg_context()
947 else if (pctx->ContextType == SMB2_ENCRYPTION_CAPABILITIES) in smb311_decode_neg_context()
950 else if (pctx->ContextType == SMB2_COMPRESSION_CAPABILITIES) in smb311_decode_neg_context()
953 else if (pctx->ContextType == SMB2_POSIX_EXTENSIONS_AVAILABLE) in smb311_decode_neg_context()
954 server->posix_ext_supported = true; in smb311_decode_neg_context()
955 else if (pctx->ContextType == SMB2_SIGNING_CAPABILITIES) in smb311_decode_neg_context()
960 le16_to_cpu(pctx->ContextType)); in smb311_decode_neg_context()
965 len_of_ctxts -= clen; in smb311_decode_neg_context()
980 buf->ccontext.DataOffset = in create_posix_buf()
982 buf->ccontext.DataLength = cpu_to_le32(4); in create_posix_buf()
983 buf->ccontext.NameOffset = in create_posix_buf()
985 buf->ccontext.NameLength = cpu_to_le16(16); in create_posix_buf()
988 buf->Name[0] = 0x93; in create_posix_buf()
989 buf->Name[1] = 0xAD; in create_posix_buf()
990 buf->Name[2] = 0x25; in create_posix_buf()
991 buf->Name[3] = 0x50; in create_posix_buf()
992 buf->Name[4] = 0x9C; in create_posix_buf()
993 buf->Name[5] = 0xB4; in create_posix_buf()
994 buf->Name[6] = 0x11; in create_posix_buf()
995 buf->Name[7] = 0xE7; in create_posix_buf()
996 buf->Name[8] = 0xB4; in create_posix_buf()
997 buf->Name[9] = 0x23; in create_posix_buf()
998 buf->Name[10] = 0x83; in create_posix_buf()
999 buf->Name[11] = 0xDE; in create_posix_buf()
1000 buf->Name[12] = 0x96; in create_posix_buf()
1001 buf->Name[13] = 0x8B; in create_posix_buf()
1002 buf->Name[14] = 0xCD; in create_posix_buf()
1003 buf->Name[15] = 0x7C; in create_posix_buf()
1004 buf->Mode = cpu_to_le32(mode); in create_posix_buf()
1018 return -ENOMEM; in add_posix_context()
1061 return -EIO; in SMB2_negotiate()
1069 req->hdr.SessionId = 0; in SMB2_negotiate()
1071 memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
1072 memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE); in SMB2_negotiate()
1074 if (strcmp(server->vals->version_string, in SMB2_negotiate()
1076 req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
1077 req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
1078 req->Dialects[2] = cpu_to_le16(SMB311_PROT_ID); in SMB2_negotiate()
1079 req->DialectCount = cpu_to_le16(3); in SMB2_negotiate()
1081 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
1083 req->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in SMB2_negotiate()
1084 req->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in SMB2_negotiate()
1085 req->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in SMB2_negotiate()
1086 req->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in SMB2_negotiate()
1087 req->DialectCount = cpu_to_le16(4); in SMB2_negotiate()
1091 req->Dialects[0] = cpu_to_le16(server->vals->protocol_id); in SMB2_negotiate()
1092 req->DialectCount = cpu_to_le16(1); in SMB2_negotiate()
1097 if (ses->sign) in SMB2_negotiate()
1098 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_REQUIRED); in SMB2_negotiate()
1100 req->SecurityMode = cpu_to_le16(SMB2_NEGOTIATE_SIGNING_ENABLED); in SMB2_negotiate()
1102 req->SecurityMode = 0; in SMB2_negotiate()
1104 req->Capabilities = cpu_to_le32(server->vals->req_capabilities); in SMB2_negotiate()
1105 if (ses->chan_max > 1) in SMB2_negotiate()
1106 req->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in SMB2_negotiate()
1109 if (server->vals->protocol_id == SMB20_PROT_ID) in SMB2_negotiate()
1110 memset(req->ClientGUID, 0, SMB2_CLIENT_GUID_SIZE); in SMB2_negotiate()
1112 memcpy(req->ClientGUID, server->client_guid, in SMB2_negotiate()
1114 if ((server->vals->protocol_id == SMB311_PROT_ID) || in SMB2_negotiate()
1115 (strcmp(server->vals->version_string, in SMB2_negotiate()
1117 (strcmp(server->vals->version_string, in SMB2_negotiate()
1134 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_negotiate()
1136 if (rc == -EOPNOTSUPP) { in SMB2_negotiate()
1142 rc = -EIO; in SMB2_negotiate()
1143 if (strcmp(server->vals->version_string, in SMB2_negotiate()
1145 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
1149 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
1153 } else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1155 server->ops = &smb311_operations; in SMB2_negotiate()
1156 server->vals = &smb311_values; in SMB2_negotiate()
1158 } else if (strcmp(server->vals->version_string, in SMB2_negotiate()
1160 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) { in SMB2_negotiate()
1164 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) { in SMB2_negotiate()
1166 server->ops = &smb21_operations; in SMB2_negotiate()
1167 server->vals = &smb21_values; in SMB2_negotiate()
1168 } else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1169 server->ops = &smb311_operations; in SMB2_negotiate()
1170 server->vals = &smb311_values; in SMB2_negotiate()
1172 } else if (le16_to_cpu(rsp->DialectRevision) != in SMB2_negotiate()
1173 server->vals->protocol_id) { in SMB2_negotiate()
1176 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
1180 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode); in SMB2_negotiate()
1182 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) in SMB2_negotiate()
1184 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) in SMB2_negotiate()
1186 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) in SMB2_negotiate()
1188 else if (rsp->DialectRevision == cpu_to_le16(SMB302_PROT_ID)) in SMB2_negotiate()
1190 else if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) in SMB2_negotiate()
1194 le16_to_cpu(rsp->DialectRevision)); in SMB2_negotiate()
1199 server->dialect = le16_to_cpu(rsp->DialectRevision); in SMB2_negotiate()
1206 memcpy(server->preauth_sha_hash, ses->preauth_sha_hash, in SMB2_negotiate()
1210 server->negflavor = CIFS_NEGFLAVOR_EXTENDED; in SMB2_negotiate()
1212 server->maxBuf = min_t(unsigned int, le32_to_cpu(rsp->MaxTransactSize), in SMB2_negotiate()
1214 server->max_read = le32_to_cpu(rsp->MaxReadSize); in SMB2_negotiate()
1215 server->max_write = le32_to_cpu(rsp->MaxWriteSize); in SMB2_negotiate()
1216 server->sec_mode = le16_to_cpu(rsp->SecurityMode); in SMB2_negotiate()
1217 if ((server->sec_mode & SMB2_SEC_MODE_FLAGS_ALL) != server->sec_mode) in SMB2_negotiate()
1219 server->sec_mode); in SMB2_negotiate()
1220 server->capabilities = le32_to_cpu(rsp->Capabilities); in SMB2_negotiate()
1222 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES; in SMB2_negotiate()
1228 if ((server->dialect == SMB30_PROT_ID || in SMB2_negotiate()
1229 server->dialect == SMB302_PROT_ID) && in SMB2_negotiate()
1230 (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_negotiate()
1231 server->cipher_type = SMB2_ENCRYPTION_AES128_CCM; in SMB2_negotiate()
1236 * See MS-SMB2 section 2.2.4: if no blob, client picks default which in SMB2_negotiate()
1238 * ses->sectype = RawNTLMSSP; in SMB2_negotiate()
1244 server->sec_ntlmssp = true; in SMB2_negotiate()
1247 rc = cifs_enable_signing(server, ses->sign); in SMB2_negotiate()
1255 rc = -EIO; in SMB2_negotiate()
1258 if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { in SMB2_negotiate()
1259 if (rsp->NegotiateContextCount) in SMB2_negotiate()
1266 if (server->cipher_type && !rc) { in SMB2_negotiate()
1271 server->secmech.enc = server->primary_server->secmech.enc; in SMB2_negotiate()
1272 server->secmech.dec = server->primary_server->secmech.dec; in SMB2_negotiate()
1287 struct TCP_Server_Info *server = tcon->ses->server; in smb3_validate_negotiate()
1292 if (server->dialect == SMB311_PROT_ID) in smb3_validate_negotiate()
1302 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) in smb3_validate_negotiate()
1305 if (tcon->ses->user_name == NULL) { in smb3_validate_negotiate()
1310 if (tcon->ses->session_flags & SMB2_SESSION_FLAG_IS_NULL) in smb3_validate_negotiate()
1315 return -ENOMEM; in smb3_validate_negotiate()
1317 pneg_inbuf->Capabilities = in smb3_validate_negotiate()
1318 cpu_to_le32(server->vals->req_capabilities); in smb3_validate_negotiate()
1319 if (tcon->ses->chan_max > 1) in smb3_validate_negotiate()
1320 pneg_inbuf->Capabilities |= cpu_to_le32(SMB2_GLOBAL_CAP_MULTI_CHANNEL); in smb3_validate_negotiate()
1322 memcpy(pneg_inbuf->Guid, server->client_guid, in smb3_validate_negotiate()
1325 if (tcon->ses->sign) in smb3_validate_negotiate()
1326 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1329 pneg_inbuf->SecurityMode = in smb3_validate_negotiate()
1332 pneg_inbuf->SecurityMode = 0; in smb3_validate_negotiate()
1335 if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1337 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1338 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1339 pneg_inbuf->Dialects[2] = cpu_to_le16(SMB311_PROT_ID); in smb3_validate_negotiate()
1340 pneg_inbuf->DialectCount = cpu_to_le16(3); in smb3_validate_negotiate()
1342 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1343 (sizeof(pneg_inbuf->Dialects[0])); in smb3_validate_negotiate()
1344 } else if (strcmp(server->vals->version_string, in smb3_validate_negotiate()
1346 pneg_inbuf->Dialects[0] = cpu_to_le16(SMB21_PROT_ID); in smb3_validate_negotiate()
1347 pneg_inbuf->Dialects[1] = cpu_to_le16(SMB30_PROT_ID); in smb3_validate_negotiate()
1348 pneg_inbuf->Dialects[2] = cpu_to_le16(SMB302_PROT_ID); in smb3_validate_negotiate()
1349 pneg_inbuf->Dialects[3] = cpu_to_le16(SMB311_PROT_ID); in smb3_validate_negotiate()
1350 pneg_inbuf->DialectCount = cpu_to_le16(4); in smb3_validate_negotiate()
1355 pneg_inbuf->Dialects[0] = in smb3_validate_negotiate()
1356 cpu_to_le16(server->vals->protocol_id); in smb3_validate_negotiate()
1357 pneg_inbuf->DialectCount = cpu_to_le16(1); in smb3_validate_negotiate()
1359 inbuflen = sizeof(*pneg_inbuf) - in smb3_validate_negotiate()
1360 sizeof(pneg_inbuf->Dialects[0]) * 3; in smb3_validate_negotiate()
1367 if (rc == -EOPNOTSUPP) { in smb3_validate_negotiate()
1378 rc = -EIO; in smb3_validate_negotiate()
1382 rc = -EIO; in smb3_validate_negotiate()
1393 if (pneg_rsp->Dialect != cpu_to_le16(server->dialect)) in smb3_validate_negotiate()
1396 if (pneg_rsp->SecurityMode != cpu_to_le16(server->sec_mode)) in smb3_validate_negotiate()
1401 if ((le32_to_cpu(pneg_rsp->Capabilities) | SMB2_NT_FIND | in smb3_validate_negotiate()
1402 SMB2_LARGE_FILES) != server->capabilities) in smb3_validate_negotiate()
1411 cifs_tcon_dbg(VFS, "protocol revalidation - security settings mismatch\n"); in smb3_validate_negotiate()
1429 if (server->sec_ntlmssp && in smb2_select_sectype()
1432 if ((server->sec_kerberos || server->sec_mskerberos) && in smb2_select_sectype()
1465 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_alloc_buffer()
1466 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_alloc_buffer()
1477 spin_lock(&ses->ses_lock); in SMB2_sess_alloc_buffer()
1478 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_alloc_buffer()
1479 spin_unlock(&ses->ses_lock); in SMB2_sess_alloc_buffer()
1482 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_sess_alloc_buffer()
1483 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_sess_alloc_buffer()
1484 req->PreviousSessionId = 0; in SMB2_sess_alloc_buffer()
1485 req->Flags = SMB2_SESSION_REQ_FLAG_BINDING; in SMB2_sess_alloc_buffer()
1486 cifs_dbg(FYI, "Binding to sess id: %llx\n", ses->Suid); in SMB2_sess_alloc_buffer()
1489 req->hdr.SessionId = 0; in SMB2_sess_alloc_buffer()
1494 req->PreviousSessionId = cpu_to_le64(sess_data->previous_session); in SMB2_sess_alloc_buffer()
1495 req->Flags = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1497 sess_data->previous_session); in SMB2_sess_alloc_buffer()
1501 if (server->credits >= server->max_credits) in SMB2_sess_alloc_buffer()
1502 req->hdr.CreditRequest = cpu_to_le16(0); in SMB2_sess_alloc_buffer()
1504 req->hdr.CreditRequest = cpu_to_le16( in SMB2_sess_alloc_buffer()
1505 min_t(int, server->max_credits - in SMB2_sess_alloc_buffer()
1506 server->credits, 130)); in SMB2_sess_alloc_buffer()
1509 if (server->sign) in SMB2_sess_alloc_buffer()
1510 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_REQUIRED; in SMB2_sess_alloc_buffer()
1512 req->SecurityMode = SMB2_NEGOTIATE_SIGNING_ENABLED; in SMB2_sess_alloc_buffer()
1514 req->SecurityMode = 0; in SMB2_sess_alloc_buffer()
1517 req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); in SMB2_sess_alloc_buffer()
1519 req->Capabilities = 0; in SMB2_sess_alloc_buffer()
1522 req->Channel = 0; /* MBZ */ in SMB2_sess_alloc_buffer()
1524 sess_data->iov[0].iov_base = (char *)req; in SMB2_sess_alloc_buffer()
1526 sess_data->iov[0].iov_len = total_len - 1; in SMB2_sess_alloc_buffer()
1531 sess_data->buf0_type = CIFS_SMALL_BUFFER; in SMB2_sess_alloc_buffer()
1539 struct kvec *iov = sess_data->iov; in SMB2_sess_free_buffer()
1542 if (sess_data->buf0_type != CIFS_NO_BUFFER && iov[0].iov_base) in SMB2_sess_free_buffer()
1545 free_rsp_buf(sess_data->buf0_type, iov[0].iov_base); in SMB2_sess_free_buffer()
1546 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_free_buffer()
1554 struct smb2_sess_setup_req *req = sess_data->iov[0].iov_base; in SMB2_sess_sendreceive()
1558 req->SecurityBufferOffset = in SMB2_sess_sendreceive()
1560 req->SecurityBufferLength = cpu_to_le16(sess_data->iov[1].iov_len); in SMB2_sess_sendreceive()
1563 rqst.rq_iov = sess_data->iov; in SMB2_sess_sendreceive()
1567 rc = cifs_send_recv(sess_data->xid, sess_data->ses, in SMB2_sess_sendreceive()
1568 sess_data->server, in SMB2_sess_sendreceive()
1570 &sess_data->buf0_type, in SMB2_sess_sendreceive()
1572 cifs_small_buf_release(sess_data->iov[0].iov_base); in SMB2_sess_sendreceive()
1574 sess_data->ses->expired_pwd = false; in SMB2_sess_sendreceive()
1575 else if ((rc == -EACCES) || (rc == -EKEYEXPIRED) || (rc == -EKEYREVOKED)) { in SMB2_sess_sendreceive()
1576 if (sess_data->ses->expired_pwd == false) in SMB2_sess_sendreceive()
1577 trace_smb3_key_expired(sess_data->server->hostname, in SMB2_sess_sendreceive()
1578 sess_data->ses->user_name, in SMB2_sess_sendreceive()
1579 sess_data->server->conn_id, in SMB2_sess_sendreceive()
1580 &sess_data->server->dstaddr, rc); in SMB2_sess_sendreceive()
1581 sess_data->ses->expired_pwd = true; in SMB2_sess_sendreceive()
1584 memcpy(&sess_data->iov[0], &rsp_iov, sizeof(struct kvec)); in SMB2_sess_sendreceive()
1593 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_establish_session()
1594 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_establish_session()
1597 if (server->ops->generate_signingkey) { in SMB2_sess_establish_session()
1598 rc = server->ops->generate_signingkey(ses, server); in SMB2_sess_establish_session()
1606 if (!server->session_estab) { in SMB2_sess_establish_session()
1607 server->sequence_number = 0x2; in SMB2_sess_establish_session()
1608 server->session_estab = true; in SMB2_sess_establish_session()
1621 struct cifs_ses *ses = sess_data->ses; in SMB2_auth_kerberos()
1622 struct TCP_Server_Info *server = sess_data->server; in SMB2_auth_kerberos()
1635 if (rc == -ENOKEY) in SMB2_auth_kerberos()
1641 msg = spnego_key->payload.data[0]; in SMB2_auth_kerberos()
1646 if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { in SMB2_auth_kerberos()
1648 CIFS_SPNEGO_UPCALL_VERSION, msg->version); in SMB2_auth_kerberos()
1649 rc = -EKEYREJECTED; in SMB2_auth_kerberos()
1653 spin_lock(&ses->ses_lock); in SMB2_auth_kerberos()
1654 is_binding = (ses->ses_status == SES_GOOD); in SMB2_auth_kerberos()
1655 spin_unlock(&ses->ses_lock); in SMB2_auth_kerberos()
1659 kfree_sensitive(ses->auth_key.response); in SMB2_auth_kerberos()
1660 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len, in SMB2_auth_kerberos()
1662 if (!ses->auth_key.response) { in SMB2_auth_kerberos()
1664 msg->sesskey_len); in SMB2_auth_kerberos()
1665 rc = -ENOMEM; in SMB2_auth_kerberos()
1668 ses->auth_key.len = msg->sesskey_len; in SMB2_auth_kerberos()
1671 sess_data->iov[1].iov_base = msg->data + msg->sesskey_len; in SMB2_auth_kerberos()
1672 sess_data->iov[1].iov_len = msg->secblob_len; in SMB2_auth_kerberos()
1678 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_auth_kerberos()
1681 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_auth_kerberos()
1682 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_auth_kerberos()
1690 kfree_sensitive(ses->auth_key.response); in SMB2_auth_kerberos()
1691 ses->auth_key.response = NULL; in SMB2_auth_kerberos()
1692 ses->auth_key.len = 0; in SMB2_auth_kerberos()
1695 sess_data->result = rc; in SMB2_auth_kerberos()
1696 sess_data->func = NULL; in SMB2_auth_kerberos()
1704 sess_data->result = -EOPNOTSUPP; in SMB2_auth_kerberos()
1705 sess_data->func = NULL; in SMB2_auth_kerberos()
1716 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_negotiate()
1717 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_auth_rawntlmssp_negotiate()
1728 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL); in SMB2_sess_auth_rawntlmssp_negotiate()
1729 if (!ses->ntlmssp) { in SMB2_sess_auth_rawntlmssp_negotiate()
1730 rc = -ENOMEM; in SMB2_sess_auth_rawntlmssp_negotiate()
1733 ses->ntlmssp->sesskey_per_smbsess = true; in SMB2_sess_auth_rawntlmssp_negotiate()
1741 sess_data->nls_cp); in SMB2_sess_auth_rawntlmssp_negotiate()
1748 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_negotiate()
1751 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_negotiate()
1752 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_negotiate()
1755 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_negotiate()
1758 if (sess_data->buf0_type != CIFS_NO_BUFFER && in SMB2_sess_auth_rawntlmssp_negotiate()
1759 rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) in SMB2_sess_auth_rawntlmssp_negotiate()
1766 le16_to_cpu(rsp->SecurityBufferOffset)) { in SMB2_sess_auth_rawntlmssp_negotiate()
1768 le16_to_cpu(rsp->SecurityBufferOffset)); in SMB2_sess_auth_rawntlmssp_negotiate()
1769 rc = -EIO; in SMB2_sess_auth_rawntlmssp_negotiate()
1772 rc = decode_ntlmssp_challenge(rsp->Buffer, in SMB2_sess_auth_rawntlmssp_negotiate()
1773 le16_to_cpu(rsp->SecurityBufferLength), ses); in SMB2_sess_auth_rawntlmssp_negotiate()
1779 spin_lock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_negotiate()
1780 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_auth_rawntlmssp_negotiate()
1781 spin_unlock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_negotiate()
1785 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_sess_auth_rawntlmssp_negotiate()
1786 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_negotiate()
1793 sess_data->result = 0; in SMB2_sess_auth_rawntlmssp_negotiate()
1794 sess_data->func = SMB2_sess_auth_rawntlmssp_authenticate; in SMB2_sess_auth_rawntlmssp_negotiate()
1798 kfree_sensitive(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_negotiate()
1799 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1800 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_negotiate()
1801 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_negotiate()
1808 struct cifs_ses *ses = sess_data->ses; in SMB2_sess_auth_rawntlmssp_authenticate()
1809 struct TCP_Server_Info *server = sess_data->server; in SMB2_sess_auth_rawntlmssp_authenticate()
1821 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1822 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_sess_auth_rawntlmssp_authenticate()
1826 sess_data->nls_cp); in SMB2_sess_auth_rawntlmssp_authenticate()
1835 rc = -EOPNOTSUPP; in SMB2_sess_auth_rawntlmssp_authenticate()
1838 sess_data->iov[1].iov_base = ntlmssp_blob; in SMB2_sess_auth_rawntlmssp_authenticate()
1839 sess_data->iov[1].iov_len = blob_length; in SMB2_sess_auth_rawntlmssp_authenticate()
1845 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; in SMB2_sess_auth_rawntlmssp_authenticate()
1847 spin_lock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_authenticate()
1848 is_binding = (ses->ses_status == SES_GOOD); in SMB2_sess_auth_rawntlmssp_authenticate()
1849 spin_unlock(&ses->ses_lock); in SMB2_sess_auth_rawntlmssp_authenticate()
1853 ses->Suid = le64_to_cpu(rsp->hdr.SessionId); in SMB2_sess_auth_rawntlmssp_authenticate()
1854 ses->session_flags = le16_to_cpu(rsp->SessionFlags); in SMB2_sess_auth_rawntlmssp_authenticate()
1859 if (ses->server->dialect < SMB30_PROT_ID) { in SMB2_sess_auth_rawntlmssp_authenticate()
1865 cifs_dbg(VFS, "Session Id %*ph\n", (int)sizeof(ses->Suid), in SMB2_sess_auth_rawntlmssp_authenticate()
1866 &ses->Suid); in SMB2_sess_auth_rawntlmssp_authenticate()
1868 SMB2_NTLMV2_SESSKEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1870 SMB3_SIGN_KEY_SIZE, ses->auth_key.response); in SMB2_sess_auth_rawntlmssp_authenticate()
1876 kfree_sensitive(ses->ntlmssp); in SMB2_sess_auth_rawntlmssp_authenticate()
1877 ses->ntlmssp = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1878 sess_data->result = rc; in SMB2_sess_auth_rawntlmssp_authenticate()
1879 sess_data->func = NULL; in SMB2_sess_auth_rawntlmssp_authenticate()
1886 struct cifs_ses *ses = sess_data->ses; in SMB2_select_sec()
1887 struct TCP_Server_Info *server = sess_data->server; in SMB2_select_sec()
1889 type = smb2_select_sectype(server, ses->sectype); in SMB2_select_sec()
1893 return -EINVAL; in SMB2_select_sec()
1898 sess_data->func = SMB2_auth_kerberos; in SMB2_select_sec()
1901 sess_data->func = SMB2_sess_auth_rawntlmssp_negotiate; in SMB2_select_sec()
1905 return -EOPNOTSUPP; in SMB2_select_sec()
1923 return -EIO; in SMB2_sess_setup()
1928 return -ENOMEM; in SMB2_sess_setup()
1930 sess_data->xid = xid; in SMB2_sess_setup()
1931 sess_data->ses = ses; in SMB2_sess_setup()
1932 sess_data->server = server; in SMB2_sess_setup()
1933 sess_data->buf0_type = CIFS_NO_BUFFER; in SMB2_sess_setup()
1934 sess_data->nls_cp = (struct nls_table *) nls_cp; in SMB2_sess_setup()
1935 sess_data->previous_session = ses->Suid; in SMB2_sess_setup()
1944 memcpy(ses->preauth_sha_hash, server->preauth_sha_hash, in SMB2_sess_setup()
1947 while (sess_data->func) in SMB2_sess_setup()
1948 sess_data->func(sess_data); in SMB2_sess_setup()
1950 if ((ses->session_flags & SMB2_SESSION_FLAG_IS_GUEST) && (ses->sign)) in SMB2_sess_setup()
1952 rc = sess_data->result; in SMB2_sess_setup()
1973 if (ses && (ses->server)) in SMB2_logoff()
1974 server = ses->server; in SMB2_logoff()
1976 return -EIO; in SMB2_logoff()
1979 spin_lock(&ses->chan_lock); in SMB2_logoff()
1981 spin_unlock(&ses->chan_lock); in SMB2_logoff()
1984 spin_unlock(&ses->chan_lock); in SMB2_logoff()
1986 rc = smb2_plain_req_init(SMB2_LOGOFF, NULL, ses->server, in SMB2_logoff()
1992 req->hdr.SessionId = cpu_to_le64(ses->Suid); in SMB2_logoff()
1994 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) in SMB2_logoff()
1996 else if (server->sign) in SMB2_logoff()
1997 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_logoff()
2008 rc = cifs_send_recv(xid, ses, ses->server, in SMB2_logoff()
2013 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]); in SMB2_logoff()
2022 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]); in cifs_stats_fail_inc()
2030 tcon->max_chunks = 256; in init_copy_chunk_defaults()
2031 tcon->max_bytes_chunk = 1048576; in init_copy_chunk_defaults()
2032 tcon->max_bytes_copy = 16777216; in init_copy_chunk_defaults()
2055 return -EIO; in SMB2_tcon()
2059 return -ENOMEM; in SMB2_tcon()
2064 return -EINVAL; in SMB2_tcon()
2069 tcon->tid = 0; in SMB2_tcon()
2070 atomic_set(&tcon->num_remote_opens, 0); in SMB2_tcon()
2083 iov[0].iov_len = total_len - 1; in SMB2_tcon()
2086 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req)); in SMB2_tcon()
2087 req->PathLength = cpu_to_le16(unc_path_len); in SMB2_tcon()
2092 * 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 in SMB2_tcon()
2093 * unless it is guest or anonymous user. See MS-SMB2 3.2.5.3.1 in SMB2_tcon()
2096 if ((server->dialect == SMB311_PROT_ID) && in SMB2_tcon()
2098 !(ses->session_flags & in SMB2_tcon()
2100 ((ses->user_name != NULL) || (ses->sectype == Kerberos))) in SMB2_tcon()
2101 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_tcon()
2108 if (server->credits >= server->max_credits) in SMB2_tcon()
2109 req->hdr.CreditRequest = cpu_to_le16(0); in SMB2_tcon()
2111 req->hdr.CreditRequest = cpu_to_le16( in SMB2_tcon()
2112 min_t(int, server->max_credits - in SMB2_tcon()
2113 server->credits, 64)); in SMB2_tcon()
2119 trace_smb3_tcon(xid, tcon->tid, ses->Suid, tree, rc); in SMB2_tcon()
2122 tcon->need_reconnect = true; in SMB2_tcon()
2126 switch (rsp->ShareType) { in SMB2_tcon()
2131 tcon->pipe = true; in SMB2_tcon()
2135 tcon->print = true; in SMB2_tcon()
2139 cifs_server_dbg(VFS, "unknown share type %d\n", rsp->ShareType); in SMB2_tcon()
2140 rc = -EOPNOTSUPP; in SMB2_tcon()
2144 tcon->share_flags = le32_to_cpu(rsp->ShareFlags); in SMB2_tcon()
2145 tcon->capabilities = rsp->Capabilities; /* we keep caps little endian */ in SMB2_tcon()
2146 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess); in SMB2_tcon()
2147 tcon->tid = le32_to_cpu(rsp->hdr.Id.SyncId.TreeId); in SMB2_tcon()
2148 strscpy(tcon->tree_name, tree, sizeof(tcon->tree_name)); in SMB2_tcon()
2150 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) && in SMB2_tcon()
2151 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0)) in SMB2_tcon()
2154 if (tcon->seal && in SMB2_tcon()
2155 !(server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION)) in SMB2_tcon()
2159 if (server->ops->validate_negotiate) in SMB2_tcon()
2160 rc = server->ops->validate_negotiate(xid, tcon); in SMB2_tcon()
2161 if (rc == 0) /* See MS-SMB2 2.2.10 and 3.2.5.5 */ in SMB2_tcon()
2162 if (tcon->share_flags & SMB2_SHAREFLAG_ISOLATED_TRANSPORT) in SMB2_tcon()
2163 server->nosharesock = true; in SMB2_tcon()
2171 if (rsp && rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) in SMB2_tcon()
2182 struct cifs_ses *ses = tcon->ses; in SMB2_tdis()
2192 if (!ses || !(ses->server)) in SMB2_tdis()
2193 return -EIO; in SMB2_tdis()
2195 trace_smb3_tdis_enter(xid, tcon->tid, ses->Suid, tcon->tree_name); in SMB2_tdis()
2196 spin_lock(&ses->chan_lock); in SMB2_tdis()
2197 if ((tcon->need_reconnect) || in SMB2_tdis()
2198 (CIFS_ALL_CHANS_NEED_RECONNECT(tcon->ses))) { in SMB2_tdis()
2199 spin_unlock(&ses->chan_lock); in SMB2_tdis()
2202 spin_unlock(&ses->chan_lock); in SMB2_tdis()
2229 trace_smb3_tdis_err(xid, tcon->tid, ses->Suid, rc); in SMB2_tdis()
2231 trace_smb3_tdis_done(xid, tcon->tid, ses->Suid); in SMB2_tdis()
2246 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_buf()
2248 buf->ccontext.DataLength = cpu_to_le32(16); in create_durable_buf()
2249 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_buf()
2251 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_buf()
2253 buf->Name[0] = 'D'; in create_durable_buf()
2254 buf->Name[1] = 'H'; in create_durable_buf()
2255 buf->Name[2] = 'n'; in create_durable_buf()
2256 buf->Name[3] = 'Q'; in create_durable_buf()
2269 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
2271 buf->ccontext.DataLength = cpu_to_le32(16); in create_reconnect_durable_buf()
2272 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_reconnect_durable_buf()
2274 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_buf()
2275 buf->Data.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_buf()
2276 buf->Data.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_buf()
2278 buf->Name[0] = 'D'; in create_reconnect_durable_buf()
2279 buf->Name[1] = 'H'; in create_reconnect_durable_buf()
2280 buf->Name[2] = 'n'; in create_reconnect_durable_buf()
2281 buf->Name[3] = 'C'; in create_reconnect_durable_buf()
2291 pdisk_id->DiskFileId, pdisk_id->VolumeId); in parse_query_id_ctxt()
2292 buf->IndexNumber = pdisk_id->DiskFileId; in parse_query_id_ctxt()
2300 u8 *beg = (u8 *)cc + le16_to_cpu(cc->DataOffset); in parse_posix_ctxt()
2301 u8 *end = beg + le32_to_cpu(cc->DataLength); in parse_posix_ctxt()
2306 posix->nlink = le32_to_cpu(*(__le32 *)(beg + 0)); in parse_posix_ctxt()
2307 posix->reparse_tag = le32_to_cpu(*(__le32 *)(beg + 4)); in parse_posix_ctxt()
2308 posix->mode = le32_to_cpu(*(__le32 *)(beg + 8)); in parse_posix_ctxt()
2316 memcpy(&posix->owner, sid, sid_len); in parse_posix_ctxt()
2324 memcpy(&posix->group, sid, sid_len); in parse_posix_ctxt()
2327 posix->nlink, posix->mode, posix->reparse_tag); in parse_posix_ctxt()
2337 struct smb2_create_rsp *rsp = rsp_iov->iov_base; in smb2_parse_contexts()
2351 off = le32_to_cpu(rsp->CreateContextsOffset); in smb2_parse_contexts()
2352 rem = le32_to_cpu(rsp->CreateContextsLength); in smb2_parse_contexts()
2353 if (check_add_overflow(off, rem, &len) || len > rsp_iov->iov_len) in smb2_parse_contexts()
2354 return -EINVAL; in smb2_parse_contexts()
2359 buf->IndexNumber = 0; in smb2_parse_contexts()
2362 doff = le16_to_cpu(cc->DataOffset); in smb2_parse_contexts()
2363 dlen = le32_to_cpu(cc->DataLength); in smb2_parse_contexts()
2365 return -EINVAL; in smb2_parse_contexts()
2367 noff = le16_to_cpu(cc->NameOffset); in smb2_parse_contexts()
2368 nlen = le16_to_cpu(cc->NameLength); in smb2_parse_contexts()
2370 return -EINVAL; in smb2_parse_contexts()
2376 *oplock = server->ops->parse_lease_buf(cc, epoch, in smb2_parse_contexts()
2395 off = le32_to_cpu(cc->Next); in smb2_parse_contexts()
2399 return -EINVAL; in smb2_parse_contexts()
2403 if (rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) in smb2_parse_contexts()
2404 *oplock = rsp->OplockLevel; in smb2_parse_contexts()
2417 iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock); in add_lease_context()
2419 return -ENOMEM; in add_lease_context()
2420 iov[num].iov_len = server->vals->create_lease_size; in add_lease_context()
2421 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; in add_lease_context()
2429 struct cifs_fid *pfid = oparms->fid; in create_durable_v2_buf()
2436 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2438 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct durable_context_v2)); in create_durable_v2_buf()
2439 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_durable_v2_buf()
2441 buf->ccontext.NameLength = cpu_to_le16(4); in create_durable_v2_buf()
2450 buf->dcontext.Timeout = cpu_to_le32(oparms->tcon->handle_timeout); in create_durable_v2_buf()
2451 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_durable_v2_buf()
2454 if (!oparms->replay) { in create_durable_v2_buf()
2455 generate_random_uuid(buf->dcontext.CreateGuid); in create_durable_v2_buf()
2456 memcpy(pfid->create_guid, buf->dcontext.CreateGuid, 16); in create_durable_v2_buf()
2458 memcpy(buf->dcontext.CreateGuid, pfid->create_guid, 16); in create_durable_v2_buf()
2461 buf->Name[0] = 'D'; in create_durable_v2_buf()
2462 buf->Name[1] = 'H'; in create_durable_v2_buf()
2463 buf->Name[2] = '2'; in create_durable_v2_buf()
2464 buf->Name[3] = 'Q'; in create_durable_v2_buf()
2478 buf->ccontext.DataOffset = in create_reconnect_durable_v2_buf()
2481 buf->ccontext.DataLength = in create_reconnect_durable_v2_buf()
2483 buf->ccontext.NameOffset = in create_reconnect_durable_v2_buf()
2486 buf->ccontext.NameLength = cpu_to_le16(4); in create_reconnect_durable_v2_buf()
2488 buf->dcontext.Fid.PersistentFileId = fid->persistent_fid; in create_reconnect_durable_v2_buf()
2489 buf->dcontext.Fid.VolatileFileId = fid->volatile_fid; in create_reconnect_durable_v2_buf()
2490 buf->dcontext.Flags = cpu_to_le32(SMB2_DHANDLE_FLAG_PERSISTENT); in create_reconnect_durable_v2_buf()
2491 memcpy(buf->dcontext.CreateGuid, fid->create_guid, 16); in create_reconnect_durable_v2_buf()
2494 buf->Name[0] = 'D'; in create_reconnect_durable_v2_buf()
2495 buf->Name[1] = 'H'; in create_reconnect_durable_v2_buf()
2496 buf->Name[2] = '2'; in create_reconnect_durable_v2_buf()
2497 buf->Name[3] = 'C'; in create_reconnect_durable_v2_buf()
2509 return -ENOMEM; in add_durable_v2_context()
2522 oparms->reconnect = false; in add_durable_reconnect_v2_context()
2524 iov[num].iov_base = create_reconnect_durable_v2_buf(oparms->fid); in add_durable_reconnect_v2_context()
2526 return -ENOMEM; in add_durable_reconnect_v2_context()
2539 if (oparms->reconnect) in add_durable_context()
2546 if (oparms->reconnect) { in add_durable_context()
2547 iov[num].iov_base = create_reconnect_durable_buf(oparms->fid); in add_durable_context()
2549 oparms->reconnect = false; in add_durable_context()
2553 return -ENOMEM; in add_durable_context()
2559 /* See MS-SMB2 2.2.13.2.7 */
2569 buf->ccontext.DataOffset = cpu_to_le16(offsetof in create_twarp_buf()
2571 buf->ccontext.DataLength = cpu_to_le32(8); in create_twarp_buf()
2572 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_twarp_buf()
2574 buf->ccontext.NameLength = cpu_to_le16(4); in create_twarp_buf()
2576 buf->Name[0] = 'T'; in create_twarp_buf()
2577 buf->Name[1] = 'W'; in create_twarp_buf()
2578 buf->Name[2] = 'r'; in create_twarp_buf()
2579 buf->Name[3] = 'p'; in create_twarp_buf()
2580 buf->Timestamp = cpu_to_le64(timewarp); in create_twarp_buf()
2584 /* See MS-SMB2 2.2.13.2.7 */
2592 return -ENOMEM; in add_twarp_context()
2598 /* See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx */
2603 /* Populate the user ownership fields S-1-5-88-1 */ in setup_owner_group_sids()
2604 sids->owner.Revision = 1; in setup_owner_group_sids()
2605 sids->owner.NumAuth = 3; in setup_owner_group_sids()
2606 sids->owner.Authority[5] = 5; in setup_owner_group_sids()
2607 sids->owner.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2608 sids->owner.SubAuthorities[1] = cpu_to_le32(1); in setup_owner_group_sids()
2609 sids->owner.SubAuthorities[2] = cpu_to_le32(current_fsuid().val); in setup_owner_group_sids()
2611 /* Populate the group ownership fields S-1-5-88-2 */ in setup_owner_group_sids()
2612 sids->group.Revision = 1; in setup_owner_group_sids()
2613 sids->group.NumAuth = 3; in setup_owner_group_sids()
2614 sids->group.Authority[5] = 5; in setup_owner_group_sids()
2615 sids->group.SubAuthorities[0] = cpu_to_le32(88); in setup_owner_group_sids()
2616 sids->group.SubAuthorities[1] = cpu_to_le32(2); in setup_owner_group_sids()
2617 sids->group.SubAuthorities[2] = cpu_to_le32(current_fsgid().val); in setup_owner_group_sids()
2619 …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()
2622 /* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */
2647 owner_offset = ptr - (__u8 *)&buf->sd; in create_sd_buf()
2648 buf->sd.OffsetOwner = cpu_to_le32(owner_offset); in create_sd_buf()
2650 buf->sd.OffsetGroup = cpu_to_le32(group_offset); in create_sd_buf()
2655 buf->sd.OffsetOwner = 0; in create_sd_buf()
2656 buf->sd.OffsetGroup = 0; in create_sd_buf()
2659 buf->ccontext.DataOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, sd)); in create_sd_buf()
2660 buf->ccontext.NameOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, Name)); in create_sd_buf()
2661 buf->ccontext.NameLength = cpu_to_le16(4); in create_sd_buf()
2663 buf->Name[0] = 'S'; in create_sd_buf()
2664 buf->Name[1] = 'e'; in create_sd_buf()
2665 buf->Name[2] = 'c'; in create_sd_buf()
2666 buf->Name[3] = 'D'; in create_sd_buf()
2667 buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */ in create_sd_buf()
2673 buf->sd.Control = cpu_to_le16(ACL_CONTROL_SR | ACL_CONTROL_DP); in create_sd_buf()
2676 buf->sd.OffsetDacl = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2681 /* create one ACE to hold the mode embedded in reserved special SID */ in create_sd_buf()
2701 acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */ in create_sd_buf()
2707 buf->ccontext.DataLength = cpu_to_le32(ptr - (__u8 *)&buf->sd); in create_sd_buf()
2708 *len = round_up((unsigned int)(ptr - (__u8 *)buf), 8); in create_sd_buf()
2721 return -ENOMEM; in add_sd_context()
2736 buf->ccontext.DataOffset = cpu_to_le16(0); in create_query_id_buf()
2737 buf->ccontext.DataLength = cpu_to_le32(0); in create_query_id_buf()
2738 buf->ccontext.NameOffset = cpu_to_le16(offsetof in create_query_id_buf()
2740 buf->ccontext.NameLength = cpu_to_le16(4); in create_query_id_buf()
2742 buf->Name[0] = 'Q'; in create_query_id_buf()
2743 buf->Name[1] = 'F'; in create_query_id_buf()
2744 buf->Name[2] = 'i'; in create_query_id_buf()
2745 buf->Name[3] = 'd'; in create_query_id_buf()
2749 /* See MS-SMB2 2.2.13.2.9 */
2757 return -ENOMEM; in add_query_id_context()
2766 struct kvec *iov = oparms->ea_cctx; in add_ea_context()
2768 if (iov && iov->iov_base && iov->iov_len) { in add_ea_context()
2787 return -EINVAL; in alloc_path_with_tree_prefix()
2790 treename_len -= 2; in alloc_path_with_tree_prefix()
2798 * final path needs to be 8-byte aligned as specified in in alloc_path_with_tree_prefix()
2799 * MS-SMB2 2.2.13 SMB2 CREATE Request. in alloc_path_with_tree_prefix()
2804 return -ENOMEM; in alloc_path_with_tree_prefix()
2828 struct cifs_ses *ses = tcon->ses; in smb311_posix_mkdir()
2856 return -ENOMEM; in smb311_posix_mkdir()
2859 rc = -EIO; in smb311_posix_mkdir()
2873 req->ImpersonationLevel = IL_IMPERSONATION; in smb311_posix_mkdir()
2874 req->DesiredAccess = cpu_to_le32(FILE_WRITE_ATTRIBUTES); in smb311_posix_mkdir()
2876 req->FileAttributes = cpu_to_le32(file_attributes); in smb311_posix_mkdir()
2877 req->ShareAccess = FILE_SHARE_ALL_LE; in smb311_posix_mkdir()
2878 req->CreateDisposition = cpu_to_le32(FILE_CREATE); in smb311_posix_mkdir()
2879 req->CreateOptions = cpu_to_le32(CREATE_NOT_FILE); in smb311_posix_mkdir()
2882 /* -1 since last byte is buf[0] which is sent below (path) */ in smb311_posix_mkdir()
2883 iov[0].iov_len = total_len - 1; in smb311_posix_mkdir()
2885 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in smb311_posix_mkdir()
2887 /* [MS-SMB2] 2.2.13 NameOffset: in smb311_posix_mkdir()
2895 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in smb311_posix_mkdir()
2898 req->hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in smb311_posix_mkdir()
2901 tcon->tree_name, utf16_path); in smb311_posix_mkdir()
2905 req->NameLength = cpu_to_le16(name_len * 2); in smb311_posix_mkdir()
2913 req->NameLength = cpu_to_le16(uni_path_len - 2); in smb311_posix_mkdir()
2918 rc = -ENOMEM; in smb311_posix_mkdir()
2932 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_NONE; in smb311_posix_mkdir()
2934 if (tcon->posix_extensions) { in smb311_posix_mkdir()
2939 req->CreateContextsOffset = cpu_to_le32( in smb311_posix_mkdir()
2942 pc_buf = iov[n_iov-1].iov_base; in smb311_posix_mkdir()
2951 trace_smb3_posix_mkdir_enter(xid, tcon->tid, ses->Suid, full_path, CREATE_NOT_FILE, in smb311_posix_mkdir()
2962 trace_smb3_posix_mkdir_err(xid, tcon->tid, ses->Suid, in smb311_posix_mkdir()
2975 rc = -EIO; in smb311_posix_mkdir()
2980 trace_smb3_posix_mkdir_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid, in smb311_posix_mkdir()
2983 SMB2_close(xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId); in smb311_posix_mkdir()
3013 struct kvec *iov = rqst->rq_iov; in SMB2_open_init()
3023 /* -1 since last byte is buf[0] which is sent below (path) */ in SMB2_open_init()
3024 iov[0].iov_len = total_len - 1; in SMB2_open_init()
3026 if (oparms->create_options & CREATE_OPTION_READONLY) in SMB2_open_init()
3028 if (oparms->create_options & CREATE_OPTION_SPECIAL) in SMB2_open_init()
3031 req->ImpersonationLevel = IL_IMPERSONATION; in SMB2_open_init()
3032 req->DesiredAccess = cpu_to_le32(oparms->desired_access); in SMB2_open_init()
3034 req->FileAttributes = cpu_to_le32(file_attributes); in SMB2_open_init()
3035 req->ShareAccess = FILE_SHARE_ALL_LE; in SMB2_open_init()
3037 req->CreateDisposition = cpu_to_le32(oparms->disposition); in SMB2_open_init()
3038 req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK); in SMB2_open_init()
3039 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); in SMB2_open_init()
3041 /* [MS-SMB2] 2.2.13 NameOffset: in SMB2_open_init()
3049 if (tcon->share_flags & SHI1005_FLAGS_DFS) { in SMB2_open_init()
3052 req->hdr.Flags |= SMB2_FLAGS_DFS_OPERATIONS; in SMB2_open_init()
3055 tcon->tree_name, path); in SMB2_open_init()
3058 req->NameLength = cpu_to_le16(name_len * 2); in SMB2_open_init()
3064 req->NameLength = cpu_to_le16(uni_path_len - 2); in SMB2_open_init()
3068 return -ENOMEM; in SMB2_open_init()
3078 if ((!server->oplocks) || (tcon->no_lease)) in SMB2_open_init()
3081 if (!(server->capabilities & SMB2_GLOBAL_CAP_LEASING) || in SMB2_open_init()
3083 req->RequestedOplockLevel = *oplock; in SMB2_open_init()
3084 else if (!(server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING) && in SMB2_open_init()
3085 (oparms->create_options & CREATE_NOT_FILE)) in SMB2_open_init()
3086 req->RequestedOplockLevel = *oplock; /* no srv lease support */ in SMB2_open_init()
3089 oparms->fid->lease_key, oplock); in SMB2_open_init()
3096 tcon->use_persistent); in SMB2_open_init()
3101 if (tcon->posix_extensions) { in SMB2_open_init()
3102 rc = add_posix_context(iov, &n_iov, oparms->mode); in SMB2_open_init()
3107 if (tcon->snapshot_time) { in SMB2_open_init()
3109 rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time); in SMB2_open_init()
3114 if ((oparms->disposition != FILE_OPEN) && (oparms->cifs_sb)) { in SMB2_open_init()
3118 if ((oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID) && in SMB2_open_init()
3119 (oparms->mode != ACL_NO_MODE)) in SMB2_open_init()
3123 oparms->mode = ACL_NO_MODE; in SMB2_open_init()
3126 if (oparms->cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) in SMB2_open_init()
3132 cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode); in SMB2_open_init()
3133 rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner); in SMB2_open_init()
3147 req->CreateContextsOffset = cpu_to_le32( in SMB2_open_init()
3150 req->CreateContextsLength = 0; in SMB2_open_init()
3152 for (unsigned int i = 2; i < (n_iov-1); i++) { in SMB2_open_init()
3154 size_t len = v->iov_len; in SMB2_open_init()
3156 (struct create_context *)v->iov_base; in SMB2_open_init()
3158 cctx->Next = cpu_to_le32(len); in SMB2_open_init()
3159 le32_add_cpu(&req->CreateContextsLength, len); in SMB2_open_init()
3161 le32_add_cpu(&req->CreateContextsLength, in SMB2_open_init()
3162 iov[n_iov-1].iov_len); in SMB2_open_init()
3165 rqst->rq_nvec = n_iov; in SMB2_open_init()
3177 if (rqst && rqst->rq_iov) { in SMB2_open_free()
3178 cifs_small_buf_release(rqst->rq_iov[0].iov_base); in SMB2_open_free()
3179 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_open_free()
3180 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_open_free()
3181 kfree(rqst->rq_iov[i].iov_base); in SMB2_open_free()
3193 struct cifs_tcon *tcon = oparms->tcon; in SMB2_open()
3194 struct cifs_ses *ses = tcon->ses; in SMB2_open()
3207 oparms->replay = !!(retries); in SMB2_open()
3211 return -EIO; in SMB2_open()
3226 trace_smb3_open_enter(xid, tcon->tid, tcon->ses->Suid, oparms->path, in SMB2_open()
3227 oparms->create_options, oparms->desired_access); in SMB2_open()
3245 trace_smb3_open_err(xid, tcon->tid, ses->Suid, in SMB2_open()
3246 oparms->create_options, oparms->desired_access, rc); in SMB2_open()
3247 if (rc == -EREMCHG) { in SMB2_open()
3249 tcon->tree_name); in SMB2_open()
3250 tcon->need_reconnect = true; in SMB2_open()
3256 trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid, in SMB2_open()
3257 oparms->create_options, oparms->desired_access); in SMB2_open()
3259 atomic_inc(&tcon->num_remote_opens); in SMB2_open()
3260 oparms->fid->persistent_fid = rsp->PersistentFileId; in SMB2_open()
3261 oparms->fid->volatile_fid = rsp->VolatileFileId; in SMB2_open()
3262 oparms->fid->access = oparms->desired_access; in SMB2_open()
3264 oparms->fid->mid = le64_to_cpu(rsp->hdr.MessageId); in SMB2_open()
3268 buf->CreationTime = rsp->CreationTime; in SMB2_open()
3269 buf->LastAccessTime = rsp->LastAccessTime; in SMB2_open()
3270 buf->LastWriteTime = rsp->LastWriteTime; in SMB2_open()
3271 buf->ChangeTime = rsp->ChangeTime; in SMB2_open()
3272 buf->AllocationSize = rsp->AllocationSize; in SMB2_open()
3273 buf->EndOfFile = rsp->EndofFile; in SMB2_open()
3274 buf->Attributes = rsp->FileAttributes; in SMB2_open()
3275 buf->NumberOfLinks = cpu_to_le32(1); in SMB2_open()
3276 buf->DeletePending = 0; in SMB2_open()
3280 rc = smb2_parse_contexts(server, &rsp_iov, &oparms->fid->epoch, in SMB2_open()
3281 oparms->fid->lease_key, oplock, buf, posix); in SMB2_open()
3301 struct kvec *iov = rqst->rq_iov; in SMB2_ioctl_init()
3319 return -ENOMEM; in SMB2_ioctl_init()
3323 req->CtlCode = cpu_to_le32(opcode); in SMB2_ioctl_init()
3324 req->PersistentFileId = persistent_fid; in SMB2_ioctl_init()
3325 req->VolatileFileId = volatile_fid; in SMB2_ioctl_init()
3337 req->InputCount = cpu_to_le32(indatalen); in SMB2_ioctl_init()
3339 req->InputOffset = in SMB2_ioctl_init()
3341 rqst->rq_nvec = 2; in SMB2_ioctl_init()
3342 iov[0].iov_len = total_len - 1; in SMB2_ioctl_init()
3346 rqst->rq_nvec = 1; in SMB2_ioctl_init()
3350 req->OutputOffset = 0; in SMB2_ioctl_init()
3351 req->OutputCount = 0; /* MBZ */ in SMB2_ioctl_init()
3368 req->MaxOutputResponse = cpu_to_le32(max_response_size); in SMB2_ioctl_init()
3369 req->hdr.CreditCharge = in SMB2_ioctl_init()
3373 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL); in SMB2_ioctl_init()
3375 /* validate negotiate request must be signed - see MS-SMB2 3.2.5.5 */ in SMB2_ioctl_init()
3377 req->hdr.Flags |= SMB2_FLAGS_SIGNED; in SMB2_ioctl_init()
3387 if (rqst && rqst->rq_iov) { in SMB2_ioctl_free()
3388 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_ioctl_free()
3389 for (i = 1; i < rqst->rq_nvec; i++) in SMB2_ioctl_free()
3390 if (rqst->rq_iov[i].iov_base != smb2_padding) in SMB2_ioctl_free()
3391 kfree(rqst->rq_iov[i].iov_base); in SMB2_ioctl_free()
3417 return -EIO; in SMB2_ioctl()
3419 ses = tcon->ses; in SMB2_ioctl()
3421 return -EIO; in SMB2_ioctl()
3429 return -EIO; in SMB2_ioctl()
3463 trace_smb3_fsctl_err(xid, persistent_fid, tcon->tid, in SMB2_ioctl()
3464 ses->Suid, 0, opcode, rc); in SMB2_ioctl()
3466 if ((rc != 0) && (rc != -EINVAL) && (rc != -E2BIG)) { in SMB2_ioctl()
3469 } else if (rc == -EINVAL) { in SMB2_ioctl()
3475 } else if (rc == -E2BIG) { in SMB2_ioctl()
3492 rc = -EIO; in SMB2_ioctl()
3496 *plen = le32_to_cpu(rsp->OutputCount); in SMB2_ioctl()
3504 rc = -EIO; in SMB2_ioctl()
3508 if (rsp_iov.iov_len - *plen < le32_to_cpu(rsp->OutputOffset)) { in SMB2_ioctl()
3510 le32_to_cpu(rsp->OutputOffset)); in SMB2_ioctl()
3512 rc = -EIO; in SMB2_ioctl()
3516 *out_data = kmemdup((char *)rsp + le32_to_cpu(rsp->OutputOffset), in SMB2_ioctl()
3519 rc = -ENOMEM; in SMB2_ioctl()
3566 struct kvec *iov = rqst->rq_iov; in SMB2_close_init()
3575 req->PersistentFileId = persistent_fid; in SMB2_close_init()
3576 req->VolatileFileId = volatile_fid; in SMB2_close_init()
3578 req->Flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB; in SMB2_close_init()
3580 req->Flags = 0; in SMB2_close_init()
3590 if (rqst && rqst->rq_iov) in SMB2_close_free()
3591 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_close_free()
3601 struct cifs_ses *ses = tcon->ses; in __SMB2_close()
3620 return -EIO; in __SMB2_close()
3634 trace_smb3_close_enter(xid, persistent_fid, tcon->tid, ses->Suid); in __SMB2_close()
3650 trace_smb3_close_err(xid, persistent_fid, tcon->tid, ses->Suid, in __SMB2_close()
3654 trace_smb3_close_done(xid, persistent_fid, tcon->tid, in __SMB2_close()
3655 ses->Suid); in __SMB2_close()
3657 memcpy(&pbuf->network_open_info, in __SMB2_close()
3658 &rsp->network_open_info, in __SMB2_close()
3659 sizeof(pbuf->network_open_info)); in __SMB2_close()
3660 atomic_dec(&tcon->num_remote_opens); in __SMB2_close()
3696 unsigned int smb_len = iov->iov_len; in smb2_validate_iov()
3697 char *end_of_smb = smb_len + (char *)iov->iov_base; in smb2_validate_iov()
3698 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_iov()
3705 return -EINVAL; in smb2_validate_iov()
3712 return -EINVAL; in smb2_validate_iov()
3717 return -EINVAL; in smb2_validate_iov()
3724 * If SMB buffer fields are valid, copy into temporary buffer to hold result.
3732 char *begin_of_buf = offset + (char *)iov->iov_base; in smb2_validate_and_copy_iov()
3736 return -EINVAL; in smb2_validate_and_copy_iov()
3755 struct kvec *iov = rqst->rq_iov; in SMB2_query_info_init()
3762 return -EINVAL; in SMB2_query_info_init()
3769 req->InfoType = info_type; in SMB2_query_info_init()
3770 req->FileInfoClass = info_class; in SMB2_query_info_init()
3771 req->PersistentFileId = persistent_fid; in SMB2_query_info_init()
3772 req->VolatileFileId = volatile_fid; in SMB2_query_info_init()
3773 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_query_info_init()
3775 req->OutputBufferLength = cpu_to_le32(output_len); in SMB2_query_info_init()
3777 req->InputBufferLength = cpu_to_le32(input_len); in SMB2_query_info_init()
3779 req->InputBufferOffset = cpu_to_le16(total_len - 1); in SMB2_query_info_init()
3780 memcpy(req->Buffer, input, input_len); in SMB2_query_info_init()
3792 if (rqst && rqst->rq_iov) in SMB2_query_info_free()
3793 cifs_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_info_free()
3808 struct cifs_ses *ses = tcon->ses; in query_info()
3817 return -EIO; in query_info()
3826 return -EIO; in query_info()
3843 trace_smb3_query_info_enter(xid, persistent_fid, tcon->tid, in query_info()
3844 ses->Suid, info_class, (__u32)info_type); in query_info()
3855 trace_smb3_query_info_err(xid, persistent_fid, tcon->tid, in query_info()
3856 ses->Suid, info_class, (__u32)info_type, rc); in query_info()
3860 trace_smb3_query_info_done(xid, persistent_fid, tcon->tid, in query_info()
3861 ses->Suid, info_class, (__u32)info_type); in query_info()
3864 *dlen = le32_to_cpu(rsp->OutputBufferLength); in query_info()
3872 rc = -ENOMEM; in query_info()
3879 rc = smb2_validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset), in query_info()
3880 le32_to_cpu(rsp->OutputBufferLength), in query_info()
3953 * See MS-SMB2 2.2.35 and 2.2.36
3963 struct kvec *iov = rqst->rq_iov; in SMB2_notify_init()
3972 req->PersistentFileId = persistent_fid; in SMB2_notify_init()
3973 req->VolatileFileId = volatile_fid; in SMB2_notify_init()
3974 /* See note 354 of MS-SMB2, 64K max */ in SMB2_notify_init()
3975 req->OutputBufferLength = in SMB2_notify_init()
3976 cpu_to_le32(SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE); in SMB2_notify_init()
3977 req->CompletionFilter = cpu_to_le32(completion_filter); in SMB2_notify_init()
3979 req->Flags = cpu_to_le16(SMB2_WATCH_TREE); in SMB2_notify_init()
3981 req->Flags = 0; in SMB2_notify_init()
3995 struct cifs_ses *ses = tcon->ses; in SMB2_change_notify()
4013 return -EIO; in SMB2_change_notify()
4032 trace_smb3_notify_enter(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
4043 trace_smb3_notify_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_change_notify()
4046 trace_smb3_notify_done(xid, persistent_fid, tcon->tid, in SMB2_change_notify()
4047 ses->Suid, (u8)watch_tree, completion_filter); in SMB2_change_notify()
4055 smb2_validate_iov(le16_to_cpu(smb_rsp->OutputBufferOffset), in SMB2_change_notify()
4056 le32_to_cpu(smb_rsp->OutputBufferLength), &rsp_iov, in SMB2_change_notify()
4059 *out_data = kmemdup((char *)smb_rsp + le16_to_cpu(smb_rsp->OutputBufferOffset), in SMB2_change_notify()
4060 le32_to_cpu(smb_rsp->OutputBufferLength), GFP_KERNEL); in SMB2_change_notify()
4062 rc = -ENOMEM; in SMB2_change_notify()
4065 *plen = le32_to_cpu(smb_rsp->OutputBufferLength); in SMB2_change_notify()
4083 * This is a no-op for now. We're not really interested in the reply, but
4084 * rather in the fact that the server sent one and that server->lstrp
4092 struct TCP_Server_Info *server = mid->callback_data; in smb2_echo_callback()
4093 struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf; in smb2_echo_callback()
4096 if (mid->mid_state == MID_RESPONSE_RECEIVED in smb2_echo_callback()
4097 || mid->mid_state == MID_RESPONSE_MALFORMED) { in smb2_echo_callback()
4098 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_echo_callback()
4099 credits.instance = server->reconnect_instance; in smb2_echo_callback()
4121 if (!server->srv_count) { in smb2_reconnect_server()
4125 server->srv_count++; in smb2_reconnect_server()
4129 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in smb2_reconnect_server()
4131 /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ in smb2_reconnect_server()
4132 mutex_lock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4135 if (server->terminate) { in smb2_reconnect_server()
4137 mutex_unlock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4146 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { in smb2_reconnect_server()
4147 spin_lock(&ses->ses_lock); in smb2_reconnect_server()
4148 if (ses->ses_status == SES_EXITING) { in smb2_reconnect_server()
4149 spin_unlock(&ses->ses_lock); in smb2_reconnect_server()
4152 spin_unlock(&ses->ses_lock); in smb2_reconnect_server()
4156 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in smb2_reconnect_server()
4157 if (tcon->need_reconnect || tcon->need_reopen_files) { in smb2_reconnect_server()
4158 tcon->tc_count++; in smb2_reconnect_server()
4159 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in smb2_reconnect_server()
4161 list_add_tail(&tcon->rlist, &tmp_list); in smb2_reconnect_server()
4169 if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) { in smb2_reconnect_server()
4170 list_add_tail(&ses->tcon_ipc->rlist, &tmp_list); in smb2_reconnect_server()
4179 spin_lock(&ses->chan_lock); in smb2_reconnect_server()
4181 list_add_tail(&ses->rlist, &tmp_ses_list); in smb2_reconnect_server()
4185 spin_unlock(&ses->chan_lock); in smb2_reconnect_server()
4195 list_del_init(&tcon->rlist); in smb2_reconnect_server()
4196 if (tcon->ipc) in smb2_reconnect_server()
4197 cifs_put_smb_ses(tcon->ses); in smb2_reconnect_server()
4210 list_del_init(&ses->rlist); in smb2_reconnect_server()
4216 tcon->status = TID_GOOD; in smb2_reconnect_server()
4217 tcon->retry = false; in smb2_reconnect_server()
4218 tcon->need_reconnect = false; in smb2_reconnect_server()
4222 tcon->ses = ses; in smb2_reconnect_server()
4226 list_del_init(&ses->rlist); in smb2_reconnect_server()
4234 queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); in smb2_reconnect_server()
4235 mutex_unlock(&pserver->reconnect_mutex); in smb2_reconnect_server()
4251 cifs_dbg(FYI, "In echo request for conn_id %lld\n", server->conn_id); in SMB2_echo()
4253 spin_lock(&server->srv_lock); in SMB2_echo()
4254 if (server->ops->need_neg && in SMB2_echo()
4255 server->ops->need_neg(server)) { in SMB2_echo()
4256 spin_unlock(&server->srv_lock); in SMB2_echo()
4258 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in SMB2_echo()
4261 spin_unlock(&server->srv_lock); in SMB2_echo()
4268 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_echo()
4285 if (rqst && rqst->rq_iov) in SMB2_flush_free()
4286 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_flush_free()
4295 struct kvec *iov = rqst->rq_iov; in SMB2_flush_init()
4304 req->PersistentFileId = persistent_fid; in SMB2_flush_init()
4305 req->VolatileFileId = volatile_fid; in SMB2_flush_init()
4317 struct cifs_ses *ses = tcon->ses; in SMB2_flush()
4333 if (!ses || !(ses->server)) in SMB2_flush()
4334 return -EIO; in SMB2_flush()
4349 trace_smb3_flush_enter(xid, persistent_fid, tcon->tid, ses->Suid); in SMB2_flush()
4359 trace_smb3_flush_err(xid, persistent_fid, tcon->tid, ses->Suid, in SMB2_flush()
4362 trace_smb3_flush_done(xid, persistent_fid, tcon->tid, in SMB2_flush()
4363 ses->Suid); in SMB2_flush()
4379 struct TCP_Server_Info *server = io_parms->server; in smb3_use_rdma_offload()
4380 struct cifs_tcon *tcon = io_parms->tcon; in smb3_use_rdma_offload()
4387 if (!server->rdma || !server->smbd_conn) in smb3_use_rdma_offload()
4391 if (server->sign) in smb3_use_rdma_offload()
4399 if (io_parms->length < server->smbd_conn->rdma_readwrite_threshold) in smb3_use_rdma_offload()
4415 int rc = -EACCES; in smb2_new_read_req()
4418 struct TCP_Server_Info *server = io_parms->server; in smb2_new_read_req()
4420 rc = smb2_plain_req_init(SMB2_READ, io_parms->tcon, server, in smb2_new_read_req()
4426 return -ECONNABORTED; in smb2_new_read_req()
4428 shdr = &req->hdr; in smb2_new_read_req()
4429 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in smb2_new_read_req()
4431 req->PersistentFileId = io_parms->persistent_fid; in smb2_new_read_req()
4432 req->VolatileFileId = io_parms->volatile_fid; in smb2_new_read_req()
4433 req->ReadChannelInfoOffset = 0; /* reserved */ in smb2_new_read_req()
4434 req->ReadChannelInfoLength = 0; /* reserved */ in smb2_new_read_req()
4435 req->Channel = 0; /* reserved */ in smb2_new_read_req()
4436 req->MinimumCount = 0; in smb2_new_read_req()
4437 req->Length = cpu_to_le32(io_parms->length); in smb2_new_read_req()
4438 req->Offset = cpu_to_le64(io_parms->offset); in smb2_new_read_req()
4440 trace_smb3_read_enter(rdata ? rdata->rreq->debug_id : 0, in smb2_new_read_req()
4441 rdata ? rdata->subreq.debug_index : 0, in smb2_new_read_req()
4442 rdata ? rdata->xid : 0, in smb2_new_read_req()
4443 io_parms->persistent_fid, in smb2_new_read_req()
4444 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in smb2_new_read_req()
4445 io_parms->offset, io_parms->length); in smb2_new_read_req()
4453 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_new_read_req()
4455 rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter, in smb2_new_read_req()
4457 if (!rdata->mr) in smb2_new_read_req()
4458 return -EAGAIN; in smb2_new_read_req()
4460 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_new_read_req()
4462 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_new_read_req()
4463 req->ReadChannelInfoOffset = in smb2_new_read_req()
4465 req->ReadChannelInfoLength = in smb2_new_read_req()
4467 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_new_read_req()
4468 v1->offset = cpu_to_le64(rdata->mr->mr->iova); in smb2_new_read_req()
4469 v1->token = cpu_to_le32(rdata->mr->mr->rkey); in smb2_new_read_req()
4470 v1->length = cpu_to_le32(rdata->mr->mr->length); in smb2_new_read_req()
4472 *total_len += sizeof(*v1) - 1; in smb2_new_read_req()
4477 /* next 8-byte aligned request */ in smb2_new_read_req()
4479 shdr->NextCommand = cpu_to_le32(*total_len); in smb2_new_read_req()
4481 shdr->NextCommand = 0; in smb2_new_read_req()
4483 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_new_read_req()
4488 shdr->SessionId = cpu_to_le64(0xFFFFFFFFFFFFFFFF); in smb2_new_read_req()
4489 shdr->Id.SyncId.TreeId = cpu_to_le32(0xFFFFFFFF); in smb2_new_read_req()
4490 req->PersistentFileId = (u64)-1; in smb2_new_read_req()
4491 req->VolatileFileId = (u64)-1; in smb2_new_read_req()
4494 if (remaining_bytes > io_parms->length) in smb2_new_read_req()
4495 req->RemainingBytes = cpu_to_le32(remaining_bytes); in smb2_new_read_req()
4497 req->RemainingBytes = 0; in smb2_new_read_req()
4508 netfs_read_subreq_terminated(&rdata->subreq, rdata->result, false); in smb2_readv_worker()
4514 struct cifs_io_subrequest *rdata = mid->callback_data; in smb2_readv_callback()
4515 struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode); in smb2_readv_callback()
4516 struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_readv_callback()
4517 struct TCP_Server_Info *server = rdata->server; in smb2_readv_callback()
4519 (struct smb2_hdr *)rdata->iov[0].iov_base; in smb2_readv_callback()
4523 .rreq_debug_id = rdata->rreq->debug_id, in smb2_readv_callback()
4524 .rreq_debug_index = rdata->subreq.debug_index, in smb2_readv_callback()
4526 struct smb_rqst rqst = { .rq_iov = &rdata->iov[1], .rq_nvec = 1 }; in smb2_readv_callback()
4527 unsigned int rreq_debug_id = rdata->rreq->debug_id; in smb2_readv_callback()
4528 unsigned int subreq_debug_index = rdata->subreq.debug_index; in smb2_readv_callback()
4530 if (rdata->got_bytes) { in smb2_readv_callback()
4531 rqst.rq_iter = rdata->subreq.io_iter; in smb2_readv_callback()
4534 WARN_ONCE(rdata->server != mid->server, in smb2_readv_callback()
4536 rdata->server, mid->server); in smb2_readv_callback()
4539 __func__, mid->mid, mid->mid_state, rdata->result, in smb2_readv_callback()
4540 rdata->got_bytes, rdata->subreq.len - rdata->subreq.transferred); in smb2_readv_callback()
4542 switch (mid->mid_state) { in smb2_readv_callback()
4544 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
4545 credits.instance = server->reconnect_instance; in smb2_readv_callback()
4547 if (server->sign && !mid->decrypted) { in smb2_readv_callback()
4550 iov_iter_truncate(&rqst.rq_iter, rdata->got_bytes); in smb2_readv_callback()
4557 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
4558 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
4562 __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); in smb2_readv_callback()
4563 rdata->result = -EAGAIN; in smb2_readv_callback()
4564 if (server->sign && rdata->got_bytes) in smb2_readv_callback()
4566 rdata->got_bytes = 0; in smb2_readv_callback()
4568 task_io_account_read(rdata->got_bytes); in smb2_readv_callback()
4569 cifs_stats_bytes_read(tcon, rdata->got_bytes); in smb2_readv_callback()
4572 credits.value = le16_to_cpu(shdr->CreditRequest); in smb2_readv_callback()
4573 credits.instance = server->reconnect_instance; in smb2_readv_callback()
4576 rdata->result = -EIO; in smb2_readv_callback()
4584 if (rdata->mr) { in smb2_readv_callback()
4585 smbd_deregister_mr(rdata->mr); in smb2_readv_callback()
4586 rdata->mr = NULL; in smb2_readv_callback()
4589 if (rdata->result && rdata->result != -ENODATA) { in smb2_readv_callback()
4591 trace_smb3_read_err(rdata->rreq->debug_id, in smb2_readv_callback()
4592 rdata->subreq.debug_index, in smb2_readv_callback()
4593 rdata->xid, in smb2_readv_callback()
4594 rdata->req->cfile->fid.persistent_fid, in smb2_readv_callback()
4595 tcon->tid, tcon->ses->Suid, in smb2_readv_callback()
4596 rdata->subreq.start + rdata->subreq.transferred, in smb2_readv_callback()
4597 rdata->subreq.len - rdata->subreq.transferred, in smb2_readv_callback()
4598 rdata->result); in smb2_readv_callback()
4600 trace_smb3_read_done(rdata->rreq->debug_id, in smb2_readv_callback()
4601 rdata->subreq.debug_index, in smb2_readv_callback()
4602 rdata->xid, in smb2_readv_callback()
4603 rdata->req->cfile->fid.persistent_fid, in smb2_readv_callback()
4604 tcon->tid, tcon->ses->Suid, in smb2_readv_callback()
4605 rdata->subreq.start + rdata->subreq.transferred, in smb2_readv_callback()
4606 rdata->got_bytes); in smb2_readv_callback()
4608 if (rdata->result == -ENODATA) { in smb2_readv_callback()
4609 __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); in smb2_readv_callback()
4610 rdata->result = 0; in smb2_readv_callback()
4612 size_t trans = rdata->subreq.transferred + rdata->got_bytes; in smb2_readv_callback()
4613 if (trans < rdata->subreq.len && in smb2_readv_callback()
4614 rdata->subreq.start + trans == ictx->remote_i_size) { in smb2_readv_callback()
4615 __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); in smb2_readv_callback()
4616 rdata->result = 0; in smb2_readv_callback()
4618 __set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags); in smb2_readv_callback()
4620 trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, in smb2_readv_callback()
4621 server->credits, server->in_flight, in smb2_readv_callback()
4623 rdata->credits.value = 0; in smb2_readv_callback()
4624 rdata->subreq.transferred += rdata->got_bytes; in smb2_readv_callback()
4625 trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_progress); in smb2_readv_callback()
4626 INIT_WORK(&rdata->subreq.work, smb2_readv_worker); in smb2_readv_callback()
4627 queue_work(cifsiod_wq, &rdata->subreq.work); in smb2_readv_callback()
4630 server->credits, server->in_flight, in smb2_readv_callback()
4635 /* smb2_async_readv - send an async read, and set up mid to handle result */
4641 struct netfs_io_subrequest *subreq = &rdata->subreq; in smb2_async_readv()
4644 struct smb_rqst rqst = { .rq_iov = rdata->iov, in smb2_async_readv()
4647 struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_async_readv()
4652 __func__, subreq->start, subreq->len); in smb2_async_readv()
4654 if (!rdata->server) in smb2_async_readv()
4655 rdata->server = cifs_pick_channel(tcon->ses); in smb2_async_readv()
4657 io_parms.tcon = tlink_tcon(rdata->req->cfile->tlink); in smb2_async_readv()
4658 io_parms.server = server = rdata->server; in smb2_async_readv()
4659 io_parms.offset = subreq->start + subreq->transferred; in smb2_async_readv()
4660 io_parms.length = subreq->len - subreq->transferred; in smb2_async_readv()
4661 io_parms.persistent_fid = rdata->req->cfile->fid.persistent_fid; in smb2_async_readv()
4662 io_parms.volatile_fid = rdata->req->cfile->fid.volatile_fid; in smb2_async_readv()
4663 io_parms.pid = rdata->req->pid; in smb2_async_readv()
4673 rdata->iov[0].iov_base = buf; in smb2_async_readv()
4674 rdata->iov[0].iov_len = total_len; in smb2_async_readv()
4675 rdata->got_bytes = 0; in smb2_async_readv()
4676 rdata->result = 0; in smb2_async_readv()
4680 if (rdata->credits.value > 0) { in smb2_async_readv()
4681 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(io_parms.length, in smb2_async_readv()
4683 credit_request = le16_to_cpu(shdr->CreditCharge) + 8; in smb2_async_readv()
4684 if (server->credits >= server->max_credits) in smb2_async_readv()
4685 shdr->CreditRequest = cpu_to_le16(0); in smb2_async_readv()
4687 shdr->CreditRequest = cpu_to_le16( in smb2_async_readv()
4688 min_t(int, server->max_credits - in smb2_async_readv()
4689 server->credits, credit_request)); in smb2_async_readv()
4701 &rdata->credits); in smb2_async_readv()
4704 trace_smb3_read_err(rdata->rreq->debug_id, in smb2_async_readv()
4705 subreq->debug_index, in smb2_async_readv()
4706 rdata->xid, io_parms.persistent_fid, in smb2_async_readv()
4707 io_parms.tcon->tid, in smb2_async_readv()
4708 io_parms.tcon->ses->Suid, in smb2_async_readv()
4710 subreq->len - subreq->transferred, rc); in smb2_async_readv()
4730 struct cifs_ses *ses = io_parms->tcon->ses; in SMB2_read()
4732 if (!io_parms->server) in SMB2_read()
4733 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_read()
4740 if (smb3_encryption_required(io_parms->tcon)) in SMB2_read()
4750 rc = cifs_send_recv(xid, ses, io_parms->server, in SMB2_read()
4755 if (rc != -ENODATA) { in SMB2_read()
4756 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); in SMB2_read()
4759 req->PersistentFileId, in SMB2_read()
4760 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4761 io_parms->offset, io_parms->length, in SMB2_read()
4765 req->PersistentFileId, io_parms->tcon->tid, in SMB2_read()
4766 ses->Suid, io_parms->offset, 0); in SMB2_read()
4769 return rc == -ENODATA ? 0 : rc; in SMB2_read()
4772 req->PersistentFileId, in SMB2_read()
4773 io_parms->tcon->tid, ses->Suid, in SMB2_read()
4774 io_parms->offset, io_parms->length); in SMB2_read()
4778 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_read()
4780 (*nbytes > io_parms->length)) { in SMB2_read()
4782 *nbytes, io_parms->length); in SMB2_read()
4783 rc = -EIO; in SMB2_read()
4788 memcpy(*buf, (char *)rsp + rsp->DataOffset, *nbytes); in SMB2_read()
4807 struct cifs_io_subrequest *wdata = mid->callback_data; in smb2_writev_callback()
4808 struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink); in smb2_writev_callback()
4809 struct TCP_Server_Info *server = wdata->server; in smb2_writev_callback()
4810 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; in smb2_writev_callback()
4814 .rreq_debug_id = wdata->rreq->debug_id, in smb2_writev_callback()
4815 .rreq_debug_index = wdata->subreq.debug_index, in smb2_writev_callback()
4817 unsigned int rreq_debug_id = wdata->rreq->debug_id; in smb2_writev_callback()
4818 unsigned int subreq_debug_index = wdata->subreq.debug_index; in smb2_writev_callback()
4822 WARN_ONCE(wdata->server != mid->server, in smb2_writev_callback()
4824 wdata->server, mid->server); in smb2_writev_callback()
4826 switch (mid->mid_state) { in smb2_writev_callback()
4828 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_writev_callback()
4829 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4834 written = le32_to_cpu(rsp->DataLength); in smb2_writev_callback()
4841 if (written > wdata->subreq.len) in smb2_writev_callback()
4846 if (written < wdata->subreq.len) { in smb2_writev_callback()
4847 wdata->result = -ENOSPC; in smb2_writev_callback()
4849 wdata->subreq.len = written; in smb2_writev_callback()
4850 __set_bit(NETFS_SREQ_MADE_PROGRESS, &wdata->subreq.flags); in smb2_writev_callback()
4855 result = -EAGAIN; in smb2_writev_callback()
4858 credits.value = le16_to_cpu(rsp->hdr.CreditRequest); in smb2_writev_callback()
4859 credits.instance = server->reconnect_instance; in smb2_writev_callback()
4862 result = -EIO; in smb2_writev_callback()
4869 * used MR as soon as I/O is finished. Hold MR longer in the later in smb2_writev_callback()
4873 if (wdata->mr) { in smb2_writev_callback()
4874 smbd_deregister_mr(wdata->mr); in smb2_writev_callback()
4875 wdata->mr = NULL; in smb2_writev_callback()
4880 trace_smb3_write_err(wdata->rreq->debug_id, in smb2_writev_callback()
4881 wdata->subreq.debug_index, in smb2_writev_callback()
4882 wdata->xid, in smb2_writev_callback()
4883 wdata->req->cfile->fid.persistent_fid, in smb2_writev_callback()
4884 tcon->tid, tcon->ses->Suid, wdata->subreq.start, in smb2_writev_callback()
4885 wdata->subreq.len, wdata->result); in smb2_writev_callback()
4886 if (wdata->result == -ENOSPC) in smb2_writev_callback()
4888 tcon->tree_name); in smb2_writev_callback()
4890 trace_smb3_write_done(wdata->rreq->debug_id, in smb2_writev_callback()
4891 wdata->subreq.debug_index, in smb2_writev_callback()
4892 wdata->xid, in smb2_writev_callback()
4893 wdata->req->cfile->fid.persistent_fid, in smb2_writev_callback()
4894 tcon->tid, tcon->ses->Suid, in smb2_writev_callback()
4895 wdata->subreq.start, wdata->subreq.len); in smb2_writev_callback()
4897 trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, wdata->credits.value, in smb2_writev_callback()
4898 server->credits, server->in_flight, in smb2_writev_callback()
4900 wdata->credits.value = 0; in smb2_writev_callback()
4901 trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_progress); in smb2_writev_callback()
4905 server->credits, server->in_flight, in smb2_writev_callback()
4910 /* smb2_async_writev - send an async write, and set up mid to handle result */
4914 int rc = -EACCES, flags = 0; in smb2_async_writev()
4917 struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink); in smb2_async_writev()
4918 struct TCP_Server_Info *server = wdata->server; in smb2_async_writev()
4921 unsigned int total_len, xid = wdata->xid; in smb2_async_writev()
4933 .offset = wdata->subreq.start, in smb2_async_writev()
4934 .length = wdata->subreq.len, in smb2_async_writev()
4935 .persistent_fid = wdata->req->cfile->fid.persistent_fid, in smb2_async_writev()
4936 .volatile_fid = wdata->req->cfile->fid.volatile_fid, in smb2_async_writev()
4937 .pid = wdata->req->pid, in smb2_async_writev()
4947 rqst.rq_iter = wdata->subreq.io_iter; in smb2_async_writev()
4949 rqst.rq_iov[0].iov_len = total_len - 1; in smb2_async_writev()
4957 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in smb2_async_writev()
4959 req->PersistentFileId = io_parms->persistent_fid; in smb2_async_writev()
4960 req->VolatileFileId = io_parms->volatile_fid; in smb2_async_writev()
4961 req->WriteChannelInfoOffset = 0; in smb2_async_writev()
4962 req->WriteChannelInfoLength = 0; in smb2_async_writev()
4963 req->Channel = SMB2_CHANNEL_NONE; in smb2_async_writev()
4964 req->Length = cpu_to_le32(io_parms->length); in smb2_async_writev()
4965 req->Offset = cpu_to_le64(io_parms->offset); in smb2_async_writev()
4966 req->DataOffset = cpu_to_le16( in smb2_async_writev()
4968 req->RemainingBytes = 0; in smb2_async_writev()
4970 trace_smb3_write_enter(wdata->rreq->debug_id, in smb2_async_writev()
4971 wdata->subreq.debug_index, in smb2_async_writev()
4972 wdata->xid, in smb2_async_writev()
4973 io_parms->persistent_fid, in smb2_async_writev()
4974 io_parms->tcon->tid, in smb2_async_writev()
4975 io_parms->tcon->ses->Suid, in smb2_async_writev()
4976 io_parms->offset, in smb2_async_writev()
4977 io_parms->length); in smb2_async_writev()
4986 bool need_invalidate = server->dialect == SMB30_PROT_ID; in smb2_async_writev()
4988 wdata->mr = smbd_register_mr(server->smbd_conn, &wdata->subreq.io_iter, in smb2_async_writev()
4990 if (!wdata->mr) { in smb2_async_writev()
4991 rc = -EAGAIN; in smb2_async_writev()
4995 req->RemainingBytes = req->Length; in smb2_async_writev()
4996 req->Length = 0; in smb2_async_writev()
4997 req->DataOffset = 0; in smb2_async_writev()
4998 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; in smb2_async_writev()
5000 req->Channel = SMB2_CHANNEL_RDMA_V1; in smb2_async_writev()
5001 req->WriteChannelInfoOffset = in smb2_async_writev()
5003 req->WriteChannelInfoLength = in smb2_async_writev()
5005 v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0]; in smb2_async_writev()
5006 v1->offset = cpu_to_le64(wdata->mr->mr->iova); in smb2_async_writev()
5007 v1->token = cpu_to_le32(wdata->mr->mr->rkey); in smb2_async_writev()
5008 v1->length = cpu_to_le32(wdata->mr->mr->length); in smb2_async_writev()
5013 * We keep wdata->subreq.io_iter, in smb2_async_writev()
5020 if (wdata->subreq.retry_count > 0) in smb2_async_writev()
5024 io_parms->offset, io_parms->length, iov_iter_count(&wdata->subreq.io_iter)); in smb2_async_writev()
5026 if (wdata->credits.value > 0) { in smb2_async_writev()
5027 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->subreq.len, in smb2_async_writev()
5029 credit_request = le16_to_cpu(shdr->CreditCharge) + 8; in smb2_async_writev()
5030 if (server->credits >= server->max_credits) in smb2_async_writev()
5031 shdr->CreditRequest = cpu_to_le16(0); in smb2_async_writev()
5033 shdr->CreditRequest = cpu_to_le16( in smb2_async_writev()
5034 min_t(int, server->max_credits - in smb2_async_writev()
5035 server->credits, credit_request)); in smb2_async_writev()
5049 wdata, flags, &wdata->credits); in smb2_async_writev()
5050 /* Can't touch wdata if rc == 0 */ in smb2_async_writev()
5052 trace_smb3_write_err(wdata->rreq->debug_id, in smb2_async_writev()
5053 wdata->subreq.debug_index, in smb2_async_writev()
5055 io_parms->persistent_fid, in smb2_async_writev()
5056 io_parms->tcon->tid, in smb2_async_writev()
5057 io_parms->tcon->ses->Suid, in smb2_async_writev()
5058 io_parms->offset, in smb2_async_writev()
5059 io_parms->length, in smb2_async_writev()
5068 trace_smb3_rw_credits(wdata->rreq->debug_id, in smb2_async_writev()
5069 wdata->subreq.debug_index, in smb2_async_writev()
5070 wdata->credits.value, in smb2_async_writev()
5071 server->credits, server->in_flight, in smb2_async_writev()
5072 -(int)wdata->credits.value, in smb2_async_writev()
5074 add_credits_and_wake_if(wdata->server, &wdata->credits, 0); in smb2_async_writev()
5104 if (!io_parms->server) in SMB2_write()
5105 io_parms->server = cifs_pick_channel(io_parms->tcon->ses); in SMB2_write()
5106 server = io_parms->server; in SMB2_write()
5108 return -ECONNABORTED; in SMB2_write()
5113 rc = smb2_plain_req_init(SMB2_WRITE, io_parms->tcon, server, in SMB2_write()
5118 if (smb3_encryption_required(io_parms->tcon)) in SMB2_write()
5121 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid); in SMB2_write()
5123 req->PersistentFileId = io_parms->persistent_fid; in SMB2_write()
5124 req->VolatileFileId = io_parms->volatile_fid; in SMB2_write()
5125 req->WriteChannelInfoOffset = 0; in SMB2_write()
5126 req->WriteChannelInfoLength = 0; in SMB2_write()
5127 req->Channel = 0; in SMB2_write()
5128 req->Length = cpu_to_le32(io_parms->length); in SMB2_write()
5129 req->Offset = cpu_to_le64(io_parms->offset); in SMB2_write()
5130 req->DataOffset = cpu_to_le16( in SMB2_write()
5132 req->RemainingBytes = 0; in SMB2_write()
5134 trace_smb3_write_enter(0, 0, xid, io_parms->persistent_fid, in SMB2_write()
5135 io_parms->tcon->tid, io_parms->tcon->ses->Suid, in SMB2_write()
5136 io_parms->offset, io_parms->length); in SMB2_write()
5140 iov[0].iov_len = total_len - 1; in SMB2_write()
5149 rc = cifs_send_recv(xid, io_parms->tcon->ses, server, in SMB2_write()
5156 req->PersistentFileId, in SMB2_write()
5157 io_parms->tcon->tid, in SMB2_write()
5158 io_parms->tcon->ses->Suid, in SMB2_write()
5159 io_parms->offset, io_parms->length, rc); in SMB2_write()
5160 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); in SMB2_write()
5163 *nbytes = le32_to_cpu(rsp->DataLength); in SMB2_write()
5164 cifs_stats_bytes_written(io_parms->tcon, *nbytes); in SMB2_write()
5166 req->PersistentFileId, in SMB2_write()
5167 io_parms->tcon->tid, in SMB2_write()
5168 io_parms->tcon->ses->Suid, in SMB2_write()
5169 io_parms->offset, *nbytes); in SMB2_write()
5176 smb2_should_replay(io_parms->tcon, &retries, &cur_sleep)) in SMB2_write()
5188 return -1; in posix_info_sid_size()
5192 return -1; in posix_info_sid_size()
5196 return -1; in posix_info_sid_size()
5216 end = beg + le32_to_cpu(p->NextEntryOffset); in posix_info_parse()
5224 return -1; in posix_info_parse()
5231 return -1; in posix_info_parse()
5238 return -1; in posix_info_parse()
5243 return -1; in posix_info_parse()
5246 return -1; in posix_info_parse()
5252 return -1; in posix_info_parse()
5256 out->base = beg; in posix_info_parse()
5257 out->size = total_len; in posix_info_parse()
5258 out->name_len = name_len; in posix_info_parse()
5259 out->name = name; in posix_info_parse()
5260 memcpy(&out->owner, owner_sid, owner_len); in posix_info_parse()
5261 memcpy(&out->group, group_sid, group_len); in posix_info_parse()
5271 return -1; in posix_info_extra_size()
5272 return len - sizeof(struct smb2_posix_info); in posix_info_extra_size()
5304 len = le32_to_cpu(dir_info->FileNameLength); in num_entries()
5318 next_offset = le32_to_cpu(dir_info->NextEntryOffset); in num_entries()
5339 unsigned int output_size = CIFSMaxBufSize - in SMB2_query_directory_init()
5340 MAX_SMB2_CREATE_RESPONSE_SIZE - in SMB2_query_directory_init()
5343 struct kvec *iov = rqst->rq_iov; in SMB2_query_directory_init()
5353 req->FileInformationClass = FILE_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5356 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5359 req->FileInformationClass = SMB_FIND_FILE_POSIX_INFO; in SMB2_query_directory_init()
5362 req->FileInformationClass = FILE_FULL_DIRECTORY_INFORMATION; in SMB2_query_directory_init()
5367 return -EINVAL; in SMB2_query_directory_init()
5370 req->FileIndex = cpu_to_le32(index); in SMB2_query_directory_init()
5371 req->PersistentFileId = persistent_fid; in SMB2_query_directory_init()
5372 req->VolatileFileId = volatile_fid; in SMB2_query_directory_init()
5375 bufptr = req->Buffer; in SMB2_query_directory_init()
5378 req->FileNameOffset = in SMB2_query_directory_init()
5380 req->FileNameLength = cpu_to_le16(len); in SMB2_query_directory_init()
5385 output_size = min_t(unsigned int, output_size, server->maxBuf); in SMB2_query_directory_init()
5387 req->OutputBufferLength = cpu_to_le32(output_size); in SMB2_query_directory_init()
5391 iov[0].iov_len = total_len - 1; in SMB2_query_directory_init()
5393 iov[1].iov_base = (char *)(req->Buffer); in SMB2_query_directory_init()
5396 trace_smb3_query_dir_enter(xid, persistent_fid, tcon->tid, in SMB2_query_directory_init()
5397 tcon->ses->Suid, index, output_size); in SMB2_query_directory_init()
5404 if (rqst && rqst->rq_iov) { in SMB2_query_directory_free()
5405 cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_query_directory_free()
5420 rsp = (struct smb2_query_directory_rsp *)rsp_iov->iov_base; in smb2_parse_query_directory()
5422 switch (srch_inf->info_level) { in smb2_parse_query_directory()
5438 srch_inf->info_level); in smb2_parse_query_directory()
5439 return -EINVAL; in smb2_parse_query_directory()
5442 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_parse_query_directory()
5443 le32_to_cpu(rsp->OutputBufferLength), rsp_iov, in smb2_parse_query_directory()
5450 srch_inf->unicode = true; in smb2_parse_query_directory()
5452 if (srch_inf->ntwrk_buf_start) { in smb2_parse_query_directory()
5453 if (srch_inf->smallBuf) in smb2_parse_query_directory()
5454 cifs_small_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
5456 cifs_buf_release(srch_inf->ntwrk_buf_start); in smb2_parse_query_directory()
5458 srch_inf->ntwrk_buf_start = (char *)rsp; in smb2_parse_query_directory()
5459 srch_inf->srch_entries_start = srch_inf->last_entry = in smb2_parse_query_directory()
5460 (char *)rsp + le16_to_cpu(rsp->OutputBufferOffset); in smb2_parse_query_directory()
5461 end_of_smb = rsp_iov->iov_len + (char *)rsp; in smb2_parse_query_directory()
5463 srch_inf->entries_in_buffer = num_entries( in smb2_parse_query_directory()
5464 srch_inf->info_level, in smb2_parse_query_directory()
5465 srch_inf->srch_entries_start, in smb2_parse_query_directory()
5467 &srch_inf->last_entry, in smb2_parse_query_directory()
5470 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; in smb2_parse_query_directory()
5472 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, in smb2_parse_query_directory()
5473 srch_inf->srch_entries_start, srch_inf->last_entry); in smb2_parse_query_directory()
5475 srch_inf->smallBuf = false; in smb2_parse_query_directory()
5477 srch_inf->smallBuf = true; in smb2_parse_query_directory()
5495 struct cifs_ses *ses = tcon->ses; in SMB2_query_directory()
5505 if (!ses || !(ses->server)) in SMB2_query_directory()
5506 return -EIO; in SMB2_query_directory()
5519 srch_inf->info_level); in SMB2_query_directory()
5531 if (rc == -ENODATA && in SMB2_query_directory()
5532 rsp->hdr.Status == STATUS_NO_MORE_FILES) { in SMB2_query_directory()
5534 tcon->tid, tcon->ses->Suid, index, 0); in SMB2_query_directory()
5535 srch_inf->endOfSearch = true; in SMB2_query_directory()
5538 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5539 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
5548 trace_smb3_query_dir_err(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5549 tcon->ses->Suid, index, 0, rc); in SMB2_query_directory()
5554 trace_smb3_query_dir_done(xid, persistent_fid, tcon->tid, in SMB2_query_directory()
5555 tcon->ses->Suid, index, srch_inf->entries_in_buffer); in SMB2_query_directory()
5576 struct kvec *iov = rqst->rq_iov; in SMB2_set_info_init()
5585 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(pid); in SMB2_set_info_init()
5586 req->InfoType = info_type; in SMB2_set_info_init()
5587 req->FileInfoClass = info_class; in SMB2_set_info_init()
5588 req->PersistentFileId = persistent_fid; in SMB2_set_info_init()
5589 req->VolatileFileId = volatile_fid; in SMB2_set_info_init()
5590 req->AdditionalInformation = cpu_to_le32(additional_info); in SMB2_set_info_init()
5592 req->BufferOffset = cpu_to_le16(sizeof(struct smb2_set_info_req)); in SMB2_set_info_init()
5593 req->BufferLength = cpu_to_le32(*size); in SMB2_set_info_init()
5595 memcpy(req->Buffer, *data, *size); in SMB2_set_info_init()
5600 iov[0].iov_len = total_len - 1; in SMB2_set_info_init()
5602 for (i = 1; i < rqst->rq_nvec; i++) { in SMB2_set_info_init()
5603 le32_add_cpu(&req->BufferLength, size[i]); in SMB2_set_info_init()
5614 if (rqst && rqst->rq_iov) in SMB2_set_info_free()
5615 cifs_buf_release(rqst->rq_iov[0].iov_base); /* request */ in SMB2_set_info_free()
5630 struct cifs_ses *ses = tcon->ses; in send_set_info()
5641 return -EIO; in send_set_info()
5644 return -EINVAL; in send_set_info()
5651 return -ENOMEM; in send_set_info()
5677 trace_smb3_set_info_err(xid, persistent_fid, tcon->tid, in send_set_info()
5678 ses->Suid, info_class, (__u32)info_type, rc); in send_set_info()
5704 trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, new_eof); in SMB2_set_eof()
5717 current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag, in SMB2_set_acl()
5727 current->tgid, FILE_FULL_EA_INFORMATION, SMB2_O_INFO_FILE, in SMB2_set_ea()
5739 struct cifs_ses *ses = tcon->ses; in SMB2_oplock_break()
5762 req->VolatileFid = volatile_fid; in SMB2_oplock_break()
5763 req->PersistentFid = persistent_fid; in SMB2_oplock_break()
5764 req->OplockLevel = oplock_level; in SMB2_oplock_break()
5765 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_oplock_break()
5798 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * in smb2_copy_fs_info_to_kstatfs()
5799 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); in smb2_copy_fs_info_to_kstatfs()
5800 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5801 kst->f_bfree = kst->f_bavail = in smb2_copy_fs_info_to_kstatfs()
5802 le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); in smb2_copy_fs_info_to_kstatfs()
5810 kst->f_bsize = le32_to_cpu(response_data->BlockSize); in copy_posix_fs_info_to_kstatfs()
5811 kst->f_blocks = le64_to_cpu(response_data->TotalBlocks); in copy_posix_fs_info_to_kstatfs()
5812 kst->f_bfree = le64_to_cpu(response_data->BlocksAvail); in copy_posix_fs_info_to_kstatfs()
5813 if (response_data->UserBlocksAvail == cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5814 kst->f_bavail = kst->f_bfree; in copy_posix_fs_info_to_kstatfs()
5816 kst->f_bavail = le64_to_cpu(response_data->UserBlocksAvail); in copy_posix_fs_info_to_kstatfs()
5817 if (response_data->TotalFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5818 kst->f_files = le64_to_cpu(response_data->TotalFileNodes); in copy_posix_fs_info_to_kstatfs()
5819 if (response_data->FreeFileNodes != cpu_to_le64(-1)) in copy_posix_fs_info_to_kstatfs()
5820 kst->f_ffree = le64_to_cpu(response_data->FreeFileNodes); in copy_posix_fs_info_to_kstatfs()
5837 if ((tcon->ses == NULL) || server == NULL) in build_qfs_info_req()
5838 return -EIO; in build_qfs_info_req()
5845 req->InfoType = SMB2_O_INFO_FILESYSTEM; in build_qfs_info_req()
5846 req->FileInfoClass = level; in build_qfs_info_req()
5847 req->PersistentFileId = persistent_fid; in build_qfs_info_req()
5848 req->VolatileFileId = volatile_fid; in build_qfs_info_req()
5850 req->InputBufferOffset = in build_qfs_info_req()
5852 req->OutputBufferLength = cpu_to_le32( in build_qfs_info_req()
5855 iov->iov_base = (char *)req; in build_qfs_info_req()
5856 iov->iov_len = total_len; in build_qfs_info_req()
5862 cifs_buf_release(iov->iov_base); in free_qfs_info_req()
5875 struct cifs_ses *ses = tcon->ses; in SMB311_posix_qfs_info()
5913 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB311_posix_qfs_info()
5914 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB311_posix_qfs_info()
5915 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB311_posix_qfs_info()
5940 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_info()
5978 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in SMB2_QFS_info()
5979 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in SMB2_QFS_info()
5980 le32_to_cpu(rsp->OutputBufferLength), &rsp_iov, in SMB2_QFS_info()
6005 struct cifs_ses *ses = tcon->ses; in SMB2_QFS_attr()
6030 return -EINVAL; in SMB2_QFS_attr()
6058 rsp_len = le32_to_cpu(rsp->OutputBufferLength); in SMB2_QFS_attr()
6059 offset = le16_to_cpu(rsp->OutputBufferOffset); in SMB2_QFS_attr()
6065 memcpy(&tcon->fsAttrInfo, offset in SMB2_QFS_attr()
6069 memcpy(&tcon->fsDevInfo, offset in SMB2_QFS_attr()
6074 tcon->ss_flags = le32_to_cpu(ss_info->Flags); in SMB2_QFS_attr()
6075 tcon->perf_sector_size = in SMB2_QFS_attr()
6076 le32_to_cpu(ss_info->PhysicalBytesPerSectorForPerf); in SMB2_QFS_attr()
6080 tcon->vol_serial_number = vol_info->VolumeSerialNumber; in SMB2_QFS_attr()
6081 tcon->vol_create_time = vol_info->VolumeCreationTime; in SMB2_QFS_attr()
6114 server = cifs_pick_channel(tcon->ses); in smb2_lockv()
6126 req->hdr.Id.SyncId.ProcessId = cpu_to_le32(pid); in smb2_lockv()
6127 req->LockCount = cpu_to_le16(num_lock); in smb2_lockv()
6129 req->PersistentFileId = persist_fid; in smb2_lockv()
6130 req->VolatileFileId = volatile_fid; in smb2_lockv()
6135 iov[0].iov_len = total_len - sizeof(struct smb2_lock_element); in smb2_lockv()
6139 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); in smb2_lockv()
6148 rc = cifs_send_recv(xid, tcon->ses, server, in smb2_lockv()
6155 trace_smb3_lock_err(xid, persist_fid, tcon->tid, in smb2_lockv()
6156 tcon->ses->Suid, rc); in smb2_lockv()
6190 struct cifs_ses *ses = tcon->ses; in SMB2_lease_break()
6198 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in SMB2_lease_break()
6209 req->hdr.CreditRequest = cpu_to_le16(1); in SMB2_lease_break()
6210 req->StructureSize = cpu_to_le16(36); in SMB2_lease_break()
6213 memcpy(req->LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in SMB2_lease_break()
6214 req->LeaseState = lease_state; in SMB2_lease_break()
6233 trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
6234 ses->Suid, *please_key_low, *please_key_high, rc); in SMB2_lease_break()
6237 trace_smb3_lease_done(le32_to_cpu(lease_state), tcon->tid, in SMB2_lease_break()
6238 ses->Suid, *please_key_low, *please_key_high); in SMB2_lease_break()