This source file includes following definitions.
- change_conf
- smb2_add_credits
- smb2_set_credits
- smb2_get_credits_field
- smb2_get_credits
- smb2_wait_mtu_credits
- smb2_adjust_credits
- smb2_get_next_mid
- smb2_revert_current_mid
- smb2_find_mid
- smb2_dump_detail
- smb2_need_neg
- smb2_negotiate
- smb2_negotiate_wsize
- smb3_negotiate_wsize
- smb2_negotiate_rsize
- smb3_negotiate_rsize
- parse_server_interfaces
- SMB3_request_interfaces
- smb2_close_cached_fid
- close_shroot
- smb2_cached_lease_break
- open_shroot
- smb3_qfs_tcon
- smb2_qfs_tcon
- smb2_is_path_accessible
- smb2_get_srv_inum
- smb2_query_file_info
- move_smb2_ea_to_cifs
- smb2_query_eas
- smb2_set_ea
- smb2_can_echo
- smb2_clear_stats
- smb2_dump_share_caps
- smb2_print_stats
- smb2_set_fid
- smb2_close_file
- SMB2_request_res_key
- smb2_ioctl_query_info
- smb2_copychunk_range
- smb2_flush_file
- smb2_read_data_offset
- smb2_read_data_length
- smb2_sync_read
- smb2_sync_write
- smb2_set_sparse
- smb2_set_file_size
- smb2_duplicate_extents
- smb2_set_compression
- smb3_set_integrity
- smb3_enum_snapshots
- smb2_query_dir_first
- smb2_query_dir_next
- smb2_close_dir
- smb2_is_status_pending
- smb2_is_session_expired
- smb2_oplock_response
- smb2_set_related
- smb2_set_next_command
- smb2_query_info_compound
- smb2_queryfs
- smb311_queryfs
- smb2_compare_fids
- smb2_mand_lock
- smb2_get_lease_key
- smb2_set_lease_key
- smb2_new_lease_key
- smb2_get_dfs_refer
- parse_reparse_posix
- parse_reparse_symlink
- parse_reparse_point
- smb2_query_symlink
- get_smb2_acl_by_fid
- get_smb2_acl_by_path
- set_smb2_acl
- get_smb2_acl
- smb3_zero_range
- smb3_punch_hole
- smb3_simple_falloc
- smb3_llseek
- smb3_fiemap
- smb3_fallocate
- smb2_downgrade_oplock
- smb21_downgrade_oplock
- smb2_set_oplock_level
- smb21_set_oplock_level
- smb3_set_oplock_level
- smb2_is_read_op
- smb21_is_read_op
- map_oplock_to_lease
- smb2_create_lease_buf
- smb3_create_lease_buf
- smb2_parse_lease_buf
- smb3_parse_lease_buf
- smb2_wp_retry_size
- smb2_dir_needs_close
- fill_transform_hdr
- smb2_sg_set_buf
- init_sg
- smb2_get_enc_key
- crypt_message
- smb3_free_compound_rqst
- smb3_init_transform_rq
- smb3_is_transform_hdr
- decrypt_raw_data
- read_data_into_pages
- init_read_bvec
- handle_read_data
- smb2_decrypt_offload
- receive_encrypted_read
- receive_encrypted_standard
- smb3_receive_transform
- smb3_handle_read_data
- smb2_next_header
- smb2_make_node
1
2
3
4
5
6
7
8 #include <linux/pagemap.h>
9 #include <linux/vfs.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <crypto/aead.h>
14 #include "cifsglob.h"
15 #include "smb2pdu.h"
16 #include "smb2proto.h"
17 #include "cifsproto.h"
18 #include "cifs_debug.h"
19 #include "cifs_unicode.h"
20 #include "smb2status.h"
21 #include "smb2glob.h"
22 #include "cifs_ioctl.h"
23 #include "smbdirect.h"
24
25
26 static int
27 change_conf(struct TCP_Server_Info *server)
28 {
29 server->credits += server->echo_credits + server->oplock_credits;
30 server->oplock_credits = server->echo_credits = 0;
31 switch (server->credits) {
32 case 0:
33 return 0;
34 case 1:
35 server->echoes = false;
36 server->oplocks = false;
37 break;
38 case 2:
39 server->echoes = true;
40 server->oplocks = false;
41 server->echo_credits = 1;
42 break;
43 default:
44 server->echoes = true;
45 if (enable_oplocks) {
46 server->oplocks = true;
47 server->oplock_credits = 1;
48 } else
49 server->oplocks = false;
50
51 server->echo_credits = 1;
52 }
53 server->credits -= server->echo_credits + server->oplock_credits;
54 return server->credits + server->echo_credits + server->oplock_credits;
55 }
56
57 static void
58 smb2_add_credits(struct TCP_Server_Info *server,
59 const struct cifs_credits *credits, const int optype)
60 {
61 int *val, rc = -1;
62 unsigned int add = credits->value;
63 unsigned int instance = credits->instance;
64 bool reconnect_detected = false;
65
66 spin_lock(&server->req_lock);
67 val = server->ops->get_credits_field(server, optype);
68
69
70 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
71 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
72 server->hostname, *val);
73 if ((instance == 0) || (instance == server->reconnect_instance))
74 *val += add;
75 else
76 reconnect_detected = true;
77
78 if (*val > 65000) {
79 *val = 65000;
80 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
81 }
82 server->in_flight--;
83 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
84 rc = change_conf(server);
85
86
87
88
89 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
90 server->oplocks) {
91 if (server->credits > 1) {
92 server->credits--;
93 server->oplock_credits++;
94 }
95 }
96 spin_unlock(&server->req_lock);
97 wake_up(&server->request_q);
98
99 if (reconnect_detected)
100 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
101 add, instance);
102
103 if (server->tcpStatus == CifsNeedReconnect
104 || server->tcpStatus == CifsExiting)
105 return;
106
107 switch (rc) {
108 case -1:
109
110 break;
111 case 0:
112 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
113 break;
114 case 1:
115 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
116 break;
117 case 2:
118 cifs_dbg(FYI, "disabling oplocks\n");
119 break;
120 default:
121 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
122 }
123 }
124
125 static void
126 smb2_set_credits(struct TCP_Server_Info *server, const int val)
127 {
128 spin_lock(&server->req_lock);
129 server->credits = val;
130 if (val == 1)
131 server->reconnect_instance++;
132 spin_unlock(&server->req_lock);
133
134 if (val == 1)
135 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
136 }
137
138 static int *
139 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
140 {
141 switch (optype) {
142 case CIFS_ECHO_OP:
143 return &server->echo_credits;
144 case CIFS_OBREAK_OP:
145 return &server->oplock_credits;
146 default:
147 return &server->credits;
148 }
149 }
150
151 static unsigned int
152 smb2_get_credits(struct mid_q_entry *mid)
153 {
154 return mid->credits_received;
155 }
156
157 static int
158 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
159 unsigned int *num, struct cifs_credits *credits)
160 {
161 int rc = 0;
162 unsigned int scredits;
163
164 spin_lock(&server->req_lock);
165 while (1) {
166 if (server->credits <= 0) {
167 spin_unlock(&server->req_lock);
168 cifs_num_waiters_inc(server);
169 rc = wait_event_killable(server->request_q,
170 has_credits(server, &server->credits, 1));
171 cifs_num_waiters_dec(server);
172 if (rc)
173 return rc;
174 spin_lock(&server->req_lock);
175 } else {
176 if (server->tcpStatus == CifsExiting) {
177 spin_unlock(&server->req_lock);
178 return -ENOENT;
179 }
180
181 scredits = server->credits;
182
183 if (scredits <= 8) {
184 *num = SMB2_MAX_BUFFER_SIZE;
185 credits->value = 0;
186 credits->instance = 0;
187 break;
188 }
189
190
191 scredits -= 8;
192 *num = min_t(unsigned int, size,
193 scredits * SMB2_MAX_BUFFER_SIZE);
194
195 credits->value =
196 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
197 credits->instance = server->reconnect_instance;
198 server->credits -= credits->value;
199 server->in_flight++;
200 if (server->in_flight > server->max_in_flight)
201 server->max_in_flight = server->in_flight;
202 break;
203 }
204 }
205 spin_unlock(&server->req_lock);
206 return rc;
207 }
208
209 static int
210 smb2_adjust_credits(struct TCP_Server_Info *server,
211 struct cifs_credits *credits,
212 const unsigned int payload_size)
213 {
214 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
215
216 if (!credits->value || credits->value == new_val)
217 return 0;
218
219 if (credits->value < new_val) {
220 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
221 credits->value, new_val);
222 return -ENOTSUPP;
223 }
224
225 spin_lock(&server->req_lock);
226
227 if (server->reconnect_instance != credits->instance) {
228 spin_unlock(&server->req_lock);
229 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
230 credits->value - new_val);
231 return -EAGAIN;
232 }
233
234 server->credits += credits->value - new_val;
235 spin_unlock(&server->req_lock);
236 wake_up(&server->request_q);
237 credits->value = new_val;
238 return 0;
239 }
240
241 static __u64
242 smb2_get_next_mid(struct TCP_Server_Info *server)
243 {
244 __u64 mid;
245
246 spin_lock(&GlobalMid_Lock);
247 mid = server->CurrentMid++;
248 spin_unlock(&GlobalMid_Lock);
249 return mid;
250 }
251
252 static void
253 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
254 {
255 spin_lock(&GlobalMid_Lock);
256 if (server->CurrentMid >= val)
257 server->CurrentMid -= val;
258 spin_unlock(&GlobalMid_Lock);
259 }
260
261 static struct mid_q_entry *
262 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
263 {
264 struct mid_q_entry *mid;
265 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
266 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
267
268 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
269 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
270 return NULL;
271 }
272
273 spin_lock(&GlobalMid_Lock);
274 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
275 if ((mid->mid == wire_mid) &&
276 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
277 (mid->command == shdr->Command)) {
278 kref_get(&mid->refcount);
279 spin_unlock(&GlobalMid_Lock);
280 return mid;
281 }
282 }
283 spin_unlock(&GlobalMid_Lock);
284 return NULL;
285 }
286
287 static void
288 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
289 {
290 #ifdef CONFIG_CIFS_DEBUG2
291 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
292
293 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
294 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
295 shdr->ProcessId);
296 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
297 server->ops->calc_smb_size(buf, server));
298 #endif
299 }
300
301 static bool
302 smb2_need_neg(struct TCP_Server_Info *server)
303 {
304 return server->max_read == 0;
305 }
306
307 static int
308 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
309 {
310 int rc;
311
312 ses->server->CurrentMid = 0;
313 rc = SMB2_negotiate(xid, ses);
314
315 if (rc == -EAGAIN)
316 rc = -EHOSTDOWN;
317 return rc;
318 }
319
320 static unsigned int
321 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
322 {
323 struct TCP_Server_Info *server = tcon->ses->server;
324 unsigned int wsize;
325
326
327 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
328 wsize = min_t(unsigned int, wsize, server->max_write);
329 #ifdef CONFIG_CIFS_SMB_DIRECT
330 if (server->rdma) {
331 if (server->sign)
332 wsize = min_t(unsigned int,
333 wsize, server->smbd_conn->max_fragmented_send_size);
334 else
335 wsize = min_t(unsigned int,
336 wsize, server->smbd_conn->max_readwrite_size);
337 }
338 #endif
339 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
340 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
341
342 return wsize;
343 }
344
345 static unsigned int
346 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
347 {
348 struct TCP_Server_Info *server = tcon->ses->server;
349 unsigned int wsize;
350
351
352 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
353 wsize = min_t(unsigned int, wsize, server->max_write);
354 #ifdef CONFIG_CIFS_SMB_DIRECT
355 if (server->rdma) {
356 if (server->sign)
357 wsize = min_t(unsigned int,
358 wsize, server->smbd_conn->max_fragmented_send_size);
359 else
360 wsize = min_t(unsigned int,
361 wsize, server->smbd_conn->max_readwrite_size);
362 }
363 #endif
364 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
365 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
366
367 return wsize;
368 }
369
370 static unsigned int
371 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
372 {
373 struct TCP_Server_Info *server = tcon->ses->server;
374 unsigned int rsize;
375
376
377 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
378 rsize = min_t(unsigned int, rsize, server->max_read);
379 #ifdef CONFIG_CIFS_SMB_DIRECT
380 if (server->rdma) {
381 if (server->sign)
382 rsize = min_t(unsigned int,
383 rsize, server->smbd_conn->max_fragmented_recv_size);
384 else
385 rsize = min_t(unsigned int,
386 rsize, server->smbd_conn->max_readwrite_size);
387 }
388 #endif
389
390 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
391 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
392
393 return rsize;
394 }
395
396 static unsigned int
397 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
398 {
399 struct TCP_Server_Info *server = tcon->ses->server;
400 unsigned int rsize;
401
402
403 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
404 rsize = min_t(unsigned int, rsize, server->max_read);
405 #ifdef CONFIG_CIFS_SMB_DIRECT
406 if (server->rdma) {
407 if (server->sign)
408 rsize = min_t(unsigned int,
409 rsize, server->smbd_conn->max_fragmented_recv_size);
410 else
411 rsize = min_t(unsigned int,
412 rsize, server->smbd_conn->max_readwrite_size);
413 }
414 #endif
415
416 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
417 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
418
419 return rsize;
420 }
421
422 static int
423 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
424 size_t buf_len,
425 struct cifs_server_iface **iface_list,
426 size_t *iface_count)
427 {
428 struct network_interface_info_ioctl_rsp *p;
429 struct sockaddr_in *addr4;
430 struct sockaddr_in6 *addr6;
431 struct iface_info_ipv4 *p4;
432 struct iface_info_ipv6 *p6;
433 struct cifs_server_iface *info;
434 ssize_t bytes_left;
435 size_t next = 0;
436 int nb_iface = 0;
437 int rc = 0;
438
439 *iface_list = NULL;
440 *iface_count = 0;
441
442
443
444
445
446 bytes_left = buf_len;
447 p = buf;
448 while (bytes_left >= sizeof(*p)) {
449 nb_iface++;
450 next = le32_to_cpu(p->Next);
451 if (!next) {
452 bytes_left -= sizeof(*p);
453 break;
454 }
455 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
456 bytes_left -= next;
457 }
458
459 if (!nb_iface) {
460 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
461 rc = -EINVAL;
462 goto out;
463 }
464
465 if (bytes_left || p->Next)
466 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
467
468
469
470
471
472
473 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
474 if (!*iface_list) {
475 rc = -ENOMEM;
476 goto out;
477 }
478
479 info = *iface_list;
480 bytes_left = buf_len;
481 p = buf;
482 while (bytes_left >= sizeof(*p)) {
483 info->speed = le64_to_cpu(p->LinkSpeed);
484 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
485 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
486
487 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
488 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
489 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
490 le32_to_cpu(p->Capability));
491
492 switch (p->Family) {
493
494
495
496
497
498 case INTERNETWORK:
499 addr4 = (struct sockaddr_in *)&info->sockaddr;
500 p4 = (struct iface_info_ipv4 *)p->Buffer;
501 addr4->sin_family = AF_INET;
502 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
503
504
505 addr4->sin_port = cpu_to_be16(CIFS_PORT);
506
507 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
508 &addr4->sin_addr);
509 break;
510 case INTERNETWORKV6:
511 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
512 p6 = (struct iface_info_ipv6 *)p->Buffer;
513 addr6->sin6_family = AF_INET6;
514 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
515
516
517 addr6->sin6_flowinfo = 0;
518 addr6->sin6_scope_id = 0;
519 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
520
521 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
522 &addr6->sin6_addr);
523 break;
524 default:
525 cifs_dbg(VFS,
526 "%s: skipping unsupported socket family\n",
527 __func__);
528 goto next_iface;
529 }
530
531 (*iface_count)++;
532 info++;
533 next_iface:
534 next = le32_to_cpu(p->Next);
535 if (!next)
536 break;
537 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
538 bytes_left -= next;
539 }
540
541 if (!*iface_count) {
542 rc = -EINVAL;
543 goto out;
544 }
545
546 out:
547 if (rc) {
548 kfree(*iface_list);
549 *iface_count = 0;
550 *iface_list = NULL;
551 }
552 return rc;
553 }
554
555
556 static int
557 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
558 {
559 int rc;
560 unsigned int ret_data_len = 0;
561 struct network_interface_info_ioctl_rsp *out_buf = NULL;
562 struct cifs_server_iface *iface_list;
563 size_t iface_count;
564 struct cifs_ses *ses = tcon->ses;
565
566 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
567 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true ,
568 NULL , 0 ,
569 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
570 if (rc == -EOPNOTSUPP) {
571 cifs_dbg(FYI,
572 "server does not support query network interfaces\n");
573 goto out;
574 } else if (rc != 0) {
575 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
576 goto out;
577 }
578
579 rc = parse_server_interfaces(out_buf, ret_data_len,
580 &iface_list, &iface_count);
581 if (rc)
582 goto out;
583
584 spin_lock(&ses->iface_lock);
585 kfree(ses->iface_list);
586 ses->iface_list = iface_list;
587 ses->iface_count = iface_count;
588 ses->iface_last_update = jiffies;
589 spin_unlock(&ses->iface_lock);
590
591 out:
592 kfree(out_buf);
593 return rc;
594 }
595
596 static void
597 smb2_close_cached_fid(struct kref *ref)
598 {
599 struct cached_fid *cfid = container_of(ref, struct cached_fid,
600 refcount);
601
602 if (cfid->is_valid) {
603 cifs_dbg(FYI, "clear cached root file handle\n");
604 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
605 cfid->fid->volatile_fid);
606 cfid->is_valid = false;
607 cfid->file_all_info_is_valid = false;
608 }
609 }
610
611 void close_shroot(struct cached_fid *cfid)
612 {
613 mutex_lock(&cfid->fid_mutex);
614 kref_put(&cfid->refcount, smb2_close_cached_fid);
615 mutex_unlock(&cfid->fid_mutex);
616 }
617
618 void
619 smb2_cached_lease_break(struct work_struct *work)
620 {
621 struct cached_fid *cfid = container_of(work,
622 struct cached_fid, lease_break);
623
624 close_shroot(cfid);
625 }
626
627
628
629
630 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
631 {
632 struct cifs_ses *ses = tcon->ses;
633 struct TCP_Server_Info *server = ses->server;
634 struct cifs_open_parms oparms;
635 struct smb2_create_rsp *o_rsp = NULL;
636 struct smb2_query_info_rsp *qi_rsp = NULL;
637 int resp_buftype[2];
638 struct smb_rqst rqst[2];
639 struct kvec rsp_iov[2];
640 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
641 struct kvec qi_iov[1];
642 int rc, flags = 0;
643 __le16 utf16_path = 0;
644 u8 oplock = SMB2_OPLOCK_LEVEL_II;
645
646 mutex_lock(&tcon->crfid.fid_mutex);
647 if (tcon->crfid.is_valid) {
648 cifs_dbg(FYI, "found a cached root file handle\n");
649 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
650 kref_get(&tcon->crfid.refcount);
651 mutex_unlock(&tcon->crfid.fid_mutex);
652 return 0;
653 }
654
655
656
657
658
659
660
661
662 mutex_unlock(&tcon->crfid.fid_mutex);
663
664 if (smb3_encryption_required(tcon))
665 flags |= CIFS_TRANSFORM_REQ;
666
667 if (!server->ops->new_lease_key)
668 return -EIO;
669
670 server->ops->new_lease_key(pfid);
671
672 memset(rqst, 0, sizeof(rqst));
673 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
674 memset(rsp_iov, 0, sizeof(rsp_iov));
675
676
677 memset(&open_iov, 0, sizeof(open_iov));
678 rqst[0].rq_iov = open_iov;
679 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
680
681 oparms.tcon = tcon;
682 oparms.create_options = 0;
683 oparms.desired_access = FILE_READ_ATTRIBUTES;
684 oparms.disposition = FILE_OPEN;
685 oparms.fid = pfid;
686 oparms.reconnect = false;
687
688 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &utf16_path);
689 if (rc)
690 goto oshr_free;
691 smb2_set_next_command(tcon, &rqst[0]);
692
693 memset(&qi_iov, 0, sizeof(qi_iov));
694 rqst[1].rq_iov = qi_iov;
695 rqst[1].rq_nvec = 1;
696
697 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
698 COMPOUND_FID, FILE_ALL_INFORMATION,
699 SMB2_O_INFO_FILE, 0,
700 sizeof(struct smb2_file_all_info) +
701 PATH_MAX * 2, 0, NULL);
702 if (rc)
703 goto oshr_free;
704
705 smb2_set_related(&rqst[1]);
706
707 rc = compound_send_recv(xid, ses, flags, 2, rqst,
708 resp_buftype, rsp_iov);
709 mutex_lock(&tcon->crfid.fid_mutex);
710
711
712
713
714
715
716 if (tcon->crfid.is_valid) {
717
718
719
720 struct cifs_fid fid = {
721 .persistent_fid = pfid->persistent_fid,
722 .volatile_fid = pfid->volatile_fid,
723 };
724
725
726
727
728
729
730 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
731 kref_get(&tcon->crfid.refcount);
732
733 mutex_unlock(&tcon->crfid.fid_mutex);
734
735 if (rc == 0) {
736
737 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
738 }
739 goto oshr_free;
740 }
741
742
743
744 if (rc) {
745 if (rc == -EREMCHG) {
746 tcon->need_reconnect = true;
747 printk_once(KERN_WARNING "server share %s deleted\n",
748 tcon->treeName);
749 }
750 goto oshr_exit;
751 }
752
753 atomic_inc(&tcon->num_remote_opens);
754
755 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
756 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
757 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
758 #ifdef CONFIG_CIFS_DEBUG2
759 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
760 #endif
761
762 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
763 tcon->crfid.tcon = tcon;
764 tcon->crfid.is_valid = true;
765 kref_init(&tcon->crfid.refcount);
766
767
768 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
769 kref_get(&tcon->crfid.refcount);
770 smb2_parse_contexts(server, o_rsp,
771 &oparms.fid->epoch,
772 oparms.fid->lease_key, &oplock, NULL);
773 } else
774 goto oshr_exit;
775
776 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
777 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
778 goto oshr_exit;
779 if (!smb2_validate_and_copy_iov(
780 le16_to_cpu(qi_rsp->OutputBufferOffset),
781 sizeof(struct smb2_file_all_info),
782 &rsp_iov[1], sizeof(struct smb2_file_all_info),
783 (char *)&tcon->crfid.file_all_info))
784 tcon->crfid.file_all_info_is_valid = 1;
785
786 oshr_exit:
787 mutex_unlock(&tcon->crfid.fid_mutex);
788 oshr_free:
789 SMB2_open_free(&rqst[0]);
790 SMB2_query_info_free(&rqst[1]);
791 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
792 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
793 return rc;
794 }
795
796 static void
797 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
798 {
799 int rc;
800 __le16 srch_path = 0;
801 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
802 struct cifs_open_parms oparms;
803 struct cifs_fid fid;
804 bool no_cached_open = tcon->nohandlecache;
805
806 oparms.tcon = tcon;
807 oparms.desired_access = FILE_READ_ATTRIBUTES;
808 oparms.disposition = FILE_OPEN;
809 oparms.create_options = 0;
810 oparms.fid = &fid;
811 oparms.reconnect = false;
812
813 if (no_cached_open)
814 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
815 NULL);
816 else
817 rc = open_shroot(xid, tcon, &fid);
818
819 if (rc)
820 return;
821
822 SMB3_request_interfaces(xid, tcon);
823
824 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
825 FS_ATTRIBUTE_INFORMATION);
826 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
827 FS_DEVICE_INFORMATION);
828 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
829 FS_VOLUME_INFORMATION);
830 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
831 FS_SECTOR_SIZE_INFORMATION);
832 if (no_cached_open)
833 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
834 else
835 close_shroot(&tcon->crfid);
836 }
837
838 static void
839 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
840 {
841 int rc;
842 __le16 srch_path = 0;
843 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
844 struct cifs_open_parms oparms;
845 struct cifs_fid fid;
846
847 oparms.tcon = tcon;
848 oparms.desired_access = FILE_READ_ATTRIBUTES;
849 oparms.disposition = FILE_OPEN;
850 oparms.create_options = 0;
851 oparms.fid = &fid;
852 oparms.reconnect = false;
853
854 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
855 if (rc)
856 return;
857
858 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
859 FS_ATTRIBUTE_INFORMATION);
860 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
861 FS_DEVICE_INFORMATION);
862 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
863 }
864
865 static int
866 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
867 struct cifs_sb_info *cifs_sb, const char *full_path)
868 {
869 int rc;
870 __le16 *utf16_path;
871 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
872 struct cifs_open_parms oparms;
873 struct cifs_fid fid;
874
875 if ((*full_path == 0) && tcon->crfid.is_valid)
876 return 0;
877
878 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
879 if (!utf16_path)
880 return -ENOMEM;
881
882 oparms.tcon = tcon;
883 oparms.desired_access = FILE_READ_ATTRIBUTES;
884 oparms.disposition = FILE_OPEN;
885 if (backup_cred(cifs_sb))
886 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
887 else
888 oparms.create_options = 0;
889 oparms.fid = &fid;
890 oparms.reconnect = false;
891
892 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
893 if (rc) {
894 kfree(utf16_path);
895 return rc;
896 }
897
898 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
899 kfree(utf16_path);
900 return rc;
901 }
902
903 static int
904 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
905 struct cifs_sb_info *cifs_sb, const char *full_path,
906 u64 *uniqueid, FILE_ALL_INFO *data)
907 {
908 *uniqueid = le64_to_cpu(data->IndexNumber);
909 return 0;
910 }
911
912 static int
913 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
914 struct cifs_fid *fid, FILE_ALL_INFO *data)
915 {
916 int rc;
917 struct smb2_file_all_info *smb2_data;
918
919 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
920 GFP_KERNEL);
921 if (smb2_data == NULL)
922 return -ENOMEM;
923
924 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
925 smb2_data);
926 if (!rc)
927 move_smb2_info_to_cifs(data, smb2_data);
928 kfree(smb2_data);
929 return rc;
930 }
931
932 #ifdef CONFIG_CIFS_XATTR
933 static ssize_t
934 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
935 struct smb2_file_full_ea_info *src, size_t src_size,
936 const unsigned char *ea_name)
937 {
938 int rc = 0;
939 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
940 char *name, *value;
941 size_t buf_size = dst_size;
942 size_t name_len, value_len, user_name_len;
943
944 while (src_size > 0) {
945 name = &src->ea_data[0];
946 name_len = (size_t)src->ea_name_length;
947 value = &src->ea_data[src->ea_name_length + 1];
948 value_len = (size_t)le16_to_cpu(src->ea_value_length);
949
950 if (name_len == 0)
951 break;
952
953 if (src_size < 8 + name_len + 1 + value_len) {
954 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
955 rc = -EIO;
956 goto out;
957 }
958
959 if (ea_name) {
960 if (ea_name_len == name_len &&
961 memcmp(ea_name, name, name_len) == 0) {
962 rc = value_len;
963 if (dst_size == 0)
964 goto out;
965 if (dst_size < value_len) {
966 rc = -ERANGE;
967 goto out;
968 }
969 memcpy(dst, value, value_len);
970 goto out;
971 }
972 } else {
973
974 user_name_len = 5 + 1 + name_len;
975
976 if (buf_size == 0) {
977
978 rc += user_name_len;
979 } else if (dst_size >= user_name_len) {
980 dst_size -= user_name_len;
981 memcpy(dst, "user.", 5);
982 dst += 5;
983 memcpy(dst, src->ea_data, name_len);
984 dst += name_len;
985 *dst = 0;
986 ++dst;
987 rc += user_name_len;
988 } else {
989
990 rc = -ERANGE;
991 break;
992 }
993 }
994
995 if (!src->next_entry_offset)
996 break;
997
998 if (src_size < le32_to_cpu(src->next_entry_offset)) {
999
1000 rc = -ERANGE;
1001 break;
1002 }
1003 src_size -= le32_to_cpu(src->next_entry_offset);
1004 src = (void *)((char *)src +
1005 le32_to_cpu(src->next_entry_offset));
1006 }
1007
1008
1009 if (ea_name)
1010 rc = -ENODATA;
1011
1012 out:
1013 return (ssize_t)rc;
1014 }
1015
1016 static ssize_t
1017 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1018 const unsigned char *path, const unsigned char *ea_name,
1019 char *ea_data, size_t buf_size,
1020 struct cifs_sb_info *cifs_sb)
1021 {
1022 int rc;
1023 __le16 *utf16_path;
1024 struct kvec rsp_iov = {NULL, 0};
1025 int buftype = CIFS_NO_BUFFER;
1026 struct smb2_query_info_rsp *rsp;
1027 struct smb2_file_full_ea_info *info = NULL;
1028
1029 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1030 if (!utf16_path)
1031 return -ENOMEM;
1032
1033 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1034 FILE_READ_EA,
1035 FILE_FULL_EA_INFORMATION,
1036 SMB2_O_INFO_FILE,
1037 CIFSMaxBufSize -
1038 MAX_SMB2_CREATE_RESPONSE_SIZE -
1039 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1040 &rsp_iov, &buftype, cifs_sb);
1041 if (rc) {
1042
1043
1044
1045
1046
1047 if (!ea_name && rc == -ENODATA)
1048 rc = 0;
1049 goto qeas_exit;
1050 }
1051
1052 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1053 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1054 le32_to_cpu(rsp->OutputBufferLength),
1055 &rsp_iov,
1056 sizeof(struct smb2_file_full_ea_info));
1057 if (rc)
1058 goto qeas_exit;
1059
1060 info = (struct smb2_file_full_ea_info *)(
1061 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1062 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1063 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1064
1065 qeas_exit:
1066 kfree(utf16_path);
1067 free_rsp_buf(buftype, rsp_iov.iov_base);
1068 return rc;
1069 }
1070
1071
1072 static int
1073 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1074 const char *path, const char *ea_name, const void *ea_value,
1075 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1076 struct cifs_sb_info *cifs_sb)
1077 {
1078 struct cifs_ses *ses = tcon->ses;
1079 __le16 *utf16_path = NULL;
1080 int ea_name_len = strlen(ea_name);
1081 int flags = 0;
1082 int len;
1083 struct smb_rqst rqst[3];
1084 int resp_buftype[3];
1085 struct kvec rsp_iov[3];
1086 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1087 struct cifs_open_parms oparms;
1088 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1089 struct cifs_fid fid;
1090 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1091 unsigned int size[1];
1092 void *data[1];
1093 struct smb2_file_full_ea_info *ea = NULL;
1094 struct kvec close_iov[1];
1095 struct smb2_query_info_rsp *rsp;
1096 int rc, used_len = 0;
1097
1098 if (smb3_encryption_required(tcon))
1099 flags |= CIFS_TRANSFORM_REQ;
1100
1101 if (ea_name_len > 255)
1102 return -EINVAL;
1103
1104 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1105 if (!utf16_path)
1106 return -ENOMEM;
1107
1108 memset(rqst, 0, sizeof(rqst));
1109 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1110 memset(rsp_iov, 0, sizeof(rsp_iov));
1111
1112 if (ses->server->ops->query_all_EAs) {
1113 if (!ea_value) {
1114 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1115 ea_name, NULL, 0,
1116 cifs_sb);
1117 if (rc == -ENODATA)
1118 goto sea_exit;
1119 } else {
1120
1121
1122
1123
1124
1125 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1126 FILE_READ_EA,
1127 FILE_FULL_EA_INFORMATION,
1128 SMB2_O_INFO_FILE,
1129 CIFSMaxBufSize -
1130 MAX_SMB2_CREATE_RESPONSE_SIZE -
1131 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1132 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1133 if (rc == 0) {
1134 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1135 used_len = le32_to_cpu(rsp->OutputBufferLength);
1136 }
1137 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1138 resp_buftype[1] = CIFS_NO_BUFFER;
1139 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1140 rc = 0;
1141
1142
1143
1144
1145 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1146 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1147 used_len + ea_name_len + ea_value_len + 1) {
1148 rc = -ENOSPC;
1149 goto sea_exit;
1150 }
1151 }
1152 }
1153
1154
1155 memset(&open_iov, 0, sizeof(open_iov));
1156 rqst[0].rq_iov = open_iov;
1157 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1158
1159 memset(&oparms, 0, sizeof(oparms));
1160 oparms.tcon = tcon;
1161 oparms.desired_access = FILE_WRITE_EA;
1162 oparms.disposition = FILE_OPEN;
1163 if (backup_cred(cifs_sb))
1164 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1165 else
1166 oparms.create_options = 0;
1167 oparms.fid = &fid;
1168 oparms.reconnect = false;
1169
1170 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
1171 if (rc)
1172 goto sea_exit;
1173 smb2_set_next_command(tcon, &rqst[0]);
1174
1175
1176
1177 memset(&si_iov, 0, sizeof(si_iov));
1178 rqst[1].rq_iov = si_iov;
1179 rqst[1].rq_nvec = 1;
1180
1181 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
1182 ea = kzalloc(len, GFP_KERNEL);
1183 if (ea == NULL) {
1184 rc = -ENOMEM;
1185 goto sea_exit;
1186 }
1187
1188 ea->ea_name_length = ea_name_len;
1189 ea->ea_value_length = cpu_to_le16(ea_value_len);
1190 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1191 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1192
1193 size[0] = len;
1194 data[0] = ea;
1195
1196 rc = SMB2_set_info_init(tcon, &rqst[1], COMPOUND_FID,
1197 COMPOUND_FID, current->tgid,
1198 FILE_FULL_EA_INFORMATION,
1199 SMB2_O_INFO_FILE, 0, data, size);
1200 smb2_set_next_command(tcon, &rqst[1]);
1201 smb2_set_related(&rqst[1]);
1202
1203
1204
1205 memset(&close_iov, 0, sizeof(close_iov));
1206 rqst[2].rq_iov = close_iov;
1207 rqst[2].rq_nvec = 1;
1208 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1209 smb2_set_related(&rqst[2]);
1210
1211 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1212 resp_buftype, rsp_iov);
1213
1214
1215 sea_exit:
1216 kfree(ea);
1217 kfree(utf16_path);
1218 SMB2_open_free(&rqst[0]);
1219 SMB2_set_info_free(&rqst[1]);
1220 SMB2_close_free(&rqst[2]);
1221 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1222 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1223 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1224 return rc;
1225 }
1226 #endif
1227
1228 static bool
1229 smb2_can_echo(struct TCP_Server_Info *server)
1230 {
1231 return server->echoes;
1232 }
1233
1234 static void
1235 smb2_clear_stats(struct cifs_tcon *tcon)
1236 {
1237 int i;
1238
1239 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1240 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1241 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1242 }
1243 }
1244
1245 static void
1246 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1247 {
1248 seq_puts(m, "\n\tShare Capabilities:");
1249 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1250 seq_puts(m, " DFS,");
1251 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1252 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1253 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1254 seq_puts(m, " SCALEOUT,");
1255 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1256 seq_puts(m, " CLUSTER,");
1257 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1258 seq_puts(m, " ASYMMETRIC,");
1259 if (tcon->capabilities == 0)
1260 seq_puts(m, " None");
1261 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1262 seq_puts(m, " Aligned,");
1263 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1264 seq_puts(m, " Partition Aligned,");
1265 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1266 seq_puts(m, " SSD,");
1267 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1268 seq_puts(m, " TRIM-support,");
1269
1270 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1271 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1272 if (tcon->perf_sector_size)
1273 seq_printf(m, "\tOptimal sector size: 0x%x",
1274 tcon->perf_sector_size);
1275 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1276 }
1277
1278 static void
1279 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1280 {
1281 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1282 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1283
1284
1285
1286
1287
1288 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1289 (long long)(tcon->bytes_read),
1290 (long long)(tcon->bytes_written));
1291 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1292 atomic_read(&tcon->num_local_opens),
1293 atomic_read(&tcon->num_remote_opens));
1294 seq_printf(m, "\nTreeConnects: %d total %d failed",
1295 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1296 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1297 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1298 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1299 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1300 seq_printf(m, "\nCreates: %d total %d failed",
1301 atomic_read(&sent[SMB2_CREATE_HE]),
1302 atomic_read(&failed[SMB2_CREATE_HE]));
1303 seq_printf(m, "\nCloses: %d total %d failed",
1304 atomic_read(&sent[SMB2_CLOSE_HE]),
1305 atomic_read(&failed[SMB2_CLOSE_HE]));
1306 seq_printf(m, "\nFlushes: %d total %d failed",
1307 atomic_read(&sent[SMB2_FLUSH_HE]),
1308 atomic_read(&failed[SMB2_FLUSH_HE]));
1309 seq_printf(m, "\nReads: %d total %d failed",
1310 atomic_read(&sent[SMB2_READ_HE]),
1311 atomic_read(&failed[SMB2_READ_HE]));
1312 seq_printf(m, "\nWrites: %d total %d failed",
1313 atomic_read(&sent[SMB2_WRITE_HE]),
1314 atomic_read(&failed[SMB2_WRITE_HE]));
1315 seq_printf(m, "\nLocks: %d total %d failed",
1316 atomic_read(&sent[SMB2_LOCK_HE]),
1317 atomic_read(&failed[SMB2_LOCK_HE]));
1318 seq_printf(m, "\nIOCTLs: %d total %d failed",
1319 atomic_read(&sent[SMB2_IOCTL_HE]),
1320 atomic_read(&failed[SMB2_IOCTL_HE]));
1321 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1322 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1323 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1324 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1325 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1326 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1327 seq_printf(m, "\nQueryInfos: %d total %d failed",
1328 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1329 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1330 seq_printf(m, "\nSetInfos: %d total %d failed",
1331 atomic_read(&sent[SMB2_SET_INFO_HE]),
1332 atomic_read(&failed[SMB2_SET_INFO_HE]));
1333 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1334 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1335 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1336 }
1337
1338 static void
1339 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1340 {
1341 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1342 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1343
1344 cfile->fid.persistent_fid = fid->persistent_fid;
1345 cfile->fid.volatile_fid = fid->volatile_fid;
1346 cfile->fid.access = fid->access;
1347 #ifdef CONFIG_CIFS_DEBUG2
1348 cfile->fid.mid = fid->mid;
1349 #endif
1350 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1351 &fid->purge_cache);
1352 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1353 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1354 }
1355
1356 static void
1357 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1358 struct cifs_fid *fid)
1359 {
1360 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1361 }
1362
1363 static int
1364 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1365 u64 persistent_fid, u64 volatile_fid,
1366 struct copychunk_ioctl *pcchunk)
1367 {
1368 int rc;
1369 unsigned int ret_data_len;
1370 struct resume_key_req *res_key;
1371
1372 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1373 FSCTL_SRV_REQUEST_RESUME_KEY, true ,
1374 NULL, 0 , CIFSMaxBufSize,
1375 (char **)&res_key, &ret_data_len);
1376
1377 if (rc) {
1378 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1379 goto req_res_key_exit;
1380 }
1381 if (ret_data_len < sizeof(struct resume_key_req)) {
1382 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1383 rc = -EINVAL;
1384 goto req_res_key_exit;
1385 }
1386 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1387
1388 req_res_key_exit:
1389 kfree(res_key);
1390 return rc;
1391 }
1392
1393 static int
1394 smb2_ioctl_query_info(const unsigned int xid,
1395 struct cifs_tcon *tcon,
1396 __le16 *path, int is_dir,
1397 unsigned long p)
1398 {
1399 struct cifs_ses *ses = tcon->ses;
1400 char __user *arg = (char __user *)p;
1401 struct smb_query_info qi;
1402 struct smb_query_info __user *pqi;
1403 int rc = 0;
1404 int flags = 0;
1405 struct smb2_query_info_rsp *qi_rsp = NULL;
1406 struct smb2_ioctl_rsp *io_rsp = NULL;
1407 void *buffer = NULL;
1408 struct smb_rqst rqst[3];
1409 int resp_buftype[3];
1410 struct kvec rsp_iov[3];
1411 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1412 struct cifs_open_parms oparms;
1413 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1414 struct cifs_fid fid;
1415 struct kvec qi_iov[1];
1416 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1417 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1418 struct kvec close_iov[1];
1419 unsigned int size[2];
1420 void *data[2];
1421
1422 memset(rqst, 0, sizeof(rqst));
1423 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1424 memset(rsp_iov, 0, sizeof(rsp_iov));
1425
1426 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1427 return -EFAULT;
1428
1429 if (qi.output_buffer_length > 1024)
1430 return -EINVAL;
1431
1432 if (!ses || !(ses->server))
1433 return -EIO;
1434
1435 if (smb3_encryption_required(tcon))
1436 flags |= CIFS_TRANSFORM_REQ;
1437
1438 buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL);
1439 if (buffer == NULL)
1440 return -ENOMEM;
1441
1442 if (copy_from_user(buffer, arg + sizeof(struct smb_query_info),
1443 qi.output_buffer_length)) {
1444 rc = -EFAULT;
1445 goto iqinf_exit;
1446 }
1447
1448
1449 memset(&open_iov, 0, sizeof(open_iov));
1450 rqst[0].rq_iov = open_iov;
1451 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1452
1453 memset(&oparms, 0, sizeof(oparms));
1454 oparms.tcon = tcon;
1455 oparms.disposition = FILE_OPEN;
1456 if (is_dir)
1457 oparms.create_options = CREATE_NOT_FILE;
1458 else
1459 oparms.create_options = CREATE_NOT_DIR;
1460 oparms.fid = &fid;
1461 oparms.reconnect = false;
1462
1463 if (qi.flags & PASSTHRU_FSCTL) {
1464 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1465 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1466 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1467 break;
1468 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1469 oparms.desired_access = GENERIC_ALL;
1470 break;
1471 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1472 oparms.desired_access = GENERIC_READ;
1473 break;
1474 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1475 oparms.desired_access = GENERIC_WRITE;
1476 break;
1477 }
1478 } else if (qi.flags & PASSTHRU_SET_INFO) {
1479 oparms.desired_access = GENERIC_WRITE;
1480 } else {
1481 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1482 }
1483
1484 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path);
1485 if (rc)
1486 goto iqinf_exit;
1487 smb2_set_next_command(tcon, &rqst[0]);
1488
1489
1490 if (qi.flags & PASSTHRU_FSCTL) {
1491
1492 if (!capable(CAP_SYS_ADMIN))
1493 rc = -EPERM;
1494 else {
1495 memset(&io_iov, 0, sizeof(io_iov));
1496 rqst[1].rq_iov = io_iov;
1497 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1498
1499 rc = SMB2_ioctl_init(tcon, &rqst[1],
1500 COMPOUND_FID, COMPOUND_FID,
1501 qi.info_type, true, buffer,
1502 qi.output_buffer_length,
1503 CIFSMaxBufSize -
1504 MAX_SMB2_CREATE_RESPONSE_SIZE -
1505 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1506 }
1507 } else if (qi.flags == PASSTHRU_SET_INFO) {
1508
1509 if (!capable(CAP_SYS_ADMIN))
1510 rc = -EPERM;
1511 else {
1512 memset(&si_iov, 0, sizeof(si_iov));
1513 rqst[1].rq_iov = si_iov;
1514 rqst[1].rq_nvec = 1;
1515
1516 size[0] = 8;
1517 data[0] = buffer;
1518
1519 rc = SMB2_set_info_init(tcon, &rqst[1],
1520 COMPOUND_FID, COMPOUND_FID,
1521 current->tgid,
1522 FILE_END_OF_FILE_INFORMATION,
1523 SMB2_O_INFO_FILE, 0, data, size);
1524 }
1525 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1526 memset(&qi_iov, 0, sizeof(qi_iov));
1527 rqst[1].rq_iov = qi_iov;
1528 rqst[1].rq_nvec = 1;
1529
1530 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
1531 COMPOUND_FID, qi.file_info_class,
1532 qi.info_type, qi.additional_information,
1533 qi.input_buffer_length,
1534 qi.output_buffer_length, buffer);
1535 } else {
1536 cifs_tcon_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags);
1537 rc = -EINVAL;
1538 }
1539
1540 if (rc)
1541 goto iqinf_exit;
1542 smb2_set_next_command(tcon, &rqst[1]);
1543 smb2_set_related(&rqst[1]);
1544
1545
1546 memset(&close_iov, 0, sizeof(close_iov));
1547 rqst[2].rq_iov = close_iov;
1548 rqst[2].rq_nvec = 1;
1549
1550 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1551 if (rc)
1552 goto iqinf_exit;
1553 smb2_set_related(&rqst[2]);
1554
1555 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1556 resp_buftype, rsp_iov);
1557 if (rc)
1558 goto iqinf_exit;
1559
1560
1561 if (qi.flags & PASSTHRU_FSCTL) {
1562 pqi = (struct smb_query_info __user *)arg;
1563 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1564 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1565 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1566 if (qi.input_buffer_length > 0 &&
1567 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length > rsp_iov[1].iov_len) {
1568 rc = -EFAULT;
1569 goto iqinf_exit;
1570 }
1571 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1572 sizeof(qi.input_buffer_length))) {
1573 rc = -EFAULT;
1574 goto iqinf_exit;
1575 }
1576 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1577 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1578 qi.input_buffer_length)) {
1579 rc = -EFAULT;
1580 goto iqinf_exit;
1581 }
1582 } else {
1583 pqi = (struct smb_query_info __user *)arg;
1584 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1585 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1586 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1587 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1588 sizeof(qi.input_buffer_length))) {
1589 rc = -EFAULT;
1590 goto iqinf_exit;
1591 }
1592 if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) {
1593 rc = -EFAULT;
1594 goto iqinf_exit;
1595 }
1596 }
1597
1598 iqinf_exit:
1599 kfree(buffer);
1600 SMB2_open_free(&rqst[0]);
1601 if (qi.flags & PASSTHRU_FSCTL)
1602 SMB2_ioctl_free(&rqst[1]);
1603 else
1604 SMB2_query_info_free(&rqst[1]);
1605
1606 SMB2_close_free(&rqst[2]);
1607 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1608 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1609 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1610 return rc;
1611 }
1612
1613 static ssize_t
1614 smb2_copychunk_range(const unsigned int xid,
1615 struct cifsFileInfo *srcfile,
1616 struct cifsFileInfo *trgtfile, u64 src_off,
1617 u64 len, u64 dest_off)
1618 {
1619 int rc;
1620 unsigned int ret_data_len;
1621 struct copychunk_ioctl *pcchunk;
1622 struct copychunk_ioctl_rsp *retbuf = NULL;
1623 struct cifs_tcon *tcon;
1624 int chunks_copied = 0;
1625 bool chunk_sizes_updated = false;
1626 ssize_t bytes_written, total_bytes_written = 0;
1627
1628 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1629
1630 if (pcchunk == NULL)
1631 return -ENOMEM;
1632
1633 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1634
1635 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1636 srcfile->fid.persistent_fid,
1637 srcfile->fid.volatile_fid, pcchunk);
1638
1639
1640 if (rc)
1641 goto cchunk_out;
1642
1643
1644 pcchunk->ChunkCount = cpu_to_le32(1);
1645 pcchunk->Reserved = 0;
1646 pcchunk->Reserved2 = 0;
1647
1648 tcon = tlink_tcon(trgtfile->tlink);
1649
1650 while (len > 0) {
1651 pcchunk->SourceOffset = cpu_to_le64(src_off);
1652 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1653 pcchunk->Length =
1654 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1655
1656
1657 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1658 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1659 true , (char *)pcchunk,
1660 sizeof(struct copychunk_ioctl), CIFSMaxBufSize,
1661 (char **)&retbuf, &ret_data_len);
1662 if (rc == 0) {
1663 if (ret_data_len !=
1664 sizeof(struct copychunk_ioctl_rsp)) {
1665 cifs_tcon_dbg(VFS, "invalid cchunk response size\n");
1666 rc = -EIO;
1667 goto cchunk_out;
1668 }
1669 if (retbuf->TotalBytesWritten == 0) {
1670 cifs_dbg(FYI, "no bytes copied\n");
1671 rc = -EIO;
1672 goto cchunk_out;
1673 }
1674
1675
1676
1677 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1678 le32_to_cpu(pcchunk->Length)) {
1679 cifs_tcon_dbg(VFS, "invalid copy chunk response\n");
1680 rc = -EIO;
1681 goto cchunk_out;
1682 }
1683 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1684 cifs_tcon_dbg(VFS, "invalid num chunks written\n");
1685 rc = -EIO;
1686 goto cchunk_out;
1687 }
1688 chunks_copied++;
1689
1690 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1691 src_off += bytes_written;
1692 dest_off += bytes_written;
1693 len -= bytes_written;
1694 total_bytes_written += bytes_written;
1695
1696 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1697 le32_to_cpu(retbuf->ChunksWritten),
1698 le32_to_cpu(retbuf->ChunkBytesWritten),
1699 bytes_written);
1700 } else if (rc == -EINVAL) {
1701 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1702 goto cchunk_out;
1703
1704 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1705 le32_to_cpu(retbuf->ChunksWritten),
1706 le32_to_cpu(retbuf->ChunkBytesWritten),
1707 le32_to_cpu(retbuf->TotalBytesWritten));
1708
1709
1710
1711
1712
1713
1714
1715
1716 if ((chunks_copied != 0) || chunk_sizes_updated)
1717 goto cchunk_out;
1718
1719
1720 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1721 tcon->max_bytes_chunk)
1722 tcon->max_bytes_chunk =
1723 le32_to_cpu(retbuf->ChunkBytesWritten);
1724 else
1725 goto cchunk_out;
1726
1727
1728 chunk_sizes_updated = true;
1729 } else
1730 goto cchunk_out;
1731 }
1732
1733 cchunk_out:
1734 kfree(pcchunk);
1735 kfree(retbuf);
1736 if (rc)
1737 return rc;
1738 else
1739 return total_bytes_written;
1740 }
1741
1742 static int
1743 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1744 struct cifs_fid *fid)
1745 {
1746 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1747 }
1748
1749 static unsigned int
1750 smb2_read_data_offset(char *buf)
1751 {
1752 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1753
1754 return rsp->DataOffset;
1755 }
1756
1757 static unsigned int
1758 smb2_read_data_length(char *buf, bool in_remaining)
1759 {
1760 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1761
1762 if (in_remaining)
1763 return le32_to_cpu(rsp->DataRemaining);
1764
1765 return le32_to_cpu(rsp->DataLength);
1766 }
1767
1768
1769 static int
1770 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1771 struct cifs_io_parms *parms, unsigned int *bytes_read,
1772 char **buf, int *buf_type)
1773 {
1774 parms->persistent_fid = pfid->persistent_fid;
1775 parms->volatile_fid = pfid->volatile_fid;
1776 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1777 }
1778
1779 static int
1780 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1781 struct cifs_io_parms *parms, unsigned int *written,
1782 struct kvec *iov, unsigned long nr_segs)
1783 {
1784
1785 parms->persistent_fid = pfid->persistent_fid;
1786 parms->volatile_fid = pfid->volatile_fid;
1787 return SMB2_write(xid, parms, written, iov, nr_segs);
1788 }
1789
1790
1791 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1792 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1793 {
1794 struct cifsInodeInfo *cifsi;
1795 int rc;
1796
1797 cifsi = CIFS_I(inode);
1798
1799
1800 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1801 return true;
1802
1803 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1804 return true;
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816 if (tcon->broken_sparse_sup)
1817 return false;
1818
1819 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1820 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1821 true ,
1822 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1823 if (rc) {
1824 tcon->broken_sparse_sup = true;
1825 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1826 return false;
1827 }
1828
1829 if (setsparse)
1830 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1831 else
1832 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1833
1834 return true;
1835 }
1836
1837 static int
1838 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1839 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1840 {
1841 __le64 eof = cpu_to_le64(size);
1842 struct inode *inode;
1843
1844
1845
1846
1847
1848 inode = d_inode(cfile->dentry);
1849
1850 if (!set_alloc && (size > inode->i_size + 8192)) {
1851 __u8 set_sparse = 1;
1852
1853
1854 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1855 }
1856
1857 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1858 cfile->fid.volatile_fid, cfile->pid, &eof);
1859 }
1860
1861 static int
1862 smb2_duplicate_extents(const unsigned int xid,
1863 struct cifsFileInfo *srcfile,
1864 struct cifsFileInfo *trgtfile, u64 src_off,
1865 u64 len, u64 dest_off)
1866 {
1867 int rc;
1868 unsigned int ret_data_len;
1869 struct duplicate_extents_to_file dup_ext_buf;
1870 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1871
1872
1873 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1874 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1875 return -EOPNOTSUPP;
1876
1877 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1878 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1879 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1880 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1881 dup_ext_buf.ByteCount = cpu_to_le64(len);
1882 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1883 src_off, dest_off, len);
1884
1885 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1886 if (rc)
1887 goto duplicate_extents_out;
1888
1889 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1890 trgtfile->fid.volatile_fid,
1891 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1892 true ,
1893 (char *)&dup_ext_buf,
1894 sizeof(struct duplicate_extents_to_file),
1895 CIFSMaxBufSize, NULL,
1896 &ret_data_len);
1897
1898 if (ret_data_len > 0)
1899 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1900
1901 duplicate_extents_out:
1902 return rc;
1903 }
1904
1905 static int
1906 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1907 struct cifsFileInfo *cfile)
1908 {
1909 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1910 cfile->fid.volatile_fid);
1911 }
1912
1913 static int
1914 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1915 struct cifsFileInfo *cfile)
1916 {
1917 struct fsctl_set_integrity_information_req integr_info;
1918 unsigned int ret_data_len;
1919
1920 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1921 integr_info.Flags = 0;
1922 integr_info.Reserved = 0;
1923
1924 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1925 cfile->fid.volatile_fid,
1926 FSCTL_SET_INTEGRITY_INFORMATION,
1927 true ,
1928 (char *)&integr_info,
1929 sizeof(struct fsctl_set_integrity_information_req),
1930 CIFSMaxBufSize, NULL,
1931 &ret_data_len);
1932
1933 }
1934
1935
1936 #define GMT_TOKEN_SIZE 50
1937
1938 #define MIN_SNAPSHOT_ARRAY_SIZE 16
1939
1940
1941
1942
1943
1944 static int
1945 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1946 struct cifsFileInfo *cfile, void __user *ioc_buf)
1947 {
1948 char *retbuf = NULL;
1949 unsigned int ret_data_len = 0;
1950 int rc;
1951 u32 max_response_size;
1952 struct smb_snapshot_array snapshot_in;
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1963 return -EFAULT;
1964
1965
1966
1967
1968
1969
1970
1971
1972 if (ret_data_len == 0)
1973 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1974 else
1975 max_response_size = CIFSMaxBufSize;
1976
1977 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1978 cfile->fid.volatile_fid,
1979 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1980 true ,
1981 NULL, 0 , max_response_size,
1982 (char **)&retbuf,
1983 &ret_data_len);
1984 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1985 rc, ret_data_len);
1986 if (rc)
1987 return rc;
1988
1989 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1990
1991 if (copy_from_user(&snapshot_in, ioc_buf,
1992 sizeof(struct smb_snapshot_array))) {
1993 rc = -EFAULT;
1994 kfree(retbuf);
1995 return rc;
1996 }
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2007 ret_data_len = sizeof(struct smb_snapshot_array);
2008
2009
2010
2011
2012
2013
2014 if (ret_data_len > (snapshot_in.snapshot_array_size +
2015 sizeof(struct smb_snapshot_array)))
2016 ret_data_len = snapshot_in.snapshot_array_size +
2017 sizeof(struct smb_snapshot_array);
2018
2019 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2020 rc = -EFAULT;
2021 }
2022
2023 kfree(retbuf);
2024 return rc;
2025 }
2026
2027 static int
2028 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2029 const char *path, struct cifs_sb_info *cifs_sb,
2030 struct cifs_fid *fid, __u16 search_flags,
2031 struct cifs_search_info *srch_inf)
2032 {
2033 __le16 *utf16_path;
2034 int rc;
2035 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2036 struct cifs_open_parms oparms;
2037
2038 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2039 if (!utf16_path)
2040 return -ENOMEM;
2041
2042 oparms.tcon = tcon;
2043 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2044 oparms.disposition = FILE_OPEN;
2045 if (backup_cred(cifs_sb))
2046 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2047 else
2048 oparms.create_options = 0;
2049 oparms.fid = fid;
2050 oparms.reconnect = false;
2051
2052 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2053 kfree(utf16_path);
2054 if (rc) {
2055 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
2056 return rc;
2057 }
2058
2059 srch_inf->entries_in_buffer = 0;
2060 srch_inf->index_of_last_entry = 2;
2061
2062 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
2063 fid->volatile_fid, 0, srch_inf);
2064 if (rc) {
2065 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
2066 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2067 }
2068 return rc;
2069 }
2070
2071 static int
2072 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2073 struct cifs_fid *fid, __u16 search_flags,
2074 struct cifs_search_info *srch_inf)
2075 {
2076 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2077 fid->volatile_fid, 0, srch_inf);
2078 }
2079
2080 static int
2081 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2082 struct cifs_fid *fid)
2083 {
2084 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2085 }
2086
2087
2088
2089
2090
2091 static bool
2092 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2093 {
2094 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2095
2096 if (shdr->Status != STATUS_PENDING)
2097 return false;
2098
2099 if (shdr->CreditRequest) {
2100 spin_lock(&server->req_lock);
2101 server->credits += le16_to_cpu(shdr->CreditRequest);
2102 spin_unlock(&server->req_lock);
2103 wake_up(&server->request_q);
2104 }
2105
2106 return true;
2107 }
2108
2109 static bool
2110 smb2_is_session_expired(char *buf)
2111 {
2112 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2113
2114 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2115 shdr->Status != STATUS_USER_SESSION_DELETED)
2116 return false;
2117
2118 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2119 le16_to_cpu(shdr->Command),
2120 le64_to_cpu(shdr->MessageId));
2121 cifs_dbg(FYI, "Session expired or deleted\n");
2122
2123 return true;
2124 }
2125
2126 static int
2127 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2128 struct cifsInodeInfo *cinode)
2129 {
2130 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2131 return SMB2_lease_break(0, tcon, cinode->lease_key,
2132 smb2_get_lease_state(cinode));
2133
2134 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2135 fid->volatile_fid,
2136 CIFS_CACHE_READ(cinode) ? 1 : 0);
2137 }
2138
2139 void
2140 smb2_set_related(struct smb_rqst *rqst)
2141 {
2142 struct smb2_sync_hdr *shdr;
2143
2144 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2145 if (shdr == NULL) {
2146 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2147 return;
2148 }
2149 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2150 }
2151
2152 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2153
2154 void
2155 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2156 {
2157 struct smb2_sync_hdr *shdr;
2158 struct cifs_ses *ses = tcon->ses;
2159 struct TCP_Server_Info *server = ses->server;
2160 unsigned long len = smb_rqst_len(server, rqst);
2161 int i, num_padding;
2162
2163 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2164 if (shdr == NULL) {
2165 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2166 return;
2167 }
2168
2169
2170
2171
2172 if (!(len & 7))
2173 goto finished;
2174
2175 num_padding = 8 - (len & 7);
2176 if (!smb3_encryption_required(tcon)) {
2177
2178
2179
2180
2181 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2182 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2183 rqst->rq_nvec++;
2184 len += num_padding;
2185 } else {
2186
2187
2188
2189
2190
2191
2192
2193 for (i = 1; i < rqst->rq_nvec; i++) {
2194 memcpy(rqst->rq_iov[0].iov_base +
2195 rqst->rq_iov[0].iov_len,
2196 rqst->rq_iov[i].iov_base,
2197 rqst->rq_iov[i].iov_len);
2198 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2199 }
2200 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2201 0, num_padding);
2202 rqst->rq_iov[0].iov_len += num_padding;
2203 len += num_padding;
2204 rqst->rq_nvec = 1;
2205 }
2206
2207 finished:
2208 shdr->NextCommand = cpu_to_le32(len);
2209 }
2210
2211
2212
2213
2214
2215 int
2216 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2217 __le16 *utf16_path, u32 desired_access,
2218 u32 class, u32 type, u32 output_len,
2219 struct kvec *rsp, int *buftype,
2220 struct cifs_sb_info *cifs_sb)
2221 {
2222 struct cifs_ses *ses = tcon->ses;
2223 int flags = 0;
2224 struct smb_rqst rqst[3];
2225 int resp_buftype[3];
2226 struct kvec rsp_iov[3];
2227 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2228 struct kvec qi_iov[1];
2229 struct kvec close_iov[1];
2230 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2231 struct cifs_open_parms oparms;
2232 struct cifs_fid fid;
2233 int rc;
2234
2235 if (smb3_encryption_required(tcon))
2236 flags |= CIFS_TRANSFORM_REQ;
2237
2238 memset(rqst, 0, sizeof(rqst));
2239 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2240 memset(rsp_iov, 0, sizeof(rsp_iov));
2241
2242 memset(&open_iov, 0, sizeof(open_iov));
2243 rqst[0].rq_iov = open_iov;
2244 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2245
2246 oparms.tcon = tcon;
2247 oparms.desired_access = desired_access;
2248 oparms.disposition = FILE_OPEN;
2249 if (cifs_sb && backup_cred(cifs_sb))
2250 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2251 else
2252 oparms.create_options = 0;
2253 oparms.fid = &fid;
2254 oparms.reconnect = false;
2255
2256 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2257 if (rc)
2258 goto qic_exit;
2259 smb2_set_next_command(tcon, &rqst[0]);
2260
2261 memset(&qi_iov, 0, sizeof(qi_iov));
2262 rqst[1].rq_iov = qi_iov;
2263 rqst[1].rq_nvec = 1;
2264
2265 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
2266 class, type, 0,
2267 output_len, 0,
2268 NULL);
2269 if (rc)
2270 goto qic_exit;
2271 smb2_set_next_command(tcon, &rqst[1]);
2272 smb2_set_related(&rqst[1]);
2273
2274 memset(&close_iov, 0, sizeof(close_iov));
2275 rqst[2].rq_iov = close_iov;
2276 rqst[2].rq_nvec = 1;
2277
2278 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2279 if (rc)
2280 goto qic_exit;
2281 smb2_set_related(&rqst[2]);
2282
2283 rc = compound_send_recv(xid, ses, flags, 3, rqst,
2284 resp_buftype, rsp_iov);
2285 if (rc) {
2286 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2287 if (rc == -EREMCHG) {
2288 tcon->need_reconnect = true;
2289 printk_once(KERN_WARNING "server share %s deleted\n",
2290 tcon->treeName);
2291 }
2292 goto qic_exit;
2293 }
2294 *rsp = rsp_iov[1];
2295 *buftype = resp_buftype[1];
2296
2297 qic_exit:
2298 SMB2_open_free(&rqst[0]);
2299 SMB2_query_info_free(&rqst[1]);
2300 SMB2_close_free(&rqst[2]);
2301 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2302 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2303 return rc;
2304 }
2305
2306 static int
2307 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2308 struct kstatfs *buf)
2309 {
2310 struct smb2_query_info_rsp *rsp;
2311 struct smb2_fs_full_size_info *info = NULL;
2312 __le16 utf16_path = 0;
2313 struct kvec rsp_iov = {NULL, 0};
2314 int buftype = CIFS_NO_BUFFER;
2315 int rc;
2316
2317
2318 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2319 FILE_READ_ATTRIBUTES,
2320 FS_FULL_SIZE_INFORMATION,
2321 SMB2_O_INFO_FILESYSTEM,
2322 sizeof(struct smb2_fs_full_size_info),
2323 &rsp_iov, &buftype, NULL);
2324 if (rc)
2325 goto qfs_exit;
2326
2327 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2328 buf->f_type = SMB2_MAGIC_NUMBER;
2329 info = (struct smb2_fs_full_size_info *)(
2330 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2331 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2332 le32_to_cpu(rsp->OutputBufferLength),
2333 &rsp_iov,
2334 sizeof(struct smb2_fs_full_size_info));
2335 if (!rc)
2336 smb2_copy_fs_info_to_kstatfs(info, buf);
2337
2338 qfs_exit:
2339 free_rsp_buf(buftype, rsp_iov.iov_base);
2340 return rc;
2341 }
2342
2343 static int
2344 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2345 struct kstatfs *buf)
2346 {
2347 int rc;
2348 __le16 srch_path = 0;
2349 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2350 struct cifs_open_parms oparms;
2351 struct cifs_fid fid;
2352
2353 if (!tcon->posix_extensions)
2354 return smb2_queryfs(xid, tcon, buf);
2355
2356 oparms.tcon = tcon;
2357 oparms.desired_access = FILE_READ_ATTRIBUTES;
2358 oparms.disposition = FILE_OPEN;
2359 oparms.create_options = 0;
2360 oparms.fid = &fid;
2361 oparms.reconnect = false;
2362
2363 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2364 if (rc)
2365 return rc;
2366
2367 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2368 fid.volatile_fid, buf);
2369 buf->f_type = SMB2_MAGIC_NUMBER;
2370 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2371 return rc;
2372 }
2373
2374 static bool
2375 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2376 {
2377 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2378 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2379 }
2380
2381 static int
2382 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2383 __u64 length, __u32 type, int lock, int unlock, bool wait)
2384 {
2385 if (unlock && !lock)
2386 type = SMB2_LOCKFLAG_UNLOCK;
2387 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2388 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2389 current->tgid, length, offset, type, wait);
2390 }
2391
2392 static void
2393 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2394 {
2395 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2396 }
2397
2398 static void
2399 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2400 {
2401 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2402 }
2403
2404 static void
2405 smb2_new_lease_key(struct cifs_fid *fid)
2406 {
2407 generate_random_uuid(fid->lease_key);
2408 }
2409
2410 static int
2411 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2412 const char *search_name,
2413 struct dfs_info3_param **target_nodes,
2414 unsigned int *num_of_nodes,
2415 const struct nls_table *nls_codepage, int remap)
2416 {
2417 int rc;
2418 __le16 *utf16_path = NULL;
2419 int utf16_path_len = 0;
2420 struct cifs_tcon *tcon;
2421 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2422 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2423 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2424
2425 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2426
2427
2428
2429
2430 tcon = ses->tcon_ipc;
2431 if (tcon == NULL) {
2432 spin_lock(&cifs_tcp_ses_lock);
2433 tcon = list_first_entry_or_null(&ses->tcon_list,
2434 struct cifs_tcon,
2435 tcon_list);
2436 if (tcon)
2437 tcon->tc_count++;
2438 spin_unlock(&cifs_tcp_ses_lock);
2439 }
2440
2441 if (tcon == NULL) {
2442 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2443 ses);
2444 rc = -ENOTCONN;
2445 goto out;
2446 }
2447
2448 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2449 &utf16_path_len,
2450 nls_codepage, remap);
2451 if (!utf16_path) {
2452 rc = -ENOMEM;
2453 goto out;
2454 }
2455
2456 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2457 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2458 if (!dfs_req) {
2459 rc = -ENOMEM;
2460 goto out;
2461 }
2462
2463
2464 dfs_req->MaxReferralLevel = DFS_VERSION;
2465
2466
2467 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2468
2469 do {
2470 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2471 FSCTL_DFS_GET_REFERRALS,
2472 true ,
2473 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2474 (char **)&dfs_rsp, &dfs_rsp_size);
2475 } while (rc == -EAGAIN);
2476
2477 if (rc) {
2478 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2479 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2480 goto out;
2481 }
2482
2483 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2484 num_of_nodes, target_nodes,
2485 nls_codepage, remap, search_name,
2486 true );
2487 if (rc) {
2488 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2489 goto out;
2490 }
2491
2492 out:
2493 if (tcon && !tcon->ipc) {
2494
2495 spin_lock(&cifs_tcp_ses_lock);
2496 tcon->tc_count--;
2497 spin_unlock(&cifs_tcp_ses_lock);
2498 }
2499 kfree(utf16_path);
2500 kfree(dfs_req);
2501 kfree(dfs_rsp);
2502 return rc;
2503 }
2504
2505 static int
2506 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2507 u32 plen, char **target_path,
2508 struct cifs_sb_info *cifs_sb)
2509 {
2510 unsigned int len;
2511
2512
2513 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2514
2515 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2516 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2517 le64_to_cpu(symlink_buf->InodeType));
2518 return -EOPNOTSUPP;
2519 }
2520
2521 *target_path = cifs_strndup_from_utf16(
2522 symlink_buf->PathBuffer,
2523 len, true, cifs_sb->local_nls);
2524 if (!(*target_path))
2525 return -ENOMEM;
2526
2527 convert_delimiter(*target_path, '/');
2528 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2529
2530 return 0;
2531 }
2532
2533 static int
2534 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2535 u32 plen, char **target_path,
2536 struct cifs_sb_info *cifs_sb)
2537 {
2538 unsigned int sub_len;
2539 unsigned int sub_offset;
2540
2541
2542
2543 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2544 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2545 if (sub_offset + 20 > plen ||
2546 sub_offset + sub_len + 20 > plen) {
2547 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2548 return -EIO;
2549 }
2550
2551 *target_path = cifs_strndup_from_utf16(
2552 symlink_buf->PathBuffer + sub_offset,
2553 sub_len, true, cifs_sb->local_nls);
2554 if (!(*target_path))
2555 return -ENOMEM;
2556
2557 convert_delimiter(*target_path, '/');
2558 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2559
2560 return 0;
2561 }
2562
2563 static int
2564 parse_reparse_point(struct reparse_data_buffer *buf,
2565 u32 plen, char **target_path,
2566 struct cifs_sb_info *cifs_sb)
2567 {
2568 if (plen < sizeof(struct reparse_data_buffer)) {
2569 cifs_dbg(VFS, "reparse buffer is too small. Must be "
2570 "at least 8 bytes but was %d\n", plen);
2571 return -EIO;
2572 }
2573
2574 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2575 sizeof(struct reparse_data_buffer)) {
2576 cifs_dbg(VFS, "srv returned invalid reparse buf "
2577 "length: %d\n", plen);
2578 return -EIO;
2579 }
2580
2581
2582 switch (le32_to_cpu(buf->ReparseTag)) {
2583 case IO_REPARSE_TAG_NFS:
2584 return parse_reparse_posix(
2585 (struct reparse_posix_data *)buf,
2586 plen, target_path, cifs_sb);
2587 case IO_REPARSE_TAG_SYMLINK:
2588 return parse_reparse_symlink(
2589 (struct reparse_symlink_data_buffer *)buf,
2590 plen, target_path, cifs_sb);
2591 default:
2592 cifs_dbg(VFS, "srv returned unknown symlink buffer "
2593 "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag));
2594 return -EOPNOTSUPP;
2595 }
2596 }
2597
2598 #define SMB2_SYMLINK_STRUCT_SIZE \
2599 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2600
2601 static int
2602 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2603 struct cifs_sb_info *cifs_sb, const char *full_path,
2604 char **target_path, bool is_reparse_point)
2605 {
2606 int rc;
2607 __le16 *utf16_path = NULL;
2608 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2609 struct cifs_open_parms oparms;
2610 struct cifs_fid fid;
2611 struct kvec err_iov = {NULL, 0};
2612 struct smb2_err_rsp *err_buf = NULL;
2613 struct smb2_symlink_err_rsp *symlink;
2614 unsigned int sub_len;
2615 unsigned int sub_offset;
2616 unsigned int print_len;
2617 unsigned int print_offset;
2618 int flags = 0;
2619 struct smb_rqst rqst[3];
2620 int resp_buftype[3];
2621 struct kvec rsp_iov[3];
2622 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2623 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2624 struct kvec close_iov[1];
2625 struct smb2_create_rsp *create_rsp;
2626 struct smb2_ioctl_rsp *ioctl_rsp;
2627 struct reparse_data_buffer *reparse_buf;
2628 u32 plen;
2629
2630 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2631
2632 *target_path = NULL;
2633
2634 if (smb3_encryption_required(tcon))
2635 flags |= CIFS_TRANSFORM_REQ;
2636
2637 memset(rqst, 0, sizeof(rqst));
2638 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2639 memset(rsp_iov, 0, sizeof(rsp_iov));
2640
2641 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2642 if (!utf16_path)
2643 return -ENOMEM;
2644
2645
2646 memset(&open_iov, 0, sizeof(open_iov));
2647 rqst[0].rq_iov = open_iov;
2648 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2649
2650 memset(&oparms, 0, sizeof(oparms));
2651 oparms.tcon = tcon;
2652 oparms.desired_access = FILE_READ_ATTRIBUTES;
2653 oparms.disposition = FILE_OPEN;
2654
2655 if (backup_cred(cifs_sb))
2656 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2657 else
2658 oparms.create_options = 0;
2659 if (is_reparse_point)
2660 oparms.create_options = OPEN_REPARSE_POINT;
2661
2662 oparms.fid = &fid;
2663 oparms.reconnect = false;
2664
2665 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2666 if (rc)
2667 goto querty_exit;
2668 smb2_set_next_command(tcon, &rqst[0]);
2669
2670
2671
2672 memset(&io_iov, 0, sizeof(io_iov));
2673 rqst[1].rq_iov = io_iov;
2674 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2675
2676 rc = SMB2_ioctl_init(tcon, &rqst[1], fid.persistent_fid,
2677 fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
2678 true , NULL, 0,
2679 CIFSMaxBufSize -
2680 MAX_SMB2_CREATE_RESPONSE_SIZE -
2681 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2682 if (rc)
2683 goto querty_exit;
2684
2685 smb2_set_next_command(tcon, &rqst[1]);
2686 smb2_set_related(&rqst[1]);
2687
2688
2689
2690 memset(&close_iov, 0, sizeof(close_iov));
2691 rqst[2].rq_iov = close_iov;
2692 rqst[2].rq_nvec = 1;
2693
2694 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2695 if (rc)
2696 goto querty_exit;
2697
2698 smb2_set_related(&rqst[2]);
2699
2700 rc = compound_send_recv(xid, tcon->ses, flags, 3, rqst,
2701 resp_buftype, rsp_iov);
2702
2703 create_rsp = rsp_iov[0].iov_base;
2704 if (create_rsp && create_rsp->sync_hdr.Status)
2705 err_iov = rsp_iov[0];
2706 ioctl_rsp = rsp_iov[1].iov_base;
2707
2708
2709
2710
2711 if ((rc == 0) && (is_reparse_point)) {
2712
2713
2714 reparse_buf = (struct reparse_data_buffer *)
2715 ((char *)ioctl_rsp +
2716 le32_to_cpu(ioctl_rsp->OutputOffset));
2717 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2718
2719 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2720 rsp_iov[1].iov_len) {
2721 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2722 plen);
2723 rc = -EIO;
2724 goto querty_exit;
2725 }
2726
2727 rc = parse_reparse_point(reparse_buf, plen, target_path,
2728 cifs_sb);
2729 goto querty_exit;
2730 }
2731
2732 if (!rc || !err_iov.iov_base) {
2733 rc = -ENOENT;
2734 goto querty_exit;
2735 }
2736
2737 err_buf = err_iov.iov_base;
2738 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2739 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2740 rc = -EINVAL;
2741 goto querty_exit;
2742 }
2743
2744 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2745 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
2746 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
2747 rc = -EINVAL;
2748 goto querty_exit;
2749 }
2750
2751
2752 rc = 0;
2753 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2754 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2755 print_len = le16_to_cpu(symlink->PrintNameLength);
2756 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2757
2758 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2759 rc = -EINVAL;
2760 goto querty_exit;
2761 }
2762
2763 if (err_iov.iov_len <
2764 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2765 rc = -EINVAL;
2766 goto querty_exit;
2767 }
2768
2769 *target_path = cifs_strndup_from_utf16(
2770 (char *)symlink->PathBuffer + sub_offset,
2771 sub_len, true, cifs_sb->local_nls);
2772 if (!(*target_path)) {
2773 rc = -ENOMEM;
2774 goto querty_exit;
2775 }
2776 convert_delimiter(*target_path, '/');
2777 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2778
2779 querty_exit:
2780 cifs_dbg(FYI, "query symlink rc %d\n", rc);
2781 kfree(utf16_path);
2782 SMB2_open_free(&rqst[0]);
2783 SMB2_ioctl_free(&rqst[1]);
2784 SMB2_close_free(&rqst[2]);
2785 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2786 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2787 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2788 return rc;
2789 }
2790
2791 static struct cifs_ntsd *
2792 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
2793 const struct cifs_fid *cifsfid, u32 *pacllen)
2794 {
2795 struct cifs_ntsd *pntsd = NULL;
2796 unsigned int xid;
2797 int rc = -EOPNOTSUPP;
2798 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2799
2800 if (IS_ERR(tlink))
2801 return ERR_CAST(tlink);
2802
2803 xid = get_xid();
2804 cifs_dbg(FYI, "trying to get acl\n");
2805
2806 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
2807 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
2808 free_xid(xid);
2809
2810 cifs_put_tlink(tlink);
2811
2812 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2813 if (rc)
2814 return ERR_PTR(rc);
2815 return pntsd;
2816
2817 }
2818
2819 static struct cifs_ntsd *
2820 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
2821 const char *path, u32 *pacllen)
2822 {
2823 struct cifs_ntsd *pntsd = NULL;
2824 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2825 unsigned int xid;
2826 int rc;
2827 struct cifs_tcon *tcon;
2828 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2829 struct cifs_fid fid;
2830 struct cifs_open_parms oparms;
2831 __le16 *utf16_path;
2832
2833 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
2834 if (IS_ERR(tlink))
2835 return ERR_CAST(tlink);
2836
2837 tcon = tlink_tcon(tlink);
2838 xid = get_xid();
2839
2840 if (backup_cred(cifs_sb))
2841 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2842 else
2843 oparms.create_options = 0;
2844
2845 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2846 if (!utf16_path) {
2847 rc = -ENOMEM;
2848 free_xid(xid);
2849 return ERR_PTR(rc);
2850 }
2851
2852 oparms.tcon = tcon;
2853 oparms.desired_access = READ_CONTROL;
2854 oparms.disposition = FILE_OPEN;
2855 oparms.fid = &fid;
2856 oparms.reconnect = false;
2857
2858 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2859 kfree(utf16_path);
2860 if (!rc) {
2861 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2862 fid.volatile_fid, (void **)&pntsd, pacllen);
2863 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2864 }
2865
2866 cifs_put_tlink(tlink);
2867 free_xid(xid);
2868
2869 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2870 if (rc)
2871 return ERR_PTR(rc);
2872 return pntsd;
2873 }
2874
2875 static int
2876 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2877 struct inode *inode, const char *path, int aclflag)
2878 {
2879 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2880 unsigned int xid;
2881 int rc, access_flags = 0;
2882 struct cifs_tcon *tcon;
2883 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2884 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2885 struct cifs_fid fid;
2886 struct cifs_open_parms oparms;
2887 __le16 *utf16_path;
2888
2889 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2890 if (IS_ERR(tlink))
2891 return PTR_ERR(tlink);
2892
2893 tcon = tlink_tcon(tlink);
2894 xid = get_xid();
2895
2896 if (backup_cred(cifs_sb))
2897 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2898 else
2899 oparms.create_options = 0;
2900
2901 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2902 access_flags = WRITE_OWNER;
2903 else
2904 access_flags = WRITE_DAC;
2905
2906 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2907 if (!utf16_path) {
2908 rc = -ENOMEM;
2909 free_xid(xid);
2910 return rc;
2911 }
2912
2913 oparms.tcon = tcon;
2914 oparms.desired_access = access_flags;
2915 oparms.disposition = FILE_OPEN;
2916 oparms.path = path;
2917 oparms.fid = &fid;
2918 oparms.reconnect = false;
2919
2920 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2921 kfree(utf16_path);
2922 if (!rc) {
2923 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2924 fid.volatile_fid, pnntsd, acllen, aclflag);
2925 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2926 }
2927
2928 cifs_put_tlink(tlink);
2929 free_xid(xid);
2930 return rc;
2931 }
2932
2933
2934 static struct cifs_ntsd *
2935 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2936 struct inode *inode, const char *path,
2937 u32 *pacllen)
2938 {
2939 struct cifs_ntsd *pntsd = NULL;
2940 struct cifsFileInfo *open_file = NULL;
2941
2942 if (inode)
2943 open_file = find_readable_file(CIFS_I(inode), true);
2944 if (!open_file)
2945 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2946
2947 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2948 cifsFileInfo_put(open_file);
2949 return pntsd;
2950 }
2951
2952 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2953 loff_t offset, loff_t len, bool keep_size)
2954 {
2955 struct cifs_ses *ses = tcon->ses;
2956 struct inode *inode;
2957 struct cifsInodeInfo *cifsi;
2958 struct cifsFileInfo *cfile = file->private_data;
2959 struct file_zero_data_information fsctl_buf;
2960 long rc;
2961 unsigned int xid;
2962 __le64 eof;
2963
2964 xid = get_xid();
2965
2966 inode = d_inode(cfile->dentry);
2967 cifsi = CIFS_I(inode);
2968
2969 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2970 ses->Suid, offset, len);
2971
2972
2973
2974 if (!CIFS_CACHE_READ(cifsi))
2975 if (keep_size == false) {
2976 rc = -EOPNOTSUPP;
2977 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
2978 tcon->tid, ses->Suid, offset, len, rc);
2979 free_xid(xid);
2980 return rc;
2981 }
2982
2983 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
2984
2985 fsctl_buf.FileOffset = cpu_to_le64(offset);
2986 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2987
2988 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2989 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true,
2990 (char *)&fsctl_buf,
2991 sizeof(struct file_zero_data_information),
2992 0, NULL, NULL);
2993 if (rc)
2994 goto zero_range_exit;
2995
2996
2997
2998
2999 if (keep_size == false && i_size_read(inode) < offset + len) {
3000 eof = cpu_to_le64(offset + len);
3001 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3002 cfile->fid.volatile_fid, cfile->pid, &eof);
3003 }
3004
3005 zero_range_exit:
3006 free_xid(xid);
3007 if (rc)
3008 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3009 ses->Suid, offset, len, rc);
3010 else
3011 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3012 ses->Suid, offset, len);
3013 return rc;
3014 }
3015
3016 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3017 loff_t offset, loff_t len)
3018 {
3019 struct inode *inode;
3020 struct cifsFileInfo *cfile = file->private_data;
3021 struct file_zero_data_information fsctl_buf;
3022 long rc;
3023 unsigned int xid;
3024 __u8 set_sparse = 1;
3025
3026 xid = get_xid();
3027
3028 inode = d_inode(cfile->dentry);
3029
3030
3031
3032 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3033 rc = -EOPNOTSUPP;
3034 free_xid(xid);
3035 return rc;
3036 }
3037
3038 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3039
3040 fsctl_buf.FileOffset = cpu_to_le64(offset);
3041 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3042
3043 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3044 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3045 true , (char *)&fsctl_buf,
3046 sizeof(struct file_zero_data_information),
3047 CIFSMaxBufSize, NULL, NULL);
3048 free_xid(xid);
3049 return rc;
3050 }
3051
3052 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3053 loff_t off, loff_t len, bool keep_size)
3054 {
3055 struct inode *inode;
3056 struct cifsInodeInfo *cifsi;
3057 struct cifsFileInfo *cfile = file->private_data;
3058 long rc = -EOPNOTSUPP;
3059 unsigned int xid;
3060 __le64 eof;
3061
3062 xid = get_xid();
3063
3064 inode = d_inode(cfile->dentry);
3065 cifsi = CIFS_I(inode);
3066
3067 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3068 tcon->ses->Suid, off, len);
3069
3070 if (!CIFS_CACHE_READ(cifsi))
3071 if (keep_size == false) {
3072 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3073 tcon->tid, tcon->ses->Suid, off, len, rc);
3074 free_xid(xid);
3075 return rc;
3076 }
3077
3078
3079
3080
3081
3082
3083 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3084 if (keep_size == true)
3085 rc = 0;
3086
3087 else if (i_size_read(inode) >= off + len)
3088
3089 rc = 0;
3090
3091 else
3092 rc = -EOPNOTSUPP;
3093 if (rc)
3094 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3095 tcon->tid, tcon->ses->Suid, off, len, rc);
3096 else
3097 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid,
3098 tcon->tid, tcon->ses->Suid, off, len);
3099 free_xid(xid);
3100 return rc;
3101 }
3102
3103 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3104
3105
3106
3107
3108
3109
3110
3111
3112 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3113 rc = -EOPNOTSUPP;
3114 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3115 tcon->tid, tcon->ses->Suid, off, len, rc);
3116 free_xid(xid);
3117 return rc;
3118 }
3119
3120 smb2_set_sparse(xid, tcon, cfile, inode, false);
3121 rc = 0;
3122 } else {
3123 smb2_set_sparse(xid, tcon, cfile, inode, false);
3124 rc = 0;
3125 if (i_size_read(inode) < off + len) {
3126 eof = cpu_to_le64(off + len);
3127 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3128 cfile->fid.volatile_fid, cfile->pid,
3129 &eof);
3130 }
3131 }
3132
3133 if (rc)
3134 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3135 tcon->ses->Suid, off, len, rc);
3136 else
3137 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3138 tcon->ses->Suid, off, len);
3139
3140 free_xid(xid);
3141 return rc;
3142 }
3143
3144 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3145 {
3146 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3147 struct cifsInodeInfo *cifsi;
3148 struct inode *inode;
3149 int rc = 0;
3150 struct file_allocated_range_buffer in_data, *out_data = NULL;
3151 u32 out_data_len;
3152 unsigned int xid;
3153
3154 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3155 return generic_file_llseek(file, offset, whence);
3156
3157 inode = d_inode(cfile->dentry);
3158 cifsi = CIFS_I(inode);
3159
3160 if (offset < 0 || offset >= i_size_read(inode))
3161 return -ENXIO;
3162
3163 xid = get_xid();
3164
3165
3166
3167
3168
3169
3170
3171 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3172 if (wrcfile) {
3173 filemap_write_and_wait(inode->i_mapping);
3174 smb2_flush_file(xid, tcon, &wrcfile->fid);
3175 cifsFileInfo_put(wrcfile);
3176 }
3177
3178 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3179 if (whence == SEEK_HOLE)
3180 offset = i_size_read(inode);
3181 goto lseek_exit;
3182 }
3183
3184 in_data.file_offset = cpu_to_le64(offset);
3185 in_data.length = cpu_to_le64(i_size_read(inode));
3186
3187 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3188 cfile->fid.volatile_fid,
3189 FSCTL_QUERY_ALLOCATED_RANGES, true,
3190 (char *)&in_data, sizeof(in_data),
3191 sizeof(struct file_allocated_range_buffer),
3192 (char **)&out_data, &out_data_len);
3193 if (rc == -E2BIG)
3194 rc = 0;
3195 if (rc)
3196 goto lseek_exit;
3197
3198 if (whence == SEEK_HOLE && out_data_len == 0)
3199 goto lseek_exit;
3200
3201 if (whence == SEEK_DATA && out_data_len == 0) {
3202 rc = -ENXIO;
3203 goto lseek_exit;
3204 }
3205
3206 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3207 rc = -EINVAL;
3208 goto lseek_exit;
3209 }
3210 if (whence == SEEK_DATA) {
3211 offset = le64_to_cpu(out_data->file_offset);
3212 goto lseek_exit;
3213 }
3214 if (offset < le64_to_cpu(out_data->file_offset))
3215 goto lseek_exit;
3216
3217 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3218
3219 lseek_exit:
3220 free_xid(xid);
3221 kfree(out_data);
3222 if (!rc)
3223 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3224 else
3225 return rc;
3226 }
3227
3228 static int smb3_fiemap(struct cifs_tcon *tcon,
3229 struct cifsFileInfo *cfile,
3230 struct fiemap_extent_info *fei, u64 start, u64 len)
3231 {
3232 unsigned int xid;
3233 struct file_allocated_range_buffer in_data, *out_data;
3234 u32 out_data_len;
3235 int i, num, rc, flags, last_blob;
3236 u64 next;
3237
3238 if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC))
3239 return -EBADR;
3240
3241 xid = get_xid();
3242 again:
3243 in_data.file_offset = cpu_to_le64(start);
3244 in_data.length = cpu_to_le64(len);
3245
3246 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3247 cfile->fid.volatile_fid,
3248 FSCTL_QUERY_ALLOCATED_RANGES, true,
3249 (char *)&in_data, sizeof(in_data),
3250 1024 * sizeof(struct file_allocated_range_buffer),
3251 (char **)&out_data, &out_data_len);
3252 if (rc == -E2BIG) {
3253 last_blob = 0;
3254 rc = 0;
3255 } else
3256 last_blob = 1;
3257 if (rc)
3258 goto out;
3259
3260 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3261 rc = -EINVAL;
3262 goto out;
3263 }
3264 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3265 rc = -EINVAL;
3266 goto out;
3267 }
3268
3269 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3270 for (i = 0; i < num; i++) {
3271 flags = 0;
3272 if (i == num - 1 && last_blob)
3273 flags |= FIEMAP_EXTENT_LAST;
3274
3275 rc = fiemap_fill_next_extent(fei,
3276 le64_to_cpu(out_data[i].file_offset),
3277 le64_to_cpu(out_data[i].file_offset),
3278 le64_to_cpu(out_data[i].length),
3279 flags);
3280 if (rc < 0)
3281 goto out;
3282 if (rc == 1) {
3283 rc = 0;
3284 goto out;
3285 }
3286 }
3287
3288 if (!last_blob) {
3289 next = le64_to_cpu(out_data[num - 1].file_offset) +
3290 le64_to_cpu(out_data[num - 1].length);
3291 len = len - (next - start);
3292 start = next;
3293 goto again;
3294 }
3295
3296 out:
3297 free_xid(xid);
3298 kfree(out_data);
3299 return rc;
3300 }
3301
3302 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3303 loff_t off, loff_t len)
3304 {
3305
3306 if (mode & FALLOC_FL_PUNCH_HOLE)
3307 return smb3_punch_hole(file, tcon, off, len);
3308 else if (mode & FALLOC_FL_ZERO_RANGE) {
3309 if (mode & FALLOC_FL_KEEP_SIZE)
3310 return smb3_zero_range(file, tcon, off, len, true);
3311 return smb3_zero_range(file, tcon, off, len, false);
3312 } else if (mode == FALLOC_FL_KEEP_SIZE)
3313 return smb3_simple_falloc(file, tcon, off, len, true);
3314 else if (mode == 0)
3315 return smb3_simple_falloc(file, tcon, off, len, false);
3316
3317 return -EOPNOTSUPP;
3318 }
3319
3320 static void
3321 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3322 struct cifsInodeInfo *cinode, bool set_level2)
3323 {
3324 if (set_level2)
3325 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
3326 0, NULL);
3327 else
3328 server->ops->set_oplock_level(cinode, 0, 0, NULL);
3329 }
3330
3331 static void
3332 smb21_downgrade_oplock(struct TCP_Server_Info *server,
3333 struct cifsInodeInfo *cinode, bool set_level2)
3334 {
3335 server->ops->set_oplock_level(cinode,
3336 set_level2 ? SMB2_LEASE_READ_CACHING_HE :
3337 0, 0, NULL);
3338 }
3339
3340 static void
3341 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3342 unsigned int epoch, bool *purge_cache)
3343 {
3344 oplock &= 0xFF;
3345 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3346 return;
3347 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3348 cinode->oplock = CIFS_CACHE_RHW_FLG;
3349 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3350 &cinode->vfs_inode);
3351 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3352 cinode->oplock = CIFS_CACHE_RW_FLG;
3353 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3354 &cinode->vfs_inode);
3355 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3356 cinode->oplock = CIFS_CACHE_READ_FLG;
3357 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3358 &cinode->vfs_inode);
3359 } else
3360 cinode->oplock = 0;
3361 }
3362
3363 static void
3364 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3365 unsigned int epoch, bool *purge_cache)
3366 {
3367 char message[5] = {0};
3368 unsigned int new_oplock = 0;
3369
3370 oplock &= 0xFF;
3371 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3372 return;
3373
3374
3375 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3376 return smb2_set_oplock_level(cinode, oplock, epoch,
3377 purge_cache);
3378
3379 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3380 new_oplock |= CIFS_CACHE_READ_FLG;
3381 strcat(message, "R");
3382 }
3383 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3384 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3385 strcat(message, "H");
3386 }
3387 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3388 new_oplock |= CIFS_CACHE_WRITE_FLG;
3389 strcat(message, "W");
3390 }
3391 if (!new_oplock)
3392 strncpy(message, "None", sizeof(message));
3393
3394 cinode->oplock = new_oplock;
3395 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3396 &cinode->vfs_inode);
3397 }
3398
3399 static void
3400 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3401 unsigned int epoch, bool *purge_cache)
3402 {
3403 unsigned int old_oplock = cinode->oplock;
3404
3405 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
3406
3407 if (purge_cache) {
3408 *purge_cache = false;
3409 if (old_oplock == CIFS_CACHE_READ_FLG) {
3410 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
3411 (epoch - cinode->epoch > 0))
3412 *purge_cache = true;
3413 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3414 (epoch - cinode->epoch > 1))
3415 *purge_cache = true;
3416 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3417 (epoch - cinode->epoch > 1))
3418 *purge_cache = true;
3419 else if (cinode->oplock == 0 &&
3420 (epoch - cinode->epoch > 0))
3421 *purge_cache = true;
3422 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
3423 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3424 (epoch - cinode->epoch > 0))
3425 *purge_cache = true;
3426 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3427 (epoch - cinode->epoch > 1))
3428 *purge_cache = true;
3429 }
3430 cinode->epoch = epoch;
3431 }
3432 }
3433
3434 static bool
3435 smb2_is_read_op(__u32 oplock)
3436 {
3437 return oplock == SMB2_OPLOCK_LEVEL_II;
3438 }
3439
3440 static bool
3441 smb21_is_read_op(__u32 oplock)
3442 {
3443 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
3444 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
3445 }
3446
3447 static __le32
3448 map_oplock_to_lease(u8 oplock)
3449 {
3450 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3451 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
3452 else if (oplock == SMB2_OPLOCK_LEVEL_II)
3453 return SMB2_LEASE_READ_CACHING;
3454 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
3455 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
3456 SMB2_LEASE_WRITE_CACHING;
3457 return 0;
3458 }
3459
3460 static char *
3461 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
3462 {
3463 struct create_lease *buf;
3464
3465 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
3466 if (!buf)
3467 return NULL;
3468
3469 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3470 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3471
3472 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3473 (struct create_lease, lcontext));
3474 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
3475 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3476 (struct create_lease, Name));
3477 buf->ccontext.NameLength = cpu_to_le16(4);
3478
3479 buf->Name[0] = 'R';
3480 buf->Name[1] = 'q';
3481 buf->Name[2] = 'L';
3482 buf->Name[3] = 's';
3483 return (char *)buf;
3484 }
3485
3486 static char *
3487 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
3488 {
3489 struct create_lease_v2 *buf;
3490
3491 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
3492 if (!buf)
3493 return NULL;
3494
3495 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3496 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3497
3498 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3499 (struct create_lease_v2, lcontext));
3500 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
3501 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3502 (struct create_lease_v2, Name));
3503 buf->ccontext.NameLength = cpu_to_le16(4);
3504
3505 buf->Name[0] = 'R';
3506 buf->Name[1] = 'q';
3507 buf->Name[2] = 'L';
3508 buf->Name[3] = 's';
3509 return (char *)buf;
3510 }
3511
3512 static __u8
3513 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3514 {
3515 struct create_lease *lc = (struct create_lease *)buf;
3516
3517 *epoch = 0;
3518 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3519 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3520 return le32_to_cpu(lc->lcontext.LeaseState);
3521 }
3522
3523 static __u8
3524 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3525 {
3526 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
3527
3528 *epoch = le16_to_cpu(lc->lcontext.Epoch);
3529 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3530 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3531 if (lease_key)
3532 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
3533 return le32_to_cpu(lc->lcontext.LeaseState);
3534 }
3535
3536 static unsigned int
3537 smb2_wp_retry_size(struct inode *inode)
3538 {
3539 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
3540 SMB2_MAX_BUFFER_SIZE);
3541 }
3542
3543 static bool
3544 smb2_dir_needs_close(struct cifsFileInfo *cfile)
3545 {
3546 return !cfile->invalidHandle;
3547 }
3548
3549 static void
3550 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
3551 struct smb_rqst *old_rq, __le16 cipher_type)
3552 {
3553 struct smb2_sync_hdr *shdr =
3554 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
3555
3556 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
3557 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
3558 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
3559 tr_hdr->Flags = cpu_to_le16(0x01);
3560 if (cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3561 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3562 else
3563 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3564 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
3565 }
3566
3567
3568
3569
3570 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
3571 unsigned int buflen)
3572 {
3573 void *addr;
3574
3575
3576
3577 if (is_vmalloc_addr(buf))
3578 addr = vmalloc_to_page(buf);
3579 else
3580 addr = virt_to_page(buf);
3581 sg_set_page(sg, addr, buflen, offset_in_page(buf));
3582 }
3583
3584
3585
3586
3587
3588
3589
3590 static struct scatterlist *
3591 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
3592 {
3593 unsigned int sg_len;
3594 struct scatterlist *sg;
3595 unsigned int i;
3596 unsigned int j;
3597 unsigned int idx = 0;
3598 int skip;
3599
3600 sg_len = 1;
3601 for (i = 0; i < num_rqst; i++)
3602 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
3603
3604 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
3605 if (!sg)
3606 return NULL;
3607
3608 sg_init_table(sg, sg_len);
3609 for (i = 0; i < num_rqst; i++) {
3610 for (j = 0; j < rqst[i].rq_nvec; j++) {
3611
3612
3613
3614
3615 skip = (i == 0) && (j == 0) ? 20 : 0;
3616 smb2_sg_set_buf(&sg[idx++],
3617 rqst[i].rq_iov[j].iov_base + skip,
3618 rqst[i].rq_iov[j].iov_len - skip);
3619 }
3620
3621 for (j = 0; j < rqst[i].rq_npages; j++) {
3622 unsigned int len, offset;
3623
3624 rqst_page_get_length(&rqst[i], j, &len, &offset);
3625 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
3626 }
3627 }
3628 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
3629 return sg;
3630 }
3631
3632 static int
3633 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
3634 {
3635 struct cifs_ses *ses;
3636 u8 *ses_enc_key;
3637
3638 spin_lock(&cifs_tcp_ses_lock);
3639 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
3640 if (ses->Suid != ses_id)
3641 continue;
3642 ses_enc_key = enc ? ses->smb3encryptionkey :
3643 ses->smb3decryptionkey;
3644 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
3645 spin_unlock(&cifs_tcp_ses_lock);
3646 return 0;
3647 }
3648 spin_unlock(&cifs_tcp_ses_lock);
3649
3650 return 1;
3651 }
3652
3653
3654
3655
3656
3657
3658
3659 static int
3660 crypt_message(struct TCP_Server_Info *server, int num_rqst,
3661 struct smb_rqst *rqst, int enc)
3662 {
3663 struct smb2_transform_hdr *tr_hdr =
3664 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
3665 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
3666 int rc = 0;
3667 struct scatterlist *sg;
3668 u8 sign[SMB2_SIGNATURE_SIZE] = {};
3669 u8 key[SMB3_SIGN_KEY_SIZE];
3670 struct aead_request *req;
3671 char *iv;
3672 unsigned int iv_len;
3673 DECLARE_CRYPTO_WAIT(wait);
3674 struct crypto_aead *tfm;
3675 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3676
3677 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
3678 if (rc) {
3679 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
3680 enc ? "en" : "de");
3681 return 0;
3682 }
3683
3684 rc = smb3_crypto_aead_allocate(server);
3685 if (rc) {
3686 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
3687 return rc;
3688 }
3689
3690 tfm = enc ? server->secmech.ccmaesencrypt :
3691 server->secmech.ccmaesdecrypt;
3692 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
3693 if (rc) {
3694 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
3695 return rc;
3696 }
3697
3698 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
3699 if (rc) {
3700 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
3701 return rc;
3702 }
3703
3704 req = aead_request_alloc(tfm, GFP_KERNEL);
3705 if (!req) {
3706 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
3707 return -ENOMEM;
3708 }
3709
3710 if (!enc) {
3711 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
3712 crypt_len += SMB2_SIGNATURE_SIZE;
3713 }
3714
3715 sg = init_sg(num_rqst, rqst, sign);
3716 if (!sg) {
3717 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
3718 rc = -ENOMEM;
3719 goto free_req;
3720 }
3721
3722 iv_len = crypto_aead_ivsize(tfm);
3723 iv = kzalloc(iv_len, GFP_KERNEL);
3724 if (!iv) {
3725 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
3726 rc = -ENOMEM;
3727 goto free_sg;
3728 }
3729
3730 if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3731 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3732 else {
3733 iv[0] = 3;
3734 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3735 }
3736
3737 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
3738 aead_request_set_ad(req, assoc_data_len);
3739
3740 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3741 crypto_req_done, &wait);
3742
3743 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
3744 : crypto_aead_decrypt(req), &wait);
3745
3746 if (!rc && enc)
3747 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
3748
3749 kfree(iv);
3750 free_sg:
3751 kfree(sg);
3752 free_req:
3753 kfree(req);
3754 return rc;
3755 }
3756
3757 void
3758 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
3759 {
3760 int i, j;
3761
3762 for (i = 0; i < num_rqst; i++) {
3763 if (rqst[i].rq_pages) {
3764 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
3765 put_page(rqst[i].rq_pages[j]);
3766 kfree(rqst[i].rq_pages);
3767 }
3768 }
3769 }
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784 static int
3785 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
3786 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
3787 {
3788 struct page **pages;
3789 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
3790 unsigned int npages;
3791 unsigned int orig_len = 0;
3792 int i, j;
3793 int rc = -ENOMEM;
3794
3795 for (i = 1; i < num_rqst; i++) {
3796 npages = old_rq[i - 1].rq_npages;
3797 pages = kmalloc_array(npages, sizeof(struct page *),
3798 GFP_KERNEL);
3799 if (!pages)
3800 goto err_free;
3801
3802 new_rq[i].rq_pages = pages;
3803 new_rq[i].rq_npages = npages;
3804 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
3805 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
3806 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
3807 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
3808 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
3809
3810 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
3811
3812 for (j = 0; j < npages; j++) {
3813 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3814 if (!pages[j])
3815 goto err_free;
3816 }
3817
3818
3819 for (j = 0; j < npages; j++) {
3820 char *dst, *src;
3821 unsigned int offset, len;
3822
3823 rqst_page_get_length(&new_rq[i], j, &len, &offset);
3824
3825 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
3826 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
3827
3828 memcpy(dst, src, len);
3829 kunmap(new_rq[i].rq_pages[j]);
3830 kunmap(old_rq[i - 1].rq_pages[j]);
3831 }
3832 }
3833
3834
3835 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
3836
3837 rc = crypt_message(server, num_rqst, new_rq, 1);
3838 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
3839 if (rc)
3840 goto err_free;
3841
3842 return rc;
3843
3844 err_free:
3845 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
3846 return rc;
3847 }
3848
3849 static int
3850 smb3_is_transform_hdr(void *buf)
3851 {
3852 struct smb2_transform_hdr *trhdr = buf;
3853
3854 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
3855 }
3856
3857 static int
3858 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
3859 unsigned int buf_data_size, struct page **pages,
3860 unsigned int npages, unsigned int page_data_size)
3861 {
3862 struct kvec iov[2];
3863 struct smb_rqst rqst = {NULL};
3864 int rc;
3865
3866 iov[0].iov_base = buf;
3867 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
3868 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
3869 iov[1].iov_len = buf_data_size;
3870
3871 rqst.rq_iov = iov;
3872 rqst.rq_nvec = 2;
3873 rqst.rq_pages = pages;
3874 rqst.rq_npages = npages;
3875 rqst.rq_pagesz = PAGE_SIZE;
3876 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
3877
3878 rc = crypt_message(server, 1, &rqst, 0);
3879 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
3880
3881 if (rc)
3882 return rc;
3883
3884 memmove(buf, iov[1].iov_base, buf_data_size);
3885
3886 server->total_read = buf_data_size + page_data_size;
3887
3888 return rc;
3889 }
3890
3891 static int
3892 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
3893 unsigned int npages, unsigned int len)
3894 {
3895 int i;
3896 int length;
3897
3898 for (i = 0; i < npages; i++) {
3899 struct page *page = pages[i];
3900 size_t n;
3901
3902 n = len;
3903 if (len >= PAGE_SIZE) {
3904
3905 n = PAGE_SIZE;
3906 len -= n;
3907 } else {
3908 zero_user(page, len, PAGE_SIZE - len);
3909 len = 0;
3910 }
3911 length = cifs_read_page_from_socket(server, page, 0, n);
3912 if (length < 0)
3913 return length;
3914 server->total_read += length;
3915 }
3916
3917 return 0;
3918 }
3919
3920 static int
3921 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
3922 unsigned int cur_off, struct bio_vec **page_vec)
3923 {
3924 struct bio_vec *bvec;
3925 int i;
3926
3927 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
3928 if (!bvec)
3929 return -ENOMEM;
3930
3931 for (i = 0; i < npages; i++) {
3932 bvec[i].bv_page = pages[i];
3933 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
3934 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
3935 data_size -= bvec[i].bv_len;
3936 }
3937
3938 if (data_size != 0) {
3939 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
3940 kfree(bvec);
3941 return -EIO;
3942 }
3943
3944 *page_vec = bvec;
3945 return 0;
3946 }
3947
3948 static int
3949 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
3950 char *buf, unsigned int buf_len, struct page **pages,
3951 unsigned int npages, unsigned int page_data_size)
3952 {
3953 unsigned int data_offset;
3954 unsigned int data_len;
3955 unsigned int cur_off;
3956 unsigned int cur_page_idx;
3957 unsigned int pad_len;
3958 struct cifs_readdata *rdata = mid->callback_data;
3959 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
3960 struct bio_vec *bvec = NULL;
3961 struct iov_iter iter;
3962 struct kvec iov;
3963 int length;
3964 bool use_rdma_mr = false;
3965
3966 if (shdr->Command != SMB2_READ) {
3967 cifs_server_dbg(VFS, "only big read responses are supported\n");
3968 return -ENOTSUPP;
3969 }
3970
3971 if (server->ops->is_session_expired &&
3972 server->ops->is_session_expired(buf)) {
3973 cifs_reconnect(server);
3974 wake_up(&server->response_q);
3975 return -1;
3976 }
3977
3978 if (server->ops->is_status_pending &&
3979 server->ops->is_status_pending(buf, server))
3980 return -1;
3981
3982
3983 rdata->iov[0].iov_base = buf;
3984 rdata->iov[0].iov_len = 0;
3985 rdata->iov[1].iov_base = buf;
3986 rdata->iov[1].iov_len =
3987 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
3988 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
3989 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
3990 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
3991 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
3992
3993 rdata->result = server->ops->map_error(buf, true);
3994 if (rdata->result != 0) {
3995 cifs_dbg(FYI, "%s: server returned error %d\n",
3996 __func__, rdata->result);
3997
3998 dequeue_mid(mid, false);
3999 return 0;
4000 }
4001
4002 data_offset = server->ops->read_data_offset(buf);
4003 #ifdef CONFIG_CIFS_SMB_DIRECT
4004 use_rdma_mr = rdata->mr;
4005 #endif
4006 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4007
4008 if (data_offset < server->vals->read_rsp_size) {
4009
4010
4011
4012
4013
4014 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4015 __func__, data_offset);
4016 data_offset = server->vals->read_rsp_size;
4017 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4018
4019 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4020 __func__, data_offset);
4021 rdata->result = -EIO;
4022 dequeue_mid(mid, rdata->result);
4023 return 0;
4024 }
4025
4026 pad_len = data_offset - server->vals->read_rsp_size;
4027
4028 if (buf_len <= data_offset) {
4029
4030 cur_page_idx = pad_len / PAGE_SIZE;
4031 cur_off = pad_len % PAGE_SIZE;
4032
4033 if (cur_page_idx != 0) {
4034
4035 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4036 __func__, data_offset);
4037 rdata->result = -EIO;
4038 dequeue_mid(mid, rdata->result);
4039 return 0;
4040 }
4041
4042 if (data_len > page_data_size - pad_len) {
4043
4044 rdata->result = -EIO;
4045 dequeue_mid(mid, rdata->result);
4046 return 0;
4047 }
4048
4049 rdata->result = init_read_bvec(pages, npages, page_data_size,
4050 cur_off, &bvec);
4051 if (rdata->result != 0) {
4052 dequeue_mid(mid, rdata->result);
4053 return 0;
4054 }
4055
4056 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4057 } else if (buf_len >= data_offset + data_len) {
4058
4059 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4060 iov.iov_base = buf + data_offset;
4061 iov.iov_len = data_len;
4062 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4063 } else {
4064
4065 WARN_ONCE(1, "buf can not contain only a part of read data");
4066 rdata->result = -EIO;
4067 dequeue_mid(mid, rdata->result);
4068 return 0;
4069 }
4070
4071 length = rdata->copy_into_pages(server, rdata, &iter);
4072
4073 kfree(bvec);
4074
4075 if (length < 0)
4076 return length;
4077
4078 dequeue_mid(mid, false);
4079 return length;
4080 }
4081
4082 struct smb2_decrypt_work {
4083 struct work_struct decrypt;
4084 struct TCP_Server_Info *server;
4085 struct page **ppages;
4086 char *buf;
4087 unsigned int npages;
4088 unsigned int len;
4089 };
4090
4091
4092 static void smb2_decrypt_offload(struct work_struct *work)
4093 {
4094 struct smb2_decrypt_work *dw = container_of(work,
4095 struct smb2_decrypt_work, decrypt);
4096 int i, rc;
4097 struct mid_q_entry *mid;
4098
4099 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4100 dw->ppages, dw->npages, dw->len);
4101 if (rc) {
4102 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4103 goto free_pages;
4104 }
4105
4106 dw->server->lstrp = jiffies;
4107 mid = smb2_find_mid(dw->server, dw->buf);
4108 if (mid == NULL)
4109 cifs_dbg(FYI, "mid not found\n");
4110 else {
4111 mid->decrypted = true;
4112 rc = handle_read_data(dw->server, mid, dw->buf,
4113 dw->server->vals->read_rsp_size,
4114 dw->ppages, dw->npages, dw->len);
4115 mid->callback(mid);
4116 cifs_mid_q_entry_release(mid);
4117 }
4118
4119 free_pages:
4120 for (i = dw->npages-1; i >= 0; i--)
4121 put_page(dw->ppages[i]);
4122
4123 kfree(dw->ppages);
4124 cifs_small_buf_release(dw->buf);
4125 kfree(dw);
4126 }
4127
4128
4129 static int
4130 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4131 int *num_mids)
4132 {
4133 char *buf = server->smallbuf;
4134 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4135 unsigned int npages;
4136 struct page **pages;
4137 unsigned int len;
4138 unsigned int buflen = server->pdu_size;
4139 int rc;
4140 int i = 0;
4141 struct smb2_decrypt_work *dw;
4142
4143 *num_mids = 1;
4144 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4145 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4146
4147 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4148 if (rc < 0)
4149 return rc;
4150 server->total_read += rc;
4151
4152 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4153 server->vals->read_rsp_size;
4154 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4155
4156 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4157 if (!pages) {
4158 rc = -ENOMEM;
4159 goto discard_data;
4160 }
4161
4162 for (; i < npages; i++) {
4163 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4164 if (!pages[i]) {
4165 rc = -ENOMEM;
4166 goto discard_data;
4167 }
4168 }
4169
4170
4171 rc = read_data_into_pages(server, pages, npages, len);
4172 if (rc)
4173 goto free_pages;
4174
4175 rc = cifs_discard_remaining_data(server);
4176 if (rc)
4177 goto free_pages;
4178
4179
4180
4181
4182
4183
4184 if ((server->min_offload) && (server->in_flight > 1) &&
4185 (server->pdu_size >= server->min_offload)) {
4186 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4187 if (dw == NULL)
4188 goto non_offloaded_decrypt;
4189
4190 dw->buf = server->smallbuf;
4191 server->smallbuf = (char *)cifs_small_buf_get();
4192
4193 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4194
4195 dw->npages = npages;
4196 dw->server = server;
4197 dw->ppages = pages;
4198 dw->len = len;
4199 queue_work(decrypt_wq, &dw->decrypt);
4200 *num_mids = 0;
4201 return -1;
4202 }
4203
4204 non_offloaded_decrypt:
4205 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4206 pages, npages, len);
4207 if (rc)
4208 goto free_pages;
4209
4210 *mid = smb2_find_mid(server, buf);
4211 if (*mid == NULL)
4212 cifs_dbg(FYI, "mid not found\n");
4213 else {
4214 cifs_dbg(FYI, "mid found\n");
4215 (*mid)->decrypted = true;
4216 rc = handle_read_data(server, *mid, buf,
4217 server->vals->read_rsp_size,
4218 pages, npages, len);
4219 }
4220
4221 free_pages:
4222 for (i = i - 1; i >= 0; i--)
4223 put_page(pages[i]);
4224 kfree(pages);
4225 return rc;
4226 discard_data:
4227 cifs_discard_remaining_data(server);
4228 goto free_pages;
4229 }
4230
4231 static int
4232 receive_encrypted_standard(struct TCP_Server_Info *server,
4233 struct mid_q_entry **mids, char **bufs,
4234 int *num_mids)
4235 {
4236 int ret, length;
4237 char *buf = server->smallbuf;
4238 struct smb2_sync_hdr *shdr;
4239 unsigned int pdu_length = server->pdu_size;
4240 unsigned int buf_size;
4241 struct mid_q_entry *mid_entry;
4242 int next_is_large;
4243 char *next_buffer = NULL;
4244
4245 *num_mids = 0;
4246
4247
4248 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4249 server->large_buf = true;
4250 memcpy(server->bigbuf, buf, server->total_read);
4251 buf = server->bigbuf;
4252 }
4253
4254
4255 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4256 pdu_length - HEADER_SIZE(server) + 1);
4257 if (length < 0)
4258 return length;
4259 server->total_read += length;
4260
4261 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4262 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
4263 if (length)
4264 return length;
4265
4266 next_is_large = server->large_buf;
4267 one_more:
4268 shdr = (struct smb2_sync_hdr *)buf;
4269 if (shdr->NextCommand) {
4270 if (next_is_large)
4271 next_buffer = (char *)cifs_buf_get();
4272 else
4273 next_buffer = (char *)cifs_small_buf_get();
4274 memcpy(next_buffer,
4275 buf + le32_to_cpu(shdr->NextCommand),
4276 pdu_length - le32_to_cpu(shdr->NextCommand));
4277 }
4278
4279 mid_entry = smb2_find_mid(server, buf);
4280 if (mid_entry == NULL)
4281 cifs_dbg(FYI, "mid not found\n");
4282 else {
4283 cifs_dbg(FYI, "mid found\n");
4284 mid_entry->decrypted = true;
4285 mid_entry->resp_buf_size = server->pdu_size;
4286 }
4287
4288 if (*num_mids >= MAX_COMPOUND) {
4289 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4290 return -1;
4291 }
4292 bufs[*num_mids] = buf;
4293 mids[(*num_mids)++] = mid_entry;
4294
4295 if (mid_entry && mid_entry->handle)
4296 ret = mid_entry->handle(server, mid_entry);
4297 else
4298 ret = cifs_handle_standard(server, mid_entry);
4299
4300 if (ret == 0 && shdr->NextCommand) {
4301 pdu_length -= le32_to_cpu(shdr->NextCommand);
4302 server->large_buf = next_is_large;
4303 if (next_is_large)
4304 server->bigbuf = buf = next_buffer;
4305 else
4306 server->smallbuf = buf = next_buffer;
4307 goto one_more;
4308 } else if (ret != 0) {
4309
4310
4311
4312
4313
4314
4315 if (next_is_large)
4316 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4317 else
4318 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4319 }
4320
4321 return ret;
4322 }
4323
4324 static int
4325 smb3_receive_transform(struct TCP_Server_Info *server,
4326 struct mid_q_entry **mids, char **bufs, int *num_mids)
4327 {
4328 char *buf = server->smallbuf;
4329 unsigned int pdu_length = server->pdu_size;
4330 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4331 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4332
4333 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4334 sizeof(struct smb2_sync_hdr)) {
4335 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4336 pdu_length);
4337 cifs_reconnect(server);
4338 wake_up(&server->response_q);
4339 return -ECONNABORTED;
4340 }
4341
4342 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4343 cifs_server_dbg(VFS, "Transform message is broken\n");
4344 cifs_reconnect(server);
4345 wake_up(&server->response_q);
4346 return -ECONNABORTED;
4347 }
4348
4349
4350 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4351 return receive_encrypted_read(server, &mids[0], num_mids);
4352 }
4353
4354 return receive_encrypted_standard(server, mids, bufs, num_mids);
4355 }
4356
4357 int
4358 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
4359 {
4360 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
4361
4362 return handle_read_data(server, mid, buf, server->pdu_size,
4363 NULL, 0, 0);
4364 }
4365
4366 static int
4367 smb2_next_header(char *buf)
4368 {
4369 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
4370 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
4371
4372 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
4373 return sizeof(struct smb2_transform_hdr) +
4374 le32_to_cpu(t_hdr->OriginalMessageSize);
4375
4376 return le32_to_cpu(hdr->NextCommand);
4377 }
4378
4379 static int
4380 smb2_make_node(unsigned int xid, struct inode *inode,
4381 struct dentry *dentry, struct cifs_tcon *tcon,
4382 char *full_path, umode_t mode, dev_t dev)
4383 {
4384 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
4385 int rc = -EPERM;
4386 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
4387 FILE_ALL_INFO *buf = NULL;
4388 struct cifs_io_parms io_parms;
4389 __u32 oplock = 0;
4390 struct cifs_fid fid;
4391 struct cifs_open_parms oparms;
4392 unsigned int bytes_written;
4393 struct win_dev *pdev;
4394 struct kvec iov[2];
4395
4396
4397
4398
4399
4400
4401
4402 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
4403 goto out;
4404
4405
4406
4407
4408
4409
4410
4411 if (!S_ISCHR(mode) && !S_ISBLK(mode))
4412 goto out;
4413
4414 cifs_dbg(FYI, "sfu compat create special file\n");
4415
4416 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
4417 if (buf == NULL) {
4418 rc = -ENOMEM;
4419 goto out;
4420 }
4421
4422 if (backup_cred(cifs_sb))
4423 create_options |= CREATE_OPEN_BACKUP_INTENT;
4424
4425 oparms.tcon = tcon;
4426 oparms.cifs_sb = cifs_sb;
4427 oparms.desired_access = GENERIC_WRITE;
4428 oparms.create_options = create_options;
4429 oparms.disposition = FILE_CREATE;
4430 oparms.path = full_path;
4431 oparms.fid = &fid;
4432 oparms.reconnect = false;
4433
4434 if (tcon->ses->server->oplocks)
4435 oplock = REQ_OPLOCK;
4436 else
4437 oplock = 0;
4438 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
4439 if (rc)
4440 goto out;
4441
4442
4443
4444
4445
4446
4447 pdev = (struct win_dev *)buf;
4448 io_parms.pid = current->tgid;
4449 io_parms.tcon = tcon;
4450 io_parms.offset = 0;
4451 io_parms.length = sizeof(struct win_dev);
4452 iov[1].iov_base = buf;
4453 iov[1].iov_len = sizeof(struct win_dev);
4454 if (S_ISCHR(mode)) {
4455 memcpy(pdev->type, "IntxCHR", 8);
4456 pdev->major = cpu_to_le64(MAJOR(dev));
4457 pdev->minor = cpu_to_le64(MINOR(dev));
4458 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4459 &bytes_written, iov, 1);
4460 } else if (S_ISBLK(mode)) {
4461 memcpy(pdev->type, "IntxBLK", 8);
4462 pdev->major = cpu_to_le64(MAJOR(dev));
4463 pdev->minor = cpu_to_le64(MINOR(dev));
4464 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4465 &bytes_written, iov, 1);
4466 }
4467 tcon->ses->server->ops->close(xid, tcon, &fid);
4468 d_drop(dentry);
4469
4470
4471 out:
4472 kfree(buf);
4473 return rc;
4474 }
4475
4476
4477 struct smb_version_operations smb20_operations = {
4478 .compare_fids = smb2_compare_fids,
4479 .setup_request = smb2_setup_request,
4480 .setup_async_request = smb2_setup_async_request,
4481 .check_receive = smb2_check_receive,
4482 .add_credits = smb2_add_credits,
4483 .set_credits = smb2_set_credits,
4484 .get_credits_field = smb2_get_credits_field,
4485 .get_credits = smb2_get_credits,
4486 .wait_mtu_credits = cifs_wait_mtu_credits,
4487 .get_next_mid = smb2_get_next_mid,
4488 .revert_current_mid = smb2_revert_current_mid,
4489 .read_data_offset = smb2_read_data_offset,
4490 .read_data_length = smb2_read_data_length,
4491 .map_error = map_smb2_to_linux_error,
4492 .find_mid = smb2_find_mid,
4493 .check_message = smb2_check_message,
4494 .dump_detail = smb2_dump_detail,
4495 .clear_stats = smb2_clear_stats,
4496 .print_stats = smb2_print_stats,
4497 .is_oplock_break = smb2_is_valid_oplock_break,
4498 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4499 .downgrade_oplock = smb2_downgrade_oplock,
4500 .need_neg = smb2_need_neg,
4501 .negotiate = smb2_negotiate,
4502 .negotiate_wsize = smb2_negotiate_wsize,
4503 .negotiate_rsize = smb2_negotiate_rsize,
4504 .sess_setup = SMB2_sess_setup,
4505 .logoff = SMB2_logoff,
4506 .tree_connect = SMB2_tcon,
4507 .tree_disconnect = SMB2_tdis,
4508 .qfs_tcon = smb2_qfs_tcon,
4509 .is_path_accessible = smb2_is_path_accessible,
4510 .can_echo = smb2_can_echo,
4511 .echo = SMB2_echo,
4512 .query_path_info = smb2_query_path_info,
4513 .get_srv_inum = smb2_get_srv_inum,
4514 .query_file_info = smb2_query_file_info,
4515 .set_path_size = smb2_set_path_size,
4516 .set_file_size = smb2_set_file_size,
4517 .set_file_info = smb2_set_file_info,
4518 .set_compression = smb2_set_compression,
4519 .mkdir = smb2_mkdir,
4520 .mkdir_setinfo = smb2_mkdir_setinfo,
4521 .rmdir = smb2_rmdir,
4522 .unlink = smb2_unlink,
4523 .rename = smb2_rename_path,
4524 .create_hardlink = smb2_create_hardlink,
4525 .query_symlink = smb2_query_symlink,
4526 .query_mf_symlink = smb3_query_mf_symlink,
4527 .create_mf_symlink = smb3_create_mf_symlink,
4528 .open = smb2_open_file,
4529 .set_fid = smb2_set_fid,
4530 .close = smb2_close_file,
4531 .flush = smb2_flush_file,
4532 .async_readv = smb2_async_readv,
4533 .async_writev = smb2_async_writev,
4534 .sync_read = smb2_sync_read,
4535 .sync_write = smb2_sync_write,
4536 .query_dir_first = smb2_query_dir_first,
4537 .query_dir_next = smb2_query_dir_next,
4538 .close_dir = smb2_close_dir,
4539 .calc_smb_size = smb2_calc_size,
4540 .is_status_pending = smb2_is_status_pending,
4541 .is_session_expired = smb2_is_session_expired,
4542 .oplock_response = smb2_oplock_response,
4543 .queryfs = smb2_queryfs,
4544 .mand_lock = smb2_mand_lock,
4545 .mand_unlock_range = smb2_unlock_range,
4546 .push_mand_locks = smb2_push_mandatory_locks,
4547 .get_lease_key = smb2_get_lease_key,
4548 .set_lease_key = smb2_set_lease_key,
4549 .new_lease_key = smb2_new_lease_key,
4550 .calc_signature = smb2_calc_signature,
4551 .is_read_op = smb2_is_read_op,
4552 .set_oplock_level = smb2_set_oplock_level,
4553 .create_lease_buf = smb2_create_lease_buf,
4554 .parse_lease_buf = smb2_parse_lease_buf,
4555 .copychunk_range = smb2_copychunk_range,
4556 .wp_retry_size = smb2_wp_retry_size,
4557 .dir_needs_close = smb2_dir_needs_close,
4558 .get_dfs_refer = smb2_get_dfs_refer,
4559 .select_sectype = smb2_select_sectype,
4560 #ifdef CONFIG_CIFS_XATTR
4561 .query_all_EAs = smb2_query_eas,
4562 .set_EA = smb2_set_ea,
4563 #endif
4564 .get_acl = get_smb2_acl,
4565 .get_acl_by_fid = get_smb2_acl_by_fid,
4566 .set_acl = set_smb2_acl,
4567 .next_header = smb2_next_header,
4568 .ioctl_query_info = smb2_ioctl_query_info,
4569 .make_node = smb2_make_node,
4570 .fiemap = smb3_fiemap,
4571 .llseek = smb3_llseek,
4572 };
4573
4574 struct smb_version_operations smb21_operations = {
4575 .compare_fids = smb2_compare_fids,
4576 .setup_request = smb2_setup_request,
4577 .setup_async_request = smb2_setup_async_request,
4578 .check_receive = smb2_check_receive,
4579 .add_credits = smb2_add_credits,
4580 .set_credits = smb2_set_credits,
4581 .get_credits_field = smb2_get_credits_field,
4582 .get_credits = smb2_get_credits,
4583 .wait_mtu_credits = smb2_wait_mtu_credits,
4584 .adjust_credits = smb2_adjust_credits,
4585 .get_next_mid = smb2_get_next_mid,
4586 .revert_current_mid = smb2_revert_current_mid,
4587 .read_data_offset = smb2_read_data_offset,
4588 .read_data_length = smb2_read_data_length,
4589 .map_error = map_smb2_to_linux_error,
4590 .find_mid = smb2_find_mid,
4591 .check_message = smb2_check_message,
4592 .dump_detail = smb2_dump_detail,
4593 .clear_stats = smb2_clear_stats,
4594 .print_stats = smb2_print_stats,
4595 .is_oplock_break = smb2_is_valid_oplock_break,
4596 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4597 .downgrade_oplock = smb21_downgrade_oplock,
4598 .need_neg = smb2_need_neg,
4599 .negotiate = smb2_negotiate,
4600 .negotiate_wsize = smb2_negotiate_wsize,
4601 .negotiate_rsize = smb2_negotiate_rsize,
4602 .sess_setup = SMB2_sess_setup,
4603 .logoff = SMB2_logoff,
4604 .tree_connect = SMB2_tcon,
4605 .tree_disconnect = SMB2_tdis,
4606 .qfs_tcon = smb2_qfs_tcon,
4607 .is_path_accessible = smb2_is_path_accessible,
4608 .can_echo = smb2_can_echo,
4609 .echo = SMB2_echo,
4610 .query_path_info = smb2_query_path_info,
4611 .get_srv_inum = smb2_get_srv_inum,
4612 .query_file_info = smb2_query_file_info,
4613 .set_path_size = smb2_set_path_size,
4614 .set_file_size = smb2_set_file_size,
4615 .set_file_info = smb2_set_file_info,
4616 .set_compression = smb2_set_compression,
4617 .mkdir = smb2_mkdir,
4618 .mkdir_setinfo = smb2_mkdir_setinfo,
4619 .rmdir = smb2_rmdir,
4620 .unlink = smb2_unlink,
4621 .rename = smb2_rename_path,
4622 .create_hardlink = smb2_create_hardlink,
4623 .query_symlink = smb2_query_symlink,
4624 .query_mf_symlink = smb3_query_mf_symlink,
4625 .create_mf_symlink = smb3_create_mf_symlink,
4626 .open = smb2_open_file,
4627 .set_fid = smb2_set_fid,
4628 .close = smb2_close_file,
4629 .flush = smb2_flush_file,
4630 .async_readv = smb2_async_readv,
4631 .async_writev = smb2_async_writev,
4632 .sync_read = smb2_sync_read,
4633 .sync_write = smb2_sync_write,
4634 .query_dir_first = smb2_query_dir_first,
4635 .query_dir_next = smb2_query_dir_next,
4636 .close_dir = smb2_close_dir,
4637 .calc_smb_size = smb2_calc_size,
4638 .is_status_pending = smb2_is_status_pending,
4639 .is_session_expired = smb2_is_session_expired,
4640 .oplock_response = smb2_oplock_response,
4641 .queryfs = smb2_queryfs,
4642 .mand_lock = smb2_mand_lock,
4643 .mand_unlock_range = smb2_unlock_range,
4644 .push_mand_locks = smb2_push_mandatory_locks,
4645 .get_lease_key = smb2_get_lease_key,
4646 .set_lease_key = smb2_set_lease_key,
4647 .new_lease_key = smb2_new_lease_key,
4648 .calc_signature = smb2_calc_signature,
4649 .is_read_op = smb21_is_read_op,
4650 .set_oplock_level = smb21_set_oplock_level,
4651 .create_lease_buf = smb2_create_lease_buf,
4652 .parse_lease_buf = smb2_parse_lease_buf,
4653 .copychunk_range = smb2_copychunk_range,
4654 .wp_retry_size = smb2_wp_retry_size,
4655 .dir_needs_close = smb2_dir_needs_close,
4656 .enum_snapshots = smb3_enum_snapshots,
4657 .get_dfs_refer = smb2_get_dfs_refer,
4658 .select_sectype = smb2_select_sectype,
4659 #ifdef CONFIG_CIFS_XATTR
4660 .query_all_EAs = smb2_query_eas,
4661 .set_EA = smb2_set_ea,
4662 #endif
4663 .get_acl = get_smb2_acl,
4664 .get_acl_by_fid = get_smb2_acl_by_fid,
4665 .set_acl = set_smb2_acl,
4666 .next_header = smb2_next_header,
4667 .ioctl_query_info = smb2_ioctl_query_info,
4668 .make_node = smb2_make_node,
4669 .fiemap = smb3_fiemap,
4670 .llseek = smb3_llseek,
4671 };
4672
4673 struct smb_version_operations smb30_operations = {
4674 .compare_fids = smb2_compare_fids,
4675 .setup_request = smb2_setup_request,
4676 .setup_async_request = smb2_setup_async_request,
4677 .check_receive = smb2_check_receive,
4678 .add_credits = smb2_add_credits,
4679 .set_credits = smb2_set_credits,
4680 .get_credits_field = smb2_get_credits_field,
4681 .get_credits = smb2_get_credits,
4682 .wait_mtu_credits = smb2_wait_mtu_credits,
4683 .adjust_credits = smb2_adjust_credits,
4684 .get_next_mid = smb2_get_next_mid,
4685 .revert_current_mid = smb2_revert_current_mid,
4686 .read_data_offset = smb2_read_data_offset,
4687 .read_data_length = smb2_read_data_length,
4688 .map_error = map_smb2_to_linux_error,
4689 .find_mid = smb2_find_mid,
4690 .check_message = smb2_check_message,
4691 .dump_detail = smb2_dump_detail,
4692 .clear_stats = smb2_clear_stats,
4693 .print_stats = smb2_print_stats,
4694 .dump_share_caps = smb2_dump_share_caps,
4695 .is_oplock_break = smb2_is_valid_oplock_break,
4696 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4697 .downgrade_oplock = smb21_downgrade_oplock,
4698 .need_neg = smb2_need_neg,
4699 .negotiate = smb2_negotiate,
4700 .negotiate_wsize = smb3_negotiate_wsize,
4701 .negotiate_rsize = smb3_negotiate_rsize,
4702 .sess_setup = SMB2_sess_setup,
4703 .logoff = SMB2_logoff,
4704 .tree_connect = SMB2_tcon,
4705 .tree_disconnect = SMB2_tdis,
4706 .qfs_tcon = smb3_qfs_tcon,
4707 .is_path_accessible = smb2_is_path_accessible,
4708 .can_echo = smb2_can_echo,
4709 .echo = SMB2_echo,
4710 .query_path_info = smb2_query_path_info,
4711 .get_srv_inum = smb2_get_srv_inum,
4712 .query_file_info = smb2_query_file_info,
4713 .set_path_size = smb2_set_path_size,
4714 .set_file_size = smb2_set_file_size,
4715 .set_file_info = smb2_set_file_info,
4716 .set_compression = smb2_set_compression,
4717 .mkdir = smb2_mkdir,
4718 .mkdir_setinfo = smb2_mkdir_setinfo,
4719 .rmdir = smb2_rmdir,
4720 .unlink = smb2_unlink,
4721 .rename = smb2_rename_path,
4722 .create_hardlink = smb2_create_hardlink,
4723 .query_symlink = smb2_query_symlink,
4724 .query_mf_symlink = smb3_query_mf_symlink,
4725 .create_mf_symlink = smb3_create_mf_symlink,
4726 .open = smb2_open_file,
4727 .set_fid = smb2_set_fid,
4728 .close = smb2_close_file,
4729 .flush = smb2_flush_file,
4730 .async_readv = smb2_async_readv,
4731 .async_writev = smb2_async_writev,
4732 .sync_read = smb2_sync_read,
4733 .sync_write = smb2_sync_write,
4734 .query_dir_first = smb2_query_dir_first,
4735 .query_dir_next = smb2_query_dir_next,
4736 .close_dir = smb2_close_dir,
4737 .calc_smb_size = smb2_calc_size,
4738 .is_status_pending = smb2_is_status_pending,
4739 .is_session_expired = smb2_is_session_expired,
4740 .oplock_response = smb2_oplock_response,
4741 .queryfs = smb2_queryfs,
4742 .mand_lock = smb2_mand_lock,
4743 .mand_unlock_range = smb2_unlock_range,
4744 .push_mand_locks = smb2_push_mandatory_locks,
4745 .get_lease_key = smb2_get_lease_key,
4746 .set_lease_key = smb2_set_lease_key,
4747 .new_lease_key = smb2_new_lease_key,
4748 .generate_signingkey = generate_smb30signingkey,
4749 .calc_signature = smb3_calc_signature,
4750 .set_integrity = smb3_set_integrity,
4751 .is_read_op = smb21_is_read_op,
4752 .set_oplock_level = smb3_set_oplock_level,
4753 .create_lease_buf = smb3_create_lease_buf,
4754 .parse_lease_buf = smb3_parse_lease_buf,
4755 .copychunk_range = smb2_copychunk_range,
4756 .duplicate_extents = smb2_duplicate_extents,
4757 .validate_negotiate = smb3_validate_negotiate,
4758 .wp_retry_size = smb2_wp_retry_size,
4759 .dir_needs_close = smb2_dir_needs_close,
4760 .fallocate = smb3_fallocate,
4761 .enum_snapshots = smb3_enum_snapshots,
4762 .init_transform_rq = smb3_init_transform_rq,
4763 .is_transform_hdr = smb3_is_transform_hdr,
4764 .receive_transform = smb3_receive_transform,
4765 .get_dfs_refer = smb2_get_dfs_refer,
4766 .select_sectype = smb2_select_sectype,
4767 #ifdef CONFIG_CIFS_XATTR
4768 .query_all_EAs = smb2_query_eas,
4769 .set_EA = smb2_set_ea,
4770 #endif
4771 .get_acl = get_smb2_acl,
4772 .get_acl_by_fid = get_smb2_acl_by_fid,
4773 .set_acl = set_smb2_acl,
4774 .next_header = smb2_next_header,
4775 .ioctl_query_info = smb2_ioctl_query_info,
4776 .make_node = smb2_make_node,
4777 .fiemap = smb3_fiemap,
4778 .llseek = smb3_llseek,
4779 };
4780
4781 struct smb_version_operations smb311_operations = {
4782 .compare_fids = smb2_compare_fids,
4783 .setup_request = smb2_setup_request,
4784 .setup_async_request = smb2_setup_async_request,
4785 .check_receive = smb2_check_receive,
4786 .add_credits = smb2_add_credits,
4787 .set_credits = smb2_set_credits,
4788 .get_credits_field = smb2_get_credits_field,
4789 .get_credits = smb2_get_credits,
4790 .wait_mtu_credits = smb2_wait_mtu_credits,
4791 .adjust_credits = smb2_adjust_credits,
4792 .get_next_mid = smb2_get_next_mid,
4793 .revert_current_mid = smb2_revert_current_mid,
4794 .read_data_offset = smb2_read_data_offset,
4795 .read_data_length = smb2_read_data_length,
4796 .map_error = map_smb2_to_linux_error,
4797 .find_mid = smb2_find_mid,
4798 .check_message = smb2_check_message,
4799 .dump_detail = smb2_dump_detail,
4800 .clear_stats = smb2_clear_stats,
4801 .print_stats = smb2_print_stats,
4802 .dump_share_caps = smb2_dump_share_caps,
4803 .is_oplock_break = smb2_is_valid_oplock_break,
4804 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4805 .downgrade_oplock = smb21_downgrade_oplock,
4806 .need_neg = smb2_need_neg,
4807 .negotiate = smb2_negotiate,
4808 .negotiate_wsize = smb3_negotiate_wsize,
4809 .negotiate_rsize = smb3_negotiate_rsize,
4810 .sess_setup = SMB2_sess_setup,
4811 .logoff = SMB2_logoff,
4812 .tree_connect = SMB2_tcon,
4813 .tree_disconnect = SMB2_tdis,
4814 .qfs_tcon = smb3_qfs_tcon,
4815 .is_path_accessible = smb2_is_path_accessible,
4816 .can_echo = smb2_can_echo,
4817 .echo = SMB2_echo,
4818 .query_path_info = smb2_query_path_info,
4819 .get_srv_inum = smb2_get_srv_inum,
4820 .query_file_info = smb2_query_file_info,
4821 .set_path_size = smb2_set_path_size,
4822 .set_file_size = smb2_set_file_size,
4823 .set_file_info = smb2_set_file_info,
4824 .set_compression = smb2_set_compression,
4825 .mkdir = smb2_mkdir,
4826 .mkdir_setinfo = smb2_mkdir_setinfo,
4827 .posix_mkdir = smb311_posix_mkdir,
4828 .rmdir = smb2_rmdir,
4829 .unlink = smb2_unlink,
4830 .rename = smb2_rename_path,
4831 .create_hardlink = smb2_create_hardlink,
4832 .query_symlink = smb2_query_symlink,
4833 .query_mf_symlink = smb3_query_mf_symlink,
4834 .create_mf_symlink = smb3_create_mf_symlink,
4835 .open = smb2_open_file,
4836 .set_fid = smb2_set_fid,
4837 .close = smb2_close_file,
4838 .flush = smb2_flush_file,
4839 .async_readv = smb2_async_readv,
4840 .async_writev = smb2_async_writev,
4841 .sync_read = smb2_sync_read,
4842 .sync_write = smb2_sync_write,
4843 .query_dir_first = smb2_query_dir_first,
4844 .query_dir_next = smb2_query_dir_next,
4845 .close_dir = smb2_close_dir,
4846 .calc_smb_size = smb2_calc_size,
4847 .is_status_pending = smb2_is_status_pending,
4848 .is_session_expired = smb2_is_session_expired,
4849 .oplock_response = smb2_oplock_response,
4850 .queryfs = smb311_queryfs,
4851 .mand_lock = smb2_mand_lock,
4852 .mand_unlock_range = smb2_unlock_range,
4853 .push_mand_locks = smb2_push_mandatory_locks,
4854 .get_lease_key = smb2_get_lease_key,
4855 .set_lease_key = smb2_set_lease_key,
4856 .new_lease_key = smb2_new_lease_key,
4857 .generate_signingkey = generate_smb311signingkey,
4858 .calc_signature = smb3_calc_signature,
4859 .set_integrity = smb3_set_integrity,
4860 .is_read_op = smb21_is_read_op,
4861 .set_oplock_level = smb3_set_oplock_level,
4862 .create_lease_buf = smb3_create_lease_buf,
4863 .parse_lease_buf = smb3_parse_lease_buf,
4864 .copychunk_range = smb2_copychunk_range,
4865 .duplicate_extents = smb2_duplicate_extents,
4866
4867 .wp_retry_size = smb2_wp_retry_size,
4868 .dir_needs_close = smb2_dir_needs_close,
4869 .fallocate = smb3_fallocate,
4870 .enum_snapshots = smb3_enum_snapshots,
4871 .init_transform_rq = smb3_init_transform_rq,
4872 .is_transform_hdr = smb3_is_transform_hdr,
4873 .receive_transform = smb3_receive_transform,
4874 .get_dfs_refer = smb2_get_dfs_refer,
4875 .select_sectype = smb2_select_sectype,
4876 #ifdef CONFIG_CIFS_XATTR
4877 .query_all_EAs = smb2_query_eas,
4878 .set_EA = smb2_set_ea,
4879 #endif
4880 .get_acl = get_smb2_acl,
4881 .get_acl_by_fid = get_smb2_acl_by_fid,
4882 .set_acl = set_smb2_acl,
4883 .next_header = smb2_next_header,
4884 .ioctl_query_info = smb2_ioctl_query_info,
4885 .make_node = smb2_make_node,
4886 .fiemap = smb3_fiemap,
4887 .llseek = smb3_llseek,
4888 };
4889
4890 struct smb_version_values smb20_values = {
4891 .version_string = SMB20_VERSION_STRING,
4892 .protocol_id = SMB20_PROT_ID,
4893 .req_capabilities = 0,
4894 .large_lock_type = 0,
4895 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4896 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4897 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4898 .header_size = sizeof(struct smb2_sync_hdr),
4899 .header_preamble_size = 0,
4900 .max_header_size = MAX_SMB2_HDR_SIZE,
4901 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4902 .lock_cmd = SMB2_LOCK,
4903 .cap_unix = 0,
4904 .cap_nt_find = SMB2_NT_FIND,
4905 .cap_large_files = SMB2_LARGE_FILES,
4906 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4907 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4908 .create_lease_size = sizeof(struct create_lease),
4909 };
4910
4911 struct smb_version_values smb21_values = {
4912 .version_string = SMB21_VERSION_STRING,
4913 .protocol_id = SMB21_PROT_ID,
4914 .req_capabilities = 0,
4915 .large_lock_type = 0,
4916 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4917 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4918 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4919 .header_size = sizeof(struct smb2_sync_hdr),
4920 .header_preamble_size = 0,
4921 .max_header_size = MAX_SMB2_HDR_SIZE,
4922 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4923 .lock_cmd = SMB2_LOCK,
4924 .cap_unix = 0,
4925 .cap_nt_find = SMB2_NT_FIND,
4926 .cap_large_files = SMB2_LARGE_FILES,
4927 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4928 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4929 .create_lease_size = sizeof(struct create_lease),
4930 };
4931
4932 struct smb_version_values smb3any_values = {
4933 .version_string = SMB3ANY_VERSION_STRING,
4934 .protocol_id = SMB302_PROT_ID,
4935 .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,
4936 .large_lock_type = 0,
4937 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4938 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4939 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4940 .header_size = sizeof(struct smb2_sync_hdr),
4941 .header_preamble_size = 0,
4942 .max_header_size = MAX_SMB2_HDR_SIZE,
4943 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4944 .lock_cmd = SMB2_LOCK,
4945 .cap_unix = 0,
4946 .cap_nt_find = SMB2_NT_FIND,
4947 .cap_large_files = SMB2_LARGE_FILES,
4948 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4949 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4950 .create_lease_size = sizeof(struct create_lease_v2),
4951 };
4952
4953 struct smb_version_values smbdefault_values = {
4954 .version_string = SMBDEFAULT_VERSION_STRING,
4955 .protocol_id = SMB302_PROT_ID,
4956 .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,
4957 .large_lock_type = 0,
4958 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4959 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4960 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4961 .header_size = sizeof(struct smb2_sync_hdr),
4962 .header_preamble_size = 0,
4963 .max_header_size = MAX_SMB2_HDR_SIZE,
4964 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4965 .lock_cmd = SMB2_LOCK,
4966 .cap_unix = 0,
4967 .cap_nt_find = SMB2_NT_FIND,
4968 .cap_large_files = SMB2_LARGE_FILES,
4969 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4970 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4971 .create_lease_size = sizeof(struct create_lease_v2),
4972 };
4973
4974 struct smb_version_values smb30_values = {
4975 .version_string = SMB30_VERSION_STRING,
4976 .protocol_id = SMB30_PROT_ID,
4977 .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,
4978 .large_lock_type = 0,
4979 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4980 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4981 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4982 .header_size = sizeof(struct smb2_sync_hdr),
4983 .header_preamble_size = 0,
4984 .max_header_size = MAX_SMB2_HDR_SIZE,
4985 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4986 .lock_cmd = SMB2_LOCK,
4987 .cap_unix = 0,
4988 .cap_nt_find = SMB2_NT_FIND,
4989 .cap_large_files = SMB2_LARGE_FILES,
4990 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4991 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4992 .create_lease_size = sizeof(struct create_lease_v2),
4993 };
4994
4995 struct smb_version_values smb302_values = {
4996 .version_string = SMB302_VERSION_STRING,
4997 .protocol_id = SMB302_PROT_ID,
4998 .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,
4999 .large_lock_type = 0,
5000 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5001 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5002 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5003 .header_size = sizeof(struct smb2_sync_hdr),
5004 .header_preamble_size = 0,
5005 .max_header_size = MAX_SMB2_HDR_SIZE,
5006 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5007 .lock_cmd = SMB2_LOCK,
5008 .cap_unix = 0,
5009 .cap_nt_find = SMB2_NT_FIND,
5010 .cap_large_files = SMB2_LARGE_FILES,
5011 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5012 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5013 .create_lease_size = sizeof(struct create_lease_v2),
5014 };
5015
5016 struct smb_version_values smb311_values = {
5017 .version_string = SMB311_VERSION_STRING,
5018 .protocol_id = SMB311_PROT_ID,
5019 .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,
5020 .large_lock_type = 0,
5021 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5022 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5023 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5024 .header_size = sizeof(struct smb2_sync_hdr),
5025 .header_preamble_size = 0,
5026 .max_header_size = MAX_SMB2_HDR_SIZE,
5027 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5028 .lock_cmd = SMB2_LOCK,
5029 .cap_unix = 0,
5030 .cap_nt_find = SMB2_NT_FIND,
5031 .cap_large_files = SMB2_LARGE_FILES,
5032 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5033 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5034 .create_lease_size = sizeof(struct create_lease_v2),
5035 };