32 #include <linux/kernel.h>
37 #include <linux/xattr.h>
85 char *
temp = (
char *)hdr;
122 if (tcon->
ses && tcon->
ses->server &&
158 cFYI(1,
"can not send cmd %d while umounting",
164 (!tcon->
ses->server))
179 switch (smb2_command) {
203 cFYI(1,
"gave up waiting on reconnect in smb_init");
219 if (!rc && tcon->
ses->need_reconnect)
230 cFYI(1,
"reconnect tcon rc = %d", rc);
247 switch (smb2_command) {
274 rc = smb2_reconnect(smb2_command, tcon);
280 if (*request_buf ==
NULL) {
285 smb2_hdr_assemble((
struct smb2_hdr *) *request_buf, smb2_command, tcon);
288 #ifdef CONFIG_CIFS_STATS2
299 free_rsp_buf(
int resp_buftype,
void *
rsp)
332 unsigned int sec_flags;
334 int blob_offset, blob_length;
338 cFYI(1,
"Negotiate protocol");
357 cFYI(1,
"sec_flags 0x%x", sec_flags);
359 req->
hdr.SessionId = 0;
364 inc_rfc1001_len(req, 2);
380 iov[0].
iov_len = get_rfc1002_length(req) + 4;
382 rc =
SendReceive2(xid, ses, iov, 1, &resp_buftype, flags);
397 cFYI(1,
"negotiated smb2.0 dialect");
399 cFYI(1,
"negotiated smb2.1 dialect");
401 cFYI(1,
"negotiated smb3.0 dialect");
403 cERROR(1,
"Illegal dialect returned by server %d",
421 if (blob_length == 0) {
422 cERROR(1,
"missing security blob on negprot");
427 cFYI(1,
"sec_flags 0x%x", sec_flags);
428 if (sec_flags & CIFSSEC_MUST_SIGN) {
429 cFYI(1,
"Signing required");
432 cERROR(1,
"signing required but server lacks support");
437 }
else if (sec_flags & CIFSSEC_MAY_SIGN) {
438 cFYI(1,
"Signing optional");
440 cFYI(1,
"Server requires signing");
447 cFYI(1,
"Signing disabled");
449 cERROR(1,
"Server requires packet signing to be enabled"
450 " in /proc/fs/cifs/SecurityFlags.");
458 #ifdef CONFIG_SMB2_ASN1
459 rc = decode_neg_token_init(security_blob, blob_length,
470 free_rsp_buf(resp_buftype, rsp);
485 unsigned int sec_flags;
489 char *ntlmssp_blob =
NULL;
490 bool use_spnego =
false;
492 cFYI(1,
"Session Setup");
511 ssetup_ntlmssp_authenticate:
525 cFYI(1,
"sec_flags 0x%x", sec_flags);
527 req->
hdr.SessionId = 0;
546 iov[0].
iov_len = get_rfc1002_length(req) + 4 - 1;
550 if (ntlmssp_blob ==
NULL) {
561 cERROR(1,
"spnego not supported for SMB2 yet");
568 security_blob = ntlmssp_blob;
571 req->
hdr.SessionId = ses->
Suid;
574 if (ntlmssp_blob ==
NULL) {
575 cERROR(1,
"failed to malloc ntlmssp blob");
582 cFYI(1,
"build_ntlmssp_auth_blob failed %d", rc);
590 cERROR(1,
"spnego not supported for SMB2 yet");
595 security_blob = ntlmssp_blob;
598 cERROR(1,
"illegal ntlmssp phase");
611 inc_rfc1001_len(req, blob_length - 1 );
617 kfree(security_blob);
622 cERROR(1,
"Unexpected more processing error");
627 cERROR(1,
"Invalid security buffer offset %d",
636 ses->
Suid = rsp->
hdr.SessionId;
654 free_rsp_buf(resp_buftype, rsp);
658 goto ssetup_ntlmssp_authenticate;
669 cFYI(1,
"disconnect session %p", ses);
681 req->
hdr.SessionId = ses->
Suid;
698 #define MAX_SHARENAME_LENGTH (255 + 80 + 1 )
715 if ((ses->
server) && tree)
720 if (tcon && tcon->bad_network_name)
724 if (unc_path ==
NULL)
729 if (unc_path_len < 2) {
742 req->
hdr.SessionId = ses->
Suid;
749 iov[0].
iov_len = get_rfc1002_length(req) + 4 - 1;
758 inc_rfc1001_len(req, unc_path_len - 1 );
768 goto tcon_error_exit;
777 cFYI(1,
"connection to disk share");
780 cFYI(1,
"connection to pipe share");
783 cFYI(1,
"connection to printer");
787 goto tcon_error_exit;
794 tcon->
tid = rsp->
hdr.TreeId;
799 cERROR(1,
"DFS capability contradicts DFS flag");
802 free_rsp_buf(resp_buftype, rsp);
808 cERROR(1,
"BAD_NETWORK_NAME: %s", tree);
809 tcon->bad_network_name =
true;
822 cFYI(1,
"Tree Disconnect");
844 create_lease_buf(
u8 *lease_key,
u8 oplock)
886 data_offset = (
char *)rsp;
911 u64 *persistent_fid,
u64 *volatile_fid,
__u32 desired_access,
927 cFYI(1,
"create/open");
934 rc = small_smb2_init(
SMB2_CREATE, tcon, (
void **) &req);
945 uni_path_len = (2 * UniStrnlen((
wchar_t *)path,
PATH_MAX)) + 2;
951 iov[0].
iov_len = get_rfc1002_length(req) + 4;
954 if (uni_path_len >= 4) {
958 if (uni_path_len % 8 != 0) {
959 copy_size = uni_path_len / 8 * 8;
960 if (copy_size < uni_path_len)
966 memcpy((
char *)copy_path, (
const char *)path,
968 uni_path_len = copy_size;
978 inc_rfc1001_len(req, uni_path_len - 1);
982 req->
hdr.smb2_buf_length) + 8 - 1);
994 iov[num_iovecs].
iov_base = create_lease_buf(oplock+1, *oplock);
1004 iov[num_iovecs-1].iov_len);
1011 rc =
SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0);
1032 *oplock = parse_lease_state(rsp);
1037 free_rsp_buf(resp_buftype, rsp);
1043 u64 persistent_fid,
u64 volatile_fid)
1055 if (ses && (ses->
server))
1060 rc = small_smb2_init(
SMB2_CLOSE, tcon, (
void **) &req);
1069 iov[0].
iov_len = get_rfc1002_length(req) + 4;
1083 free_rsp_buf(resp_buftype, rsp);
1089 struct smb2_hdr *hdr,
unsigned int min_buf_size)
1093 char *end_of_smb = smb_len + 4 + (
char *)hdr;
1094 char *begin_of_buf = 4 + offset + (
char *)hdr;
1098 if (buffer_length < min_buf_size) {
1099 cERROR(1,
"buffer length %d smaller than minimum size %d",
1100 buffer_length, min_buf_size);
1105 if ((smb_len > 0x7FFFFF) || (buffer_length > 0x7FFFFF)) {
1106 cERROR(1,
"buffer length %d or smb length %d too large",
1107 buffer_length, smb_len);
1111 if ((begin_of_buf > end_of_smb) || (end_of_buf > end_of_smb)) {
1112 cERROR(1,
"illegal server response, bad offset to data");
1124 validate_and_copy_buf(
unsigned int offset,
unsigned int buffer_length,
1125 struct smb2_hdr *hdr,
unsigned int minbufsize,
1129 char *begin_of_buf = 4 + offset + (
char *)hdr;
1135 rc = validate_buf(offset, buffer_length, hdr, minbufsize);
1139 memcpy(data, begin_of_buf, buffer_length);
1145 query_info(
const unsigned int xid,
struct cifs_tcon *tcon,
1146 u64 persistent_fid,
u64 volatile_fid,
u8 info_class,
1147 size_t output_len,
size_t min_len,
void *data)
1157 cFYI(1,
"Query Info");
1159 if (ses && (ses->
server))
1177 iov[0].iov_base = (
char *)req;
1179 iov[0].iov_len = get_rfc1002_length(req) + 4;
1191 &rsp->
hdr, min_len, data);
1194 free_rsp_buf(resp_buftype, rsp);
1200 u64 persistent_fid,
u64 volatile_fid,
1203 return query_info(xid, tcon, persistent_fid, volatile_fid,
1211 u64 persistent_fid,
u64 volatile_fid,
__le64 *uniqueid)
1213 return query_info(xid, tcon, persistent_fid, volatile_fid,
1231 unsigned int credits_received = 1;
1249 cFYI(1,
"In echo request");
1259 iov.
iov_len = get_rfc1002_length(req) + 4;
1264 cFYI(1,
"Echo request failed: %d", rc);
1283 if (ses && (ses->
server))
1288 rc = small_smb2_init(
SMB2_FLUSH, tcon, (
void **) &req);
1297 iov[0].
iov_len = get_rfc1002_length(req) + 4;
1301 if ((rc != 0) && tcon)
1304 free_rsp_buf(resp_buftype, iov[0].
iov_base);
1319 rc = small_smb2_init(
SMB2_READ, io_parms->
tcon, (
void **) &req);
1322 if (io_parms->
tcon->ses->server ==
NULL)
1339 req->
hdr.NextCommand =
1342 req->
hdr.NextCommand = 0;
1349 req->
hdr.SessionId = 0xFFFFFFFF;
1350 req->
hdr.TreeId = 0xFFFFFFFF;
1355 if (remaining_bytes > io_parms->
length)
1362 iov[0].
iov_len = get_rfc1002_length(req) + 4;
1373 unsigned int credits_received = 1;
1376 .rq_pages = rdata->
pages,
1378 .rq_pagesz = rdata->
pagesz,
1379 .rq_tailsz = rdata->
tailsz };
1381 cFYI(1,
"%s: mid=%llu state=%d result=%d bytes=%u", __func__,
1382 mid->
mid, mid->
mid_state, rdata->result, rdata->bytes);
1386 credits_received =
le16_to_cpu(buf->CreditRequest);
1394 cERROR(1,
"SMB signature verification returned "
1398 task_io_account_read(rdata->bytes);
1406 if (rdata->result != -
ENODATA)
1407 rdata->result = -
EIO;
1415 add_credits(server, credits_received, 0);
1428 cFYI(1,
"%s: offset=%llu bytes=%u", __func__,
1431 io_parms.
tcon = tlink_tcon(rdata->
cfile->tlink);
1434 io_parms.persistent_fid = rdata->
cfile->fid.persistent_fid;
1435 io_parms.volatile_fid = rdata->
cfile->fid.volatile_fid;
1436 io_parms.
pid = rdata->
pid;
1437 rc = smb2_new_read_req(&rdata->
iov, &io_parms, 0, 0);
1443 rdata->
iov.iov_len = get_rfc1002_length(rdata->
iov.iov_base) + 4;
1460 unsigned int *
nbytes,
char **buf,
int *buf_type)
1462 int resp_buftype, rc = -
EACCES;
1467 rc = smb2_new_read_req(iov, io_parms, 0, 0);
1477 free_rsp_buf(resp_buftype, iov[0].iov_base);
1483 cERROR(1,
"Send error in read = %d", rc);
1487 (*nbytes > io_parms->
length)) {
1488 cFYI(1,
"bad length %d for count %d", *nbytes,
1498 free_rsp_buf(resp_buftype, iov[0].iov_base);
1518 unsigned int written;
1520 unsigned int credits_received = 1;
1536 if (written > wdata->
bytes)
1539 if (written < wdata->
bytes)
1542 wdata->
bytes = written;
1558 add_credits(tcon->
ses->server, credits_received, 0);
1571 rc = small_smb2_init(
SMB2_WRITE, tcon, (
void **) &req);
1573 goto async_writev_out;
1589 iov.
iov_len = get_rfc1002_length(req) + 4 - 1;
1603 inc_rfc1001_len(&req->
hdr, wdata->
bytes - 1 );
1607 smb2_writev_callback, wdata, 0);
1627 unsigned int *
nbytes,
struct kvec *iov,
int n_vec)
1638 rc = small_smb2_init(
SMB2_WRITE, io_parms->
tcon, (
void **) &req);
1642 if (io_parms->
tcon->ses->server ==
NULL)
1661 iov[0].
iov_len = get_rfc1002_length(req) + 4 - 1;
1664 inc_rfc1001_len(req, io_parms->
length - 1 );
1672 cERROR(1,
"Send error in write = %d", rc);
1676 free_rsp_buf(resp_buftype, rsp);
1681 num_entries(
char *bufstart,
char *end_of_buf,
char **lastentry,
size_t size)
1684 unsigned int entrycount = 0;
1685 unsigned int next_offset = 0;
1686 FILE_DIRECTORY_INFO *entryptr;
1688 if (bufstart ==
NULL)
1691 entryptr = (FILE_DIRECTORY_INFO *)bufstart;
1694 entryptr = (FILE_DIRECTORY_INFO *)
1695 ((
char *)entryptr + next_offset);
1697 if ((
char *)entryptr + size > end_of_buf) {
1698 cERROR(1,
"malformed search entry would overflow");
1703 if ((
char *)entryptr + len + size > end_of_buf) {
1704 cERROR(1,
"directory entry name would overflow frame "
1705 "end of buf %p", end_of_buf);
1709 *lastentry = (
char *)entryptr;
1712 next_offset =
le32_to_cpu(entryptr->NextEntryOffset);
1740 size_t info_buf_size;
1742 if (ses && (ses->
server))
1754 info_buf_size =
sizeof(FILE_DIRECTORY_INFO) - 1;
1758 info_buf_size =
sizeof(SEARCH_ID_FULL_DIR_INFO) - 1;
1761 cERROR(1,
"info level %u isn't supported",
1773 memcpy(bufptr, &asteriks, len);
1782 output_size =
min_t(
unsigned int, output_size, server->
maxBuf);
1783 output_size =
min_t(
unsigned int, output_size, 2 << 15);
1788 iov[0].
iov_len = get_rfc1002_length(req) + 4 - 1;
1793 inc_rfc1001_len(req, len - 1 );
1821 end_of_smb = get_rfc1002_length(rsp) + 4 + (
char *)&rsp->
hdr;
1826 cFYI(1,
"num entries %d last_index %lld srch start %p srch end %p",
1834 cERROR(1,
"illegal search buffer type");
1844 free_rsp_buf(resp_buftype, rsp);
1849 send_set_info(
const unsigned int xid,
struct cifs_tcon *tcon,
1850 u64 persistent_fid,
u64 volatile_fid,
u32 pid,
int info_class,
1851 unsigned int num,
void **data,
unsigned int *size)
1862 if (ses && (ses->
server))
1892 inc_rfc1001_len(req, *size - 1 );
1898 iov[0].
iov_len = get_rfc1002_length(req) + 4;
1900 for (i = 1; i < num; i++) {
1901 inc_rfc1001_len(req, size[i]);
1907 rc =
SendReceive2(xid, ses, iov, num, &resp_buftype, 0);
1915 free_rsp_buf(resp_buftype, rsp);
1922 u64 persistent_fid,
u64 volatile_fid,
__le16 *target_file)
1926 unsigned int size[2];
1928 int len = (2 * UniStrnlen((
wchar_t *)target_file,
PATH_MAX));
1942 data[1] = target_file;
1945 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
1954 u64 persistent_fid,
u64 volatile_fid,
__le16 *target_file)
1958 unsigned int size[2];
1960 int len = (2 * UniStrnlen((
wchar_t *)target_file,
PATH_MAX));
1974 data[1] = target_file;
1977 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
1996 return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid,
2002 u64 persistent_fid,
u64 volatile_fid, FILE_BASIC_INFO *buf)
2005 size =
sizeof(FILE_BASIC_INFO);
2006 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2008 (
void **)&buf, &size);
2013 const u64 persistent_fid,
const u64 volatile_fid,
2019 cFYI(1,
"SMB2_oplock_break");
2035 cFYI(1,
"Send error in Oplock Break = %d", rc);
2055 int outbuf_len,
u64 persistent_fid,
u64 volatile_fid)
2060 cFYI(1,
"Query FSInfo level %d", level);
2081 iov->
iov_len = get_rfc1002_length(req) + 4;
2087 u64 persistent_fid,
u64 volatile_fid,
struct kstatfs *fsdata)
2098 persistent_fid, volatile_fid);
2102 rc =
SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0);
2115 copy_fs_info_to_kstatfs(info, fsdata);
2118 free_rsp_buf(resp_buftype, iov.
iov_base);
2133 cFYI(1,
"smb2_lockv num lock %d", num_lock);
2135 rc = small_smb2_init(
SMB2_LOCK, tcon, (
void **) &req);
2157 cFYI(1,
"Send error in smb2_lockv = %d", rc);
2178 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock);
2188 cFYI(1,
"SMB2_lease_break");
2196 inc_rfc1001_len(req, 12);
2206 cFYI(1,
"Send error in Lease Break = %d", rc);