]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - fs/cifs/smb2ops.c
CIFS: Do not reconnect TCP session in add_credits()
[mirror_ubuntu-hirsute-kernel.git] / fs / cifs / smb2ops.c
1 /*
2 * SMB2 version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
26 #include "cifsglob.h"
27 #include "smb2pdu.h"
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
33 #include "smb2glob.h"
34 #include "cifs_ioctl.h"
35 #include "smbdirect.h"
36
37 /* Change credits for different ops and return the total number of credits */
38 static int
39 change_conf(struct TCP_Server_Info *server)
40 {
41 server->credits += server->echo_credits + server->oplock_credits;
42 server->oplock_credits = server->echo_credits = 0;
43 switch (server->credits) {
44 case 0:
45 return 0;
46 case 1:
47 server->echoes = false;
48 server->oplocks = false;
49 break;
50 case 2:
51 server->echoes = true;
52 server->oplocks = false;
53 server->echo_credits = 1;
54 break;
55 default:
56 server->echoes = true;
57 if (enable_oplocks) {
58 server->oplocks = true;
59 server->oplock_credits = 1;
60 } else
61 server->oplocks = false;
62
63 server->echo_credits = 1;
64 }
65 server->credits -= server->echo_credits + server->oplock_credits;
66 return server->credits + server->echo_credits + server->oplock_credits;
67 }
68
69 static void
70 smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
71 const int optype)
72 {
73 int *val, rc = -1;
74
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
77
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
81 server->hostname, *val);
82
83 *val += add;
84 if (*val > 65000) {
85 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
86 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
87 }
88 server->in_flight--;
89 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
90 rc = change_conf(server);
91 /*
92 * Sometimes server returns 0 credits on oplock break ack - we need to
93 * rebalance credits in this case.
94 */
95 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
96 server->oplocks) {
97 if (server->credits > 1) {
98 server->credits--;
99 server->oplock_credits++;
100 }
101 }
102 spin_unlock(&server->req_lock);
103 wake_up(&server->request_q);
104
105 if (server->tcpStatus == CifsNeedReconnect)
106 return;
107
108 switch (rc) {
109 case -1:
110 /* change_conf hasn't been executed */
111 break;
112 case 0:
113 cifs_dbg(VFS, "Possible client or server bug - zero credits\n");
114 break;
115 case 1:
116 cifs_dbg(VFS, "disabling echoes and oplocks\n");
117 break;
118 case 2:
119 cifs_dbg(FYI, "disabling oplocks\n");
120 break;
121 default:
122 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
123 }
124 }
125
126 static void
127 smb2_set_credits(struct TCP_Server_Info *server, const int val)
128 {
129 spin_lock(&server->req_lock);
130 server->credits = val;
131 if (val == 1)
132 server->reconnect_instance++;
133 spin_unlock(&server->req_lock);
134 /* don't log while holding the lock */
135 if (val == 1)
136 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
137 }
138
139 static int *
140 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
141 {
142 switch (optype) {
143 case CIFS_ECHO_OP:
144 return &server->echo_credits;
145 case CIFS_OBREAK_OP:
146 return &server->oplock_credits;
147 default:
148 return &server->credits;
149 }
150 }
151
152 static unsigned int
153 smb2_get_credits(struct mid_q_entry *mid)
154 {
155 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
156
157 return le16_to_cpu(shdr->CreditRequest);
158 }
159
160 static int
161 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
162 unsigned int *num, unsigned int *credits)
163 {
164 int rc = 0;
165 unsigned int scredits;
166
167 spin_lock(&server->req_lock);
168 while (1) {
169 if (server->credits <= 0) {
170 spin_unlock(&server->req_lock);
171 cifs_num_waiters_inc(server);
172 rc = wait_event_killable(server->request_q,
173 has_credits(server, &server->credits));
174 cifs_num_waiters_dec(server);
175 if (rc)
176 return rc;
177 spin_lock(&server->req_lock);
178 } else {
179 if (server->tcpStatus == CifsExiting) {
180 spin_unlock(&server->req_lock);
181 return -ENOENT;
182 }
183
184 scredits = server->credits;
185 /* can deadlock with reopen */
186 if (scredits <= 8) {
187 *num = SMB2_MAX_BUFFER_SIZE;
188 *credits = 0;
189 break;
190 }
191
192 /* leave some credits for reopen and other ops */
193 scredits -= 8;
194 *num = min_t(unsigned int, size,
195 scredits * SMB2_MAX_BUFFER_SIZE);
196
197 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
198 server->credits -= *credits;
199 server->in_flight++;
200 break;
201 }
202 }
203 spin_unlock(&server->req_lock);
204 return rc;
205 }
206
207 static __u64
208 smb2_get_next_mid(struct TCP_Server_Info *server)
209 {
210 __u64 mid;
211 /* for SMB2 we need the current value */
212 spin_lock(&GlobalMid_Lock);
213 mid = server->CurrentMid++;
214 spin_unlock(&GlobalMid_Lock);
215 return mid;
216 }
217
218 static struct mid_q_entry *
219 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
220 {
221 struct mid_q_entry *mid;
222 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
223 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
224
225 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
226 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
227 return NULL;
228 }
229
230 spin_lock(&GlobalMid_Lock);
231 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
232 if ((mid->mid == wire_mid) &&
233 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
234 (mid->command == shdr->Command)) {
235 kref_get(&mid->refcount);
236 spin_unlock(&GlobalMid_Lock);
237 return mid;
238 }
239 }
240 spin_unlock(&GlobalMid_Lock);
241 return NULL;
242 }
243
244 static void
245 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
246 {
247 #ifdef CONFIG_CIFS_DEBUG2
248 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
249
250 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
251 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
252 shdr->ProcessId);
253 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
254 server->ops->calc_smb_size(buf, server));
255 #endif
256 }
257
258 static bool
259 smb2_need_neg(struct TCP_Server_Info *server)
260 {
261 return server->max_read == 0;
262 }
263
264 static int
265 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
266 {
267 int rc;
268 ses->server->CurrentMid = 0;
269 rc = SMB2_negotiate(xid, ses);
270 /* BB we probably don't need to retry with modern servers */
271 if (rc == -EAGAIN)
272 rc = -EHOSTDOWN;
273 return rc;
274 }
275
276 static unsigned int
277 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
278 {
279 struct TCP_Server_Info *server = tcon->ses->server;
280 unsigned int wsize;
281
282 /* start with specified wsize, or default */
283 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
284 wsize = min_t(unsigned int, wsize, server->max_write);
285 #ifdef CONFIG_CIFS_SMB_DIRECT
286 if (server->rdma) {
287 if (server->sign)
288 wsize = min_t(unsigned int,
289 wsize, server->smbd_conn->max_fragmented_send_size);
290 else
291 wsize = min_t(unsigned int,
292 wsize, server->smbd_conn->max_readwrite_size);
293 }
294 #endif
295 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
296 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
297
298 return wsize;
299 }
300
301 static unsigned int
302 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
303 {
304 struct TCP_Server_Info *server = tcon->ses->server;
305 unsigned int wsize;
306
307 /* start with specified wsize, or default */
308 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
309 wsize = min_t(unsigned int, wsize, server->max_write);
310 #ifdef CONFIG_CIFS_SMB_DIRECT
311 if (server->rdma) {
312 if (server->sign)
313 wsize = min_t(unsigned int,
314 wsize, server->smbd_conn->max_fragmented_send_size);
315 else
316 wsize = min_t(unsigned int,
317 wsize, server->smbd_conn->max_readwrite_size);
318 }
319 #endif
320 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
321 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
322
323 return wsize;
324 }
325
326 static unsigned int
327 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
328 {
329 struct TCP_Server_Info *server = tcon->ses->server;
330 unsigned int rsize;
331
332 /* start with specified rsize, or default */
333 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
334 rsize = min_t(unsigned int, rsize, server->max_read);
335 #ifdef CONFIG_CIFS_SMB_DIRECT
336 if (server->rdma) {
337 if (server->sign)
338 rsize = min_t(unsigned int,
339 rsize, server->smbd_conn->max_fragmented_recv_size);
340 else
341 rsize = min_t(unsigned int,
342 rsize, server->smbd_conn->max_readwrite_size);
343 }
344 #endif
345
346 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
347 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
348
349 return rsize;
350 }
351
352 static unsigned int
353 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
354 {
355 struct TCP_Server_Info *server = tcon->ses->server;
356 unsigned int rsize;
357
358 /* start with specified rsize, or default */
359 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
360 rsize = min_t(unsigned int, rsize, server->max_read);
361 #ifdef CONFIG_CIFS_SMB_DIRECT
362 if (server->rdma) {
363 if (server->sign)
364 rsize = min_t(unsigned int,
365 rsize, server->smbd_conn->max_fragmented_recv_size);
366 else
367 rsize = min_t(unsigned int,
368 rsize, server->smbd_conn->max_readwrite_size);
369 }
370 #endif
371
372 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
373 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
374
375 return rsize;
376 }
377
378 static int
379 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
380 size_t buf_len,
381 struct cifs_server_iface **iface_list,
382 size_t *iface_count)
383 {
384 struct network_interface_info_ioctl_rsp *p;
385 struct sockaddr_in *addr4;
386 struct sockaddr_in6 *addr6;
387 struct iface_info_ipv4 *p4;
388 struct iface_info_ipv6 *p6;
389 struct cifs_server_iface *info;
390 ssize_t bytes_left;
391 size_t next = 0;
392 int nb_iface = 0;
393 int rc = 0;
394
395 *iface_list = NULL;
396 *iface_count = 0;
397
398 /*
399 * Fist pass: count and sanity check
400 */
401
402 bytes_left = buf_len;
403 p = buf;
404 while (bytes_left >= sizeof(*p)) {
405 nb_iface++;
406 next = le32_to_cpu(p->Next);
407 if (!next) {
408 bytes_left -= sizeof(*p);
409 break;
410 }
411 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
412 bytes_left -= next;
413 }
414
415 if (!nb_iface) {
416 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
417 rc = -EINVAL;
418 goto out;
419 }
420
421 if (bytes_left || p->Next)
422 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
423
424
425 /*
426 * Second pass: extract info to internal structure
427 */
428
429 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
430 if (!*iface_list) {
431 rc = -ENOMEM;
432 goto out;
433 }
434
435 info = *iface_list;
436 bytes_left = buf_len;
437 p = buf;
438 while (bytes_left >= sizeof(*p)) {
439 info->speed = le64_to_cpu(p->LinkSpeed);
440 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
441 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
442
443 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
444 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
445 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
446 le32_to_cpu(p->Capability));
447
448 switch (p->Family) {
449 /*
450 * The kernel and wire socket structures have the same
451 * layout and use network byte order but make the
452 * conversion explicit in case either one changes.
453 */
454 case INTERNETWORK:
455 addr4 = (struct sockaddr_in *)&info->sockaddr;
456 p4 = (struct iface_info_ipv4 *)p->Buffer;
457 addr4->sin_family = AF_INET;
458 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
459
460 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
461 addr4->sin_port = cpu_to_be16(CIFS_PORT);
462
463 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
464 &addr4->sin_addr);
465 break;
466 case INTERNETWORKV6:
467 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
468 p6 = (struct iface_info_ipv6 *)p->Buffer;
469 addr6->sin6_family = AF_INET6;
470 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
471
472 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
473 addr6->sin6_flowinfo = 0;
474 addr6->sin6_scope_id = 0;
475 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
476
477 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
478 &addr6->sin6_addr);
479 break;
480 default:
481 cifs_dbg(VFS,
482 "%s: skipping unsupported socket family\n",
483 __func__);
484 goto next_iface;
485 }
486
487 (*iface_count)++;
488 info++;
489 next_iface:
490 next = le32_to_cpu(p->Next);
491 if (!next)
492 break;
493 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
494 bytes_left -= next;
495 }
496
497 if (!*iface_count) {
498 rc = -EINVAL;
499 goto out;
500 }
501
502 out:
503 if (rc) {
504 kfree(*iface_list);
505 *iface_count = 0;
506 *iface_list = NULL;
507 }
508 return rc;
509 }
510
511
512 static int
513 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
514 {
515 int rc;
516 unsigned int ret_data_len = 0;
517 struct network_interface_info_ioctl_rsp *out_buf = NULL;
518 struct cifs_server_iface *iface_list;
519 size_t iface_count;
520 struct cifs_ses *ses = tcon->ses;
521
522 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
523 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
524 NULL /* no data input */, 0 /* no data input */,
525 (char **)&out_buf, &ret_data_len);
526 if (rc == -EOPNOTSUPP) {
527 cifs_dbg(FYI,
528 "server does not support query network interfaces\n");
529 goto out;
530 } else if (rc != 0) {
531 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
532 goto out;
533 }
534
535 rc = parse_server_interfaces(out_buf, ret_data_len,
536 &iface_list, &iface_count);
537 if (rc)
538 goto out;
539
540 spin_lock(&ses->iface_lock);
541 kfree(ses->iface_list);
542 ses->iface_list = iface_list;
543 ses->iface_count = iface_count;
544 ses->iface_last_update = jiffies;
545 spin_unlock(&ses->iface_lock);
546
547 out:
548 kfree(out_buf);
549 return rc;
550 }
551
552 static void
553 smb2_close_cached_fid(struct kref *ref)
554 {
555 struct cached_fid *cfid = container_of(ref, struct cached_fid,
556 refcount);
557
558 if (cfid->is_valid) {
559 cifs_dbg(FYI, "clear cached root file handle\n");
560 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
561 cfid->fid->volatile_fid);
562 cfid->is_valid = false;
563 }
564 }
565
566 void close_shroot(struct cached_fid *cfid)
567 {
568 mutex_lock(&cfid->fid_mutex);
569 kref_put(&cfid->refcount, smb2_close_cached_fid);
570 mutex_unlock(&cfid->fid_mutex);
571 }
572
573 void
574 smb2_cached_lease_break(struct work_struct *work)
575 {
576 struct cached_fid *cfid = container_of(work,
577 struct cached_fid, lease_break);
578
579 close_shroot(cfid);
580 }
581
582 /*
583 * Open the directory at the root of a share
584 */
585 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
586 {
587 struct cifs_open_parms oparams;
588 int rc;
589 __le16 srch_path = 0; /* Null - since an open of top of share */
590 u8 oplock = SMB2_OPLOCK_LEVEL_II;
591
592 mutex_lock(&tcon->crfid.fid_mutex);
593 if (tcon->crfid.is_valid) {
594 cifs_dbg(FYI, "found a cached root file handle\n");
595 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
596 kref_get(&tcon->crfid.refcount);
597 mutex_unlock(&tcon->crfid.fid_mutex);
598 return 0;
599 }
600
601 oparams.tcon = tcon;
602 oparams.create_options = 0;
603 oparams.desired_access = FILE_READ_ATTRIBUTES;
604 oparams.disposition = FILE_OPEN;
605 oparams.fid = pfid;
606 oparams.reconnect = false;
607
608 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
609 if (rc == 0) {
610 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
611 tcon->crfid.tcon = tcon;
612 tcon->crfid.is_valid = true;
613 kref_init(&tcon->crfid.refcount);
614 kref_get(&tcon->crfid.refcount);
615 }
616 mutex_unlock(&tcon->crfid.fid_mutex);
617 return rc;
618 }
619
620 static void
621 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
622 {
623 int rc;
624 __le16 srch_path = 0; /* Null - open root of share */
625 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
626 struct cifs_open_parms oparms;
627 struct cifs_fid fid;
628 bool no_cached_open = tcon->nohandlecache;
629
630 oparms.tcon = tcon;
631 oparms.desired_access = FILE_READ_ATTRIBUTES;
632 oparms.disposition = FILE_OPEN;
633 oparms.create_options = 0;
634 oparms.fid = &fid;
635 oparms.reconnect = false;
636
637 if (no_cached_open)
638 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
639 NULL);
640 else
641 rc = open_shroot(xid, tcon, &fid);
642
643 if (rc)
644 return;
645
646 SMB3_request_interfaces(xid, tcon);
647
648 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
649 FS_ATTRIBUTE_INFORMATION);
650 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
651 FS_DEVICE_INFORMATION);
652 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
653 FS_VOLUME_INFORMATION);
654 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
655 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
656 if (no_cached_open)
657 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
658 else
659 close_shroot(&tcon->crfid);
660
661 return;
662 }
663
664 static void
665 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
666 {
667 int rc;
668 __le16 srch_path = 0; /* Null - open root of share */
669 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
670 struct cifs_open_parms oparms;
671 struct cifs_fid fid;
672
673 oparms.tcon = tcon;
674 oparms.desired_access = FILE_READ_ATTRIBUTES;
675 oparms.disposition = FILE_OPEN;
676 oparms.create_options = 0;
677 oparms.fid = &fid;
678 oparms.reconnect = false;
679
680 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
681 if (rc)
682 return;
683
684 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
685 FS_ATTRIBUTE_INFORMATION);
686 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
687 FS_DEVICE_INFORMATION);
688 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
689 return;
690 }
691
692 static int
693 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
694 struct cifs_sb_info *cifs_sb, const char *full_path)
695 {
696 int rc;
697 __le16 *utf16_path;
698 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
699 struct cifs_open_parms oparms;
700 struct cifs_fid fid;
701
702 if ((*full_path == 0) && tcon->crfid.is_valid)
703 return 0;
704
705 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
706 if (!utf16_path)
707 return -ENOMEM;
708
709 oparms.tcon = tcon;
710 oparms.desired_access = FILE_READ_ATTRIBUTES;
711 oparms.disposition = FILE_OPEN;
712 if (backup_cred(cifs_sb))
713 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
714 else
715 oparms.create_options = 0;
716 oparms.fid = &fid;
717 oparms.reconnect = false;
718
719 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
720 if (rc) {
721 kfree(utf16_path);
722 return rc;
723 }
724
725 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
726 kfree(utf16_path);
727 return rc;
728 }
729
730 static int
731 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
732 struct cifs_sb_info *cifs_sb, const char *full_path,
733 u64 *uniqueid, FILE_ALL_INFO *data)
734 {
735 *uniqueid = le64_to_cpu(data->IndexNumber);
736 return 0;
737 }
738
739 static int
740 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
741 struct cifs_fid *fid, FILE_ALL_INFO *data)
742 {
743 int rc;
744 struct smb2_file_all_info *smb2_data;
745
746 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
747 GFP_KERNEL);
748 if (smb2_data == NULL)
749 return -ENOMEM;
750
751 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
752 smb2_data);
753 if (!rc)
754 move_smb2_info_to_cifs(data, smb2_data);
755 kfree(smb2_data);
756 return rc;
757 }
758
759 #ifdef CONFIG_CIFS_XATTR
760 static ssize_t
761 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
762 struct smb2_file_full_ea_info *src, size_t src_size,
763 const unsigned char *ea_name)
764 {
765 int rc = 0;
766 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
767 char *name, *value;
768 size_t buf_size = dst_size;
769 size_t name_len, value_len, user_name_len;
770
771 while (src_size > 0) {
772 name = &src->ea_data[0];
773 name_len = (size_t)src->ea_name_length;
774 value = &src->ea_data[src->ea_name_length + 1];
775 value_len = (size_t)le16_to_cpu(src->ea_value_length);
776
777 if (name_len == 0) {
778 break;
779 }
780
781 if (src_size < 8 + name_len + 1 + value_len) {
782 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
783 rc = -EIO;
784 goto out;
785 }
786
787 if (ea_name) {
788 if (ea_name_len == name_len &&
789 memcmp(ea_name, name, name_len) == 0) {
790 rc = value_len;
791 if (dst_size == 0)
792 goto out;
793 if (dst_size < value_len) {
794 rc = -ERANGE;
795 goto out;
796 }
797 memcpy(dst, value, value_len);
798 goto out;
799 }
800 } else {
801 /* 'user.' plus a terminating null */
802 user_name_len = 5 + 1 + name_len;
803
804 if (buf_size == 0) {
805 /* skip copy - calc size only */
806 rc += user_name_len;
807 } else if (dst_size >= user_name_len) {
808 dst_size -= user_name_len;
809 memcpy(dst, "user.", 5);
810 dst += 5;
811 memcpy(dst, src->ea_data, name_len);
812 dst += name_len;
813 *dst = 0;
814 ++dst;
815 rc += user_name_len;
816 } else {
817 /* stop before overrun buffer */
818 rc = -ERANGE;
819 break;
820 }
821 }
822
823 if (!src->next_entry_offset)
824 break;
825
826 if (src_size < le32_to_cpu(src->next_entry_offset)) {
827 /* stop before overrun buffer */
828 rc = -ERANGE;
829 break;
830 }
831 src_size -= le32_to_cpu(src->next_entry_offset);
832 src = (void *)((char *)src +
833 le32_to_cpu(src->next_entry_offset));
834 }
835
836 /* didn't find the named attribute */
837 if (ea_name)
838 rc = -ENODATA;
839
840 out:
841 return (ssize_t)rc;
842 }
843
844 static ssize_t
845 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
846 const unsigned char *path, const unsigned char *ea_name,
847 char *ea_data, size_t buf_size,
848 struct cifs_sb_info *cifs_sb)
849 {
850 int rc;
851 __le16 *utf16_path;
852 struct kvec rsp_iov = {NULL, 0};
853 int buftype = CIFS_NO_BUFFER;
854 struct smb2_query_info_rsp *rsp;
855 struct smb2_file_full_ea_info *info = NULL;
856
857 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
858 if (!utf16_path)
859 return -ENOMEM;
860
861 rc = smb2_query_info_compound(xid, tcon, utf16_path,
862 FILE_READ_EA,
863 FILE_FULL_EA_INFORMATION,
864 SMB2_O_INFO_FILE,
865 SMB2_MAX_EA_BUF,
866 &rsp_iov, &buftype, cifs_sb);
867 if (rc) {
868 /*
869 * If ea_name is NULL (listxattr) and there are no EAs,
870 * return 0 as it's not an error. Otherwise, the specified
871 * ea_name was not found.
872 */
873 if (!ea_name && rc == -ENODATA)
874 rc = 0;
875 goto qeas_exit;
876 }
877
878 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
879 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
880 le32_to_cpu(rsp->OutputBufferLength),
881 &rsp_iov,
882 sizeof(struct smb2_file_full_ea_info));
883 if (rc)
884 goto qeas_exit;
885
886 info = (struct smb2_file_full_ea_info *)(
887 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
888 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
889 le32_to_cpu(rsp->OutputBufferLength), ea_name);
890
891 qeas_exit:
892 kfree(utf16_path);
893 free_rsp_buf(buftype, rsp_iov.iov_base);
894 return rc;
895 }
896
897
898 static int
899 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
900 const char *path, const char *ea_name, const void *ea_value,
901 const __u16 ea_value_len, const struct nls_table *nls_codepage,
902 struct cifs_sb_info *cifs_sb)
903 {
904 struct cifs_ses *ses = tcon->ses;
905 __le16 *utf16_path = NULL;
906 int ea_name_len = strlen(ea_name);
907 int flags = 0;
908 int len;
909 struct smb_rqst rqst[3];
910 int resp_buftype[3];
911 struct kvec rsp_iov[3];
912 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
913 struct cifs_open_parms oparms;
914 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
915 struct cifs_fid fid;
916 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
917 unsigned int size[1];
918 void *data[1];
919 struct smb2_file_full_ea_info *ea = NULL;
920 struct kvec close_iov[1];
921 int rc;
922
923 if (smb3_encryption_required(tcon))
924 flags |= CIFS_TRANSFORM_REQ;
925
926 if (ea_name_len > 255)
927 return -EINVAL;
928
929 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
930 if (!utf16_path)
931 return -ENOMEM;
932
933 memset(rqst, 0, sizeof(rqst));
934 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
935 memset(rsp_iov, 0, sizeof(rsp_iov));
936
937 /* Open */
938 memset(&open_iov, 0, sizeof(open_iov));
939 rqst[0].rq_iov = open_iov;
940 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
941
942 memset(&oparms, 0, sizeof(oparms));
943 oparms.tcon = tcon;
944 oparms.desired_access = FILE_WRITE_EA;
945 oparms.disposition = FILE_OPEN;
946 if (backup_cred(cifs_sb))
947 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
948 else
949 oparms.create_options = 0;
950 oparms.fid = &fid;
951 oparms.reconnect = false;
952
953 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
954 if (rc)
955 goto sea_exit;
956 smb2_set_next_command(tcon, &rqst[0]);
957
958
959 /* Set Info */
960 memset(&si_iov, 0, sizeof(si_iov));
961 rqst[1].rq_iov = si_iov;
962 rqst[1].rq_nvec = 1;
963
964 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
965 ea = kzalloc(len, GFP_KERNEL);
966 if (ea == NULL) {
967 rc = -ENOMEM;
968 goto sea_exit;
969 }
970
971 ea->ea_name_length = ea_name_len;
972 ea->ea_value_length = cpu_to_le16(ea_value_len);
973 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
974 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
975
976 size[0] = len;
977 data[0] = ea;
978
979 rc = SMB2_set_info_init(tcon, &rqst[1], COMPOUND_FID,
980 COMPOUND_FID, current->tgid,
981 FILE_FULL_EA_INFORMATION,
982 SMB2_O_INFO_FILE, 0, data, size);
983 smb2_set_next_command(tcon, &rqst[1]);
984 smb2_set_related(&rqst[1]);
985
986
987 /* Close */
988 memset(&close_iov, 0, sizeof(close_iov));
989 rqst[2].rq_iov = close_iov;
990 rqst[2].rq_nvec = 1;
991 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
992 smb2_set_related(&rqst[2]);
993
994 rc = compound_send_recv(xid, ses, flags, 3, rqst,
995 resp_buftype, rsp_iov);
996
997 sea_exit:
998 kfree(ea);
999 kfree(utf16_path);
1000 SMB2_open_free(&rqst[0]);
1001 SMB2_set_info_free(&rqst[1]);
1002 SMB2_close_free(&rqst[2]);
1003 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1004 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1005 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1006 return rc;
1007 }
1008 #endif
1009
1010 static bool
1011 smb2_can_echo(struct TCP_Server_Info *server)
1012 {
1013 return server->echoes;
1014 }
1015
1016 static void
1017 smb2_clear_stats(struct cifs_tcon *tcon)
1018 {
1019 int i;
1020 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1021 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1022 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1023 }
1024 }
1025
1026 static void
1027 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1028 {
1029 seq_puts(m, "\n\tShare Capabilities:");
1030 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1031 seq_puts(m, " DFS,");
1032 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1033 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1034 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1035 seq_puts(m, " SCALEOUT,");
1036 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1037 seq_puts(m, " CLUSTER,");
1038 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1039 seq_puts(m, " ASYMMETRIC,");
1040 if (tcon->capabilities == 0)
1041 seq_puts(m, " None");
1042 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1043 seq_puts(m, " Aligned,");
1044 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1045 seq_puts(m, " Partition Aligned,");
1046 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1047 seq_puts(m, " SSD,");
1048 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1049 seq_puts(m, " TRIM-support,");
1050
1051 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1052 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1053 if (tcon->perf_sector_size)
1054 seq_printf(m, "\tOptimal sector size: 0x%x",
1055 tcon->perf_sector_size);
1056 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1057 }
1058
1059 static void
1060 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1061 {
1062 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1063 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1064
1065 /*
1066 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1067 * totals (requests sent) since those SMBs are per-session not per tcon
1068 */
1069 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1070 (long long)(tcon->bytes_read),
1071 (long long)(tcon->bytes_written));
1072 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1073 atomic_read(&tcon->num_local_opens),
1074 atomic_read(&tcon->num_remote_opens));
1075 seq_printf(m, "\nTreeConnects: %d total %d failed",
1076 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1077 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1078 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1079 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1080 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1081 seq_printf(m, "\nCreates: %d total %d failed",
1082 atomic_read(&sent[SMB2_CREATE_HE]),
1083 atomic_read(&failed[SMB2_CREATE_HE]));
1084 seq_printf(m, "\nCloses: %d total %d failed",
1085 atomic_read(&sent[SMB2_CLOSE_HE]),
1086 atomic_read(&failed[SMB2_CLOSE_HE]));
1087 seq_printf(m, "\nFlushes: %d total %d failed",
1088 atomic_read(&sent[SMB2_FLUSH_HE]),
1089 atomic_read(&failed[SMB2_FLUSH_HE]));
1090 seq_printf(m, "\nReads: %d total %d failed",
1091 atomic_read(&sent[SMB2_READ_HE]),
1092 atomic_read(&failed[SMB2_READ_HE]));
1093 seq_printf(m, "\nWrites: %d total %d failed",
1094 atomic_read(&sent[SMB2_WRITE_HE]),
1095 atomic_read(&failed[SMB2_WRITE_HE]));
1096 seq_printf(m, "\nLocks: %d total %d failed",
1097 atomic_read(&sent[SMB2_LOCK_HE]),
1098 atomic_read(&failed[SMB2_LOCK_HE]));
1099 seq_printf(m, "\nIOCTLs: %d total %d failed",
1100 atomic_read(&sent[SMB2_IOCTL_HE]),
1101 atomic_read(&failed[SMB2_IOCTL_HE]));
1102 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1103 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1104 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1105 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1106 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1107 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1108 seq_printf(m, "\nQueryInfos: %d total %d failed",
1109 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1110 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1111 seq_printf(m, "\nSetInfos: %d total %d failed",
1112 atomic_read(&sent[SMB2_SET_INFO_HE]),
1113 atomic_read(&failed[SMB2_SET_INFO_HE]));
1114 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1115 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1116 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1117 }
1118
1119 static void
1120 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1121 {
1122 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1123 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1124
1125 cfile->fid.persistent_fid = fid->persistent_fid;
1126 cfile->fid.volatile_fid = fid->volatile_fid;
1127 #ifdef CONFIG_CIFS_DEBUG2
1128 cfile->fid.mid = fid->mid;
1129 #endif /* CIFS_DEBUG2 */
1130 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1131 &fid->purge_cache);
1132 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1133 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1134 }
1135
1136 static void
1137 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1138 struct cifs_fid *fid)
1139 {
1140 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1141 }
1142
1143 static int
1144 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1145 u64 persistent_fid, u64 volatile_fid,
1146 struct copychunk_ioctl *pcchunk)
1147 {
1148 int rc;
1149 unsigned int ret_data_len;
1150 struct resume_key_req *res_key;
1151
1152 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1153 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1154 NULL, 0 /* no input */,
1155 (char **)&res_key, &ret_data_len);
1156
1157 if (rc) {
1158 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1159 goto req_res_key_exit;
1160 }
1161 if (ret_data_len < sizeof(struct resume_key_req)) {
1162 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1163 rc = -EINVAL;
1164 goto req_res_key_exit;
1165 }
1166 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1167
1168 req_res_key_exit:
1169 kfree(res_key);
1170 return rc;
1171 }
1172
1173 static int
1174 smb2_ioctl_query_info(const unsigned int xid,
1175 struct cifs_tcon *tcon,
1176 __le16 *path, int is_dir,
1177 unsigned long p)
1178 {
1179 struct cifs_ses *ses = tcon->ses;
1180 char __user *arg = (char __user *)p;
1181 struct smb_query_info qi;
1182 struct smb_query_info __user *pqi;
1183 int rc = 0;
1184 int flags = 0;
1185 struct smb2_query_info_rsp *rsp = NULL;
1186 void *buffer = NULL;
1187 struct smb_rqst rqst[3];
1188 int resp_buftype[3];
1189 struct kvec rsp_iov[3];
1190 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1191 struct cifs_open_parms oparms;
1192 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1193 struct cifs_fid fid;
1194 struct kvec qi_iov[1];
1195 struct kvec close_iov[1];
1196
1197 memset(rqst, 0, sizeof(rqst));
1198 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1199 memset(rsp_iov, 0, sizeof(rsp_iov));
1200
1201 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1202 return -EFAULT;
1203
1204 if (qi.output_buffer_length > 1024)
1205 return -EINVAL;
1206
1207 if (!ses || !(ses->server))
1208 return -EIO;
1209
1210 if (smb3_encryption_required(tcon))
1211 flags |= CIFS_TRANSFORM_REQ;
1212
1213 buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL);
1214 if (buffer == NULL)
1215 return -ENOMEM;
1216
1217 if (copy_from_user(buffer, arg + sizeof(struct smb_query_info),
1218 qi.output_buffer_length)) {
1219 rc = -EFAULT;
1220 goto iqinf_exit;
1221 }
1222
1223 /* Open */
1224 memset(&open_iov, 0, sizeof(open_iov));
1225 rqst[0].rq_iov = open_iov;
1226 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1227
1228 memset(&oparms, 0, sizeof(oparms));
1229 oparms.tcon = tcon;
1230 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1231 oparms.disposition = FILE_OPEN;
1232 if (is_dir)
1233 oparms.create_options = CREATE_NOT_FILE;
1234 else
1235 oparms.create_options = CREATE_NOT_DIR;
1236 oparms.fid = &fid;
1237 oparms.reconnect = false;
1238
1239 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path);
1240 if (rc)
1241 goto iqinf_exit;
1242 smb2_set_next_command(tcon, &rqst[0]);
1243
1244 /* Query */
1245 memset(&qi_iov, 0, sizeof(qi_iov));
1246 rqst[1].rq_iov = qi_iov;
1247 rqst[1].rq_nvec = 1;
1248
1249 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1250 qi.file_info_class, qi.info_type,
1251 qi.additional_information,
1252 qi.input_buffer_length,
1253 qi.output_buffer_length, buffer);
1254 if (rc)
1255 goto iqinf_exit;
1256 smb2_set_next_command(tcon, &rqst[1]);
1257 smb2_set_related(&rqst[1]);
1258
1259 /* Close */
1260 memset(&close_iov, 0, sizeof(close_iov));
1261 rqst[2].rq_iov = close_iov;
1262 rqst[2].rq_nvec = 1;
1263
1264 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1265 if (rc)
1266 goto iqinf_exit;
1267 smb2_set_related(&rqst[2]);
1268
1269 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1270 resp_buftype, rsp_iov);
1271 if (rc)
1272 goto iqinf_exit;
1273 pqi = (struct smb_query_info __user *)arg;
1274 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1275 if (le32_to_cpu(rsp->OutputBufferLength) < qi.input_buffer_length)
1276 qi.input_buffer_length = le32_to_cpu(rsp->OutputBufferLength);
1277 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1278 sizeof(qi.input_buffer_length))) {
1279 rc = -EFAULT;
1280 goto iqinf_exit;
1281 }
1282 if (copy_to_user(pqi + 1, rsp->Buffer, qi.input_buffer_length)) {
1283 rc = -EFAULT;
1284 goto iqinf_exit;
1285 }
1286
1287 iqinf_exit:
1288 kfree(buffer);
1289 SMB2_open_free(&rqst[0]);
1290 SMB2_query_info_free(&rqst[1]);
1291 SMB2_close_free(&rqst[2]);
1292 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1293 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1294 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1295 return rc;
1296 }
1297
1298 static ssize_t
1299 smb2_copychunk_range(const unsigned int xid,
1300 struct cifsFileInfo *srcfile,
1301 struct cifsFileInfo *trgtfile, u64 src_off,
1302 u64 len, u64 dest_off)
1303 {
1304 int rc;
1305 unsigned int ret_data_len;
1306 struct copychunk_ioctl *pcchunk;
1307 struct copychunk_ioctl_rsp *retbuf = NULL;
1308 struct cifs_tcon *tcon;
1309 int chunks_copied = 0;
1310 bool chunk_sizes_updated = false;
1311 ssize_t bytes_written, total_bytes_written = 0;
1312
1313 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1314
1315 if (pcchunk == NULL)
1316 return -ENOMEM;
1317
1318 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1319 /* Request a key from the server to identify the source of the copy */
1320 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1321 srcfile->fid.persistent_fid,
1322 srcfile->fid.volatile_fid, pcchunk);
1323
1324 /* Note: request_res_key sets res_key null only if rc !=0 */
1325 if (rc)
1326 goto cchunk_out;
1327
1328 /* For now array only one chunk long, will make more flexible later */
1329 pcchunk->ChunkCount = cpu_to_le32(1);
1330 pcchunk->Reserved = 0;
1331 pcchunk->Reserved2 = 0;
1332
1333 tcon = tlink_tcon(trgtfile->tlink);
1334
1335 while (len > 0) {
1336 pcchunk->SourceOffset = cpu_to_le64(src_off);
1337 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1338 pcchunk->Length =
1339 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1340
1341 /* Request server copy to target from src identified by key */
1342 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1343 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1344 true /* is_fsctl */, (char *)pcchunk,
1345 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1346 &ret_data_len);
1347 if (rc == 0) {
1348 if (ret_data_len !=
1349 sizeof(struct copychunk_ioctl_rsp)) {
1350 cifs_dbg(VFS, "invalid cchunk response size\n");
1351 rc = -EIO;
1352 goto cchunk_out;
1353 }
1354 if (retbuf->TotalBytesWritten == 0) {
1355 cifs_dbg(FYI, "no bytes copied\n");
1356 rc = -EIO;
1357 goto cchunk_out;
1358 }
1359 /*
1360 * Check if server claimed to write more than we asked
1361 */
1362 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1363 le32_to_cpu(pcchunk->Length)) {
1364 cifs_dbg(VFS, "invalid copy chunk response\n");
1365 rc = -EIO;
1366 goto cchunk_out;
1367 }
1368 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1369 cifs_dbg(VFS, "invalid num chunks written\n");
1370 rc = -EIO;
1371 goto cchunk_out;
1372 }
1373 chunks_copied++;
1374
1375 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1376 src_off += bytes_written;
1377 dest_off += bytes_written;
1378 len -= bytes_written;
1379 total_bytes_written += bytes_written;
1380
1381 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1382 le32_to_cpu(retbuf->ChunksWritten),
1383 le32_to_cpu(retbuf->ChunkBytesWritten),
1384 bytes_written);
1385 } else if (rc == -EINVAL) {
1386 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1387 goto cchunk_out;
1388
1389 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1390 le32_to_cpu(retbuf->ChunksWritten),
1391 le32_to_cpu(retbuf->ChunkBytesWritten),
1392 le32_to_cpu(retbuf->TotalBytesWritten));
1393
1394 /*
1395 * Check if this is the first request using these sizes,
1396 * (ie check if copy succeed once with original sizes
1397 * and check if the server gave us different sizes after
1398 * we already updated max sizes on previous request).
1399 * if not then why is the server returning an error now
1400 */
1401 if ((chunks_copied != 0) || chunk_sizes_updated)
1402 goto cchunk_out;
1403
1404 /* Check that server is not asking us to grow size */
1405 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1406 tcon->max_bytes_chunk)
1407 tcon->max_bytes_chunk =
1408 le32_to_cpu(retbuf->ChunkBytesWritten);
1409 else
1410 goto cchunk_out; /* server gave us bogus size */
1411
1412 /* No need to change MaxChunks since already set to 1 */
1413 chunk_sizes_updated = true;
1414 } else
1415 goto cchunk_out;
1416 }
1417
1418 cchunk_out:
1419 kfree(pcchunk);
1420 kfree(retbuf);
1421 if (rc)
1422 return rc;
1423 else
1424 return total_bytes_written;
1425 }
1426
1427 static int
1428 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1429 struct cifs_fid *fid)
1430 {
1431 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1432 }
1433
1434 static unsigned int
1435 smb2_read_data_offset(char *buf)
1436 {
1437 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1438 return rsp->DataOffset;
1439 }
1440
1441 static unsigned int
1442 smb2_read_data_length(char *buf, bool in_remaining)
1443 {
1444 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1445
1446 if (in_remaining)
1447 return le32_to_cpu(rsp->DataRemaining);
1448
1449 return le32_to_cpu(rsp->DataLength);
1450 }
1451
1452
1453 static int
1454 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1455 struct cifs_io_parms *parms, unsigned int *bytes_read,
1456 char **buf, int *buf_type)
1457 {
1458 parms->persistent_fid = pfid->persistent_fid;
1459 parms->volatile_fid = pfid->volatile_fid;
1460 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1461 }
1462
1463 static int
1464 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1465 struct cifs_io_parms *parms, unsigned int *written,
1466 struct kvec *iov, unsigned long nr_segs)
1467 {
1468
1469 parms->persistent_fid = pfid->persistent_fid;
1470 parms->volatile_fid = pfid->volatile_fid;
1471 return SMB2_write(xid, parms, written, iov, nr_segs);
1472 }
1473
1474 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1475 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1476 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1477 {
1478 struct cifsInodeInfo *cifsi;
1479 int rc;
1480
1481 cifsi = CIFS_I(inode);
1482
1483 /* if file already sparse don't bother setting sparse again */
1484 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1485 return true; /* already sparse */
1486
1487 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1488 return true; /* already not sparse */
1489
1490 /*
1491 * Can't check for sparse support on share the usual way via the
1492 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1493 * since Samba server doesn't set the flag on the share, yet
1494 * supports the set sparse FSCTL and returns sparse correctly
1495 * in the file attributes. If we fail setting sparse though we
1496 * mark that server does not support sparse files for this share
1497 * to avoid repeatedly sending the unsupported fsctl to server
1498 * if the file is repeatedly extended.
1499 */
1500 if (tcon->broken_sparse_sup)
1501 return false;
1502
1503 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1504 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1505 true /* is_fctl */,
1506 &setsparse, 1, NULL, NULL);
1507 if (rc) {
1508 tcon->broken_sparse_sup = true;
1509 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1510 return false;
1511 }
1512
1513 if (setsparse)
1514 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1515 else
1516 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1517
1518 return true;
1519 }
1520
1521 static int
1522 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1523 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1524 {
1525 __le64 eof = cpu_to_le64(size);
1526 struct inode *inode;
1527
1528 /*
1529 * If extending file more than one page make sparse. Many Linux fs
1530 * make files sparse by default when extending via ftruncate
1531 */
1532 inode = d_inode(cfile->dentry);
1533
1534 if (!set_alloc && (size > inode->i_size + 8192)) {
1535 __u8 set_sparse = 1;
1536
1537 /* whether set sparse succeeds or not, extend the file */
1538 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1539 }
1540
1541 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1542 cfile->fid.volatile_fid, cfile->pid, &eof);
1543 }
1544
1545 static int
1546 smb2_duplicate_extents(const unsigned int xid,
1547 struct cifsFileInfo *srcfile,
1548 struct cifsFileInfo *trgtfile, u64 src_off,
1549 u64 len, u64 dest_off)
1550 {
1551 int rc;
1552 unsigned int ret_data_len;
1553 struct duplicate_extents_to_file dup_ext_buf;
1554 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1555
1556 /* server fileays advertise duplicate extent support with this flag */
1557 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1558 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1559 return -EOPNOTSUPP;
1560
1561 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1562 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1563 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1564 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1565 dup_ext_buf.ByteCount = cpu_to_le64(len);
1566 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1567 src_off, dest_off, len);
1568
1569 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1570 if (rc)
1571 goto duplicate_extents_out;
1572
1573 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1574 trgtfile->fid.volatile_fid,
1575 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1576 true /* is_fsctl */,
1577 (char *)&dup_ext_buf,
1578 sizeof(struct duplicate_extents_to_file),
1579 NULL,
1580 &ret_data_len);
1581
1582 if (ret_data_len > 0)
1583 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1584
1585 duplicate_extents_out:
1586 return rc;
1587 }
1588
1589 static int
1590 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1591 struct cifsFileInfo *cfile)
1592 {
1593 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1594 cfile->fid.volatile_fid);
1595 }
1596
1597 static int
1598 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1599 struct cifsFileInfo *cfile)
1600 {
1601 struct fsctl_set_integrity_information_req integr_info;
1602 unsigned int ret_data_len;
1603
1604 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1605 integr_info.Flags = 0;
1606 integr_info.Reserved = 0;
1607
1608 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1609 cfile->fid.volatile_fid,
1610 FSCTL_SET_INTEGRITY_INFORMATION,
1611 true /* is_fsctl */,
1612 (char *)&integr_info,
1613 sizeof(struct fsctl_set_integrity_information_req),
1614 NULL,
1615 &ret_data_len);
1616
1617 }
1618
1619 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1620 #define GMT_TOKEN_SIZE 50
1621
1622 /*
1623 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1624 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1625 */
1626 static int
1627 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1628 struct cifsFileInfo *cfile, void __user *ioc_buf)
1629 {
1630 char *retbuf = NULL;
1631 unsigned int ret_data_len = 0;
1632 int rc;
1633 struct smb_snapshot_array snapshot_in;
1634
1635 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1636 cfile->fid.volatile_fid,
1637 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1638 true /* is_fsctl */,
1639 NULL, 0 /* no input data */,
1640 (char **)&retbuf,
1641 &ret_data_len);
1642 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1643 rc, ret_data_len);
1644 if (rc)
1645 return rc;
1646
1647 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1648 /* Fixup buffer */
1649 if (copy_from_user(&snapshot_in, ioc_buf,
1650 sizeof(struct smb_snapshot_array))) {
1651 rc = -EFAULT;
1652 kfree(retbuf);
1653 return rc;
1654 }
1655
1656 /*
1657 * Check for min size, ie not large enough to fit even one GMT
1658 * token (snapshot). On the first ioctl some users may pass in
1659 * smaller size (or zero) to simply get the size of the array
1660 * so the user space caller can allocate sufficient memory
1661 * and retry the ioctl again with larger array size sufficient
1662 * to hold all of the snapshot GMT tokens on the second try.
1663 */
1664 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1665 ret_data_len = sizeof(struct smb_snapshot_array);
1666
1667 /*
1668 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1669 * the snapshot array (of 50 byte GMT tokens) each
1670 * representing an available previous version of the data
1671 */
1672 if (ret_data_len > (snapshot_in.snapshot_array_size +
1673 sizeof(struct smb_snapshot_array)))
1674 ret_data_len = snapshot_in.snapshot_array_size +
1675 sizeof(struct smb_snapshot_array);
1676
1677 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1678 rc = -EFAULT;
1679 }
1680
1681 kfree(retbuf);
1682 return rc;
1683 }
1684
1685 static int
1686 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1687 const char *path, struct cifs_sb_info *cifs_sb,
1688 struct cifs_fid *fid, __u16 search_flags,
1689 struct cifs_search_info *srch_inf)
1690 {
1691 __le16 *utf16_path;
1692 int rc;
1693 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1694 struct cifs_open_parms oparms;
1695
1696 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1697 if (!utf16_path)
1698 return -ENOMEM;
1699
1700 oparms.tcon = tcon;
1701 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1702 oparms.disposition = FILE_OPEN;
1703 if (backup_cred(cifs_sb))
1704 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1705 else
1706 oparms.create_options = 0;
1707 oparms.fid = fid;
1708 oparms.reconnect = false;
1709
1710 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1711 kfree(utf16_path);
1712 if (rc) {
1713 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1714 return rc;
1715 }
1716
1717 srch_inf->entries_in_buffer = 0;
1718 srch_inf->index_of_last_entry = 2;
1719
1720 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1721 fid->volatile_fid, 0, srch_inf);
1722 if (rc) {
1723 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1724 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1725 }
1726 return rc;
1727 }
1728
1729 static int
1730 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1731 struct cifs_fid *fid, __u16 search_flags,
1732 struct cifs_search_info *srch_inf)
1733 {
1734 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1735 fid->volatile_fid, 0, srch_inf);
1736 }
1737
1738 static int
1739 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1740 struct cifs_fid *fid)
1741 {
1742 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1743 }
1744
1745 /*
1746 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1747 * the number of credits and return true. Otherwise - return false.
1748 */
1749 static bool
1750 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1751 {
1752 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1753
1754 if (shdr->Status != STATUS_PENDING)
1755 return false;
1756
1757 if (!length) {
1758 spin_lock(&server->req_lock);
1759 server->credits += le16_to_cpu(shdr->CreditRequest);
1760 spin_unlock(&server->req_lock);
1761 wake_up(&server->request_q);
1762 }
1763
1764 return true;
1765 }
1766
1767 static bool
1768 smb2_is_session_expired(char *buf)
1769 {
1770 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1771
1772 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1773 shdr->Status != STATUS_USER_SESSION_DELETED)
1774 return false;
1775
1776 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
1777 le16_to_cpu(shdr->Command),
1778 le64_to_cpu(shdr->MessageId));
1779 cifs_dbg(FYI, "Session expired or deleted\n");
1780
1781 return true;
1782 }
1783
1784 static int
1785 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1786 struct cifsInodeInfo *cinode)
1787 {
1788 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1789 return SMB2_lease_break(0, tcon, cinode->lease_key,
1790 smb2_get_lease_state(cinode));
1791
1792 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1793 fid->volatile_fid,
1794 CIFS_CACHE_READ(cinode) ? 1 : 0);
1795 }
1796
1797 void
1798 smb2_set_related(struct smb_rqst *rqst)
1799 {
1800 struct smb2_sync_hdr *shdr;
1801
1802 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1803 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1804 }
1805
1806 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
1807
1808 void
1809 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
1810 {
1811 struct smb2_sync_hdr *shdr;
1812 struct cifs_ses *ses = tcon->ses;
1813 struct TCP_Server_Info *server = ses->server;
1814 unsigned long len = smb_rqst_len(server, rqst);
1815 int i, num_padding;
1816
1817 /* SMB headers in a compound are 8 byte aligned. */
1818
1819 /* No padding needed */
1820 if (!(len & 7))
1821 goto finished;
1822
1823 num_padding = 8 - (len & 7);
1824 if (!smb3_encryption_required(tcon)) {
1825 /*
1826 * If we do not have encryption then we can just add an extra
1827 * iov for the padding.
1828 */
1829 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
1830 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
1831 rqst->rq_nvec++;
1832 len += num_padding;
1833 } else {
1834 /*
1835 * We can not add a small padding iov for the encryption case
1836 * because the encryption framework can not handle the padding
1837 * iovs.
1838 * We have to flatten this into a single buffer and add
1839 * the padding to it.
1840 */
1841 for (i = 1; i < rqst->rq_nvec; i++) {
1842 memcpy(rqst->rq_iov[0].iov_base +
1843 rqst->rq_iov[0].iov_len,
1844 rqst->rq_iov[i].iov_base,
1845 rqst->rq_iov[i].iov_len);
1846 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
1847 }
1848 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
1849 0, num_padding);
1850 rqst->rq_iov[0].iov_len += num_padding;
1851 len += num_padding;
1852 rqst->rq_nvec = 1;
1853 }
1854
1855 finished:
1856 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1857 shdr->NextCommand = cpu_to_le32(len);
1858 }
1859
1860 /*
1861 * Passes the query info response back to the caller on success.
1862 * Caller need to free this with free_rsp_buf().
1863 */
1864 int
1865 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
1866 __le16 *utf16_path, u32 desired_access,
1867 u32 class, u32 type, u32 output_len,
1868 struct kvec *rsp, int *buftype,
1869 struct cifs_sb_info *cifs_sb)
1870 {
1871 struct cifs_ses *ses = tcon->ses;
1872 int flags = 0;
1873 struct smb_rqst rqst[3];
1874 int resp_buftype[3];
1875 struct kvec rsp_iov[3];
1876 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1877 struct kvec qi_iov[1];
1878 struct kvec close_iov[1];
1879 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1880 struct cifs_open_parms oparms;
1881 struct cifs_fid fid;
1882 int rc;
1883
1884 if (smb3_encryption_required(tcon))
1885 flags |= CIFS_TRANSFORM_REQ;
1886
1887 memset(rqst, 0, sizeof(rqst));
1888 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1889 memset(rsp_iov, 0, sizeof(rsp_iov));
1890
1891 memset(&open_iov, 0, sizeof(open_iov));
1892 rqst[0].rq_iov = open_iov;
1893 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1894
1895 oparms.tcon = tcon;
1896 oparms.desired_access = desired_access;
1897 oparms.disposition = FILE_OPEN;
1898 if (cifs_sb && backup_cred(cifs_sb))
1899 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1900 else
1901 oparms.create_options = 0;
1902 oparms.fid = &fid;
1903 oparms.reconnect = false;
1904
1905 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
1906 if (rc)
1907 goto qic_exit;
1908 smb2_set_next_command(tcon, &rqst[0]);
1909
1910 memset(&qi_iov, 0, sizeof(qi_iov));
1911 rqst[1].rq_iov = qi_iov;
1912 rqst[1].rq_nvec = 1;
1913
1914 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1915 class, type, 0,
1916 output_len, 0,
1917 NULL);
1918 if (rc)
1919 goto qic_exit;
1920 smb2_set_next_command(tcon, &rqst[1]);
1921 smb2_set_related(&rqst[1]);
1922
1923 memset(&close_iov, 0, sizeof(close_iov));
1924 rqst[2].rq_iov = close_iov;
1925 rqst[2].rq_nvec = 1;
1926
1927 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1928 if (rc)
1929 goto qic_exit;
1930 smb2_set_related(&rqst[2]);
1931
1932 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1933 resp_buftype, rsp_iov);
1934 if (rc) {
1935 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1936 goto qic_exit;
1937 }
1938 *rsp = rsp_iov[1];
1939 *buftype = resp_buftype[1];
1940
1941 qic_exit:
1942 SMB2_open_free(&rqst[0]);
1943 SMB2_query_info_free(&rqst[1]);
1944 SMB2_close_free(&rqst[2]);
1945 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1946 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1947 return rc;
1948 }
1949
1950 static int
1951 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1952 struct kstatfs *buf)
1953 {
1954 struct smb2_query_info_rsp *rsp;
1955 struct smb2_fs_full_size_info *info = NULL;
1956 __le16 utf16_path = 0; /* Null - open root of share */
1957 struct kvec rsp_iov = {NULL, 0};
1958 int buftype = CIFS_NO_BUFFER;
1959 int rc;
1960
1961
1962 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
1963 FILE_READ_ATTRIBUTES,
1964 FS_FULL_SIZE_INFORMATION,
1965 SMB2_O_INFO_FILESYSTEM,
1966 sizeof(struct smb2_fs_full_size_info),
1967 &rsp_iov, &buftype, NULL);
1968 if (rc)
1969 goto qfs_exit;
1970
1971 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1972 buf->f_type = SMB2_MAGIC_NUMBER;
1973 info = (struct smb2_fs_full_size_info *)(
1974 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1975 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1976 le32_to_cpu(rsp->OutputBufferLength),
1977 &rsp_iov,
1978 sizeof(struct smb2_fs_full_size_info));
1979 if (!rc)
1980 smb2_copy_fs_info_to_kstatfs(info, buf);
1981
1982 qfs_exit:
1983 free_rsp_buf(buftype, rsp_iov.iov_base);
1984 return rc;
1985 }
1986
1987 static int
1988 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1989 struct kstatfs *buf)
1990 {
1991 int rc;
1992 __le16 srch_path = 0; /* Null - open root of share */
1993 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1994 struct cifs_open_parms oparms;
1995 struct cifs_fid fid;
1996
1997 if (!tcon->posix_extensions)
1998 return smb2_queryfs(xid, tcon, buf);
1999
2000 oparms.tcon = tcon;
2001 oparms.desired_access = FILE_READ_ATTRIBUTES;
2002 oparms.disposition = FILE_OPEN;
2003 oparms.create_options = 0;
2004 oparms.fid = &fid;
2005 oparms.reconnect = false;
2006
2007 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2008 if (rc)
2009 return rc;
2010
2011 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2012 fid.volatile_fid, buf);
2013 buf->f_type = SMB2_MAGIC_NUMBER;
2014 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2015 return rc;
2016 }
2017
2018 static bool
2019 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2020 {
2021 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2022 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2023 }
2024
2025 static int
2026 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2027 __u64 length, __u32 type, int lock, int unlock, bool wait)
2028 {
2029 if (unlock && !lock)
2030 type = SMB2_LOCKFLAG_UNLOCK;
2031 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2032 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2033 current->tgid, length, offset, type, wait);
2034 }
2035
2036 static void
2037 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2038 {
2039 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2040 }
2041
2042 static void
2043 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2044 {
2045 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2046 }
2047
2048 static void
2049 smb2_new_lease_key(struct cifs_fid *fid)
2050 {
2051 generate_random_uuid(fid->lease_key);
2052 }
2053
2054 static int
2055 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2056 const char *search_name,
2057 struct dfs_info3_param **target_nodes,
2058 unsigned int *num_of_nodes,
2059 const struct nls_table *nls_codepage, int remap)
2060 {
2061 int rc;
2062 __le16 *utf16_path = NULL;
2063 int utf16_path_len = 0;
2064 struct cifs_tcon *tcon;
2065 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2066 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2067 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2068
2069 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
2070
2071 /*
2072 * Try to use the IPC tcon, otherwise just use any
2073 */
2074 tcon = ses->tcon_ipc;
2075 if (tcon == NULL) {
2076 spin_lock(&cifs_tcp_ses_lock);
2077 tcon = list_first_entry_or_null(&ses->tcon_list,
2078 struct cifs_tcon,
2079 tcon_list);
2080 if (tcon)
2081 tcon->tc_count++;
2082 spin_unlock(&cifs_tcp_ses_lock);
2083 }
2084
2085 if (tcon == NULL) {
2086 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2087 ses);
2088 rc = -ENOTCONN;
2089 goto out;
2090 }
2091
2092 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2093 &utf16_path_len,
2094 nls_codepage, remap);
2095 if (!utf16_path) {
2096 rc = -ENOMEM;
2097 goto out;
2098 }
2099
2100 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2101 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2102 if (!dfs_req) {
2103 rc = -ENOMEM;
2104 goto out;
2105 }
2106
2107 /* Highest DFS referral version understood */
2108 dfs_req->MaxReferralLevel = DFS_VERSION;
2109
2110 /* Path to resolve in an UTF-16 null-terminated string */
2111 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2112
2113 do {
2114 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2115 FSCTL_DFS_GET_REFERRALS,
2116 true /* is_fsctl */,
2117 (char *)dfs_req, dfs_req_size,
2118 (char **)&dfs_rsp, &dfs_rsp_size);
2119 } while (rc == -EAGAIN);
2120
2121 if (rc) {
2122 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2123 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
2124 goto out;
2125 }
2126
2127 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2128 num_of_nodes, target_nodes,
2129 nls_codepage, remap, search_name,
2130 true /* is_unicode */);
2131 if (rc) {
2132 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
2133 goto out;
2134 }
2135
2136 out:
2137 if (tcon && !tcon->ipc) {
2138 /* ipc tcons are not refcounted */
2139 spin_lock(&cifs_tcp_ses_lock);
2140 tcon->tc_count--;
2141 spin_unlock(&cifs_tcp_ses_lock);
2142 }
2143 kfree(utf16_path);
2144 kfree(dfs_req);
2145 kfree(dfs_rsp);
2146 return rc;
2147 }
2148 #define SMB2_SYMLINK_STRUCT_SIZE \
2149 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2150
2151 static int
2152 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2153 const char *full_path, char **target_path,
2154 struct cifs_sb_info *cifs_sb)
2155 {
2156 int rc;
2157 __le16 *utf16_path;
2158 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2159 struct cifs_open_parms oparms;
2160 struct cifs_fid fid;
2161 struct kvec err_iov = {NULL, 0};
2162 struct smb2_err_rsp *err_buf = NULL;
2163 int resp_buftype;
2164 struct smb2_symlink_err_rsp *symlink;
2165 unsigned int sub_len;
2166 unsigned int sub_offset;
2167 unsigned int print_len;
2168 unsigned int print_offset;
2169
2170 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2171
2172 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2173 if (!utf16_path)
2174 return -ENOMEM;
2175
2176 oparms.tcon = tcon;
2177 oparms.desired_access = FILE_READ_ATTRIBUTES;
2178 oparms.disposition = FILE_OPEN;
2179 if (backup_cred(cifs_sb))
2180 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2181 else
2182 oparms.create_options = 0;
2183 oparms.fid = &fid;
2184 oparms.reconnect = false;
2185
2186 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
2187 &resp_buftype);
2188 if (!rc || !err_iov.iov_base) {
2189 rc = -ENOENT;
2190 goto free_path;
2191 }
2192
2193 err_buf = err_iov.iov_base;
2194 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2195 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2196 rc = -ENOENT;
2197 goto querty_exit;
2198 }
2199
2200 /* open must fail on symlink - reset rc */
2201 rc = 0;
2202 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2203 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2204 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2205 print_len = le16_to_cpu(symlink->PrintNameLength);
2206 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2207
2208 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2209 rc = -ENOENT;
2210 goto querty_exit;
2211 }
2212
2213 if (err_iov.iov_len <
2214 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2215 rc = -ENOENT;
2216 goto querty_exit;
2217 }
2218
2219 *target_path = cifs_strndup_from_utf16(
2220 (char *)symlink->PathBuffer + sub_offset,
2221 sub_len, true, cifs_sb->local_nls);
2222 if (!(*target_path)) {
2223 rc = -ENOMEM;
2224 goto querty_exit;
2225 }
2226 convert_delimiter(*target_path, '/');
2227 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2228
2229 querty_exit:
2230 free_rsp_buf(resp_buftype, err_buf);
2231 free_path:
2232 kfree(utf16_path);
2233 return rc;
2234 }
2235
2236 #ifdef CONFIG_CIFS_ACL
2237 static struct cifs_ntsd *
2238 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
2239 const struct cifs_fid *cifsfid, u32 *pacllen)
2240 {
2241 struct cifs_ntsd *pntsd = NULL;
2242 unsigned int xid;
2243 int rc = -EOPNOTSUPP;
2244 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2245
2246 if (IS_ERR(tlink))
2247 return ERR_CAST(tlink);
2248
2249 xid = get_xid();
2250 cifs_dbg(FYI, "trying to get acl\n");
2251
2252 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
2253 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
2254 free_xid(xid);
2255
2256 cifs_put_tlink(tlink);
2257
2258 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2259 if (rc)
2260 return ERR_PTR(rc);
2261 return pntsd;
2262
2263 }
2264
2265 static struct cifs_ntsd *
2266 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
2267 const char *path, u32 *pacllen)
2268 {
2269 struct cifs_ntsd *pntsd = NULL;
2270 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2271 unsigned int xid;
2272 int rc;
2273 struct cifs_tcon *tcon;
2274 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2275 struct cifs_fid fid;
2276 struct cifs_open_parms oparms;
2277 __le16 *utf16_path;
2278
2279 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
2280 if (IS_ERR(tlink))
2281 return ERR_CAST(tlink);
2282
2283 tcon = tlink_tcon(tlink);
2284 xid = get_xid();
2285
2286 if (backup_cred(cifs_sb))
2287 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2288 else
2289 oparms.create_options = 0;
2290
2291 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2292 if (!utf16_path) {
2293 rc = -ENOMEM;
2294 free_xid(xid);
2295 return ERR_PTR(rc);
2296 }
2297
2298 oparms.tcon = tcon;
2299 oparms.desired_access = READ_CONTROL;
2300 oparms.disposition = FILE_OPEN;
2301 oparms.fid = &fid;
2302 oparms.reconnect = false;
2303
2304 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2305 kfree(utf16_path);
2306 if (!rc) {
2307 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2308 fid.volatile_fid, (void **)&pntsd, pacllen);
2309 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2310 }
2311
2312 cifs_put_tlink(tlink);
2313 free_xid(xid);
2314
2315 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2316 if (rc)
2317 return ERR_PTR(rc);
2318 return pntsd;
2319 }
2320
2321 #ifdef CONFIG_CIFS_ACL
2322 static int
2323 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2324 struct inode *inode, const char *path, int aclflag)
2325 {
2326 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2327 unsigned int xid;
2328 int rc, access_flags = 0;
2329 struct cifs_tcon *tcon;
2330 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2331 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2332 struct cifs_fid fid;
2333 struct cifs_open_parms oparms;
2334 __le16 *utf16_path;
2335
2336 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2337 if (IS_ERR(tlink))
2338 return PTR_ERR(tlink);
2339
2340 tcon = tlink_tcon(tlink);
2341 xid = get_xid();
2342
2343 if (backup_cred(cifs_sb))
2344 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2345 else
2346 oparms.create_options = 0;
2347
2348 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2349 access_flags = WRITE_OWNER;
2350 else
2351 access_flags = WRITE_DAC;
2352
2353 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2354 if (!utf16_path) {
2355 rc = -ENOMEM;
2356 free_xid(xid);
2357 return rc;
2358 }
2359
2360 oparms.tcon = tcon;
2361 oparms.desired_access = access_flags;
2362 oparms.disposition = FILE_OPEN;
2363 oparms.path = path;
2364 oparms.fid = &fid;
2365 oparms.reconnect = false;
2366
2367 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2368 kfree(utf16_path);
2369 if (!rc) {
2370 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2371 fid.volatile_fid, pnntsd, acllen, aclflag);
2372 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2373 }
2374
2375 cifs_put_tlink(tlink);
2376 free_xid(xid);
2377 return rc;
2378 }
2379 #endif /* CIFS_ACL */
2380
2381 /* Retrieve an ACL from the server */
2382 static struct cifs_ntsd *
2383 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2384 struct inode *inode, const char *path,
2385 u32 *pacllen)
2386 {
2387 struct cifs_ntsd *pntsd = NULL;
2388 struct cifsFileInfo *open_file = NULL;
2389
2390 if (inode)
2391 open_file = find_readable_file(CIFS_I(inode), true);
2392 if (!open_file)
2393 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2394
2395 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2396 cifsFileInfo_put(open_file);
2397 return pntsd;
2398 }
2399 #endif
2400
2401 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2402 loff_t offset, loff_t len, bool keep_size)
2403 {
2404 struct inode *inode;
2405 struct cifsInodeInfo *cifsi;
2406 struct cifsFileInfo *cfile = file->private_data;
2407 struct file_zero_data_information fsctl_buf;
2408 long rc;
2409 unsigned int xid;
2410
2411 xid = get_xid();
2412
2413 inode = d_inode(cfile->dentry);
2414 cifsi = CIFS_I(inode);
2415
2416 /* if file not oplocked can't be sure whether asking to extend size */
2417 if (!CIFS_CACHE_READ(cifsi))
2418 if (keep_size == false) {
2419 rc = -EOPNOTSUPP;
2420 free_xid(xid);
2421 return rc;
2422 }
2423
2424 /*
2425 * Must check if file sparse since fallocate -z (zero range) assumes
2426 * non-sparse allocation
2427 */
2428 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2429 rc = -EOPNOTSUPP;
2430 free_xid(xid);
2431 return rc;
2432 }
2433
2434 /*
2435 * need to make sure we are not asked to extend the file since the SMB3
2436 * fsctl does not change the file size. In the future we could change
2437 * this to zero the first part of the range then set the file size
2438 * which for a non sparse file would zero the newly extended range
2439 */
2440 if (keep_size == false)
2441 if (i_size_read(inode) < offset + len) {
2442 rc = -EOPNOTSUPP;
2443 free_xid(xid);
2444 return rc;
2445 }
2446
2447 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2448
2449 fsctl_buf.FileOffset = cpu_to_le64(offset);
2450 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2451
2452 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2453 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2454 true /* is_fctl */, (char *)&fsctl_buf,
2455 sizeof(struct file_zero_data_information), NULL, NULL);
2456 free_xid(xid);
2457 return rc;
2458 }
2459
2460 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2461 loff_t offset, loff_t len)
2462 {
2463 struct inode *inode;
2464 struct cifsInodeInfo *cifsi;
2465 struct cifsFileInfo *cfile = file->private_data;
2466 struct file_zero_data_information fsctl_buf;
2467 long rc;
2468 unsigned int xid;
2469 __u8 set_sparse = 1;
2470
2471 xid = get_xid();
2472
2473 inode = d_inode(cfile->dentry);
2474 cifsi = CIFS_I(inode);
2475
2476 /* Need to make file sparse, if not already, before freeing range. */
2477 /* Consider adding equivalent for compressed since it could also work */
2478 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2479 rc = -EOPNOTSUPP;
2480 free_xid(xid);
2481 return rc;
2482 }
2483
2484 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2485
2486 fsctl_buf.FileOffset = cpu_to_le64(offset);
2487 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2488
2489 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2490 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2491 true /* is_fctl */, (char *)&fsctl_buf,
2492 sizeof(struct file_zero_data_information), NULL, NULL);
2493 free_xid(xid);
2494 return rc;
2495 }
2496
2497 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2498 loff_t off, loff_t len, bool keep_size)
2499 {
2500 struct inode *inode;
2501 struct cifsInodeInfo *cifsi;
2502 struct cifsFileInfo *cfile = file->private_data;
2503 long rc = -EOPNOTSUPP;
2504 unsigned int xid;
2505
2506 xid = get_xid();
2507
2508 inode = d_inode(cfile->dentry);
2509 cifsi = CIFS_I(inode);
2510
2511 /* if file not oplocked can't be sure whether asking to extend size */
2512 if (!CIFS_CACHE_READ(cifsi))
2513 if (keep_size == false) {
2514 free_xid(xid);
2515 return rc;
2516 }
2517
2518 /*
2519 * Files are non-sparse by default so falloc may be a no-op
2520 * Must check if file sparse. If not sparse, and not extending
2521 * then no need to do anything since file already allocated
2522 */
2523 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2524 if (keep_size == true)
2525 rc = 0;
2526 /* check if extending file */
2527 else if (i_size_read(inode) >= off + len)
2528 /* not extending file and already not sparse */
2529 rc = 0;
2530 /* BB: in future add else clause to extend file */
2531 else
2532 rc = -EOPNOTSUPP;
2533 free_xid(xid);
2534 return rc;
2535 }
2536
2537 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2538 /*
2539 * Check if falloc starts within first few pages of file
2540 * and ends within a few pages of the end of file to
2541 * ensure that most of file is being forced to be
2542 * fallocated now. If so then setting whole file sparse
2543 * ie potentially making a few extra pages at the beginning
2544 * or end of the file non-sparse via set_sparse is harmless.
2545 */
2546 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2547 rc = -EOPNOTSUPP;
2548 free_xid(xid);
2549 return rc;
2550 }
2551
2552 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
2553 }
2554 /* BB: else ... in future add code to extend file and set sparse */
2555
2556
2557 free_xid(xid);
2558 return rc;
2559 }
2560
2561
2562 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2563 loff_t off, loff_t len)
2564 {
2565 /* KEEP_SIZE already checked for by do_fallocate */
2566 if (mode & FALLOC_FL_PUNCH_HOLE)
2567 return smb3_punch_hole(file, tcon, off, len);
2568 else if (mode & FALLOC_FL_ZERO_RANGE) {
2569 if (mode & FALLOC_FL_KEEP_SIZE)
2570 return smb3_zero_range(file, tcon, off, len, true);
2571 return smb3_zero_range(file, tcon, off, len, false);
2572 } else if (mode == FALLOC_FL_KEEP_SIZE)
2573 return smb3_simple_falloc(file, tcon, off, len, true);
2574 else if (mode == 0)
2575 return smb3_simple_falloc(file, tcon, off, len, false);
2576
2577 return -EOPNOTSUPP;
2578 }
2579
2580 static void
2581 smb2_downgrade_oplock(struct TCP_Server_Info *server,
2582 struct cifsInodeInfo *cinode, bool set_level2)
2583 {
2584 if (set_level2)
2585 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2586 0, NULL);
2587 else
2588 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2589 }
2590
2591 static void
2592 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2593 unsigned int epoch, bool *purge_cache)
2594 {
2595 oplock &= 0xFF;
2596 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2597 return;
2598 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2599 cinode->oplock = CIFS_CACHE_RHW_FLG;
2600 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2601 &cinode->vfs_inode);
2602 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
2603 cinode->oplock = CIFS_CACHE_RW_FLG;
2604 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2605 &cinode->vfs_inode);
2606 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2607 cinode->oplock = CIFS_CACHE_READ_FLG;
2608 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2609 &cinode->vfs_inode);
2610 } else
2611 cinode->oplock = 0;
2612 }
2613
2614 static void
2615 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2616 unsigned int epoch, bool *purge_cache)
2617 {
2618 char message[5] = {0};
2619
2620 oplock &= 0xFF;
2621 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2622 return;
2623
2624 cinode->oplock = 0;
2625 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2626 cinode->oplock |= CIFS_CACHE_READ_FLG;
2627 strcat(message, "R");
2628 }
2629 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2630 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2631 strcat(message, "H");
2632 }
2633 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2634 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2635 strcat(message, "W");
2636 }
2637 if (!cinode->oplock)
2638 strcat(message, "None");
2639 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2640 &cinode->vfs_inode);
2641 }
2642
2643 static void
2644 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2645 unsigned int epoch, bool *purge_cache)
2646 {
2647 unsigned int old_oplock = cinode->oplock;
2648
2649 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2650
2651 if (purge_cache) {
2652 *purge_cache = false;
2653 if (old_oplock == CIFS_CACHE_READ_FLG) {
2654 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2655 (epoch - cinode->epoch > 0))
2656 *purge_cache = true;
2657 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2658 (epoch - cinode->epoch > 1))
2659 *purge_cache = true;
2660 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2661 (epoch - cinode->epoch > 1))
2662 *purge_cache = true;
2663 else if (cinode->oplock == 0 &&
2664 (epoch - cinode->epoch > 0))
2665 *purge_cache = true;
2666 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2667 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2668 (epoch - cinode->epoch > 0))
2669 *purge_cache = true;
2670 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2671 (epoch - cinode->epoch > 1))
2672 *purge_cache = true;
2673 }
2674 cinode->epoch = epoch;
2675 }
2676 }
2677
2678 static bool
2679 smb2_is_read_op(__u32 oplock)
2680 {
2681 return oplock == SMB2_OPLOCK_LEVEL_II;
2682 }
2683
2684 static bool
2685 smb21_is_read_op(__u32 oplock)
2686 {
2687 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2688 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2689 }
2690
2691 static __le32
2692 map_oplock_to_lease(u8 oplock)
2693 {
2694 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2695 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2696 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2697 return SMB2_LEASE_READ_CACHING;
2698 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2699 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2700 SMB2_LEASE_WRITE_CACHING;
2701 return 0;
2702 }
2703
2704 static char *
2705 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2706 {
2707 struct create_lease *buf;
2708
2709 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2710 if (!buf)
2711 return NULL;
2712
2713 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2714 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2715
2716 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2717 (struct create_lease, lcontext));
2718 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2719 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2720 (struct create_lease, Name));
2721 buf->ccontext.NameLength = cpu_to_le16(4);
2722 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2723 buf->Name[0] = 'R';
2724 buf->Name[1] = 'q';
2725 buf->Name[2] = 'L';
2726 buf->Name[3] = 's';
2727 return (char *)buf;
2728 }
2729
2730 static char *
2731 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2732 {
2733 struct create_lease_v2 *buf;
2734
2735 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2736 if (!buf)
2737 return NULL;
2738
2739 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2740 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2741
2742 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2743 (struct create_lease_v2, lcontext));
2744 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2745 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2746 (struct create_lease_v2, Name));
2747 buf->ccontext.NameLength = cpu_to_le16(4);
2748 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2749 buf->Name[0] = 'R';
2750 buf->Name[1] = 'q';
2751 buf->Name[2] = 'L';
2752 buf->Name[3] = 's';
2753 return (char *)buf;
2754 }
2755
2756 static __u8
2757 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2758 {
2759 struct create_lease *lc = (struct create_lease *)buf;
2760
2761 *epoch = 0; /* not used */
2762 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2763 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2764 return le32_to_cpu(lc->lcontext.LeaseState);
2765 }
2766
2767 static __u8
2768 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2769 {
2770 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2771
2772 *epoch = le16_to_cpu(lc->lcontext.Epoch);
2773 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2774 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2775 if (lease_key)
2776 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
2777 return le32_to_cpu(lc->lcontext.LeaseState);
2778 }
2779
2780 static unsigned int
2781 smb2_wp_retry_size(struct inode *inode)
2782 {
2783 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2784 SMB2_MAX_BUFFER_SIZE);
2785 }
2786
2787 static bool
2788 smb2_dir_needs_close(struct cifsFileInfo *cfile)
2789 {
2790 return !cfile->invalidHandle;
2791 }
2792
2793 static void
2794 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2795 struct smb_rqst *old_rq)
2796 {
2797 struct smb2_sync_hdr *shdr =
2798 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
2799
2800 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2801 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2802 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2803 tr_hdr->Flags = cpu_to_le16(0x01);
2804 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2805 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2806 }
2807
2808 /* We can not use the normal sg_set_buf() as we will sometimes pass a
2809 * stack object as buf.
2810 */
2811 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2812 unsigned int buflen)
2813 {
2814 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2815 }
2816
2817 /* Assumes the first rqst has a transform header as the first iov.
2818 * I.e.
2819 * rqst[0].rq_iov[0] is transform header
2820 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
2821 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
2822 */
2823 static struct scatterlist *
2824 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
2825 {
2826 unsigned int sg_len;
2827 struct scatterlist *sg;
2828 unsigned int i;
2829 unsigned int j;
2830 unsigned int idx = 0;
2831 int skip;
2832
2833 sg_len = 1;
2834 for (i = 0; i < num_rqst; i++)
2835 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
2836
2837 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2838 if (!sg)
2839 return NULL;
2840
2841 sg_init_table(sg, sg_len);
2842 for (i = 0; i < num_rqst; i++) {
2843 for (j = 0; j < rqst[i].rq_nvec; j++) {
2844 /*
2845 * The first rqst has a transform header where the
2846 * first 20 bytes are not part of the encrypted blob
2847 */
2848 skip = (i == 0) && (j == 0) ? 20 : 0;
2849 smb2_sg_set_buf(&sg[idx++],
2850 rqst[i].rq_iov[j].iov_base + skip,
2851 rqst[i].rq_iov[j].iov_len - skip);
2852 }
2853
2854 for (j = 0; j < rqst[i].rq_npages; j++) {
2855 unsigned int len, offset;
2856
2857 rqst_page_get_length(&rqst[i], j, &len, &offset);
2858 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
2859 }
2860 }
2861 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
2862 return sg;
2863 }
2864
2865 static int
2866 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2867 {
2868 struct cifs_ses *ses;
2869 u8 *ses_enc_key;
2870
2871 spin_lock(&cifs_tcp_ses_lock);
2872 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2873 if (ses->Suid != ses_id)
2874 continue;
2875 ses_enc_key = enc ? ses->smb3encryptionkey :
2876 ses->smb3decryptionkey;
2877 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2878 spin_unlock(&cifs_tcp_ses_lock);
2879 return 0;
2880 }
2881 spin_unlock(&cifs_tcp_ses_lock);
2882
2883 return 1;
2884 }
2885 /*
2886 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2887 * iov[0] - transform header (associate data),
2888 * iov[1-N] - SMB2 header and pages - data to encrypt.
2889 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2890 * untouched.
2891 */
2892 static int
2893 crypt_message(struct TCP_Server_Info *server, int num_rqst,
2894 struct smb_rqst *rqst, int enc)
2895 {
2896 struct smb2_transform_hdr *tr_hdr =
2897 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
2898 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2899 int rc = 0;
2900 struct scatterlist *sg;
2901 u8 sign[SMB2_SIGNATURE_SIZE] = {};
2902 u8 key[SMB3_SIGN_KEY_SIZE];
2903 struct aead_request *req;
2904 char *iv;
2905 unsigned int iv_len;
2906 DECLARE_CRYPTO_WAIT(wait);
2907 struct crypto_aead *tfm;
2908 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2909
2910 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2911 if (rc) {
2912 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2913 enc ? "en" : "de");
2914 return 0;
2915 }
2916
2917 rc = smb3_crypto_aead_allocate(server);
2918 if (rc) {
2919 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2920 return rc;
2921 }
2922
2923 tfm = enc ? server->secmech.ccmaesencrypt :
2924 server->secmech.ccmaesdecrypt;
2925 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
2926 if (rc) {
2927 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2928 return rc;
2929 }
2930
2931 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2932 if (rc) {
2933 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2934 return rc;
2935 }
2936
2937 req = aead_request_alloc(tfm, GFP_KERNEL);
2938 if (!req) {
2939 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2940 return -ENOMEM;
2941 }
2942
2943 if (!enc) {
2944 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2945 crypt_len += SMB2_SIGNATURE_SIZE;
2946 }
2947
2948 sg = init_sg(num_rqst, rqst, sign);
2949 if (!sg) {
2950 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2951 rc = -ENOMEM;
2952 goto free_req;
2953 }
2954
2955 iv_len = crypto_aead_ivsize(tfm);
2956 iv = kzalloc(iv_len, GFP_KERNEL);
2957 if (!iv) {
2958 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
2959 rc = -ENOMEM;
2960 goto free_sg;
2961 }
2962 iv[0] = 3;
2963 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2964
2965 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2966 aead_request_set_ad(req, assoc_data_len);
2967
2968 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2969 crypto_req_done, &wait);
2970
2971 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2972 : crypto_aead_decrypt(req), &wait);
2973
2974 if (!rc && enc)
2975 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2976
2977 kfree(iv);
2978 free_sg:
2979 kfree(sg);
2980 free_req:
2981 kfree(req);
2982 return rc;
2983 }
2984
2985 void
2986 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
2987 {
2988 int i, j;
2989
2990 for (i = 0; i < num_rqst; i++) {
2991 if (rqst[i].rq_pages) {
2992 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
2993 put_page(rqst[i].rq_pages[j]);
2994 kfree(rqst[i].rq_pages);
2995 }
2996 }
2997 }
2998
2999 /*
3000 * This function will initialize new_rq and encrypt the content.
3001 * The first entry, new_rq[0], only contains a single iov which contains
3002 * a smb2_transform_hdr and is pre-allocated by the caller.
3003 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3004 *
3005 * The end result is an array of smb_rqst structures where the first structure
3006 * only contains a single iov for the transform header which we then can pass
3007 * to crypt_message().
3008 *
3009 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3010 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3011 */
3012 static int
3013 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
3014 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
3015 {
3016 struct page **pages;
3017 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
3018 unsigned int npages;
3019 unsigned int orig_len = 0;
3020 int i, j;
3021 int rc = -ENOMEM;
3022
3023 for (i = 1; i < num_rqst; i++) {
3024 npages = old_rq[i - 1].rq_npages;
3025 pages = kmalloc_array(npages, sizeof(struct page *),
3026 GFP_KERNEL);
3027 if (!pages)
3028 goto err_free;
3029
3030 new_rq[i].rq_pages = pages;
3031 new_rq[i].rq_npages = npages;
3032 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
3033 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
3034 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
3035 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
3036 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
3037
3038 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
3039
3040 for (j = 0; j < npages; j++) {
3041 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3042 if (!pages[j])
3043 goto err_free;
3044 }
3045
3046 /* copy pages form the old */
3047 for (j = 0; j < npages; j++) {
3048 char *dst, *src;
3049 unsigned int offset, len;
3050
3051 rqst_page_get_length(&new_rq[i], j, &len, &offset);
3052
3053 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
3054 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
3055
3056 memcpy(dst, src, len);
3057 kunmap(new_rq[i].rq_pages[j]);
3058 kunmap(old_rq[i - 1].rq_pages[j]);
3059 }
3060 }
3061
3062 /* fill the 1st iov with a transform header */
3063 fill_transform_hdr(tr_hdr, orig_len, old_rq);
3064
3065 rc = crypt_message(server, num_rqst, new_rq, 1);
3066 cifs_dbg(FYI, "encrypt message returned %d", rc);
3067 if (rc)
3068 goto err_free;
3069
3070 return rc;
3071
3072 err_free:
3073 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
3074 return rc;
3075 }
3076
3077 static int
3078 smb3_is_transform_hdr(void *buf)
3079 {
3080 struct smb2_transform_hdr *trhdr = buf;
3081
3082 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
3083 }
3084
3085 static int
3086 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
3087 unsigned int buf_data_size, struct page **pages,
3088 unsigned int npages, unsigned int page_data_size)
3089 {
3090 struct kvec iov[2];
3091 struct smb_rqst rqst = {NULL};
3092 int rc;
3093
3094 iov[0].iov_base = buf;
3095 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
3096 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
3097 iov[1].iov_len = buf_data_size;
3098
3099 rqst.rq_iov = iov;
3100 rqst.rq_nvec = 2;
3101 rqst.rq_pages = pages;
3102 rqst.rq_npages = npages;
3103 rqst.rq_pagesz = PAGE_SIZE;
3104 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
3105
3106 rc = crypt_message(server, 1, &rqst, 0);
3107 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
3108
3109 if (rc)
3110 return rc;
3111
3112 memmove(buf, iov[1].iov_base, buf_data_size);
3113
3114 server->total_read = buf_data_size + page_data_size;
3115
3116 return rc;
3117 }
3118
3119 static int
3120 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
3121 unsigned int npages, unsigned int len)
3122 {
3123 int i;
3124 int length;
3125
3126 for (i = 0; i < npages; i++) {
3127 struct page *page = pages[i];
3128 size_t n;
3129
3130 n = len;
3131 if (len >= PAGE_SIZE) {
3132 /* enough data to fill the page */
3133 n = PAGE_SIZE;
3134 len -= n;
3135 } else {
3136 zero_user(page, len, PAGE_SIZE - len);
3137 len = 0;
3138 }
3139 length = cifs_read_page_from_socket(server, page, 0, n);
3140 if (length < 0)
3141 return length;
3142 server->total_read += length;
3143 }
3144
3145 return 0;
3146 }
3147
3148 static int
3149 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
3150 unsigned int cur_off, struct bio_vec **page_vec)
3151 {
3152 struct bio_vec *bvec;
3153 int i;
3154
3155 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
3156 if (!bvec)
3157 return -ENOMEM;
3158
3159 for (i = 0; i < npages; i++) {
3160 bvec[i].bv_page = pages[i];
3161 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
3162 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
3163 data_size -= bvec[i].bv_len;
3164 }
3165
3166 if (data_size != 0) {
3167 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
3168 kfree(bvec);
3169 return -EIO;
3170 }
3171
3172 *page_vec = bvec;
3173 return 0;
3174 }
3175
3176 static int
3177 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
3178 char *buf, unsigned int buf_len, struct page **pages,
3179 unsigned int npages, unsigned int page_data_size)
3180 {
3181 unsigned int data_offset;
3182 unsigned int data_len;
3183 unsigned int cur_off;
3184 unsigned int cur_page_idx;
3185 unsigned int pad_len;
3186 struct cifs_readdata *rdata = mid->callback_data;
3187 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
3188 struct bio_vec *bvec = NULL;
3189 struct iov_iter iter;
3190 struct kvec iov;
3191 int length;
3192 bool use_rdma_mr = false;
3193
3194 if (shdr->Command != SMB2_READ) {
3195 cifs_dbg(VFS, "only big read responses are supported\n");
3196 return -ENOTSUPP;
3197 }
3198
3199 if (server->ops->is_session_expired &&
3200 server->ops->is_session_expired(buf)) {
3201 cifs_reconnect(server);
3202 wake_up(&server->response_q);
3203 return -1;
3204 }
3205
3206 if (server->ops->is_status_pending &&
3207 server->ops->is_status_pending(buf, server, 0))
3208 return -1;
3209
3210 rdata->result = server->ops->map_error(buf, false);
3211 if (rdata->result != 0) {
3212 cifs_dbg(FYI, "%s: server returned error %d\n",
3213 __func__, rdata->result);
3214 dequeue_mid(mid, rdata->result);
3215 return 0;
3216 }
3217
3218 data_offset = server->ops->read_data_offset(buf);
3219 #ifdef CONFIG_CIFS_SMB_DIRECT
3220 use_rdma_mr = rdata->mr;
3221 #endif
3222 data_len = server->ops->read_data_length(buf, use_rdma_mr);
3223
3224 if (data_offset < server->vals->read_rsp_size) {
3225 /*
3226 * win2k8 sometimes sends an offset of 0 when the read
3227 * is beyond the EOF. Treat it as if the data starts just after
3228 * the header.
3229 */
3230 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
3231 __func__, data_offset);
3232 data_offset = server->vals->read_rsp_size;
3233 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
3234 /* data_offset is beyond the end of smallbuf */
3235 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
3236 __func__, data_offset);
3237 rdata->result = -EIO;
3238 dequeue_mid(mid, rdata->result);
3239 return 0;
3240 }
3241
3242 pad_len = data_offset - server->vals->read_rsp_size;
3243
3244 if (buf_len <= data_offset) {
3245 /* read response payload is in pages */
3246 cur_page_idx = pad_len / PAGE_SIZE;
3247 cur_off = pad_len % PAGE_SIZE;
3248
3249 if (cur_page_idx != 0) {
3250 /* data offset is beyond the 1st page of response */
3251 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
3252 __func__, data_offset);
3253 rdata->result = -EIO;
3254 dequeue_mid(mid, rdata->result);
3255 return 0;
3256 }
3257
3258 if (data_len > page_data_size - pad_len) {
3259 /* data_len is corrupt -- discard frame */
3260 rdata->result = -EIO;
3261 dequeue_mid(mid, rdata->result);
3262 return 0;
3263 }
3264
3265 rdata->result = init_read_bvec(pages, npages, page_data_size,
3266 cur_off, &bvec);
3267 if (rdata->result != 0) {
3268 dequeue_mid(mid, rdata->result);
3269 return 0;
3270 }
3271
3272 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
3273 } else if (buf_len >= data_offset + data_len) {
3274 /* read response payload is in buf */
3275 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
3276 iov.iov_base = buf + data_offset;
3277 iov.iov_len = data_len;
3278 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
3279 } else {
3280 /* read response payload cannot be in both buf and pages */
3281 WARN_ONCE(1, "buf can not contain only a part of read data");
3282 rdata->result = -EIO;
3283 dequeue_mid(mid, rdata->result);
3284 return 0;
3285 }
3286
3287 /* set up first iov for signature check */
3288 rdata->iov[0].iov_base = buf;
3289 rdata->iov[0].iov_len = 4;
3290 rdata->iov[1].iov_base = buf + 4;
3291 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
3292 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
3293 rdata->iov[0].iov_base, server->vals->read_rsp_size);
3294
3295 length = rdata->copy_into_pages(server, rdata, &iter);
3296
3297 kfree(bvec);
3298
3299 if (length < 0)
3300 return length;
3301
3302 dequeue_mid(mid, false);
3303 return length;
3304 }
3305
3306 static int
3307 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
3308 {
3309 char *buf = server->smallbuf;
3310 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3311 unsigned int npages;
3312 struct page **pages;
3313 unsigned int len;
3314 unsigned int buflen = server->pdu_size;
3315 int rc;
3316 int i = 0;
3317
3318 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
3319 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
3320
3321 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
3322 if (rc < 0)
3323 return rc;
3324 server->total_read += rc;
3325
3326 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
3327 server->vals->read_rsp_size;
3328 npages = DIV_ROUND_UP(len, PAGE_SIZE);
3329
3330 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
3331 if (!pages) {
3332 rc = -ENOMEM;
3333 goto discard_data;
3334 }
3335
3336 for (; i < npages; i++) {
3337 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3338 if (!pages[i]) {
3339 rc = -ENOMEM;
3340 goto discard_data;
3341 }
3342 }
3343
3344 /* read read data into pages */
3345 rc = read_data_into_pages(server, pages, npages, len);
3346 if (rc)
3347 goto free_pages;
3348
3349 rc = cifs_discard_remaining_data(server);
3350 if (rc)
3351 goto free_pages;
3352
3353 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
3354 pages, npages, len);
3355 if (rc)
3356 goto free_pages;
3357
3358 *mid = smb2_find_mid(server, buf);
3359 if (*mid == NULL)
3360 cifs_dbg(FYI, "mid not found\n");
3361 else {
3362 cifs_dbg(FYI, "mid found\n");
3363 (*mid)->decrypted = true;
3364 rc = handle_read_data(server, *mid, buf,
3365 server->vals->read_rsp_size,
3366 pages, npages, len);
3367 }
3368
3369 free_pages:
3370 for (i = i - 1; i >= 0; i--)
3371 put_page(pages[i]);
3372 kfree(pages);
3373 return rc;
3374 discard_data:
3375 cifs_discard_remaining_data(server);
3376 goto free_pages;
3377 }
3378
3379 static int
3380 receive_encrypted_standard(struct TCP_Server_Info *server,
3381 struct mid_q_entry **mids, char **bufs,
3382 int *num_mids)
3383 {
3384 int ret, length;
3385 char *buf = server->smallbuf;
3386 char *tmpbuf;
3387 struct smb2_sync_hdr *shdr;
3388 unsigned int pdu_length = server->pdu_size;
3389 unsigned int buf_size;
3390 struct mid_q_entry *mid_entry;
3391 int next_is_large;
3392 char *next_buffer = NULL;
3393
3394 *num_mids = 0;
3395
3396 /* switch to large buffer if too big for a small one */
3397 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
3398 server->large_buf = true;
3399 memcpy(server->bigbuf, buf, server->total_read);
3400 buf = server->bigbuf;
3401 }
3402
3403 /* now read the rest */
3404 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
3405 pdu_length - HEADER_SIZE(server) + 1);
3406 if (length < 0)
3407 return length;
3408 server->total_read += length;
3409
3410 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
3411 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
3412 if (length)
3413 return length;
3414
3415 next_is_large = server->large_buf;
3416 one_more:
3417 shdr = (struct smb2_sync_hdr *)buf;
3418 if (shdr->NextCommand) {
3419 if (next_is_large) {
3420 tmpbuf = server->bigbuf;
3421 next_buffer = (char *)cifs_buf_get();
3422 } else {
3423 tmpbuf = server->smallbuf;
3424 next_buffer = (char *)cifs_small_buf_get();
3425 }
3426 memcpy(next_buffer,
3427 tmpbuf + le32_to_cpu(shdr->NextCommand),
3428 pdu_length - le32_to_cpu(shdr->NextCommand));
3429 }
3430
3431 mid_entry = smb2_find_mid(server, buf);
3432 if (mid_entry == NULL)
3433 cifs_dbg(FYI, "mid not found\n");
3434 else {
3435 cifs_dbg(FYI, "mid found\n");
3436 mid_entry->decrypted = true;
3437 mid_entry->resp_buf_size = server->pdu_size;
3438 }
3439
3440 if (*num_mids >= MAX_COMPOUND) {
3441 cifs_dbg(VFS, "too many PDUs in compound\n");
3442 return -1;
3443 }
3444 bufs[*num_mids] = buf;
3445 mids[(*num_mids)++] = mid_entry;
3446
3447 if (mid_entry && mid_entry->handle)
3448 ret = mid_entry->handle(server, mid_entry);
3449 else
3450 ret = cifs_handle_standard(server, mid_entry);
3451
3452 if (ret == 0 && shdr->NextCommand) {
3453 pdu_length -= le32_to_cpu(shdr->NextCommand);
3454 server->large_buf = next_is_large;
3455 if (next_is_large)
3456 server->bigbuf = next_buffer;
3457 else
3458 server->smallbuf = next_buffer;
3459
3460 buf += le32_to_cpu(shdr->NextCommand);
3461 goto one_more;
3462 }
3463
3464 return ret;
3465 }
3466
3467 static int
3468 smb3_receive_transform(struct TCP_Server_Info *server,
3469 struct mid_q_entry **mids, char **bufs, int *num_mids)
3470 {
3471 char *buf = server->smallbuf;
3472 unsigned int pdu_length = server->pdu_size;
3473 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3474 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3475
3476 if (pdu_length < sizeof(struct smb2_transform_hdr) +
3477 sizeof(struct smb2_sync_hdr)) {
3478 cifs_dbg(VFS, "Transform message is too small (%u)\n",
3479 pdu_length);
3480 cifs_reconnect(server);
3481 wake_up(&server->response_q);
3482 return -ECONNABORTED;
3483 }
3484
3485 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
3486 cifs_dbg(VFS, "Transform message is broken\n");
3487 cifs_reconnect(server);
3488 wake_up(&server->response_q);
3489 return -ECONNABORTED;
3490 }
3491
3492 /* TODO: add support for compounds containing READ. */
3493 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
3494 *num_mids = 1;
3495 return receive_encrypted_read(server, &mids[0]);
3496 }
3497
3498 return receive_encrypted_standard(server, mids, bufs, num_mids);
3499 }
3500
3501 int
3502 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
3503 {
3504 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
3505
3506 return handle_read_data(server, mid, buf, server->pdu_size,
3507 NULL, 0, 0);
3508 }
3509
3510 static int
3511 smb2_next_header(char *buf)
3512 {
3513 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
3514 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
3515
3516 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
3517 return sizeof(struct smb2_transform_hdr) +
3518 le32_to_cpu(t_hdr->OriginalMessageSize);
3519
3520 return le32_to_cpu(hdr->NextCommand);
3521 }
3522
3523 struct smb_version_operations smb20_operations = {
3524 .compare_fids = smb2_compare_fids,
3525 .setup_request = smb2_setup_request,
3526 .setup_async_request = smb2_setup_async_request,
3527 .check_receive = smb2_check_receive,
3528 .add_credits = smb2_add_credits,
3529 .set_credits = smb2_set_credits,
3530 .get_credits_field = smb2_get_credits_field,
3531 .get_credits = smb2_get_credits,
3532 .wait_mtu_credits = cifs_wait_mtu_credits,
3533 .get_next_mid = smb2_get_next_mid,
3534 .read_data_offset = smb2_read_data_offset,
3535 .read_data_length = smb2_read_data_length,
3536 .map_error = map_smb2_to_linux_error,
3537 .find_mid = smb2_find_mid,
3538 .check_message = smb2_check_message,
3539 .dump_detail = smb2_dump_detail,
3540 .clear_stats = smb2_clear_stats,
3541 .print_stats = smb2_print_stats,
3542 .is_oplock_break = smb2_is_valid_oplock_break,
3543 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3544 .downgrade_oplock = smb2_downgrade_oplock,
3545 .need_neg = smb2_need_neg,
3546 .negotiate = smb2_negotiate,
3547 .negotiate_wsize = smb2_negotiate_wsize,
3548 .negotiate_rsize = smb2_negotiate_rsize,
3549 .sess_setup = SMB2_sess_setup,
3550 .logoff = SMB2_logoff,
3551 .tree_connect = SMB2_tcon,
3552 .tree_disconnect = SMB2_tdis,
3553 .qfs_tcon = smb2_qfs_tcon,
3554 .is_path_accessible = smb2_is_path_accessible,
3555 .can_echo = smb2_can_echo,
3556 .echo = SMB2_echo,
3557 .query_path_info = smb2_query_path_info,
3558 .get_srv_inum = smb2_get_srv_inum,
3559 .query_file_info = smb2_query_file_info,
3560 .set_path_size = smb2_set_path_size,
3561 .set_file_size = smb2_set_file_size,
3562 .set_file_info = smb2_set_file_info,
3563 .set_compression = smb2_set_compression,
3564 .mkdir = smb2_mkdir,
3565 .mkdir_setinfo = smb2_mkdir_setinfo,
3566 .rmdir = smb2_rmdir,
3567 .unlink = smb2_unlink,
3568 .rename = smb2_rename_path,
3569 .create_hardlink = smb2_create_hardlink,
3570 .query_symlink = smb2_query_symlink,
3571 .query_mf_symlink = smb3_query_mf_symlink,
3572 .create_mf_symlink = smb3_create_mf_symlink,
3573 .open = smb2_open_file,
3574 .set_fid = smb2_set_fid,
3575 .close = smb2_close_file,
3576 .flush = smb2_flush_file,
3577 .async_readv = smb2_async_readv,
3578 .async_writev = smb2_async_writev,
3579 .sync_read = smb2_sync_read,
3580 .sync_write = smb2_sync_write,
3581 .query_dir_first = smb2_query_dir_first,
3582 .query_dir_next = smb2_query_dir_next,
3583 .close_dir = smb2_close_dir,
3584 .calc_smb_size = smb2_calc_size,
3585 .is_status_pending = smb2_is_status_pending,
3586 .is_session_expired = smb2_is_session_expired,
3587 .oplock_response = smb2_oplock_response,
3588 .queryfs = smb2_queryfs,
3589 .mand_lock = smb2_mand_lock,
3590 .mand_unlock_range = smb2_unlock_range,
3591 .push_mand_locks = smb2_push_mandatory_locks,
3592 .get_lease_key = smb2_get_lease_key,
3593 .set_lease_key = smb2_set_lease_key,
3594 .new_lease_key = smb2_new_lease_key,
3595 .calc_signature = smb2_calc_signature,
3596 .is_read_op = smb2_is_read_op,
3597 .set_oplock_level = smb2_set_oplock_level,
3598 .create_lease_buf = smb2_create_lease_buf,
3599 .parse_lease_buf = smb2_parse_lease_buf,
3600 .copychunk_range = smb2_copychunk_range,
3601 .wp_retry_size = smb2_wp_retry_size,
3602 .dir_needs_close = smb2_dir_needs_close,
3603 .get_dfs_refer = smb2_get_dfs_refer,
3604 .select_sectype = smb2_select_sectype,
3605 #ifdef CONFIG_CIFS_XATTR
3606 .query_all_EAs = smb2_query_eas,
3607 .set_EA = smb2_set_ea,
3608 #endif /* CIFS_XATTR */
3609 #ifdef CONFIG_CIFS_ACL
3610 .get_acl = get_smb2_acl,
3611 .get_acl_by_fid = get_smb2_acl_by_fid,
3612 .set_acl = set_smb2_acl,
3613 #endif /* CIFS_ACL */
3614 .next_header = smb2_next_header,
3615 .ioctl_query_info = smb2_ioctl_query_info,
3616 };
3617
3618 struct smb_version_operations smb21_operations = {
3619 .compare_fids = smb2_compare_fids,
3620 .setup_request = smb2_setup_request,
3621 .setup_async_request = smb2_setup_async_request,
3622 .check_receive = smb2_check_receive,
3623 .add_credits = smb2_add_credits,
3624 .set_credits = smb2_set_credits,
3625 .get_credits_field = smb2_get_credits_field,
3626 .get_credits = smb2_get_credits,
3627 .wait_mtu_credits = smb2_wait_mtu_credits,
3628 .get_next_mid = smb2_get_next_mid,
3629 .read_data_offset = smb2_read_data_offset,
3630 .read_data_length = smb2_read_data_length,
3631 .map_error = map_smb2_to_linux_error,
3632 .find_mid = smb2_find_mid,
3633 .check_message = smb2_check_message,
3634 .dump_detail = smb2_dump_detail,
3635 .clear_stats = smb2_clear_stats,
3636 .print_stats = smb2_print_stats,
3637 .is_oplock_break = smb2_is_valid_oplock_break,
3638 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3639 .downgrade_oplock = smb2_downgrade_oplock,
3640 .need_neg = smb2_need_neg,
3641 .negotiate = smb2_negotiate,
3642 .negotiate_wsize = smb2_negotiate_wsize,
3643 .negotiate_rsize = smb2_negotiate_rsize,
3644 .sess_setup = SMB2_sess_setup,
3645 .logoff = SMB2_logoff,
3646 .tree_connect = SMB2_tcon,
3647 .tree_disconnect = SMB2_tdis,
3648 .qfs_tcon = smb2_qfs_tcon,
3649 .is_path_accessible = smb2_is_path_accessible,
3650 .can_echo = smb2_can_echo,
3651 .echo = SMB2_echo,
3652 .query_path_info = smb2_query_path_info,
3653 .get_srv_inum = smb2_get_srv_inum,
3654 .query_file_info = smb2_query_file_info,
3655 .set_path_size = smb2_set_path_size,
3656 .set_file_size = smb2_set_file_size,
3657 .set_file_info = smb2_set_file_info,
3658 .set_compression = smb2_set_compression,
3659 .mkdir = smb2_mkdir,
3660 .mkdir_setinfo = smb2_mkdir_setinfo,
3661 .rmdir = smb2_rmdir,
3662 .unlink = smb2_unlink,
3663 .rename = smb2_rename_path,
3664 .create_hardlink = smb2_create_hardlink,
3665 .query_symlink = smb2_query_symlink,
3666 .query_mf_symlink = smb3_query_mf_symlink,
3667 .create_mf_symlink = smb3_create_mf_symlink,
3668 .open = smb2_open_file,
3669 .set_fid = smb2_set_fid,
3670 .close = smb2_close_file,
3671 .flush = smb2_flush_file,
3672 .async_readv = smb2_async_readv,
3673 .async_writev = smb2_async_writev,
3674 .sync_read = smb2_sync_read,
3675 .sync_write = smb2_sync_write,
3676 .query_dir_first = smb2_query_dir_first,
3677 .query_dir_next = smb2_query_dir_next,
3678 .close_dir = smb2_close_dir,
3679 .calc_smb_size = smb2_calc_size,
3680 .is_status_pending = smb2_is_status_pending,
3681 .is_session_expired = smb2_is_session_expired,
3682 .oplock_response = smb2_oplock_response,
3683 .queryfs = smb2_queryfs,
3684 .mand_lock = smb2_mand_lock,
3685 .mand_unlock_range = smb2_unlock_range,
3686 .push_mand_locks = smb2_push_mandatory_locks,
3687 .get_lease_key = smb2_get_lease_key,
3688 .set_lease_key = smb2_set_lease_key,
3689 .new_lease_key = smb2_new_lease_key,
3690 .calc_signature = smb2_calc_signature,
3691 .is_read_op = smb21_is_read_op,
3692 .set_oplock_level = smb21_set_oplock_level,
3693 .create_lease_buf = smb2_create_lease_buf,
3694 .parse_lease_buf = smb2_parse_lease_buf,
3695 .copychunk_range = smb2_copychunk_range,
3696 .wp_retry_size = smb2_wp_retry_size,
3697 .dir_needs_close = smb2_dir_needs_close,
3698 .enum_snapshots = smb3_enum_snapshots,
3699 .get_dfs_refer = smb2_get_dfs_refer,
3700 .select_sectype = smb2_select_sectype,
3701 #ifdef CONFIG_CIFS_XATTR
3702 .query_all_EAs = smb2_query_eas,
3703 .set_EA = smb2_set_ea,
3704 #endif /* CIFS_XATTR */
3705 #ifdef CONFIG_CIFS_ACL
3706 .get_acl = get_smb2_acl,
3707 .get_acl_by_fid = get_smb2_acl_by_fid,
3708 .set_acl = set_smb2_acl,
3709 #endif /* CIFS_ACL */
3710 .next_header = smb2_next_header,
3711 .ioctl_query_info = smb2_ioctl_query_info,
3712 };
3713
3714 struct smb_version_operations smb30_operations = {
3715 .compare_fids = smb2_compare_fids,
3716 .setup_request = smb2_setup_request,
3717 .setup_async_request = smb2_setup_async_request,
3718 .check_receive = smb2_check_receive,
3719 .add_credits = smb2_add_credits,
3720 .set_credits = smb2_set_credits,
3721 .get_credits_field = smb2_get_credits_field,
3722 .get_credits = smb2_get_credits,
3723 .wait_mtu_credits = smb2_wait_mtu_credits,
3724 .get_next_mid = smb2_get_next_mid,
3725 .read_data_offset = smb2_read_data_offset,
3726 .read_data_length = smb2_read_data_length,
3727 .map_error = map_smb2_to_linux_error,
3728 .find_mid = smb2_find_mid,
3729 .check_message = smb2_check_message,
3730 .dump_detail = smb2_dump_detail,
3731 .clear_stats = smb2_clear_stats,
3732 .print_stats = smb2_print_stats,
3733 .dump_share_caps = smb2_dump_share_caps,
3734 .is_oplock_break = smb2_is_valid_oplock_break,
3735 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3736 .downgrade_oplock = smb2_downgrade_oplock,
3737 .need_neg = smb2_need_neg,
3738 .negotiate = smb2_negotiate,
3739 .negotiate_wsize = smb3_negotiate_wsize,
3740 .negotiate_rsize = smb3_negotiate_rsize,
3741 .sess_setup = SMB2_sess_setup,
3742 .logoff = SMB2_logoff,
3743 .tree_connect = SMB2_tcon,
3744 .tree_disconnect = SMB2_tdis,
3745 .qfs_tcon = smb3_qfs_tcon,
3746 .is_path_accessible = smb2_is_path_accessible,
3747 .can_echo = smb2_can_echo,
3748 .echo = SMB2_echo,
3749 .query_path_info = smb2_query_path_info,
3750 .get_srv_inum = smb2_get_srv_inum,
3751 .query_file_info = smb2_query_file_info,
3752 .set_path_size = smb2_set_path_size,
3753 .set_file_size = smb2_set_file_size,
3754 .set_file_info = smb2_set_file_info,
3755 .set_compression = smb2_set_compression,
3756 .mkdir = smb2_mkdir,
3757 .mkdir_setinfo = smb2_mkdir_setinfo,
3758 .rmdir = smb2_rmdir,
3759 .unlink = smb2_unlink,
3760 .rename = smb2_rename_path,
3761 .create_hardlink = smb2_create_hardlink,
3762 .query_symlink = smb2_query_symlink,
3763 .query_mf_symlink = smb3_query_mf_symlink,
3764 .create_mf_symlink = smb3_create_mf_symlink,
3765 .open = smb2_open_file,
3766 .set_fid = smb2_set_fid,
3767 .close = smb2_close_file,
3768 .flush = smb2_flush_file,
3769 .async_readv = smb2_async_readv,
3770 .async_writev = smb2_async_writev,
3771 .sync_read = smb2_sync_read,
3772 .sync_write = smb2_sync_write,
3773 .query_dir_first = smb2_query_dir_first,
3774 .query_dir_next = smb2_query_dir_next,
3775 .close_dir = smb2_close_dir,
3776 .calc_smb_size = smb2_calc_size,
3777 .is_status_pending = smb2_is_status_pending,
3778 .is_session_expired = smb2_is_session_expired,
3779 .oplock_response = smb2_oplock_response,
3780 .queryfs = smb2_queryfs,
3781 .mand_lock = smb2_mand_lock,
3782 .mand_unlock_range = smb2_unlock_range,
3783 .push_mand_locks = smb2_push_mandatory_locks,
3784 .get_lease_key = smb2_get_lease_key,
3785 .set_lease_key = smb2_set_lease_key,
3786 .new_lease_key = smb2_new_lease_key,
3787 .generate_signingkey = generate_smb30signingkey,
3788 .calc_signature = smb3_calc_signature,
3789 .set_integrity = smb3_set_integrity,
3790 .is_read_op = smb21_is_read_op,
3791 .set_oplock_level = smb3_set_oplock_level,
3792 .create_lease_buf = smb3_create_lease_buf,
3793 .parse_lease_buf = smb3_parse_lease_buf,
3794 .copychunk_range = smb2_copychunk_range,
3795 .duplicate_extents = smb2_duplicate_extents,
3796 .validate_negotiate = smb3_validate_negotiate,
3797 .wp_retry_size = smb2_wp_retry_size,
3798 .dir_needs_close = smb2_dir_needs_close,
3799 .fallocate = smb3_fallocate,
3800 .enum_snapshots = smb3_enum_snapshots,
3801 .init_transform_rq = smb3_init_transform_rq,
3802 .is_transform_hdr = smb3_is_transform_hdr,
3803 .receive_transform = smb3_receive_transform,
3804 .get_dfs_refer = smb2_get_dfs_refer,
3805 .select_sectype = smb2_select_sectype,
3806 #ifdef CONFIG_CIFS_XATTR
3807 .query_all_EAs = smb2_query_eas,
3808 .set_EA = smb2_set_ea,
3809 #endif /* CIFS_XATTR */
3810 #ifdef CONFIG_CIFS_ACL
3811 .get_acl = get_smb2_acl,
3812 .get_acl_by_fid = get_smb2_acl_by_fid,
3813 .set_acl = set_smb2_acl,
3814 #endif /* CIFS_ACL */
3815 .next_header = smb2_next_header,
3816 .ioctl_query_info = smb2_ioctl_query_info,
3817 };
3818
3819 struct smb_version_operations smb311_operations = {
3820 .compare_fids = smb2_compare_fids,
3821 .setup_request = smb2_setup_request,
3822 .setup_async_request = smb2_setup_async_request,
3823 .check_receive = smb2_check_receive,
3824 .add_credits = smb2_add_credits,
3825 .set_credits = smb2_set_credits,
3826 .get_credits_field = smb2_get_credits_field,
3827 .get_credits = smb2_get_credits,
3828 .wait_mtu_credits = smb2_wait_mtu_credits,
3829 .get_next_mid = smb2_get_next_mid,
3830 .read_data_offset = smb2_read_data_offset,
3831 .read_data_length = smb2_read_data_length,
3832 .map_error = map_smb2_to_linux_error,
3833 .find_mid = smb2_find_mid,
3834 .check_message = smb2_check_message,
3835 .dump_detail = smb2_dump_detail,
3836 .clear_stats = smb2_clear_stats,
3837 .print_stats = smb2_print_stats,
3838 .dump_share_caps = smb2_dump_share_caps,
3839 .is_oplock_break = smb2_is_valid_oplock_break,
3840 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3841 .downgrade_oplock = smb2_downgrade_oplock,
3842 .need_neg = smb2_need_neg,
3843 .negotiate = smb2_negotiate,
3844 .negotiate_wsize = smb3_negotiate_wsize,
3845 .negotiate_rsize = smb3_negotiate_rsize,
3846 .sess_setup = SMB2_sess_setup,
3847 .logoff = SMB2_logoff,
3848 .tree_connect = SMB2_tcon,
3849 .tree_disconnect = SMB2_tdis,
3850 .qfs_tcon = smb3_qfs_tcon,
3851 .is_path_accessible = smb2_is_path_accessible,
3852 .can_echo = smb2_can_echo,
3853 .echo = SMB2_echo,
3854 .query_path_info = smb2_query_path_info,
3855 .get_srv_inum = smb2_get_srv_inum,
3856 .query_file_info = smb2_query_file_info,
3857 .set_path_size = smb2_set_path_size,
3858 .set_file_size = smb2_set_file_size,
3859 .set_file_info = smb2_set_file_info,
3860 .set_compression = smb2_set_compression,
3861 .mkdir = smb2_mkdir,
3862 .mkdir_setinfo = smb2_mkdir_setinfo,
3863 .posix_mkdir = smb311_posix_mkdir,
3864 .rmdir = smb2_rmdir,
3865 .unlink = smb2_unlink,
3866 .rename = smb2_rename_path,
3867 .create_hardlink = smb2_create_hardlink,
3868 .query_symlink = smb2_query_symlink,
3869 .query_mf_symlink = smb3_query_mf_symlink,
3870 .create_mf_symlink = smb3_create_mf_symlink,
3871 .open = smb2_open_file,
3872 .set_fid = smb2_set_fid,
3873 .close = smb2_close_file,
3874 .flush = smb2_flush_file,
3875 .async_readv = smb2_async_readv,
3876 .async_writev = smb2_async_writev,
3877 .sync_read = smb2_sync_read,
3878 .sync_write = smb2_sync_write,
3879 .query_dir_first = smb2_query_dir_first,
3880 .query_dir_next = smb2_query_dir_next,
3881 .close_dir = smb2_close_dir,
3882 .calc_smb_size = smb2_calc_size,
3883 .is_status_pending = smb2_is_status_pending,
3884 .is_session_expired = smb2_is_session_expired,
3885 .oplock_response = smb2_oplock_response,
3886 .queryfs = smb311_queryfs,
3887 .mand_lock = smb2_mand_lock,
3888 .mand_unlock_range = smb2_unlock_range,
3889 .push_mand_locks = smb2_push_mandatory_locks,
3890 .get_lease_key = smb2_get_lease_key,
3891 .set_lease_key = smb2_set_lease_key,
3892 .new_lease_key = smb2_new_lease_key,
3893 .generate_signingkey = generate_smb311signingkey,
3894 .calc_signature = smb3_calc_signature,
3895 .set_integrity = smb3_set_integrity,
3896 .is_read_op = smb21_is_read_op,
3897 .set_oplock_level = smb3_set_oplock_level,
3898 .create_lease_buf = smb3_create_lease_buf,
3899 .parse_lease_buf = smb3_parse_lease_buf,
3900 .copychunk_range = smb2_copychunk_range,
3901 .duplicate_extents = smb2_duplicate_extents,
3902 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3903 .wp_retry_size = smb2_wp_retry_size,
3904 .dir_needs_close = smb2_dir_needs_close,
3905 .fallocate = smb3_fallocate,
3906 .enum_snapshots = smb3_enum_snapshots,
3907 .init_transform_rq = smb3_init_transform_rq,
3908 .is_transform_hdr = smb3_is_transform_hdr,
3909 .receive_transform = smb3_receive_transform,
3910 .get_dfs_refer = smb2_get_dfs_refer,
3911 .select_sectype = smb2_select_sectype,
3912 #ifdef CONFIG_CIFS_XATTR
3913 .query_all_EAs = smb2_query_eas,
3914 .set_EA = smb2_set_ea,
3915 #endif /* CIFS_XATTR */
3916 #ifdef CONFIG_CIFS_ACL
3917 .get_acl = get_smb2_acl,
3918 .get_acl_by_fid = get_smb2_acl_by_fid,
3919 .set_acl = set_smb2_acl,
3920 #endif /* CIFS_ACL */
3921 .next_header = smb2_next_header,
3922 .ioctl_query_info = smb2_ioctl_query_info,
3923 };
3924
3925 struct smb_version_values smb20_values = {
3926 .version_string = SMB20_VERSION_STRING,
3927 .protocol_id = SMB20_PROT_ID,
3928 .req_capabilities = 0, /* MBZ */
3929 .large_lock_type = 0,
3930 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3931 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3932 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3933 .header_size = sizeof(struct smb2_sync_hdr),
3934 .header_preamble_size = 0,
3935 .max_header_size = MAX_SMB2_HDR_SIZE,
3936 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3937 .lock_cmd = SMB2_LOCK,
3938 .cap_unix = 0,
3939 .cap_nt_find = SMB2_NT_FIND,
3940 .cap_large_files = SMB2_LARGE_FILES,
3941 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3942 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3943 .create_lease_size = sizeof(struct create_lease),
3944 };
3945
3946 struct smb_version_values smb21_values = {
3947 .version_string = SMB21_VERSION_STRING,
3948 .protocol_id = SMB21_PROT_ID,
3949 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3950 .large_lock_type = 0,
3951 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3952 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3953 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3954 .header_size = sizeof(struct smb2_sync_hdr),
3955 .header_preamble_size = 0,
3956 .max_header_size = MAX_SMB2_HDR_SIZE,
3957 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3958 .lock_cmd = SMB2_LOCK,
3959 .cap_unix = 0,
3960 .cap_nt_find = SMB2_NT_FIND,
3961 .cap_large_files = SMB2_LARGE_FILES,
3962 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3963 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3964 .create_lease_size = sizeof(struct create_lease),
3965 };
3966
3967 struct smb_version_values smb3any_values = {
3968 .version_string = SMB3ANY_VERSION_STRING,
3969 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3970 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3971 .large_lock_type = 0,
3972 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3973 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3974 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3975 .header_size = sizeof(struct smb2_sync_hdr),
3976 .header_preamble_size = 0,
3977 .max_header_size = MAX_SMB2_HDR_SIZE,
3978 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3979 .lock_cmd = SMB2_LOCK,
3980 .cap_unix = 0,
3981 .cap_nt_find = SMB2_NT_FIND,
3982 .cap_large_files = SMB2_LARGE_FILES,
3983 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3984 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3985 .create_lease_size = sizeof(struct create_lease_v2),
3986 };
3987
3988 struct smb_version_values smbdefault_values = {
3989 .version_string = SMBDEFAULT_VERSION_STRING,
3990 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3991 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3992 .large_lock_type = 0,
3993 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3994 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3995 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3996 .header_size = sizeof(struct smb2_sync_hdr),
3997 .header_preamble_size = 0,
3998 .max_header_size = MAX_SMB2_HDR_SIZE,
3999 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4000 .lock_cmd = SMB2_LOCK,
4001 .cap_unix = 0,
4002 .cap_nt_find = SMB2_NT_FIND,
4003 .cap_large_files = SMB2_LARGE_FILES,
4004 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4005 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4006 .create_lease_size = sizeof(struct create_lease_v2),
4007 };
4008
4009 struct smb_version_values smb30_values = {
4010 .version_string = SMB30_VERSION_STRING,
4011 .protocol_id = SMB30_PROT_ID,
4012 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
4013 .large_lock_type = 0,
4014 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4015 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4016 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4017 .header_size = sizeof(struct smb2_sync_hdr),
4018 .header_preamble_size = 0,
4019 .max_header_size = MAX_SMB2_HDR_SIZE,
4020 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4021 .lock_cmd = SMB2_LOCK,
4022 .cap_unix = 0,
4023 .cap_nt_find = SMB2_NT_FIND,
4024 .cap_large_files = SMB2_LARGE_FILES,
4025 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4026 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4027 .create_lease_size = sizeof(struct create_lease_v2),
4028 };
4029
4030 struct smb_version_values smb302_values = {
4031 .version_string = SMB302_VERSION_STRING,
4032 .protocol_id = SMB302_PROT_ID,
4033 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
4034 .large_lock_type = 0,
4035 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4036 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4037 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4038 .header_size = sizeof(struct smb2_sync_hdr),
4039 .header_preamble_size = 0,
4040 .max_header_size = MAX_SMB2_HDR_SIZE,
4041 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4042 .lock_cmd = SMB2_LOCK,
4043 .cap_unix = 0,
4044 .cap_nt_find = SMB2_NT_FIND,
4045 .cap_large_files = SMB2_LARGE_FILES,
4046 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4047 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4048 .create_lease_size = sizeof(struct create_lease_v2),
4049 };
4050
4051 struct smb_version_values smb311_values = {
4052 .version_string = SMB311_VERSION_STRING,
4053 .protocol_id = SMB311_PROT_ID,
4054 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
4055 .large_lock_type = 0,
4056 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4057 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4058 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4059 .header_size = sizeof(struct smb2_sync_hdr),
4060 .header_preamble_size = 0,
4061 .max_header_size = MAX_SMB2_HDR_SIZE,
4062 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4063 .lock_cmd = SMB2_LOCK,
4064 .cap_unix = 0,
4065 .cap_nt_find = SMB2_NT_FIND,
4066 .cap_large_files = SMB2_LARGE_FILES,
4067 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4068 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4069 .create_lease_size = sizeof(struct create_lease_v2),
4070 };