blob: bdb963d0ba32069035bdd23c9046985b41feb2bb [file] [log] [blame]
Steve French1080ef72011-02-24 18:07:19 +00001/*
2 * SMB2 version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -070020#include <linux/pagemap.h>
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070021#include <linux/vfs.h>
Steve Frenchf29ebb42014-07-19 21:44:58 -050022#include <linux/falloc.h>
Pavel Shilovsky026e93d2016-11-03 16:47:37 -070023#include <linux/scatterlist.h>
Tobias Regnery4fa8e502017-03-30 12:34:14 +020024#include <linux/uuid.h>
Pavel Shilovsky026e93d2016-11-03 16:47:37 -070025#include <crypto/aead.h>
Steve French1080ef72011-02-24 18:07:19 +000026#include "cifsglob.h"
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040027#include "smb2pdu.h"
28#include "smb2proto.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040029#include "cifsproto.h"
30#include "cifs_debug.h"
Pavel Shilovskyb42bf882013-08-14 19:25:21 +040031#include "cifs_unicode.h"
Pavel Shilovsky2e44b282012-09-18 16:20:33 -070032#include "smb2status.h"
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -070033#include "smb2glob.h"
Steve French834170c2016-09-30 21:14:26 -050034#include "cifs_ioctl.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040035
36static int
37change_conf(struct TCP_Server_Info *server)
38{
39 server->credits += server->echo_credits + server->oplock_credits;
40 server->oplock_credits = server->echo_credits = 0;
41 switch (server->credits) {
42 case 0:
43 return -1;
44 case 1:
45 server->echoes = false;
46 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050047 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040048 break;
49 case 2:
50 server->echoes = true;
51 server->oplocks = false;
52 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050053 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040054 break;
55 default:
56 server->echoes = true;
Steve Frenche0ddde92015-09-22 09:29:38 -050057 if (enable_oplocks) {
58 server->oplocks = true;
59 server->oplock_credits = 1;
60 } else
61 server->oplocks = false;
62
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040063 server->echo_credits = 1;
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040064 }
65 server->credits -= server->echo_credits + server->oplock_credits;
66 return 0;
67}
68
69static void
70smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
71 const int optype)
72{
73 int *val, rc = 0;
74 spin_lock(&server->req_lock);
75 val = server->ops->get_credits_field(server, optype);
76 *val += add;
Steve French141891f2016-09-23 00:44:16 -050077 if (*val > 65000) {
78 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
79 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
80 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040081 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040082 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040083 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070084 /*
85 * Sometimes server returns 0 credits on oplock break ack - we need to
86 * rebalance credits in this case.
87 */
88 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
89 server->oplocks) {
90 if (server->credits > 1) {
91 server->credits--;
92 server->oplock_credits++;
93 }
94 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040095 spin_unlock(&server->req_lock);
96 wake_up(&server->request_q);
97 if (rc)
98 cifs_reconnect(server);
99}
100
101static void
102smb2_set_credits(struct TCP_Server_Info *server, const int val)
103{
104 spin_lock(&server->req_lock);
105 server->credits = val;
106 spin_unlock(&server->req_lock);
107}
108
109static int *
110smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
111{
112 switch (optype) {
113 case CIFS_ECHO_OP:
114 return &server->echo_credits;
115 case CIFS_OBREAK_OP:
116 return &server->oplock_credits;
117 default:
118 return &server->credits;
119 }
120}
121
122static unsigned int
123smb2_get_credits(struct mid_q_entry *mid)
124{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700125 struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf);
126
127 return le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky28ea5292012-05-23 16:18:00 +0400128}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400129
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400130static int
131smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
132 unsigned int *num, unsigned int *credits)
133{
134 int rc = 0;
135 unsigned int scredits;
136
137 spin_lock(&server->req_lock);
138 while (1) {
139 if (server->credits <= 0) {
140 spin_unlock(&server->req_lock);
141 cifs_num_waiters_inc(server);
142 rc = wait_event_killable(server->request_q,
143 has_credits(server, &server->credits));
144 cifs_num_waiters_dec(server);
145 if (rc)
146 return rc;
147 spin_lock(&server->req_lock);
148 } else {
149 if (server->tcpStatus == CifsExiting) {
150 spin_unlock(&server->req_lock);
151 return -ENOENT;
152 }
153
154 scredits = server->credits;
155 /* can deadlock with reopen */
156 if (scredits == 1) {
157 *num = SMB2_MAX_BUFFER_SIZE;
158 *credits = 0;
159 break;
160 }
161
162 /* leave one credit for a possible reopen */
163 scredits--;
164 *num = min_t(unsigned int, size,
165 scredits * SMB2_MAX_BUFFER_SIZE);
166
167 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
168 server->credits -= *credits;
169 server->in_flight++;
170 break;
171 }
172 }
173 spin_unlock(&server->req_lock);
174 return rc;
175}
176
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400177static __u64
178smb2_get_next_mid(struct TCP_Server_Info *server)
179{
180 __u64 mid;
181 /* for SMB2 we need the current value */
182 spin_lock(&GlobalMid_Lock);
183 mid = server->CurrentMid++;
184 spin_unlock(&GlobalMid_Lock);
185 return mid;
186}
Steve French1080ef72011-02-24 18:07:19 +0000187
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400188static struct mid_q_entry *
189smb2_find_mid(struct TCP_Server_Info *server, char *buf)
190{
191 struct mid_q_entry *mid;
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700192 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
193 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400194
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700195 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
Steve French373512e2015-12-18 13:05:30 -0600196 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
197 return NULL;
198 }
199
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400200 spin_lock(&GlobalMid_Lock);
201 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000202 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400203 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700204 (mid->command == shdr->Command)) {
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400205 spin_unlock(&GlobalMid_Lock);
206 return mid;
207 }
208 }
209 spin_unlock(&GlobalMid_Lock);
210 return NULL;
211}
212
213static void
214smb2_dump_detail(void *buf)
215{
216#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700217 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400218
Joe Perchesf96637b2013-05-04 22:12:25 -0500219 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700220 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
221 shdr->ProcessId);
222 cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400223#endif
224}
225
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400226static bool
227smb2_need_neg(struct TCP_Server_Info *server)
228{
229 return server->max_read == 0;
230}
231
232static int
233smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
234{
235 int rc;
236 ses->server->CurrentMid = 0;
237 rc = SMB2_negotiate(xid, ses);
238 /* BB we probably don't need to retry with modern servers */
239 if (rc == -EAGAIN)
240 rc = -EHOSTDOWN;
241 return rc;
242}
243
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700244static unsigned int
245smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
246{
247 struct TCP_Server_Info *server = tcon->ses->server;
248 unsigned int wsize;
249
250 /* start with specified wsize, or default */
251 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
252 wsize = min_t(unsigned int, wsize, server->max_write);
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400253
254 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
255 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700256
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700257 return wsize;
258}
259
260static unsigned int
261smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
262{
263 struct TCP_Server_Info *server = tcon->ses->server;
264 unsigned int rsize;
265
266 /* start with specified rsize, or default */
267 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
268 rsize = min_t(unsigned int, rsize, server->max_read);
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400269
270 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
271 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700272
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700273 return rsize;
274}
275
Steve Frenchc481e9f2013-10-14 01:21:53 -0500276#ifdef CONFIG_CIFS_STATS2
277static int
278SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
279{
280 int rc;
281 unsigned int ret_data_len = 0;
282 struct network_interface_info_ioctl_rsp *out_buf;
283
284 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
285 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +0100286 false /* use_ipc */,
Steve Frenchc481e9f2013-10-14 01:21:53 -0500287 NULL /* no data input */, 0 /* no data input */,
288 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500289 if (rc != 0)
290 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
291 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
292 cifs_dbg(VFS, "server returned bad net interface info buf\n");
293 rc = -EINVAL;
294 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500295 /* Dump info on first interface */
296 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
297 le32_to_cpu(out_buf->Capability));
298 cifs_dbg(FYI, "Link Speed %lld\n",
299 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500300 }
Steve French24df1482016-09-29 04:20:23 -0500301 kfree(out_buf);
Steve Frenchc481e9f2013-10-14 01:21:53 -0500302 return rc;
303}
304#endif /* STATS2 */
305
Steve French34f62642013-10-09 02:07:00 -0500306static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500307smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
308{
309 int rc;
310 __le16 srch_path = 0; /* Null - open root of share */
311 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
312 struct cifs_open_parms oparms;
313 struct cifs_fid fid;
314
315 oparms.tcon = tcon;
316 oparms.desired_access = FILE_READ_ATTRIBUTES;
317 oparms.disposition = FILE_OPEN;
318 oparms.create_options = 0;
319 oparms.fid = &fid;
320 oparms.reconnect = false;
321
322 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
323 if (rc)
324 return;
325
Steve Frenchc481e9f2013-10-14 01:21:53 -0500326#ifdef CONFIG_CIFS_STATS2
327 SMB3_request_interfaces(xid, tcon);
328#endif /* STATS2 */
329
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500330 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
331 FS_ATTRIBUTE_INFORMATION);
332 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
333 FS_DEVICE_INFORMATION);
334 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
335 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
336 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
337 return;
338}
339
340static void
Steve French34f62642013-10-09 02:07:00 -0500341smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
342{
343 int rc;
344 __le16 srch_path = 0; /* Null - open root of share */
345 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
346 struct cifs_open_parms oparms;
347 struct cifs_fid fid;
348
349 oparms.tcon = tcon;
350 oparms.desired_access = FILE_READ_ATTRIBUTES;
351 oparms.disposition = FILE_OPEN;
352 oparms.create_options = 0;
353 oparms.fid = &fid;
354 oparms.reconnect = false;
355
356 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
357 if (rc)
358 return;
359
Steven French21671142013-10-09 13:36:35 -0500360 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
361 FS_ATTRIBUTE_INFORMATION);
362 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
363 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500364 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
365 return;
366}
367
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400368static int
369smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
370 struct cifs_sb_info *cifs_sb, const char *full_path)
371{
372 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400373 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700374 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400375 struct cifs_open_parms oparms;
376 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400377
378 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
379 if (!utf16_path)
380 return -ENOMEM;
381
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400382 oparms.tcon = tcon;
383 oparms.desired_access = FILE_READ_ATTRIBUTES;
384 oparms.disposition = FILE_OPEN;
385 oparms.create_options = 0;
386 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400387 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400388
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400389 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400390 if (rc) {
391 kfree(utf16_path);
392 return rc;
393 }
394
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400395 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400396 kfree(utf16_path);
397 return rc;
398}
399
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400400static int
401smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
402 struct cifs_sb_info *cifs_sb, const char *full_path,
403 u64 *uniqueid, FILE_ALL_INFO *data)
404{
405 *uniqueid = le64_to_cpu(data->IndexNumber);
406 return 0;
407}
408
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700409static int
410smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
411 struct cifs_fid *fid, FILE_ALL_INFO *data)
412{
413 int rc;
414 struct smb2_file_all_info *smb2_data;
415
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400416 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700417 GFP_KERNEL);
418 if (smb2_data == NULL)
419 return -ENOMEM;
420
421 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
422 smb2_data);
423 if (!rc)
424 move_smb2_info_to_cifs(data, smb2_data);
425 kfree(smb2_data);
426 return rc;
427}
428
Arnd Bergmann1368f152017-09-05 11:24:15 +0200429#ifdef CONFIG_CIFS_XATTR
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000430static ssize_t
431move_smb2_ea_to_cifs(char *dst, size_t dst_size,
432 struct smb2_file_full_ea_info *src, size_t src_size,
433 const unsigned char *ea_name)
434{
435 int rc = 0;
436 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
437 char *name, *value;
438 size_t name_len, value_len, user_name_len;
439
440 while (src_size > 0) {
441 name = &src->ea_data[0];
442 name_len = (size_t)src->ea_name_length;
443 value = &src->ea_data[src->ea_name_length + 1];
444 value_len = (size_t)le16_to_cpu(src->ea_value_length);
445
446 if (name_len == 0) {
447 break;
448 }
449
450 if (src_size < 8 + name_len + 1 + value_len) {
451 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
452 rc = -EIO;
453 goto out;
454 }
455
456 if (ea_name) {
457 if (ea_name_len == name_len &&
458 memcmp(ea_name, name, name_len) == 0) {
459 rc = value_len;
460 if (dst_size == 0)
461 goto out;
462 if (dst_size < value_len) {
463 rc = -ERANGE;
464 goto out;
465 }
466 memcpy(dst, value, value_len);
467 goto out;
468 }
469 } else {
470 /* 'user.' plus a terminating null */
471 user_name_len = 5 + 1 + name_len;
472
473 rc += user_name_len;
474
475 if (dst_size >= user_name_len) {
476 dst_size -= user_name_len;
477 memcpy(dst, "user.", 5);
478 dst += 5;
479 memcpy(dst, src->ea_data, name_len);
480 dst += name_len;
481 *dst = 0;
482 ++dst;
483 } else if (dst_size == 0) {
484 /* skip copy - calc size only */
485 } else {
486 /* stop before overrun buffer */
487 rc = -ERANGE;
488 break;
489 }
490 }
491
492 if (!src->next_entry_offset)
493 break;
494
495 if (src_size < le32_to_cpu(src->next_entry_offset)) {
496 /* stop before overrun buffer */
497 rc = -ERANGE;
498 break;
499 }
500 src_size -= le32_to_cpu(src->next_entry_offset);
501 src = (void *)((char *)src +
502 le32_to_cpu(src->next_entry_offset));
503 }
504
505 /* didn't find the named attribute */
506 if (ea_name)
507 rc = -ENODATA;
508
509out:
510 return (ssize_t)rc;
511}
512
513static ssize_t
514smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
515 const unsigned char *path, const unsigned char *ea_name,
516 char *ea_data, size_t buf_size,
517 struct cifs_sb_info *cifs_sb)
518{
519 int rc;
520 __le16 *utf16_path;
521 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
522 struct cifs_open_parms oparms;
523 struct cifs_fid fid;
524 struct smb2_file_full_ea_info *smb2_data;
Ronnie Sahlberg7cb3def2017-09-28 09:39:58 +1000525 int ea_buf_size = SMB2_MIN_EA_BUF;
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000526
527 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
528 if (!utf16_path)
529 return -ENOMEM;
530
531 oparms.tcon = tcon;
532 oparms.desired_access = FILE_READ_EA;
533 oparms.disposition = FILE_OPEN;
534 oparms.create_options = 0;
535 oparms.fid = &fid;
536 oparms.reconnect = false;
537
538 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
539 kfree(utf16_path);
540 if (rc) {
541 cifs_dbg(FYI, "open failed rc=%d\n", rc);
542 return rc;
543 }
544
Ronnie Sahlberg7cb3def2017-09-28 09:39:58 +1000545 while (1) {
546 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
547 if (smb2_data == NULL) {
548 SMB2_close(xid, tcon, fid.persistent_fid,
549 fid.volatile_fid);
550 return -ENOMEM;
551 }
552
553 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
554 fid.volatile_fid,
555 ea_buf_size, smb2_data);
556
557 if (rc != -E2BIG)
558 break;
559
560 kfree(smb2_data);
561 ea_buf_size <<= 1;
562
563 if (ea_buf_size > SMB2_MAX_EA_BUF) {
564 cifs_dbg(VFS, "EA size is too large\n");
565 SMB2_close(xid, tcon, fid.persistent_fid,
566 fid.volatile_fid);
567 return -ENOMEM;
568 }
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000569 }
570
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000571 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
572
573 if (!rc)
574 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
575 SMB2_MAX_EA_BUF, ea_name);
576
577 kfree(smb2_data);
578 return rc;
579}
580
Ronnie Sahlberg55175542017-08-24 11:24:56 +1000581
582static int
583smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
584 const char *path, const char *ea_name, const void *ea_value,
585 const __u16 ea_value_len, const struct nls_table *nls_codepage,
586 struct cifs_sb_info *cifs_sb)
587{
588 int rc;
589 __le16 *utf16_path;
590 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
591 struct cifs_open_parms oparms;
592 struct cifs_fid fid;
593 struct smb2_file_full_ea_info *ea;
594 int ea_name_len = strlen(ea_name);
595 int len;
596
597 if (ea_name_len > 255)
598 return -EINVAL;
599
600 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
601 if (!utf16_path)
602 return -ENOMEM;
603
604 oparms.tcon = tcon;
605 oparms.desired_access = FILE_WRITE_EA;
606 oparms.disposition = FILE_OPEN;
607 oparms.create_options = 0;
608 oparms.fid = &fid;
609 oparms.reconnect = false;
610
611 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
612 kfree(utf16_path);
613 if (rc) {
614 cifs_dbg(FYI, "open failed rc=%d\n", rc);
615 return rc;
616 }
617
618 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
619 ea = kzalloc(len, GFP_KERNEL);
620 if (ea == NULL) {
621 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
622 return -ENOMEM;
623 }
624
625 ea->ea_name_length = ea_name_len;
626 ea->ea_value_length = cpu_to_le16(ea_value_len);
627 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
628 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
629
630 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
631 len);
632 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
633
634 return rc;
635}
Arnd Bergmann1368f152017-09-05 11:24:15 +0200636#endif
Ronnie Sahlberg55175542017-08-24 11:24:56 +1000637
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400638static bool
639smb2_can_echo(struct TCP_Server_Info *server)
640{
641 return server->echoes;
642}
643
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400644static void
645smb2_clear_stats(struct cifs_tcon *tcon)
646{
647#ifdef CONFIG_CIFS_STATS
648 int i;
649 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
650 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
651 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
652 }
653#endif
654}
655
656static void
Steve French769ee6a2013-06-19 14:15:30 -0500657smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
658{
659 seq_puts(m, "\n\tShare Capabilities:");
660 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
661 seq_puts(m, " DFS,");
662 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
663 seq_puts(m, " CONTINUOUS AVAILABILITY,");
664 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
665 seq_puts(m, " SCALEOUT,");
666 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
667 seq_puts(m, " CLUSTER,");
668 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
669 seq_puts(m, " ASYMMETRIC,");
670 if (tcon->capabilities == 0)
671 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500672 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
673 seq_puts(m, " Aligned,");
674 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
675 seq_puts(m, " Partition Aligned,");
676 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
677 seq_puts(m, " SSD,");
678 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
679 seq_puts(m, " TRIM-support,");
680
Steve French769ee6a2013-06-19 14:15:30 -0500681 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500682 if (tcon->perf_sector_size)
683 seq_printf(m, "\tOptimal sector size: 0x%x",
684 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500685}
686
687static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400688smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
689{
690#ifdef CONFIG_CIFS_STATS
691 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
692 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
693 seq_printf(m, "\nNegotiates: %d sent %d failed",
694 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
695 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
696 seq_printf(m, "\nSessionSetups: %d sent %d failed",
697 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
698 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400699 seq_printf(m, "\nLogoffs: %d sent %d failed",
700 atomic_read(&sent[SMB2_LOGOFF_HE]),
701 atomic_read(&failed[SMB2_LOGOFF_HE]));
702 seq_printf(m, "\nTreeConnects: %d sent %d failed",
703 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
704 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
705 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
706 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
707 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
708 seq_printf(m, "\nCreates: %d sent %d failed",
709 atomic_read(&sent[SMB2_CREATE_HE]),
710 atomic_read(&failed[SMB2_CREATE_HE]));
711 seq_printf(m, "\nCloses: %d sent %d failed",
712 atomic_read(&sent[SMB2_CLOSE_HE]),
713 atomic_read(&failed[SMB2_CLOSE_HE]));
714 seq_printf(m, "\nFlushes: %d sent %d failed",
715 atomic_read(&sent[SMB2_FLUSH_HE]),
716 atomic_read(&failed[SMB2_FLUSH_HE]));
717 seq_printf(m, "\nReads: %d sent %d failed",
718 atomic_read(&sent[SMB2_READ_HE]),
719 atomic_read(&failed[SMB2_READ_HE]));
720 seq_printf(m, "\nWrites: %d sent %d failed",
721 atomic_read(&sent[SMB2_WRITE_HE]),
722 atomic_read(&failed[SMB2_WRITE_HE]));
723 seq_printf(m, "\nLocks: %d sent %d failed",
724 atomic_read(&sent[SMB2_LOCK_HE]),
725 atomic_read(&failed[SMB2_LOCK_HE]));
726 seq_printf(m, "\nIOCTLs: %d sent %d failed",
727 atomic_read(&sent[SMB2_IOCTL_HE]),
728 atomic_read(&failed[SMB2_IOCTL_HE]));
729 seq_printf(m, "\nCancels: %d sent %d failed",
730 atomic_read(&sent[SMB2_CANCEL_HE]),
731 atomic_read(&failed[SMB2_CANCEL_HE]));
732 seq_printf(m, "\nEchos: %d sent %d failed",
733 atomic_read(&sent[SMB2_ECHO_HE]),
734 atomic_read(&failed[SMB2_ECHO_HE]));
735 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
736 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
737 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
738 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
739 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
740 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
741 seq_printf(m, "\nQueryInfos: %d sent %d failed",
742 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
743 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
744 seq_printf(m, "\nSetInfos: %d sent %d failed",
745 atomic_read(&sent[SMB2_SET_INFO_HE]),
746 atomic_read(&failed[SMB2_SET_INFO_HE]));
747 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
748 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
749 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
750#endif
751}
752
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700753static void
754smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
755{
David Howells2b0143b2015-03-17 22:25:59 +0000756 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400757 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
758
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700759 cfile->fid.persistent_fid = fid->persistent_fid;
760 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400761 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
762 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400763 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Aurelien Aptel94f87372016-09-22 07:38:50 +0200764 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700765}
766
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400767static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700768smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
769 struct cifs_fid *fid)
770{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400771 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700772}
773
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700774static int
Steve French41c13582013-11-14 00:05:36 -0600775SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
776 u64 persistent_fid, u64 volatile_fid,
777 struct copychunk_ioctl *pcchunk)
778{
779 int rc;
780 unsigned int ret_data_len;
781 struct resume_key_req *res_key;
782
783 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
784 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +0100785 false /* use_ipc */,
Steve French41c13582013-11-14 00:05:36 -0600786 NULL, 0 /* no input */,
787 (char **)&res_key, &ret_data_len);
788
789 if (rc) {
790 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
791 goto req_res_key_exit;
792 }
793 if (ret_data_len < sizeof(struct resume_key_req)) {
794 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
795 rc = -EINVAL;
796 goto req_res_key_exit;
797 }
798 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
799
800req_res_key_exit:
801 kfree(res_key);
802 return rc;
803}
804
Sachin Prabhu620d8742017-02-10 16:03:51 +0530805static ssize_t
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500806smb2_copychunk_range(const unsigned int xid,
Steve French41c13582013-11-14 00:05:36 -0600807 struct cifsFileInfo *srcfile,
808 struct cifsFileInfo *trgtfile, u64 src_off,
809 u64 len, u64 dest_off)
810{
811 int rc;
812 unsigned int ret_data_len;
813 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600814 struct copychunk_ioctl_rsp *retbuf = NULL;
815 struct cifs_tcon *tcon;
816 int chunks_copied = 0;
817 bool chunk_sizes_updated = false;
Sachin Prabhu620d8742017-02-10 16:03:51 +0530818 ssize_t bytes_written, total_bytes_written = 0;
Steve French41c13582013-11-14 00:05:36 -0600819
820 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
821
822 if (pcchunk == NULL)
823 return -ENOMEM;
824
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500825 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
Steve French41c13582013-11-14 00:05:36 -0600826 /* Request a key from the server to identify the source of the copy */
827 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
828 srcfile->fid.persistent_fid,
829 srcfile->fid.volatile_fid, pcchunk);
830
831 /* Note: request_res_key sets res_key null only if rc !=0 */
832 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600833 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600834
835 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800836 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600837 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600838 pcchunk->Reserved2 = 0;
839
Steve French9bf0c9c2013-11-16 18:05:28 -0600840 tcon = tlink_tcon(trgtfile->tlink);
841
842 while (len > 0) {
843 pcchunk->SourceOffset = cpu_to_le64(src_off);
844 pcchunk->TargetOffset = cpu_to_le64(dest_off);
845 pcchunk->Length =
846 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
847
848 /* Request server copy to target from src identified by key */
849 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600850 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
Aurelien Aptel51146622017-02-28 15:08:41 +0100851 true /* is_fsctl */, false /* use_ipc */,
852 (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600853 sizeof(struct copychunk_ioctl), (char **)&retbuf,
854 &ret_data_len);
855 if (rc == 0) {
856 if (ret_data_len !=
857 sizeof(struct copychunk_ioctl_rsp)) {
858 cifs_dbg(VFS, "invalid cchunk response size\n");
859 rc = -EIO;
860 goto cchunk_out;
861 }
862 if (retbuf->TotalBytesWritten == 0) {
863 cifs_dbg(FYI, "no bytes copied\n");
864 rc = -EIO;
865 goto cchunk_out;
866 }
867 /*
868 * Check if server claimed to write more than we asked
869 */
870 if (le32_to_cpu(retbuf->TotalBytesWritten) >
871 le32_to_cpu(pcchunk->Length)) {
872 cifs_dbg(VFS, "invalid copy chunk response\n");
873 rc = -EIO;
874 goto cchunk_out;
875 }
876 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
877 cifs_dbg(VFS, "invalid num chunks written\n");
878 rc = -EIO;
879 goto cchunk_out;
880 }
881 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600882
Sachin Prabhu620d8742017-02-10 16:03:51 +0530883 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
884 src_off += bytes_written;
885 dest_off += bytes_written;
886 len -= bytes_written;
887 total_bytes_written += bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600888
Sachin Prabhu620d8742017-02-10 16:03:51 +0530889 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
Steve French9bf0c9c2013-11-16 18:05:28 -0600890 le32_to_cpu(retbuf->ChunksWritten),
891 le32_to_cpu(retbuf->ChunkBytesWritten),
Sachin Prabhu620d8742017-02-10 16:03:51 +0530892 bytes_written);
Steve French9bf0c9c2013-11-16 18:05:28 -0600893 } else if (rc == -EINVAL) {
894 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
895 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600896
Steve French9bf0c9c2013-11-16 18:05:28 -0600897 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
898 le32_to_cpu(retbuf->ChunksWritten),
899 le32_to_cpu(retbuf->ChunkBytesWritten),
900 le32_to_cpu(retbuf->TotalBytesWritten));
901
902 /*
903 * Check if this is the first request using these sizes,
904 * (ie check if copy succeed once with original sizes
905 * and check if the server gave us different sizes after
906 * we already updated max sizes on previous request).
907 * if not then why is the server returning an error now
908 */
909 if ((chunks_copied != 0) || chunk_sizes_updated)
910 goto cchunk_out;
911
912 /* Check that server is not asking us to grow size */
913 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
914 tcon->max_bytes_chunk)
915 tcon->max_bytes_chunk =
916 le32_to_cpu(retbuf->ChunkBytesWritten);
917 else
918 goto cchunk_out; /* server gave us bogus size */
919
920 /* No need to change MaxChunks since already set to 1 */
921 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000922 } else
923 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600924 }
925
926cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600927 kfree(pcchunk);
Steve French24df1482016-09-29 04:20:23 -0500928 kfree(retbuf);
Sachin Prabhu620d8742017-02-10 16:03:51 +0530929 if (rc)
930 return rc;
931 else
932 return total_bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600933}
934
935static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700936smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
937 struct cifs_fid *fid)
938{
939 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
940}
941
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700942static unsigned int
943smb2_read_data_offset(char *buf)
944{
945 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
946 return rsp->DataOffset;
947}
948
949static unsigned int
950smb2_read_data_length(char *buf)
951{
952 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
953 return le32_to_cpu(rsp->DataLength);
954}
955
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700956
957static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500958smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700959 struct cifs_io_parms *parms, unsigned int *bytes_read,
960 char **buf, int *buf_type)
961{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500962 parms->persistent_fid = pfid->persistent_fid;
963 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700964 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
965}
966
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700967static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500968smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700969 struct cifs_io_parms *parms, unsigned int *written,
970 struct kvec *iov, unsigned long nr_segs)
971{
972
Steve Frenchdb8b6312014-09-22 05:13:55 -0500973 parms->persistent_fid = pfid->persistent_fid;
974 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700975 return SMB2_write(xid, parms, written, iov, nr_segs);
976}
977
Steve Frenchd43cc792014-08-13 17:16:29 -0500978/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
979static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
980 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
981{
982 struct cifsInodeInfo *cifsi;
983 int rc;
984
985 cifsi = CIFS_I(inode);
986
987 /* if file already sparse don't bother setting sparse again */
988 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
989 return true; /* already sparse */
990
991 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
992 return true; /* already not sparse */
993
994 /*
995 * Can't check for sparse support on share the usual way via the
996 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
997 * since Samba server doesn't set the flag on the share, yet
998 * supports the set sparse FSCTL and returns sparse correctly
999 * in the file attributes. If we fail setting sparse though we
1000 * mark that server does not support sparse files for this share
1001 * to avoid repeatedly sending the unsupported fsctl to server
1002 * if the file is repeatedly extended.
1003 */
1004 if (tcon->broken_sparse_sup)
1005 return false;
1006
1007 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1008 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
Aurelien Aptel51146622017-02-28 15:08:41 +01001009 true /* is_fctl */, false /* use_ipc */,
1010 &setsparse, 1, NULL, NULL);
Steve Frenchd43cc792014-08-13 17:16:29 -05001011 if (rc) {
1012 tcon->broken_sparse_sup = true;
1013 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1014 return false;
1015 }
1016
1017 if (setsparse)
1018 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1019 else
1020 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1021
1022 return true;
1023}
1024
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001025static int
1026smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1027 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1028{
1029 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -05001030 struct inode *inode;
1031
1032 /*
1033 * If extending file more than one page make sparse. Many Linux fs
1034 * make files sparse by default when extending via ftruncate
1035 */
David Howells2b0143b2015-03-17 22:25:59 +00001036 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -05001037
1038 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -05001039 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -05001040
Steve Frenchd43cc792014-08-13 17:16:29 -05001041 /* whether set sparse succeeds or not, extend the file */
1042 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -05001043 }
1044
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001045 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -05001046 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001047}
1048
Steve French02b16662015-06-27 21:18:36 -07001049static int
1050smb2_duplicate_extents(const unsigned int xid,
1051 struct cifsFileInfo *srcfile,
1052 struct cifsFileInfo *trgtfile, u64 src_off,
1053 u64 len, u64 dest_off)
1054{
1055 int rc;
1056 unsigned int ret_data_len;
Steve French02b16662015-06-27 21:18:36 -07001057 struct duplicate_extents_to_file dup_ext_buf;
1058 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1059
1060 /* server fileays advertise duplicate extent support with this flag */
1061 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1062 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1063 return -EOPNOTSUPP;
1064
1065 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1066 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1067 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1068 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1069 dup_ext_buf.ByteCount = cpu_to_le64(len);
1070 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1071 src_off, dest_off, len);
1072
1073 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1074 if (rc)
1075 goto duplicate_extents_out;
1076
1077 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1078 trgtfile->fid.volatile_fid,
1079 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
Aurelien Aptel51146622017-02-28 15:08:41 +01001080 true /* is_fsctl */, false /* use_ipc */,
1081 (char *)&dup_ext_buf,
Steve French02b16662015-06-27 21:18:36 -07001082 sizeof(struct duplicate_extents_to_file),
Steve French24df1482016-09-29 04:20:23 -05001083 NULL,
Steve French02b16662015-06-27 21:18:36 -07001084 &ret_data_len);
1085
1086 if (ret_data_len > 0)
1087 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1088
1089duplicate_extents_out:
1090 return rc;
1091}
Steve French02b16662015-06-27 21:18:36 -07001092
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001093static int
Steve French64a5cfa2013-10-14 15:31:32 -05001094smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1095 struct cifsFileInfo *cfile)
1096{
1097 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1098 cfile->fid.volatile_fid);
1099}
1100
1101static int
Steve Frenchb3152e22015-06-24 03:17:02 -05001102smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1103 struct cifsFileInfo *cfile)
1104{
1105 struct fsctl_set_integrity_information_req integr_info;
Steve Frenchb3152e22015-06-24 03:17:02 -05001106 unsigned int ret_data_len;
1107
1108 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1109 integr_info.Flags = 0;
1110 integr_info.Reserved = 0;
1111
1112 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1113 cfile->fid.volatile_fid,
1114 FSCTL_SET_INTEGRITY_INFORMATION,
Aurelien Aptel51146622017-02-28 15:08:41 +01001115 true /* is_fsctl */, false /* use_ipc */,
1116 (char *)&integr_info,
Steve Frenchb3152e22015-06-24 03:17:02 -05001117 sizeof(struct fsctl_set_integrity_information_req),
Steve French24df1482016-09-29 04:20:23 -05001118 NULL,
Steve Frenchb3152e22015-06-24 03:17:02 -05001119 &ret_data_len);
1120
1121}
1122
1123static int
Steve French834170c2016-09-30 21:14:26 -05001124smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1125 struct cifsFileInfo *cfile, void __user *ioc_buf)
1126{
1127 char *retbuf = NULL;
1128 unsigned int ret_data_len = 0;
1129 int rc;
1130 struct smb_snapshot_array snapshot_in;
1131
1132 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1133 cfile->fid.volatile_fid,
1134 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
Aurelien Aptel51146622017-02-28 15:08:41 +01001135 true /* is_fsctl */, false /* use_ipc */,
1136 NULL, 0 /* no input data */,
Steve French834170c2016-09-30 21:14:26 -05001137 (char **)&retbuf,
1138 &ret_data_len);
1139 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1140 rc, ret_data_len);
1141 if (rc)
1142 return rc;
1143
1144 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1145 /* Fixup buffer */
1146 if (copy_from_user(&snapshot_in, ioc_buf,
1147 sizeof(struct smb_snapshot_array))) {
1148 rc = -EFAULT;
1149 kfree(retbuf);
1150 return rc;
1151 }
1152 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
1153 rc = -ERANGE;
David Disseldorp0e5c7952017-05-03 17:39:09 +02001154 kfree(retbuf);
Steve French834170c2016-09-30 21:14:26 -05001155 return rc;
1156 }
1157
1158 if (ret_data_len > snapshot_in.snapshot_array_size)
1159 ret_data_len = snapshot_in.snapshot_array_size;
1160
1161 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1162 rc = -EFAULT;
1163 }
1164
1165 kfree(retbuf);
1166 return rc;
1167}
1168
1169static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001170smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1171 const char *path, struct cifs_sb_info *cifs_sb,
1172 struct cifs_fid *fid, __u16 search_flags,
1173 struct cifs_search_info *srch_inf)
1174{
1175 __le16 *utf16_path;
1176 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001177 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001178 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001179
1180 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1181 if (!utf16_path)
1182 return -ENOMEM;
1183
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001184 oparms.tcon = tcon;
1185 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1186 oparms.disposition = FILE_OPEN;
1187 oparms.create_options = 0;
1188 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001189 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001190
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001191 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001192 kfree(utf16_path);
1193 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -07001194 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001195 return rc;
1196 }
1197
1198 srch_inf->entries_in_buffer = 0;
1199 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001200
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001201 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1202 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001203 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -07001204 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001205 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001206 }
1207 return rc;
1208}
1209
1210static int
1211smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1212 struct cifs_fid *fid, __u16 search_flags,
1213 struct cifs_search_info *srch_inf)
1214{
1215 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1216 fid->volatile_fid, 0, srch_inf);
1217}
1218
1219static int
1220smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1221 struct cifs_fid *fid)
1222{
1223 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1224}
1225
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001226/*
1227* If we negotiate SMB2 protocol and get STATUS_PENDING - update
1228* the number of credits and return true. Otherwise - return false.
1229*/
1230static bool
1231smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1232{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001233 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001234
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001235 if (shdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001236 return false;
1237
1238 if (!length) {
1239 spin_lock(&server->req_lock);
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001240 server->credits += le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001241 spin_unlock(&server->req_lock);
1242 wake_up(&server->request_q);
1243 }
1244
1245 return true;
1246}
1247
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07001248static bool
1249smb2_is_session_expired(char *buf)
1250{
1251 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
1252
1253 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
1254 return false;
1255
1256 cifs_dbg(FYI, "Session expired\n");
1257 return true;
1258}
1259
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001260static int
1261smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1262 struct cifsInodeInfo *cinode)
1263{
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001264 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1265 return SMB2_lease_break(0, tcon, cinode->lease_key,
1266 smb2_get_lease_state(cinode));
1267
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001268 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1269 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +04001270 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001271}
1272
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001273static int
1274smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1275 struct kstatfs *buf)
1276{
1277 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001278 __le16 srch_path = 0; /* Null - open root of share */
1279 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001280 struct cifs_open_parms oparms;
1281 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001282
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001283 oparms.tcon = tcon;
1284 oparms.desired_access = FILE_READ_ATTRIBUTES;
1285 oparms.disposition = FILE_OPEN;
1286 oparms.create_options = 0;
1287 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001288 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001289
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001290 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001291 if (rc)
1292 return rc;
1293 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001294 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1295 buf);
1296 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001297 return rc;
1298}
1299
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001300static bool
1301smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1302{
1303 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1304 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1305}
1306
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001307static int
1308smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1309 __u64 length, __u32 type, int lock, int unlock, bool wait)
1310{
1311 if (unlock && !lock)
1312 type = SMB2_LOCKFLAG_UNLOCK;
1313 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1314 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1315 current->tgid, length, offset, type, wait);
1316}
1317
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001318static void
1319smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1320{
1321 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1322}
1323
1324static void
1325smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1326{
1327 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1328}
1329
1330static void
1331smb2_new_lease_key(struct cifs_fid *fid)
1332{
Steve Frenchfa70b872016-09-22 00:39:34 -05001333 generate_random_uuid(fid->lease_key);
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001334}
1335
Aurelien Aptel9d496402017-02-13 16:16:49 +01001336static int
1337smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1338 const char *search_name,
1339 struct dfs_info3_param **target_nodes,
1340 unsigned int *num_of_nodes,
1341 const struct nls_table *nls_codepage, int remap)
1342{
1343 int rc;
1344 __le16 *utf16_path = NULL;
1345 int utf16_path_len = 0;
1346 struct cifs_tcon *tcon;
1347 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1348 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1349 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1350
1351 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1352
1353 /*
1354 * Use any tcon from the current session. Here, the first one.
1355 */
1356 spin_lock(&cifs_tcp_ses_lock);
1357 tcon = list_first_entry_or_null(&ses->tcon_list, struct cifs_tcon,
1358 tcon_list);
1359 if (tcon)
1360 tcon->tc_count++;
1361 spin_unlock(&cifs_tcp_ses_lock);
1362
1363 if (!tcon) {
1364 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1365 ses);
1366 rc = -ENOTCONN;
1367 goto out;
1368 }
1369
1370 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1371 &utf16_path_len,
1372 nls_codepage, remap);
1373 if (!utf16_path) {
1374 rc = -ENOMEM;
1375 goto out;
1376 }
1377
1378 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1379 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1380 if (!dfs_req) {
1381 rc = -ENOMEM;
1382 goto out;
1383 }
1384
1385 /* Highest DFS referral version understood */
1386 dfs_req->MaxReferralLevel = DFS_VERSION;
1387
1388 /* Path to resolve in an UTF-16 null-terminated string */
1389 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1390
1391 do {
1392 /* try first with IPC */
1393 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1394 FSCTL_DFS_GET_REFERRALS,
1395 true /* is_fsctl */, true /* use_ipc */,
1396 (char *)dfs_req, dfs_req_size,
1397 (char **)&dfs_rsp, &dfs_rsp_size);
1398 if (rc == -ENOTCONN) {
1399 /* try with normal tcon */
1400 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1401 FSCTL_DFS_GET_REFERRALS,
1402 true /* is_fsctl */, false /*use_ipc*/,
1403 (char *)dfs_req, dfs_req_size,
1404 (char **)&dfs_rsp, &dfs_rsp_size);
1405 }
1406 } while (rc == -EAGAIN);
1407
1408 if (rc) {
1409 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
1410 goto out;
1411 }
1412
1413 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1414 num_of_nodes, target_nodes,
1415 nls_codepage, remap, search_name,
1416 true /* is_unicode */);
1417 if (rc) {
1418 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1419 goto out;
1420 }
1421
1422 out:
1423 if (tcon) {
1424 spin_lock(&cifs_tcp_ses_lock);
1425 tcon->tc_count--;
1426 spin_unlock(&cifs_tcp_ses_lock);
1427 }
1428 kfree(utf16_path);
1429 kfree(dfs_req);
1430 kfree(dfs_rsp);
1431 return rc;
1432}
Pavel Shilovsky78932422016-07-24 10:37:38 +03001433#define SMB2_SYMLINK_STRUCT_SIZE \
1434 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1435
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001436static int
1437smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1438 const char *full_path, char **target_path,
1439 struct cifs_sb_info *cifs_sb)
1440{
1441 int rc;
1442 __le16 *utf16_path;
1443 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1444 struct cifs_open_parms oparms;
1445 struct cifs_fid fid;
1446 struct smb2_err_rsp *err_buf = NULL;
1447 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovsky78932422016-07-24 10:37:38 +03001448 unsigned int sub_len;
1449 unsigned int sub_offset;
1450 unsigned int print_len;
1451 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001452
1453 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1454
1455 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1456 if (!utf16_path)
1457 return -ENOMEM;
1458
1459 oparms.tcon = tcon;
1460 oparms.desired_access = FILE_READ_ATTRIBUTES;
1461 oparms.disposition = FILE_OPEN;
1462 oparms.create_options = 0;
1463 oparms.fid = &fid;
1464 oparms.reconnect = false;
1465
1466 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1467
1468 if (!rc || !err_buf) {
1469 kfree(utf16_path);
1470 return -ENOENT;
1471 }
Pavel Shilovsky78932422016-07-24 10:37:38 +03001472
1473 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1474 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1475 kfree(utf16_path);
1476 return -ENOENT;
1477 }
1478
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001479 /* open must fail on symlink - reset rc */
1480 rc = 0;
1481 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1482 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1483 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovsky78932422016-07-24 10:37:38 +03001484 print_len = le16_to_cpu(symlink->PrintNameLength);
1485 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1486
1487 if (get_rfc1002_length(err_buf) + 4 <
1488 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1489 kfree(utf16_path);
1490 return -ENOENT;
1491 }
1492
1493 if (get_rfc1002_length(err_buf) + 4 <
1494 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1495 kfree(utf16_path);
1496 return -ENOENT;
1497 }
1498
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001499 *target_path = cifs_strndup_from_utf16(
1500 (char *)symlink->PathBuffer + sub_offset,
1501 sub_len, true, cifs_sb->local_nls);
1502 if (!(*target_path)) {
1503 kfree(utf16_path);
1504 return -ENOMEM;
1505 }
1506 convert_delimiter(*target_path, '/');
1507 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1508 kfree(utf16_path);
1509 return rc;
1510}
1511
Arnd Bergmann84908422017-06-27 17:06:13 +02001512#ifdef CONFIG_CIFS_ACL
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001513static struct cifs_ntsd *
1514get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1515 const struct cifs_fid *cifsfid, u32 *pacllen)
1516{
1517 struct cifs_ntsd *pntsd = NULL;
1518 unsigned int xid;
1519 int rc = -EOPNOTSUPP;
1520 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1521
1522 if (IS_ERR(tlink))
1523 return ERR_CAST(tlink);
1524
1525 xid = get_xid();
1526 cifs_dbg(FYI, "trying to get acl\n");
1527
1528 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1529 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1530 free_xid(xid);
1531
1532 cifs_put_tlink(tlink);
1533
1534 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1535 if (rc)
1536 return ERR_PTR(rc);
1537 return pntsd;
1538
1539}
1540
1541static struct cifs_ntsd *
1542get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1543 const char *path, u32 *pacllen)
1544{
1545 struct cifs_ntsd *pntsd = NULL;
1546 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1547 unsigned int xid;
1548 int rc;
1549 struct cifs_tcon *tcon;
1550 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1551 struct cifs_fid fid;
1552 struct cifs_open_parms oparms;
1553 __le16 *utf16_path;
1554
1555 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1556 if (IS_ERR(tlink))
1557 return ERR_CAST(tlink);
1558
1559 tcon = tlink_tcon(tlink);
1560 xid = get_xid();
1561
1562 if (backup_cred(cifs_sb))
Colin Ian King709340a2017-07-05 13:47:34 +01001563 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001564 else
1565 oparms.create_options = 0;
1566
1567 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1568 if (!utf16_path)
1569 return ERR_PTR(-ENOMEM);
1570
1571 oparms.tcon = tcon;
1572 oparms.desired_access = READ_CONTROL;
1573 oparms.disposition = FILE_OPEN;
1574 oparms.fid = &fid;
1575 oparms.reconnect = false;
1576
1577 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
1578 kfree(utf16_path);
1579 if (!rc) {
1580 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1581 fid.volatile_fid, (void **)&pntsd, pacllen);
1582 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1583 }
1584
1585 cifs_put_tlink(tlink);
1586 free_xid(xid);
1587
1588 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1589 if (rc)
1590 return ERR_PTR(rc);
1591 return pntsd;
1592}
1593
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05001594#ifdef CONFIG_CIFS_ACL
1595static int
1596set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1597 struct inode *inode, const char *path, int aclflag)
1598{
1599 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1600 unsigned int xid;
1601 int rc, access_flags = 0;
1602 struct cifs_tcon *tcon;
1603 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1604 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1605 struct cifs_fid fid;
1606 struct cifs_open_parms oparms;
1607 __le16 *utf16_path;
1608
1609 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
1610 if (IS_ERR(tlink))
1611 return PTR_ERR(tlink);
1612
1613 tcon = tlink_tcon(tlink);
1614 xid = get_xid();
1615
1616 if (backup_cred(cifs_sb))
1617 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1618 else
1619 oparms.create_options = 0;
1620
1621 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
1622 access_flags = WRITE_OWNER;
1623 else
1624 access_flags = WRITE_DAC;
1625
1626 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1627 if (!utf16_path)
1628 return -ENOMEM;
1629
1630 oparms.tcon = tcon;
1631 oparms.desired_access = access_flags;
1632 oparms.disposition = FILE_OPEN;
1633 oparms.path = path;
1634 oparms.fid = &fid;
1635 oparms.reconnect = false;
1636
1637 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
1638 kfree(utf16_path);
1639 if (!rc) {
1640 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1641 fid.volatile_fid, pnntsd, acllen, aclflag);
1642 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1643 }
1644
1645 cifs_put_tlink(tlink);
1646 free_xid(xid);
1647 return rc;
1648}
1649#endif /* CIFS_ACL */
1650
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001651/* Retrieve an ACL from the server */
1652static struct cifs_ntsd *
1653get_smb2_acl(struct cifs_sb_info *cifs_sb,
1654 struct inode *inode, const char *path,
1655 u32 *pacllen)
1656{
1657 struct cifs_ntsd *pntsd = NULL;
1658 struct cifsFileInfo *open_file = NULL;
1659
1660 if (inode)
1661 open_file = find_readable_file(CIFS_I(inode), true);
1662 if (!open_file)
1663 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
1664
1665 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
1666 cifsFileInfo_put(open_file);
1667 return pntsd;
1668}
Arnd Bergmann84908422017-06-27 17:06:13 +02001669#endif
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001670
Steve French30175622014-08-17 18:16:40 -05001671static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1672 loff_t offset, loff_t len, bool keep_size)
1673{
1674 struct inode *inode;
1675 struct cifsInodeInfo *cifsi;
1676 struct cifsFileInfo *cfile = file->private_data;
1677 struct file_zero_data_information fsctl_buf;
1678 long rc;
1679 unsigned int xid;
1680
1681 xid = get_xid();
1682
David Howells2b0143b2015-03-17 22:25:59 +00001683 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001684 cifsi = CIFS_I(inode);
1685
1686 /* if file not oplocked can't be sure whether asking to extend size */
1687 if (!CIFS_CACHE_READ(cifsi))
1688 if (keep_size == false)
1689 return -EOPNOTSUPP;
1690
Steve French2bb93d22014-08-20 18:56:29 -05001691 /*
Steve French30175622014-08-17 18:16:40 -05001692 * Must check if file sparse since fallocate -z (zero range) assumes
1693 * non-sparse allocation
1694 */
1695 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1696 return -EOPNOTSUPP;
1697
1698 /*
1699 * need to make sure we are not asked to extend the file since the SMB3
1700 * fsctl does not change the file size. In the future we could change
1701 * this to zero the first part of the range then set the file size
1702 * which for a non sparse file would zero the newly extended range
1703 */
1704 if (keep_size == false)
1705 if (i_size_read(inode) < offset + len)
1706 return -EOPNOTSUPP;
1707
1708 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1709
1710 fsctl_buf.FileOffset = cpu_to_le64(offset);
1711 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1712
1713 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1714 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel51146622017-02-28 15:08:41 +01001715 true /* is_fctl */, false /* use_ipc */,
1716 (char *)&fsctl_buf,
Steve French30175622014-08-17 18:16:40 -05001717 sizeof(struct file_zero_data_information), NULL, NULL);
1718 free_xid(xid);
1719 return rc;
1720}
1721
Steve French31742c52014-08-17 08:38:47 -05001722static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1723 loff_t offset, loff_t len)
1724{
1725 struct inode *inode;
1726 struct cifsInodeInfo *cifsi;
1727 struct cifsFileInfo *cfile = file->private_data;
1728 struct file_zero_data_information fsctl_buf;
1729 long rc;
1730 unsigned int xid;
1731 __u8 set_sparse = 1;
1732
1733 xid = get_xid();
1734
David Howells2b0143b2015-03-17 22:25:59 +00001735 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001736 cifsi = CIFS_I(inode);
1737
1738 /* Need to make file sparse, if not already, before freeing range. */
1739 /* Consider adding equivalent for compressed since it could also work */
1740 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1741 return -EOPNOTSUPP;
1742
1743 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1744
1745 fsctl_buf.FileOffset = cpu_to_le64(offset);
1746 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1747
1748 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1749 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel51146622017-02-28 15:08:41 +01001750 true /* is_fctl */, false /* use_ipc */,
1751 (char *)&fsctl_buf,
Steve French31742c52014-08-17 08:38:47 -05001752 sizeof(struct file_zero_data_information), NULL, NULL);
1753 free_xid(xid);
1754 return rc;
1755}
1756
Steve French9ccf3212014-10-18 17:01:15 -05001757static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1758 loff_t off, loff_t len, bool keep_size)
1759{
1760 struct inode *inode;
1761 struct cifsInodeInfo *cifsi;
1762 struct cifsFileInfo *cfile = file->private_data;
1763 long rc = -EOPNOTSUPP;
1764 unsigned int xid;
1765
1766 xid = get_xid();
1767
David Howells2b0143b2015-03-17 22:25:59 +00001768 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001769 cifsi = CIFS_I(inode);
1770
1771 /* if file not oplocked can't be sure whether asking to extend size */
1772 if (!CIFS_CACHE_READ(cifsi))
1773 if (keep_size == false)
1774 return -EOPNOTSUPP;
1775
1776 /*
1777 * Files are non-sparse by default so falloc may be a no-op
1778 * Must check if file sparse. If not sparse, and not extending
1779 * then no need to do anything since file already allocated
1780 */
1781 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1782 if (keep_size == true)
1783 return 0;
1784 /* check if extending file */
1785 else if (i_size_read(inode) >= off + len)
1786 /* not extending file and already not sparse */
1787 return 0;
1788 /* BB: in future add else clause to extend file */
1789 else
1790 return -EOPNOTSUPP;
1791 }
1792
1793 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1794 /*
1795 * Check if falloc starts within first few pages of file
1796 * and ends within a few pages of the end of file to
1797 * ensure that most of file is being forced to be
1798 * fallocated now. If so then setting whole file sparse
1799 * ie potentially making a few extra pages at the beginning
1800 * or end of the file non-sparse via set_sparse is harmless.
1801 */
1802 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1803 return -EOPNOTSUPP;
1804
1805 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1806 }
1807 /* BB: else ... in future add code to extend file and set sparse */
1808
1809
1810 free_xid(xid);
1811 return rc;
1812}
1813
1814
Steve French31742c52014-08-17 08:38:47 -05001815static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1816 loff_t off, loff_t len)
1817{
1818 /* KEEP_SIZE already checked for by do_fallocate */
1819 if (mode & FALLOC_FL_PUNCH_HOLE)
1820 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001821 else if (mode & FALLOC_FL_ZERO_RANGE) {
1822 if (mode & FALLOC_FL_KEEP_SIZE)
1823 return smb3_zero_range(file, tcon, off, len, true);
1824 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001825 } else if (mode == FALLOC_FL_KEEP_SIZE)
1826 return smb3_simple_falloc(file, tcon, off, len, true);
1827 else if (mode == 0)
1828 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001829
1830 return -EOPNOTSUPP;
1831}
1832
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001833static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001834smb2_downgrade_oplock(struct TCP_Server_Info *server,
1835 struct cifsInodeInfo *cinode, bool set_level2)
1836{
1837 if (set_level2)
1838 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1839 0, NULL);
1840 else
1841 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1842}
1843
1844static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001845smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1846 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001847{
1848 oplock &= 0xFF;
1849 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1850 return;
1851 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001852 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001853 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1854 &cinode->vfs_inode);
1855 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001856 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001857 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1858 &cinode->vfs_inode);
1859 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1860 cinode->oplock = CIFS_CACHE_READ_FLG;
1861 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1862 &cinode->vfs_inode);
1863 } else
1864 cinode->oplock = 0;
1865}
1866
1867static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001868smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1869 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001870{
1871 char message[5] = {0};
1872
1873 oplock &= 0xFF;
1874 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1875 return;
1876
1877 cinode->oplock = 0;
1878 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1879 cinode->oplock |= CIFS_CACHE_READ_FLG;
1880 strcat(message, "R");
1881 }
1882 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1883 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1884 strcat(message, "H");
1885 }
1886 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1887 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1888 strcat(message, "W");
1889 }
1890 if (!cinode->oplock)
1891 strcat(message, "None");
1892 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1893 &cinode->vfs_inode);
1894}
1895
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001896static void
1897smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1898 unsigned int epoch, bool *purge_cache)
1899{
1900 unsigned int old_oplock = cinode->oplock;
1901
1902 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1903
1904 if (purge_cache) {
1905 *purge_cache = false;
1906 if (old_oplock == CIFS_CACHE_READ_FLG) {
1907 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1908 (epoch - cinode->epoch > 0))
1909 *purge_cache = true;
1910 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1911 (epoch - cinode->epoch > 1))
1912 *purge_cache = true;
1913 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1914 (epoch - cinode->epoch > 1))
1915 *purge_cache = true;
1916 else if (cinode->oplock == 0 &&
1917 (epoch - cinode->epoch > 0))
1918 *purge_cache = true;
1919 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1920 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1921 (epoch - cinode->epoch > 0))
1922 *purge_cache = true;
1923 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1924 (epoch - cinode->epoch > 1))
1925 *purge_cache = true;
1926 }
1927 cinode->epoch = epoch;
1928 }
1929}
1930
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001931static bool
1932smb2_is_read_op(__u32 oplock)
1933{
1934 return oplock == SMB2_OPLOCK_LEVEL_II;
1935}
1936
1937static bool
1938smb21_is_read_op(__u32 oplock)
1939{
1940 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1941 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1942}
1943
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001944static __le32
1945map_oplock_to_lease(u8 oplock)
1946{
1947 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1948 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1949 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1950 return SMB2_LEASE_READ_CACHING;
1951 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1952 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1953 SMB2_LEASE_WRITE_CACHING;
1954 return 0;
1955}
1956
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001957static char *
1958smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1959{
1960 struct create_lease *buf;
1961
1962 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1963 if (!buf)
1964 return NULL;
1965
1966 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1967 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001968 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001969
1970 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1971 (struct create_lease, lcontext));
1972 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1973 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1974 (struct create_lease, Name));
1975 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001976 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001977 buf->Name[0] = 'R';
1978 buf->Name[1] = 'q';
1979 buf->Name[2] = 'L';
1980 buf->Name[3] = 's';
1981 return (char *)buf;
1982}
1983
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001984static char *
1985smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1986{
1987 struct create_lease_v2 *buf;
1988
1989 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1990 if (!buf)
1991 return NULL;
1992
1993 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1994 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1995 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1996
1997 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1998 (struct create_lease_v2, lcontext));
1999 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2000 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2001 (struct create_lease_v2, Name));
2002 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07002003 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002004 buf->Name[0] = 'R';
2005 buf->Name[1] = 'q';
2006 buf->Name[2] = 'L';
2007 buf->Name[3] = 's';
2008 return (char *)buf;
2009}
2010
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002011static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002012smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002013{
2014 struct create_lease *lc = (struct create_lease *)buf;
2015
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002016 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002017 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2018 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2019 return le32_to_cpu(lc->lcontext.LeaseState);
2020}
2021
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002022static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002023smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002024{
2025 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2026
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002027 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002028 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2029 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2030 return le32_to_cpu(lc->lcontext.LeaseState);
2031}
2032
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002033static unsigned int
2034smb2_wp_retry_size(struct inode *inode)
2035{
2036 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2037 SMB2_MAX_BUFFER_SIZE);
2038}
2039
Pavel Shilovsky52755802014-08-18 20:49:57 +04002040static bool
2041smb2_dir_needs_close(struct cifsFileInfo *cfile)
2042{
2043 return !cfile->invalidHandle;
2044}
2045
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002046static void
2047fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
2048{
2049 struct smb2_sync_hdr *shdr =
2050 (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base;
2051 unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
2052
2053 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2054 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2055 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2056 tr_hdr->Flags = cpu_to_le16(0x01);
2057 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2058 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2059 inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4);
2060 inc_rfc1001_len(tr_hdr, orig_len);
2061}
2062
2063static struct scatterlist *
2064init_sg(struct smb_rqst *rqst, u8 *sign)
2065{
2066 unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
2067 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
2068 struct scatterlist *sg;
2069 unsigned int i;
2070 unsigned int j;
2071
2072 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2073 if (!sg)
2074 return NULL;
2075
2076 sg_init_table(sg, sg_len);
2077 sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
2078 for (i = 1; i < rqst->rq_nvec; i++)
2079 sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
2080 rqst->rq_iov[i].iov_len);
2081 for (j = 0; i < sg_len - 1; i++, j++) {
2082 unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
2083 : rqst->rq_tailsz;
2084 sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
2085 }
2086 sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
2087 return sg;
2088}
2089
2090struct cifs_crypt_result {
2091 int err;
2092 struct completion completion;
2093};
2094
2095static void cifs_crypt_complete(struct crypto_async_request *req, int err)
2096{
2097 struct cifs_crypt_result *res = req->data;
2098
2099 if (err == -EINPROGRESS)
2100 return;
2101
2102 res->err = err;
2103 complete(&res->completion);
2104}
2105
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002106static int
2107smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2108{
2109 struct cifs_ses *ses;
2110 u8 *ses_enc_key;
2111
2112 spin_lock(&cifs_tcp_ses_lock);
2113 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2114 if (ses->Suid != ses_id)
2115 continue;
2116 ses_enc_key = enc ? ses->smb3encryptionkey :
2117 ses->smb3decryptionkey;
2118 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2119 spin_unlock(&cifs_tcp_ses_lock);
2120 return 0;
2121 }
2122 spin_unlock(&cifs_tcp_ses_lock);
2123
2124 return 1;
2125}
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002126/*
2127 * Encrypt or decrypt @rqst message. @rqst has the following format:
2128 * iov[0] - transform header (associate data),
2129 * iov[1-N] and pages - data to encrypt.
2130 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2131 * untouched.
2132 */
2133static int
2134crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
2135{
2136 struct smb2_transform_hdr *tr_hdr =
2137 (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
2138 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002139 int rc = 0;
2140 struct scatterlist *sg;
2141 u8 sign[SMB2_SIGNATURE_SIZE] = {};
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002142 u8 key[SMB3_SIGN_KEY_SIZE];
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002143 struct aead_request *req;
2144 char *iv;
2145 unsigned int iv_len;
2146 struct cifs_crypt_result result = {0, };
2147 struct crypto_aead *tfm;
2148 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2149
2150 init_completion(&result.completion);
2151
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002152 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2153 if (rc) {
2154 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2155 enc ? "en" : "de");
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002156 return 0;
2157 }
2158
2159 rc = smb3_crypto_aead_allocate(server);
2160 if (rc) {
2161 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2162 return rc;
2163 }
2164
2165 tfm = enc ? server->secmech.ccmaesencrypt :
2166 server->secmech.ccmaesdecrypt;
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002167 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002168 if (rc) {
2169 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2170 return rc;
2171 }
2172
2173 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2174 if (rc) {
2175 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2176 return rc;
2177 }
2178
2179 req = aead_request_alloc(tfm, GFP_KERNEL);
2180 if (!req) {
2181 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2182 return -ENOMEM;
2183 }
2184
2185 if (!enc) {
2186 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2187 crypt_len += SMB2_SIGNATURE_SIZE;
2188 }
2189
2190 sg = init_sg(rqst, sign);
2191 if (!sg) {
Christophe Jaillet517a6e42017-06-11 09:12:47 +02002192 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2193 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002194 goto free_req;
2195 }
2196
2197 iv_len = crypto_aead_ivsize(tfm);
2198 iv = kzalloc(iv_len, GFP_KERNEL);
2199 if (!iv) {
2200 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
Christophe Jaillet517a6e42017-06-11 09:12:47 +02002201 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002202 goto free_sg;
2203 }
2204 iv[0] = 3;
2205 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2206
2207 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2208 aead_request_set_ad(req, assoc_data_len);
2209
2210 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2211 cifs_crypt_complete, &result);
2212
2213 rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
2214
2215 if (rc == -EINPROGRESS || rc == -EBUSY) {
2216 wait_for_completion(&result.completion);
2217 rc = result.err;
2218 }
2219
2220 if (!rc && enc)
2221 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2222
2223 kfree(iv);
2224free_sg:
2225 kfree(sg);
2226free_req:
2227 kfree(req);
2228 return rc;
2229}
2230
2231static int
2232smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
2233 struct smb_rqst *old_rq)
2234{
2235 struct kvec *iov;
2236 struct page **pages;
2237 struct smb2_transform_hdr *tr_hdr;
2238 unsigned int npages = old_rq->rq_npages;
2239 int i;
2240 int rc = -ENOMEM;
2241
2242 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2243 if (!pages)
2244 return rc;
2245
2246 new_rq->rq_pages = pages;
2247 new_rq->rq_npages = old_rq->rq_npages;
2248 new_rq->rq_pagesz = old_rq->rq_pagesz;
2249 new_rq->rq_tailsz = old_rq->rq_tailsz;
2250
2251 for (i = 0; i < npages; i++) {
2252 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2253 if (!pages[i])
2254 goto err_free_pages;
2255 }
2256
2257 iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL);
2258 if (!iov)
2259 goto err_free_pages;
2260
2261 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2262 memcpy(&iov[1], &old_rq->rq_iov[1],
2263 sizeof(struct kvec) * (old_rq->rq_nvec - 1));
2264 new_rq->rq_iov = iov;
2265 new_rq->rq_nvec = old_rq->rq_nvec;
2266
2267 tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
2268 if (!tr_hdr)
2269 goto err_free_iov;
2270
2271 /* fill the 1st iov with a transform header */
2272 fill_transform_hdr(tr_hdr, old_rq);
2273 new_rq->rq_iov[0].iov_base = tr_hdr;
2274 new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2275
2276 /* copy pages form the old */
2277 for (i = 0; i < npages; i++) {
2278 char *dst = kmap(new_rq->rq_pages[i]);
2279 char *src = kmap(old_rq->rq_pages[i]);
2280 unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz :
2281 new_rq->rq_tailsz;
2282 memcpy(dst, src, len);
2283 kunmap(new_rq->rq_pages[i]);
2284 kunmap(old_rq->rq_pages[i]);
2285 }
2286
2287 rc = crypt_message(server, new_rq, 1);
2288 cifs_dbg(FYI, "encrypt message returned %d", rc);
2289 if (rc)
2290 goto err_free_tr_hdr;
2291
2292 return rc;
2293
2294err_free_tr_hdr:
2295 kfree(tr_hdr);
2296err_free_iov:
2297 kfree(iov);
2298err_free_pages:
2299 for (i = i - 1; i >= 0; i--)
2300 put_page(pages[i]);
2301 kfree(pages);
2302 return rc;
2303}
2304
2305static void
2306smb3_free_transform_rq(struct smb_rqst *rqst)
2307{
2308 int i = rqst->rq_npages - 1;
2309
2310 for (; i >= 0; i--)
2311 put_page(rqst->rq_pages[i]);
2312 kfree(rqst->rq_pages);
2313 /* free transform header */
2314 kfree(rqst->rq_iov[0].iov_base);
2315 kfree(rqst->rq_iov);
2316}
2317
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002318static int
2319smb3_is_transform_hdr(void *buf)
2320{
2321 struct smb2_transform_hdr *trhdr = buf;
2322
2323 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2324}
2325
2326static int
2327decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2328 unsigned int buf_data_size, struct page **pages,
2329 unsigned int npages, unsigned int page_data_size)
2330{
2331 struct kvec iov[2];
2332 struct smb_rqst rqst = {NULL};
2333 struct smb2_hdr *hdr;
2334 int rc;
2335
2336 iov[0].iov_base = buf;
2337 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2338 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2339 iov[1].iov_len = buf_data_size;
2340
2341 rqst.rq_iov = iov;
2342 rqst.rq_nvec = 2;
2343 rqst.rq_pages = pages;
2344 rqst.rq_npages = npages;
2345 rqst.rq_pagesz = PAGE_SIZE;
2346 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2347
2348 rc = crypt_message(server, &rqst, 0);
2349 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2350
2351 if (rc)
2352 return rc;
2353
2354 memmove(buf + 4, iov[1].iov_base, buf_data_size);
2355 hdr = (struct smb2_hdr *)buf;
2356 hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size);
2357 server->total_read = buf_data_size + page_data_size + 4;
2358
2359 return rc;
2360}
2361
2362static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002363read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2364 unsigned int npages, unsigned int len)
2365{
2366 int i;
2367 int length;
2368
2369 for (i = 0; i < npages; i++) {
2370 struct page *page = pages[i];
2371 size_t n;
2372
2373 n = len;
2374 if (len >= PAGE_SIZE) {
2375 /* enough data to fill the page */
2376 n = PAGE_SIZE;
2377 len -= n;
2378 } else {
2379 zero_user(page, len, PAGE_SIZE - len);
2380 len = 0;
2381 }
2382 length = cifs_read_page_from_socket(server, page, n);
2383 if (length < 0)
2384 return length;
2385 server->total_read += length;
2386 }
2387
2388 return 0;
2389}
2390
2391static int
2392init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2393 unsigned int cur_off, struct bio_vec **page_vec)
2394{
2395 struct bio_vec *bvec;
2396 int i;
2397
2398 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2399 if (!bvec)
2400 return -ENOMEM;
2401
2402 for (i = 0; i < npages; i++) {
2403 bvec[i].bv_page = pages[i];
2404 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2405 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2406 data_size -= bvec[i].bv_len;
2407 }
2408
2409 if (data_size != 0) {
2410 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2411 kfree(bvec);
2412 return -EIO;
2413 }
2414
2415 *page_vec = bvec;
2416 return 0;
2417}
2418
2419static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002420handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2421 char *buf, unsigned int buf_len, struct page **pages,
2422 unsigned int npages, unsigned int page_data_size)
2423{
2424 unsigned int data_offset;
2425 unsigned int data_len;
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002426 unsigned int cur_off;
2427 unsigned int cur_page_idx;
2428 unsigned int pad_len;
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002429 struct cifs_readdata *rdata = mid->callback_data;
2430 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
2431 struct bio_vec *bvec = NULL;
2432 struct iov_iter iter;
2433 struct kvec iov;
2434 int length;
2435
2436 if (shdr->Command != SMB2_READ) {
2437 cifs_dbg(VFS, "only big read responses are supported\n");
2438 return -ENOTSUPP;
2439 }
2440
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002441 if (server->ops->is_session_expired &&
2442 server->ops->is_session_expired(buf)) {
2443 cifs_reconnect(server);
2444 wake_up(&server->response_q);
2445 return -1;
2446 }
2447
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002448 if (server->ops->is_status_pending &&
2449 server->ops->is_status_pending(buf, server, 0))
2450 return -1;
2451
2452 rdata->result = server->ops->map_error(buf, false);
2453 if (rdata->result != 0) {
2454 cifs_dbg(FYI, "%s: server returned error %d\n",
2455 __func__, rdata->result);
2456 dequeue_mid(mid, rdata->result);
2457 return 0;
2458 }
2459
2460 data_offset = server->ops->read_data_offset(buf) + 4;
2461 data_len = server->ops->read_data_length(buf);
2462
2463 if (data_offset < server->vals->read_rsp_size) {
2464 /*
2465 * win2k8 sometimes sends an offset of 0 when the read
2466 * is beyond the EOF. Treat it as if the data starts just after
2467 * the header.
2468 */
2469 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2470 __func__, data_offset);
2471 data_offset = server->vals->read_rsp_size;
2472 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2473 /* data_offset is beyond the end of smallbuf */
2474 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2475 __func__, data_offset);
2476 rdata->result = -EIO;
2477 dequeue_mid(mid, rdata->result);
2478 return 0;
2479 }
2480
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002481 pad_len = data_offset - server->vals->read_rsp_size;
2482
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002483 if (buf_len <= data_offset) {
2484 /* read response payload is in pages */
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002485 cur_page_idx = pad_len / PAGE_SIZE;
2486 cur_off = pad_len % PAGE_SIZE;
2487
2488 if (cur_page_idx != 0) {
2489 /* data offset is beyond the 1st page of response */
2490 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2491 __func__, data_offset);
2492 rdata->result = -EIO;
2493 dequeue_mid(mid, rdata->result);
2494 return 0;
2495 }
2496
2497 if (data_len > page_data_size - pad_len) {
2498 /* data_len is corrupt -- discard frame */
2499 rdata->result = -EIO;
2500 dequeue_mid(mid, rdata->result);
2501 return 0;
2502 }
2503
2504 rdata->result = init_read_bvec(pages, npages, page_data_size,
2505 cur_off, &bvec);
2506 if (rdata->result != 0) {
2507 dequeue_mid(mid, rdata->result);
2508 return 0;
2509 }
2510
2511 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002512 } else if (buf_len >= data_offset + data_len) {
2513 /* read response payload is in buf */
2514 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2515 iov.iov_base = buf + data_offset;
2516 iov.iov_len = data_len;
2517 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2518 } else {
2519 /* read response payload cannot be in both buf and pages */
2520 WARN_ONCE(1, "buf can not contain only a part of read data");
2521 rdata->result = -EIO;
2522 dequeue_mid(mid, rdata->result);
2523 return 0;
2524 }
2525
2526 /* set up first iov for signature check */
2527 rdata->iov[0].iov_base = buf;
2528 rdata->iov[0].iov_len = 4;
2529 rdata->iov[1].iov_base = buf + 4;
2530 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2531 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2532 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2533
2534 length = rdata->copy_into_pages(server, rdata, &iter);
2535
2536 kfree(bvec);
2537
2538 if (length < 0)
2539 return length;
2540
2541 dequeue_mid(mid, false);
2542 return length;
2543}
2544
2545static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002546receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2547{
2548 char *buf = server->smallbuf;
2549 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2550 unsigned int npages;
2551 struct page **pages;
2552 unsigned int len;
2553 unsigned int buflen = get_rfc1002_length(buf) + 4;
2554 int rc;
2555 int i = 0;
2556
2557 len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 +
2558 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2559
2560 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2561 if (rc < 0)
2562 return rc;
2563 server->total_read += rc;
2564
2565 len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 -
2566 server->vals->read_rsp_size;
2567 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2568
2569 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2570 if (!pages) {
2571 rc = -ENOMEM;
2572 goto discard_data;
2573 }
2574
2575 for (; i < npages; i++) {
2576 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2577 if (!pages[i]) {
2578 rc = -ENOMEM;
2579 goto discard_data;
2580 }
2581 }
2582
2583 /* read read data into pages */
2584 rc = read_data_into_pages(server, pages, npages, len);
2585 if (rc)
2586 goto free_pages;
2587
Pavel Shilovsky350be252017-04-10 10:31:33 -07002588 rc = cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002589 if (rc)
2590 goto free_pages;
2591
2592 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4,
2593 pages, npages, len);
2594 if (rc)
2595 goto free_pages;
2596
2597 *mid = smb2_find_mid(server, buf);
2598 if (*mid == NULL)
2599 cifs_dbg(FYI, "mid not found\n");
2600 else {
2601 cifs_dbg(FYI, "mid found\n");
2602 (*mid)->decrypted = true;
2603 rc = handle_read_data(server, *mid, buf,
2604 server->vals->read_rsp_size,
2605 pages, npages, len);
2606 }
2607
2608free_pages:
2609 for (i = i - 1; i >= 0; i--)
2610 put_page(pages[i]);
2611 kfree(pages);
2612 return rc;
2613discard_data:
Pavel Shilovsky350be252017-04-10 10:31:33 -07002614 cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002615 goto free_pages;
2616}
2617
2618static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002619receive_encrypted_standard(struct TCP_Server_Info *server,
2620 struct mid_q_entry **mid)
2621{
2622 int length;
2623 char *buf = server->smallbuf;
2624 unsigned int pdu_length = get_rfc1002_length(buf);
2625 unsigned int buf_size;
2626 struct mid_q_entry *mid_entry;
2627
2628 /* switch to large buffer if too big for a small one */
2629 if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) {
2630 server->large_buf = true;
2631 memcpy(server->bigbuf, buf, server->total_read);
2632 buf = server->bigbuf;
2633 }
2634
2635 /* now read the rest */
2636 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
2637 pdu_length - HEADER_SIZE(server) + 1 + 4);
2638 if (length < 0)
2639 return length;
2640 server->total_read += length;
2641
2642 buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr);
2643 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
2644 if (length)
2645 return length;
2646
2647 mid_entry = smb2_find_mid(server, buf);
2648 if (mid_entry == NULL)
2649 cifs_dbg(FYI, "mid not found\n");
2650 else {
2651 cifs_dbg(FYI, "mid found\n");
2652 mid_entry->decrypted = true;
2653 }
2654
2655 *mid = mid_entry;
2656
2657 if (mid_entry && mid_entry->handle)
2658 return mid_entry->handle(server, mid_entry);
2659
2660 return cifs_handle_standard(server, mid_entry);
2661}
2662
2663static int
2664smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2665{
2666 char *buf = server->smallbuf;
2667 unsigned int pdu_length = get_rfc1002_length(buf);
2668 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2669 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2670
2671 if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) +
2672 sizeof(struct smb2_sync_hdr)) {
2673 cifs_dbg(VFS, "Transform message is too small (%u)\n",
2674 pdu_length);
2675 cifs_reconnect(server);
2676 wake_up(&server->response_q);
2677 return -ECONNABORTED;
2678 }
2679
2680 if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
2681 cifs_dbg(VFS, "Transform message is broken\n");
2682 cifs_reconnect(server);
2683 wake_up(&server->response_q);
2684 return -ECONNABORTED;
2685 }
2686
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002687 if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
2688 return receive_encrypted_read(server, mid);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002689
2690 return receive_encrypted_standard(server, mid);
2691}
2692
2693int
2694smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
2695{
2696 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
2697
2698 return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4,
2699 NULL, 0, 0);
2700}
2701
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002702struct smb_version_operations smb20_operations = {
2703 .compare_fids = smb2_compare_fids,
2704 .setup_request = smb2_setup_request,
2705 .setup_async_request = smb2_setup_async_request,
2706 .check_receive = smb2_check_receive,
2707 .add_credits = smb2_add_credits,
2708 .set_credits = smb2_set_credits,
2709 .get_credits_field = smb2_get_credits_field,
2710 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002711 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002712 .get_next_mid = smb2_get_next_mid,
2713 .read_data_offset = smb2_read_data_offset,
2714 .read_data_length = smb2_read_data_length,
2715 .map_error = map_smb2_to_linux_error,
2716 .find_mid = smb2_find_mid,
2717 .check_message = smb2_check_message,
2718 .dump_detail = smb2_dump_detail,
2719 .clear_stats = smb2_clear_stats,
2720 .print_stats = smb2_print_stats,
2721 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002722 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002723 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002724 .need_neg = smb2_need_neg,
2725 .negotiate = smb2_negotiate,
2726 .negotiate_wsize = smb2_negotiate_wsize,
2727 .negotiate_rsize = smb2_negotiate_rsize,
2728 .sess_setup = SMB2_sess_setup,
2729 .logoff = SMB2_logoff,
2730 .tree_connect = SMB2_tcon,
2731 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002732 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002733 .is_path_accessible = smb2_is_path_accessible,
2734 .can_echo = smb2_can_echo,
2735 .echo = SMB2_echo,
2736 .query_path_info = smb2_query_path_info,
2737 .get_srv_inum = smb2_get_srv_inum,
2738 .query_file_info = smb2_query_file_info,
2739 .set_path_size = smb2_set_path_size,
2740 .set_file_size = smb2_set_file_size,
2741 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002742 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002743 .mkdir = smb2_mkdir,
2744 .mkdir_setinfo = smb2_mkdir_setinfo,
2745 .rmdir = smb2_rmdir,
2746 .unlink = smb2_unlink,
2747 .rename = smb2_rename_path,
2748 .create_hardlink = smb2_create_hardlink,
2749 .query_symlink = smb2_query_symlink,
Sachin Prabhu5b23c972016-07-11 16:53:20 +01002750 .query_mf_symlink = smb3_query_mf_symlink,
2751 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002752 .open = smb2_open_file,
2753 .set_fid = smb2_set_fid,
2754 .close = smb2_close_file,
2755 .flush = smb2_flush_file,
2756 .async_readv = smb2_async_readv,
2757 .async_writev = smb2_async_writev,
2758 .sync_read = smb2_sync_read,
2759 .sync_write = smb2_sync_write,
2760 .query_dir_first = smb2_query_dir_first,
2761 .query_dir_next = smb2_query_dir_next,
2762 .close_dir = smb2_close_dir,
2763 .calc_smb_size = smb2_calc_size,
2764 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002765 .is_session_expired = smb2_is_session_expired,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002766 .oplock_response = smb2_oplock_response,
2767 .queryfs = smb2_queryfs,
2768 .mand_lock = smb2_mand_lock,
2769 .mand_unlock_range = smb2_unlock_range,
2770 .push_mand_locks = smb2_push_mandatory_locks,
2771 .get_lease_key = smb2_get_lease_key,
2772 .set_lease_key = smb2_set_lease_key,
2773 .new_lease_key = smb2_new_lease_key,
2774 .calc_signature = smb2_calc_signature,
2775 .is_read_op = smb2_is_read_op,
2776 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002777 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002778 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002779 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002780 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002781 .dir_needs_close = smb2_dir_needs_close,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002782 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302783 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002784#ifdef CONFIG_CIFS_XATTR
2785 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002786 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002787#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002788#ifdef CONFIG_CIFS_ACL
2789 .get_acl = get_smb2_acl,
2790 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002791 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002792#endif /* CIFS_ACL */
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002793};
2794
Steve French1080ef72011-02-24 18:07:19 +00002795struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07002796 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002797 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04002798 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002799 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04002800 .add_credits = smb2_add_credits,
2801 .set_credits = smb2_set_credits,
2802 .get_credits_field = smb2_get_credits_field,
2803 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002804 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002805 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002806 .read_data_offset = smb2_read_data_offset,
2807 .read_data_length = smb2_read_data_length,
2808 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04002809 .find_mid = smb2_find_mid,
2810 .check_message = smb2_check_message,
2811 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04002812 .clear_stats = smb2_clear_stats,
2813 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002814 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002815 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002816 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04002817 .need_neg = smb2_need_neg,
2818 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07002819 .negotiate_wsize = smb2_negotiate_wsize,
2820 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04002821 .sess_setup = SMB2_sess_setup,
2822 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04002823 .tree_connect = SMB2_tcon,
2824 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002825 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04002826 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04002827 .can_echo = smb2_can_echo,
2828 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04002829 .query_path_info = smb2_query_path_info,
2830 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07002831 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07002832 .set_path_size = smb2_set_path_size,
2833 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07002834 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002835 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04002836 .mkdir = smb2_mkdir,
2837 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04002838 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07002839 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07002840 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07002841 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002842 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002843 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002844 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07002845 .open = smb2_open_file,
2846 .set_fid = smb2_set_fid,
2847 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07002848 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002849 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07002850 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07002851 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07002852 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07002853 .query_dir_first = smb2_query_dir_first,
2854 .query_dir_next = smb2_query_dir_next,
2855 .close_dir = smb2_close_dir,
2856 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07002857 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002858 .is_session_expired = smb2_is_session_expired,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002859 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07002860 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07002861 .mand_lock = smb2_mand_lock,
2862 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07002863 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07002864 .get_lease_key = smb2_get_lease_key,
2865 .set_lease_key = smb2_set_lease_key,
2866 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06002867 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002868 .is_read_op = smb21_is_read_op,
2869 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002870 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002871 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002872 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002873 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002874 .dir_needs_close = smb2_dir_needs_close,
Steve French834170c2016-09-30 21:14:26 -05002875 .enum_snapshots = smb3_enum_snapshots,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002876 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302877 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002878#ifdef CONFIG_CIFS_XATTR
2879 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002880 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002881#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002882#ifdef CONFIG_CIFS_ACL
2883 .get_acl = get_smb2_acl,
2884 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002885 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002886#endif /* CIFS_ACL */
Steve French38107d42012-12-08 22:08:06 -06002887};
2888
Steve French38107d42012-12-08 22:08:06 -06002889struct smb_version_operations smb30_operations = {
2890 .compare_fids = smb2_compare_fids,
2891 .setup_request = smb2_setup_request,
2892 .setup_async_request = smb2_setup_async_request,
2893 .check_receive = smb2_check_receive,
2894 .add_credits = smb2_add_credits,
2895 .set_credits = smb2_set_credits,
2896 .get_credits_field = smb2_get_credits_field,
2897 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002898 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06002899 .get_next_mid = smb2_get_next_mid,
2900 .read_data_offset = smb2_read_data_offset,
2901 .read_data_length = smb2_read_data_length,
2902 .map_error = map_smb2_to_linux_error,
2903 .find_mid = smb2_find_mid,
2904 .check_message = smb2_check_message,
2905 .dump_detail = smb2_dump_detail,
2906 .clear_stats = smb2_clear_stats,
2907 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05002908 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06002909 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002910 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002911 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06002912 .need_neg = smb2_need_neg,
2913 .negotiate = smb2_negotiate,
2914 .negotiate_wsize = smb2_negotiate_wsize,
2915 .negotiate_rsize = smb2_negotiate_rsize,
2916 .sess_setup = SMB2_sess_setup,
2917 .logoff = SMB2_logoff,
2918 .tree_connect = SMB2_tcon,
2919 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05002920 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06002921 .is_path_accessible = smb2_is_path_accessible,
2922 .can_echo = smb2_can_echo,
2923 .echo = SMB2_echo,
2924 .query_path_info = smb2_query_path_info,
2925 .get_srv_inum = smb2_get_srv_inum,
2926 .query_file_info = smb2_query_file_info,
2927 .set_path_size = smb2_set_path_size,
2928 .set_file_size = smb2_set_file_size,
2929 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002930 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06002931 .mkdir = smb2_mkdir,
2932 .mkdir_setinfo = smb2_mkdir_setinfo,
2933 .rmdir = smb2_rmdir,
2934 .unlink = smb2_unlink,
2935 .rename = smb2_rename_path,
2936 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002937 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002938 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002939 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06002940 .open = smb2_open_file,
2941 .set_fid = smb2_set_fid,
2942 .close = smb2_close_file,
2943 .flush = smb2_flush_file,
2944 .async_readv = smb2_async_readv,
2945 .async_writev = smb2_async_writev,
2946 .sync_read = smb2_sync_read,
2947 .sync_write = smb2_sync_write,
2948 .query_dir_first = smb2_query_dir_first,
2949 .query_dir_next = smb2_query_dir_next,
2950 .close_dir = smb2_close_dir,
2951 .calc_smb_size = smb2_calc_size,
2952 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002953 .is_session_expired = smb2_is_session_expired,
Steve French38107d42012-12-08 22:08:06 -06002954 .oplock_response = smb2_oplock_response,
2955 .queryfs = smb2_queryfs,
2956 .mand_lock = smb2_mand_lock,
2957 .mand_unlock_range = smb2_unlock_range,
2958 .push_mand_locks = smb2_push_mandatory_locks,
2959 .get_lease_key = smb2_get_lease_key,
2960 .set_lease_key = smb2_set_lease_key,
2961 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06002962 .generate_signingkey = generate_smb30signingkey,
Steve French38107d42012-12-08 22:08:06 -06002963 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05002964 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002965 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002966 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002967 .create_lease_buf = smb3_create_lease_buf,
2968 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002969 .copychunk_range = smb2_copychunk_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05002970 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06002971 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002972 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002973 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05002974 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05002975 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002976 .init_transform_rq = smb3_init_transform_rq,
2977 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002978 .is_transform_hdr = smb3_is_transform_hdr,
2979 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002980 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302981 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002982#ifdef CONFIG_CIFS_XATTR
2983 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002984 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002985#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002986#ifdef CONFIG_CIFS_ACL
2987 .get_acl = get_smb2_acl,
2988 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002989 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002990#endif /* CIFS_ACL */
Steve French1080ef72011-02-24 18:07:19 +00002991};
2992
Steve Frenchaab18932015-06-23 23:37:11 -05002993#ifdef CONFIG_CIFS_SMB311
2994struct smb_version_operations smb311_operations = {
2995 .compare_fids = smb2_compare_fids,
2996 .setup_request = smb2_setup_request,
2997 .setup_async_request = smb2_setup_async_request,
2998 .check_receive = smb2_check_receive,
2999 .add_credits = smb2_add_credits,
3000 .set_credits = smb2_set_credits,
3001 .get_credits_field = smb2_get_credits_field,
3002 .get_credits = smb2_get_credits,
3003 .wait_mtu_credits = smb2_wait_mtu_credits,
3004 .get_next_mid = smb2_get_next_mid,
3005 .read_data_offset = smb2_read_data_offset,
3006 .read_data_length = smb2_read_data_length,
3007 .map_error = map_smb2_to_linux_error,
3008 .find_mid = smb2_find_mid,
3009 .check_message = smb2_check_message,
3010 .dump_detail = smb2_dump_detail,
3011 .clear_stats = smb2_clear_stats,
3012 .print_stats = smb2_print_stats,
3013 .dump_share_caps = smb2_dump_share_caps,
3014 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08003015 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Steve Frenchaab18932015-06-23 23:37:11 -05003016 .downgrade_oplock = smb2_downgrade_oplock,
3017 .need_neg = smb2_need_neg,
3018 .negotiate = smb2_negotiate,
3019 .negotiate_wsize = smb2_negotiate_wsize,
3020 .negotiate_rsize = smb2_negotiate_rsize,
3021 .sess_setup = SMB2_sess_setup,
3022 .logoff = SMB2_logoff,
3023 .tree_connect = SMB2_tcon,
3024 .tree_disconnect = SMB2_tdis,
3025 .qfs_tcon = smb3_qfs_tcon,
3026 .is_path_accessible = smb2_is_path_accessible,
3027 .can_echo = smb2_can_echo,
3028 .echo = SMB2_echo,
3029 .query_path_info = smb2_query_path_info,
3030 .get_srv_inum = smb2_get_srv_inum,
3031 .query_file_info = smb2_query_file_info,
3032 .set_path_size = smb2_set_path_size,
3033 .set_file_size = smb2_set_file_size,
3034 .set_file_info = smb2_set_file_info,
3035 .set_compression = smb2_set_compression,
3036 .mkdir = smb2_mkdir,
3037 .mkdir_setinfo = smb2_mkdir_setinfo,
3038 .rmdir = smb2_rmdir,
3039 .unlink = smb2_unlink,
3040 .rename = smb2_rename_path,
3041 .create_hardlink = smb2_create_hardlink,
3042 .query_symlink = smb2_query_symlink,
3043 .query_mf_symlink = smb3_query_mf_symlink,
3044 .create_mf_symlink = smb3_create_mf_symlink,
3045 .open = smb2_open_file,
3046 .set_fid = smb2_set_fid,
3047 .close = smb2_close_file,
3048 .flush = smb2_flush_file,
3049 .async_readv = smb2_async_readv,
3050 .async_writev = smb2_async_writev,
3051 .sync_read = smb2_sync_read,
3052 .sync_write = smb2_sync_write,
3053 .query_dir_first = smb2_query_dir_first,
3054 .query_dir_next = smb2_query_dir_next,
3055 .close_dir = smb2_close_dir,
3056 .calc_smb_size = smb2_calc_size,
3057 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07003058 .is_session_expired = smb2_is_session_expired,
Steve Frenchaab18932015-06-23 23:37:11 -05003059 .oplock_response = smb2_oplock_response,
3060 .queryfs = smb2_queryfs,
3061 .mand_lock = smb2_mand_lock,
3062 .mand_unlock_range = smb2_unlock_range,
3063 .push_mand_locks = smb2_push_mandatory_locks,
3064 .get_lease_key = smb2_get_lease_key,
3065 .set_lease_key = smb2_set_lease_key,
3066 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06003067 .generate_signingkey = generate_smb311signingkey,
Steve Frenchaab18932015-06-23 23:37:11 -05003068 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05003069 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05003070 .is_read_op = smb21_is_read_op,
3071 .set_oplock_level = smb3_set_oplock_level,
3072 .create_lease_buf = smb3_create_lease_buf,
3073 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05003074 .copychunk_range = smb2_copychunk_range,
Steve French02b16662015-06-27 21:18:36 -07003075 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05003076/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3077 .wp_retry_size = smb2_wp_retry_size,
3078 .dir_needs_close = smb2_dir_needs_close,
3079 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05003080 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07003081 .init_transform_rq = smb3_init_transform_rq,
3082 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08003083 .is_transform_hdr = smb3_is_transform_hdr,
3084 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01003085 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05303086 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10003087#ifdef CONFIG_CIFS_XATTR
3088 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10003089 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10003090#endif /* CIFS_XATTR */
Steve Frenchaab18932015-06-23 23:37:11 -05003091};
3092#endif /* CIFS_SMB311 */
3093
Steve Frenchdd446b12012-11-28 23:21:06 -06003094struct smb_version_values smb20_values = {
3095 .version_string = SMB20_VERSION_STRING,
3096 .protocol_id = SMB20_PROT_ID,
3097 .req_capabilities = 0, /* MBZ */
3098 .large_lock_type = 0,
3099 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3100 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3101 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3102 .header_size = sizeof(struct smb2_hdr),
3103 .max_header_size = MAX_SMB2_HDR_SIZE,
3104 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3105 .lock_cmd = SMB2_LOCK,
3106 .cap_unix = 0,
3107 .cap_nt_find = SMB2_NT_FIND,
3108 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04003109 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3110 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04003111 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06003112};
3113
Steve French1080ef72011-02-24 18:07:19 +00003114struct smb_version_values smb21_values = {
3115 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05003116 .protocol_id = SMB21_PROT_ID,
3117 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3118 .large_lock_type = 0,
3119 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3120 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3121 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3122 .header_size = sizeof(struct smb2_hdr),
3123 .max_header_size = MAX_SMB2_HDR_SIZE,
3124 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3125 .lock_cmd = SMB2_LOCK,
3126 .cap_unix = 0,
3127 .cap_nt_find = SMB2_NT_FIND,
3128 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04003129 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3130 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04003131 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05003132};
3133
Steve French9764c022017-09-17 10:41:35 -05003134struct smb_version_values smb3any_values = {
3135 .version_string = SMB3ANY_VERSION_STRING,
3136 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3137 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3138 .large_lock_type = 0,
3139 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3140 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3141 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3142 .header_size = sizeof(struct smb2_hdr),
3143 .max_header_size = MAX_SMB2_HDR_SIZE,
3144 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3145 .lock_cmd = SMB2_LOCK,
3146 .cap_unix = 0,
3147 .cap_nt_find = SMB2_NT_FIND,
3148 .cap_large_files = SMB2_LARGE_FILES,
3149 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3150 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3151 .create_lease_size = sizeof(struct create_lease_v2),
3152};
3153
3154struct smb_version_values smbdefault_values = {
3155 .version_string = SMBDEFAULT_VERSION_STRING,
3156 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3157 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3158 .large_lock_type = 0,
3159 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3160 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3161 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3162 .header_size = sizeof(struct smb2_hdr),
3163 .max_header_size = MAX_SMB2_HDR_SIZE,
3164 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3165 .lock_cmd = SMB2_LOCK,
3166 .cap_unix = 0,
3167 .cap_nt_find = SMB2_NT_FIND,
3168 .cap_large_files = SMB2_LARGE_FILES,
3169 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3170 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3171 .create_lease_size = sizeof(struct create_lease_v2),
3172};
3173
Steve Frenche4aa25e2012-10-01 12:26:22 -05003174struct smb_version_values smb30_values = {
3175 .version_string = SMB30_VERSION_STRING,
3176 .protocol_id = SMB30_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06003177 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07003178 .large_lock_type = 0,
3179 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3180 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3181 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04003182 .header_size = sizeof(struct smb2_hdr),
3183 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07003184 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04003185 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04003186 .cap_unix = 0,
3187 .cap_nt_find = SMB2_NT_FIND,
3188 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04003189 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3190 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04003191 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00003192};
Steve French20b6d8b2013-06-12 22:48:41 -05003193
3194struct smb_version_values smb302_values = {
3195 .version_string = SMB302_VERSION_STRING,
3196 .protocol_id = SMB302_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06003197 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Steve French20b6d8b2013-06-12 22:48:41 -05003198 .large_lock_type = 0,
3199 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3200 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3201 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3202 .header_size = sizeof(struct smb2_hdr),
3203 .max_header_size = MAX_SMB2_HDR_SIZE,
3204 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3205 .lock_cmd = SMB2_LOCK,
3206 .cap_unix = 0,
3207 .cap_nt_find = SMB2_NT_FIND,
3208 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton502858822013-06-27 12:45:00 -04003209 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3210 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04003211 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05003212};
Steve French5f7fbf72014-12-17 22:52:58 -06003213
3214#ifdef CONFIG_CIFS_SMB311
3215struct smb_version_values smb311_values = {
3216 .version_string = SMB311_VERSION_STRING,
3217 .protocol_id = SMB311_PROT_ID,
Steve French19558802017-06-21 16:50:20 -05003218 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
Steve French5f7fbf72014-12-17 22:52:58 -06003219 .large_lock_type = 0,
3220 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3221 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3222 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3223 .header_size = sizeof(struct smb2_hdr),
3224 .max_header_size = MAX_SMB2_HDR_SIZE,
3225 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3226 .lock_cmd = SMB2_LOCK,
3227 .cap_unix = 0,
3228 .cap_nt_find = SMB2_NT_FIND,
3229 .cap_large_files = SMB2_LARGE_FILES,
3230 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3231 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3232 .create_lease_size = sizeof(struct create_lease_v2),
3233};
3234#endif /* SMB311 */