blob: dfd6fb02b7a3080fa751eaa2531e453f30ece54d [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"
Long Li09902f82017-11-22 17:38:39 -070035#include "smbdirect.h"
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040036
37static int
38change_conf(struct TCP_Server_Info *server)
39{
40 server->credits += server->echo_credits + server->oplock_credits;
41 server->oplock_credits = server->echo_credits = 0;
42 switch (server->credits) {
43 case 0:
44 return -1;
45 case 1:
46 server->echoes = false;
47 server->oplocks = false;
Joe Perchesf96637b2013-05-04 22:12:25 -050048 cifs_dbg(VFS, "disabling echoes and oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040049 break;
50 case 2:
51 server->echoes = true;
52 server->oplocks = false;
53 server->echo_credits = 1;
Joe Perchesf96637b2013-05-04 22:12:25 -050054 cifs_dbg(FYI, "disabling oplocks\n");
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040055 break;
56 default:
57 server->echoes = true;
Steve Frenche0ddde92015-09-22 09:29:38 -050058 if (enable_oplocks) {
59 server->oplocks = true;
60 server->oplock_credits = 1;
61 } else
62 server->oplocks = false;
63
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040064 server->echo_credits = 1;
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040065 }
66 server->credits -= server->echo_credits + server->oplock_credits;
67 return 0;
68}
69
70static void
71smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
72 const int optype)
73{
74 int *val, rc = 0;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
77 *val += add;
Steve French141891f2016-09-23 00:44:16 -050078 if (*val > 65000) {
79 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
80 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
81 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040082 server->in_flight--;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +040083 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040084 rc = change_conf(server);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -070085 /*
86 * Sometimes server returns 0 credits on oplock break ack - we need to
87 * rebalance credits in this case.
88 */
89 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
90 server->oplocks) {
91 if (server->credits > 1) {
92 server->credits--;
93 server->oplock_credits++;
94 }
95 }
Pavel Shilovsky28ea5292012-05-23 16:18:00 +040096 spin_unlock(&server->req_lock);
97 wake_up(&server->request_q);
98 if (rc)
99 cifs_reconnect(server);
100}
101
102static void
103smb2_set_credits(struct TCP_Server_Info *server, const int val)
104{
105 spin_lock(&server->req_lock);
106 server->credits = val;
107 spin_unlock(&server->req_lock);
108}
109
110static int *
111smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
112{
113 switch (optype) {
114 case CIFS_ECHO_OP:
115 return &server->echo_credits;
116 case CIFS_OBREAK_OP:
117 return &server->oplock_credits;
118 default:
119 return &server->credits;
120 }
121}
122
123static unsigned int
124smb2_get_credits(struct mid_q_entry *mid)
125{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700126 struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf);
127
128 return le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky28ea5292012-05-23 16:18:00 +0400129}
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400130
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400131static int
132smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
133 unsigned int *num, unsigned int *credits)
134{
135 int rc = 0;
136 unsigned int scredits;
137
138 spin_lock(&server->req_lock);
139 while (1) {
140 if (server->credits <= 0) {
141 spin_unlock(&server->req_lock);
142 cifs_num_waiters_inc(server);
143 rc = wait_event_killable(server->request_q,
144 has_credits(server, &server->credits));
145 cifs_num_waiters_dec(server);
146 if (rc)
147 return rc;
148 spin_lock(&server->req_lock);
149 } else {
150 if (server->tcpStatus == CifsExiting) {
151 spin_unlock(&server->req_lock);
152 return -ENOENT;
153 }
154
155 scredits = server->credits;
156 /* can deadlock with reopen */
157 if (scredits == 1) {
158 *num = SMB2_MAX_BUFFER_SIZE;
159 *credits = 0;
160 break;
161 }
162
163 /* leave one credit for a possible reopen */
164 scredits--;
165 *num = min_t(unsigned int, size,
166 scredits * SMB2_MAX_BUFFER_SIZE);
167
168 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
169 server->credits -= *credits;
170 server->in_flight++;
171 break;
172 }
173 }
174 spin_unlock(&server->req_lock);
175 return rc;
176}
177
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +0400178static __u64
179smb2_get_next_mid(struct TCP_Server_Info *server)
180{
181 __u64 mid;
182 /* for SMB2 we need the current value */
183 spin_lock(&GlobalMid_Lock);
184 mid = server->CurrentMid++;
185 spin_unlock(&GlobalMid_Lock);
186 return mid;
187}
Steve French1080ef72011-02-24 18:07:19 +0000188
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400189static struct mid_q_entry *
190smb2_find_mid(struct TCP_Server_Info *server, char *buf)
191{
192 struct mid_q_entry *mid;
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700193 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
194 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400195
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700196 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
Steve French373512e2015-12-18 13:05:30 -0600197 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
198 return NULL;
199 }
200
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400201 spin_lock(&GlobalMid_Lock);
202 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
Sachin Prabhu9235d092014-12-09 17:37:00 +0000203 if ((mid->mid == wire_mid) &&
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400204 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700205 (mid->command == shdr->Command)) {
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400206 spin_unlock(&GlobalMid_Lock);
207 return mid;
208 }
209 }
210 spin_unlock(&GlobalMid_Lock);
211 return NULL;
212}
213
214static void
215smb2_dump_detail(void *buf)
216{
217#ifdef CONFIG_CIFS_DEBUG2
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700218 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400219
Joe Perchesf96637b2013-05-04 22:12:25 -0500220 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700221 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
222 shdr->ProcessId);
223 cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf));
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400224#endif
225}
226
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400227static bool
228smb2_need_neg(struct TCP_Server_Info *server)
229{
230 return server->max_read == 0;
231}
232
233static int
234smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
235{
236 int rc;
237 ses->server->CurrentMid = 0;
238 rc = SMB2_negotiate(xid, ses);
239 /* BB we probably don't need to retry with modern servers */
240 if (rc == -EAGAIN)
241 rc = -EHOSTDOWN;
242 return rc;
243}
244
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700245static unsigned int
246smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
247{
248 struct TCP_Server_Info *server = tcon->ses->server;
249 unsigned int wsize;
250
251 /* start with specified wsize, or default */
252 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
253 wsize = min_t(unsigned int, wsize, server->max_write);
Long Li09902f82017-11-22 17:38:39 -0700254#ifdef CONFIG_CIFS_SMB_DIRECT
255 if (server->rdma)
256 wsize = min_t(unsigned int,
257 wsize, server->smbd_conn->max_readwrite_size);
258#endif
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +0400259 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
260 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700261
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700262 return wsize;
263}
264
265static unsigned int
266smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
267{
268 struct TCP_Server_Info *server = tcon->ses->server;
269 unsigned int rsize;
270
271 /* start with specified rsize, or default */
272 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
273 rsize = min_t(unsigned int, rsize, server->max_read);
Long Li09902f82017-11-22 17:38:39 -0700274#ifdef CONFIG_CIFS_SMB_DIRECT
275 if (server->rdma)
276 rsize = min_t(unsigned int,
277 rsize, server->smbd_conn->max_readwrite_size);
278#endif
Pavel Shilovskybed9da02014-06-25 11:28:57 +0400279
280 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
281 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700282
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -0700283 return rsize;
284}
285
Steve Frenchc481e9f2013-10-14 01:21:53 -0500286#ifdef CONFIG_CIFS_STATS2
287static int
288SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
289{
290 int rc;
291 unsigned int ret_data_len = 0;
292 struct network_interface_info_ioctl_rsp *out_buf;
293
294 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
295 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
296 NULL /* no data input */, 0 /* no data input */,
297 (char **)&out_buf, &ret_data_len);
Steve French9ffc5412014-10-16 15:13:14 -0500298 if (rc != 0)
299 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
300 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
301 cifs_dbg(VFS, "server returned bad net interface info buf\n");
302 rc = -EINVAL;
303 } else {
Steve Frenchc481e9f2013-10-14 01:21:53 -0500304 /* Dump info on first interface */
305 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
306 le32_to_cpu(out_buf->Capability));
307 cifs_dbg(FYI, "Link Speed %lld\n",
308 le64_to_cpu(out_buf->LinkSpeed));
Steve French9ffc5412014-10-16 15:13:14 -0500309 }
Steve French24df1482016-09-29 04:20:23 -0500310 kfree(out_buf);
Steve Frenchc481e9f2013-10-14 01:21:53 -0500311 return rc;
312}
313#endif /* STATS2 */
314
Steve French34f62642013-10-09 02:07:00 -0500315static void
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500316smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
317{
318 int rc;
319 __le16 srch_path = 0; /* Null - open root of share */
320 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
321 struct cifs_open_parms oparms;
322 struct cifs_fid fid;
323
324 oparms.tcon = tcon;
325 oparms.desired_access = FILE_READ_ATTRIBUTES;
326 oparms.disposition = FILE_OPEN;
327 oparms.create_options = 0;
328 oparms.fid = &fid;
329 oparms.reconnect = false;
330
331 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
332 if (rc)
333 return;
334
Steve Frenchc481e9f2013-10-14 01:21:53 -0500335#ifdef CONFIG_CIFS_STATS2
336 SMB3_request_interfaces(xid, tcon);
337#endif /* STATS2 */
338
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500339 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
340 FS_ATTRIBUTE_INFORMATION);
341 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
342 FS_DEVICE_INFORMATION);
343 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
344 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
345 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
346 return;
347}
348
349static void
Steve French34f62642013-10-09 02:07:00 -0500350smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
351{
352 int rc;
353 __le16 srch_path = 0; /* Null - open root of share */
354 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
355 struct cifs_open_parms oparms;
356 struct cifs_fid fid;
357
358 oparms.tcon = tcon;
359 oparms.desired_access = FILE_READ_ATTRIBUTES;
360 oparms.disposition = FILE_OPEN;
361 oparms.create_options = 0;
362 oparms.fid = &fid;
363 oparms.reconnect = false;
364
365 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
366 if (rc)
367 return;
368
Steven French21671142013-10-09 13:36:35 -0500369 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
370 FS_ATTRIBUTE_INFORMATION);
371 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
372 FS_DEVICE_INFORMATION);
Steve French34f62642013-10-09 02:07:00 -0500373 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
374 return;
375}
376
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400377static int
378smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
379 struct cifs_sb_info *cifs_sb, const char *full_path)
380{
381 int rc;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400382 __le16 *utf16_path;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -0700383 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400384 struct cifs_open_parms oparms;
385 struct cifs_fid fid;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400386
387 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
388 if (!utf16_path)
389 return -ENOMEM;
390
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400391 oparms.tcon = tcon;
392 oparms.desired_access = FILE_READ_ATTRIBUTES;
393 oparms.disposition = FILE_OPEN;
394 oparms.create_options = 0;
395 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400396 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400397
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400398 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400399 if (rc) {
400 kfree(utf16_path);
401 return rc;
402 }
403
Pavel Shilovsky064f6042013-07-09 18:20:30 +0400404 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400405 kfree(utf16_path);
406 return rc;
407}
408
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400409static int
410smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
411 struct cifs_sb_info *cifs_sb, const char *full_path,
412 u64 *uniqueid, FILE_ALL_INFO *data)
413{
414 *uniqueid = le64_to_cpu(data->IndexNumber);
415 return 0;
416}
417
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700418static int
419smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
420 struct cifs_fid *fid, FILE_ALL_INFO *data)
421{
422 int rc;
423 struct smb2_file_all_info *smb2_data;
424
Pavel Shilovsky1bbe4992014-08-22 13:32:11 +0400425 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -0700426 GFP_KERNEL);
427 if (smb2_data == NULL)
428 return -ENOMEM;
429
430 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
431 smb2_data);
432 if (!rc)
433 move_smb2_info_to_cifs(data, smb2_data);
434 kfree(smb2_data);
435 return rc;
436}
437
Arnd Bergmann1368f152017-09-05 11:24:15 +0200438#ifdef CONFIG_CIFS_XATTR
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000439static ssize_t
440move_smb2_ea_to_cifs(char *dst, size_t dst_size,
441 struct smb2_file_full_ea_info *src, size_t src_size,
442 const unsigned char *ea_name)
443{
444 int rc = 0;
445 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
446 char *name, *value;
447 size_t name_len, value_len, user_name_len;
448
449 while (src_size > 0) {
450 name = &src->ea_data[0];
451 name_len = (size_t)src->ea_name_length;
452 value = &src->ea_data[src->ea_name_length + 1];
453 value_len = (size_t)le16_to_cpu(src->ea_value_length);
454
455 if (name_len == 0) {
456 break;
457 }
458
459 if (src_size < 8 + name_len + 1 + value_len) {
460 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
461 rc = -EIO;
462 goto out;
463 }
464
465 if (ea_name) {
466 if (ea_name_len == name_len &&
467 memcmp(ea_name, name, name_len) == 0) {
468 rc = value_len;
469 if (dst_size == 0)
470 goto out;
471 if (dst_size < value_len) {
472 rc = -ERANGE;
473 goto out;
474 }
475 memcpy(dst, value, value_len);
476 goto out;
477 }
478 } else {
479 /* 'user.' plus a terminating null */
480 user_name_len = 5 + 1 + name_len;
481
482 rc += user_name_len;
483
484 if (dst_size >= user_name_len) {
485 dst_size -= user_name_len;
486 memcpy(dst, "user.", 5);
487 dst += 5;
488 memcpy(dst, src->ea_data, name_len);
489 dst += name_len;
490 *dst = 0;
491 ++dst;
492 } else if (dst_size == 0) {
493 /* skip copy - calc size only */
494 } else {
495 /* stop before overrun buffer */
496 rc = -ERANGE;
497 break;
498 }
499 }
500
501 if (!src->next_entry_offset)
502 break;
503
504 if (src_size < le32_to_cpu(src->next_entry_offset)) {
505 /* stop before overrun buffer */
506 rc = -ERANGE;
507 break;
508 }
509 src_size -= le32_to_cpu(src->next_entry_offset);
510 src = (void *)((char *)src +
511 le32_to_cpu(src->next_entry_offset));
512 }
513
514 /* didn't find the named attribute */
515 if (ea_name)
516 rc = -ENODATA;
517
518out:
519 return (ssize_t)rc;
520}
521
522static ssize_t
523smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
524 const unsigned char *path, const unsigned char *ea_name,
525 char *ea_data, size_t buf_size,
526 struct cifs_sb_info *cifs_sb)
527{
528 int rc;
529 __le16 *utf16_path;
530 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
531 struct cifs_open_parms oparms;
532 struct cifs_fid fid;
533 struct smb2_file_full_ea_info *smb2_data;
Ronnie Sahlberg7cb3def2017-09-28 09:39:58 +1000534 int ea_buf_size = SMB2_MIN_EA_BUF;
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000535
536 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
537 if (!utf16_path)
538 return -ENOMEM;
539
540 oparms.tcon = tcon;
541 oparms.desired_access = FILE_READ_EA;
542 oparms.disposition = FILE_OPEN;
543 oparms.create_options = 0;
544 oparms.fid = &fid;
545 oparms.reconnect = false;
546
547 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
548 kfree(utf16_path);
549 if (rc) {
550 cifs_dbg(FYI, "open failed rc=%d\n", rc);
551 return rc;
552 }
553
Ronnie Sahlberg7cb3def2017-09-28 09:39:58 +1000554 while (1) {
555 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
556 if (smb2_data == NULL) {
557 SMB2_close(xid, tcon, fid.persistent_fid,
558 fid.volatile_fid);
559 return -ENOMEM;
560 }
561
562 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
563 fid.volatile_fid,
564 ea_buf_size, smb2_data);
565
566 if (rc != -E2BIG)
567 break;
568
569 kfree(smb2_data);
570 ea_buf_size <<= 1;
571
572 if (ea_buf_size > SMB2_MAX_EA_BUF) {
573 cifs_dbg(VFS, "EA size is too large\n");
574 SMB2_close(xid, tcon, fid.persistent_fid,
575 fid.volatile_fid);
576 return -ENOMEM;
577 }
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000578 }
579
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +1000580 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
581
582 if (!rc)
583 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
584 SMB2_MAX_EA_BUF, ea_name);
585
586 kfree(smb2_data);
587 return rc;
588}
589
Ronnie Sahlberg55175542017-08-24 11:24:56 +1000590
591static int
592smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
593 const char *path, const char *ea_name, const void *ea_value,
594 const __u16 ea_value_len, const struct nls_table *nls_codepage,
595 struct cifs_sb_info *cifs_sb)
596{
597 int rc;
598 __le16 *utf16_path;
599 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
600 struct cifs_open_parms oparms;
601 struct cifs_fid fid;
602 struct smb2_file_full_ea_info *ea;
603 int ea_name_len = strlen(ea_name);
604 int len;
605
606 if (ea_name_len > 255)
607 return -EINVAL;
608
609 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
610 if (!utf16_path)
611 return -ENOMEM;
612
613 oparms.tcon = tcon;
614 oparms.desired_access = FILE_WRITE_EA;
615 oparms.disposition = FILE_OPEN;
616 oparms.create_options = 0;
617 oparms.fid = &fid;
618 oparms.reconnect = false;
619
620 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
621 kfree(utf16_path);
622 if (rc) {
623 cifs_dbg(FYI, "open failed rc=%d\n", rc);
624 return rc;
625 }
626
627 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
628 ea = kzalloc(len, GFP_KERNEL);
629 if (ea == NULL) {
630 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
631 return -ENOMEM;
632 }
633
634 ea->ea_name_length = ea_name_len;
635 ea->ea_value_length = cpu_to_le16(ea_value_len);
636 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
637 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
638
639 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
640 len);
641 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
642
643 return rc;
644}
Arnd Bergmann1368f152017-09-05 11:24:15 +0200645#endif
Ronnie Sahlberg55175542017-08-24 11:24:56 +1000646
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400647static bool
648smb2_can_echo(struct TCP_Server_Info *server)
649{
650 return server->echoes;
651}
652
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400653static void
654smb2_clear_stats(struct cifs_tcon *tcon)
655{
656#ifdef CONFIG_CIFS_STATS
657 int i;
658 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
659 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
660 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
661 }
662#endif
663}
664
665static void
Steve French769ee6a2013-06-19 14:15:30 -0500666smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
667{
668 seq_puts(m, "\n\tShare Capabilities:");
669 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
670 seq_puts(m, " DFS,");
671 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
672 seq_puts(m, " CONTINUOUS AVAILABILITY,");
673 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
674 seq_puts(m, " SCALEOUT,");
675 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
676 seq_puts(m, " CLUSTER,");
677 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
678 seq_puts(m, " ASYMMETRIC,");
679 if (tcon->capabilities == 0)
680 seq_puts(m, " None");
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500681 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
682 seq_puts(m, " Aligned,");
683 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
684 seq_puts(m, " Partition Aligned,");
685 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
686 seq_puts(m, " SSD,");
687 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
688 seq_puts(m, " TRIM-support,");
689
Steve French769ee6a2013-06-19 14:15:30 -0500690 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
Steven Frenchaf6a12e2013-10-09 20:55:53 -0500691 if (tcon->perf_sector_size)
692 seq_printf(m, "\tOptimal sector size: 0x%x",
693 tcon->perf_sector_size);
Steve French769ee6a2013-06-19 14:15:30 -0500694}
695
696static void
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400697smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
698{
699#ifdef CONFIG_CIFS_STATS
700 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
701 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
702 seq_printf(m, "\nNegotiates: %d sent %d failed",
703 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
704 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
705 seq_printf(m, "\nSessionSetups: %d sent %d failed",
706 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
707 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
Pavel Shilovskyd60622e2012-05-28 15:19:39 +0400708 seq_printf(m, "\nLogoffs: %d sent %d failed",
709 atomic_read(&sent[SMB2_LOGOFF_HE]),
710 atomic_read(&failed[SMB2_LOGOFF_HE]));
711 seq_printf(m, "\nTreeConnects: %d sent %d failed",
712 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
713 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
714 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
715 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
716 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
717 seq_printf(m, "\nCreates: %d sent %d failed",
718 atomic_read(&sent[SMB2_CREATE_HE]),
719 atomic_read(&failed[SMB2_CREATE_HE]));
720 seq_printf(m, "\nCloses: %d sent %d failed",
721 atomic_read(&sent[SMB2_CLOSE_HE]),
722 atomic_read(&failed[SMB2_CLOSE_HE]));
723 seq_printf(m, "\nFlushes: %d sent %d failed",
724 atomic_read(&sent[SMB2_FLUSH_HE]),
725 atomic_read(&failed[SMB2_FLUSH_HE]));
726 seq_printf(m, "\nReads: %d sent %d failed",
727 atomic_read(&sent[SMB2_READ_HE]),
728 atomic_read(&failed[SMB2_READ_HE]));
729 seq_printf(m, "\nWrites: %d sent %d failed",
730 atomic_read(&sent[SMB2_WRITE_HE]),
731 atomic_read(&failed[SMB2_WRITE_HE]));
732 seq_printf(m, "\nLocks: %d sent %d failed",
733 atomic_read(&sent[SMB2_LOCK_HE]),
734 atomic_read(&failed[SMB2_LOCK_HE]));
735 seq_printf(m, "\nIOCTLs: %d sent %d failed",
736 atomic_read(&sent[SMB2_IOCTL_HE]),
737 atomic_read(&failed[SMB2_IOCTL_HE]));
738 seq_printf(m, "\nCancels: %d sent %d failed",
739 atomic_read(&sent[SMB2_CANCEL_HE]),
740 atomic_read(&failed[SMB2_CANCEL_HE]));
741 seq_printf(m, "\nEchos: %d sent %d failed",
742 atomic_read(&sent[SMB2_ECHO_HE]),
743 atomic_read(&failed[SMB2_ECHO_HE]));
744 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
745 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
746 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
747 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
748 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
749 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
750 seq_printf(m, "\nQueryInfos: %d sent %d failed",
751 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
752 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
753 seq_printf(m, "\nSetInfos: %d sent %d failed",
754 atomic_read(&sent[SMB2_SET_INFO_HE]),
755 atomic_read(&failed[SMB2_SET_INFO_HE]));
756 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
757 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
758 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
759#endif
760}
761
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700762static void
763smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
764{
David Howells2b0143b2015-03-17 22:25:59 +0000765 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400766 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
767
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700768 cfile->fid.persistent_fid = fid->persistent_fid;
769 cfile->fid.volatile_fid = fid->volatile_fid;
Pavel Shilovsky42873b02013-09-05 21:30:16 +0400770 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
771 &fid->purge_cache);
Pavel Shilovsky18cceb62013-09-05 13:01:06 +0400772 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
Aurelien Aptel94f87372016-09-22 07:38:50 +0200773 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700774}
775
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400776static void
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700777smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
778 struct cifs_fid *fid)
779{
Pavel Shilovsky760ad0c2012-09-25 11:00:07 +0400780 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700781}
782
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700783static int
Steve French41c13582013-11-14 00:05:36 -0600784SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
785 u64 persistent_fid, u64 volatile_fid,
786 struct copychunk_ioctl *pcchunk)
787{
788 int rc;
789 unsigned int ret_data_len;
790 struct resume_key_req *res_key;
791
792 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
793 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
794 NULL, 0 /* no input */,
795 (char **)&res_key, &ret_data_len);
796
797 if (rc) {
798 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
799 goto req_res_key_exit;
800 }
801 if (ret_data_len < sizeof(struct resume_key_req)) {
802 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
803 rc = -EINVAL;
804 goto req_res_key_exit;
805 }
806 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
807
808req_res_key_exit:
809 kfree(res_key);
810 return rc;
811}
812
Sachin Prabhu620d8742017-02-10 16:03:51 +0530813static ssize_t
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500814smb2_copychunk_range(const unsigned int xid,
Steve French41c13582013-11-14 00:05:36 -0600815 struct cifsFileInfo *srcfile,
816 struct cifsFileInfo *trgtfile, u64 src_off,
817 u64 len, u64 dest_off)
818{
819 int rc;
820 unsigned int ret_data_len;
821 struct copychunk_ioctl *pcchunk;
Steve French9bf0c9c2013-11-16 18:05:28 -0600822 struct copychunk_ioctl_rsp *retbuf = NULL;
823 struct cifs_tcon *tcon;
824 int chunks_copied = 0;
825 bool chunk_sizes_updated = false;
Sachin Prabhu620d8742017-02-10 16:03:51 +0530826 ssize_t bytes_written, total_bytes_written = 0;
Steve French41c13582013-11-14 00:05:36 -0600827
828 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
829
830 if (pcchunk == NULL)
831 return -ENOMEM;
832
Sachin Prabhu312bbc52017-04-04 02:12:04 -0500833 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
Steve French41c13582013-11-14 00:05:36 -0600834 /* Request a key from the server to identify the source of the copy */
835 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
836 srcfile->fid.persistent_fid,
837 srcfile->fid.volatile_fid, pcchunk);
838
839 /* Note: request_res_key sets res_key null only if rc !=0 */
840 if (rc)
Steve French9bf0c9c2013-11-16 18:05:28 -0600841 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600842
843 /* For now array only one chunk long, will make more flexible later */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800844 pcchunk->ChunkCount = cpu_to_le32(1);
Steve French41c13582013-11-14 00:05:36 -0600845 pcchunk->Reserved = 0;
Steve French41c13582013-11-14 00:05:36 -0600846 pcchunk->Reserved2 = 0;
847
Steve French9bf0c9c2013-11-16 18:05:28 -0600848 tcon = tlink_tcon(trgtfile->tlink);
849
850 while (len > 0) {
851 pcchunk->SourceOffset = cpu_to_le64(src_off);
852 pcchunk->TargetOffset = cpu_to_le64(dest_off);
853 pcchunk->Length =
854 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
855
856 /* Request server copy to target from src identified by key */
857 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
Steve French41c13582013-11-14 00:05:36 -0600858 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
Aurelien Aptel63a83b82018-01-24 13:46:11 +0100859 true /* is_fsctl */, (char *)pcchunk,
Steve French9bf0c9c2013-11-16 18:05:28 -0600860 sizeof(struct copychunk_ioctl), (char **)&retbuf,
861 &ret_data_len);
862 if (rc == 0) {
863 if (ret_data_len !=
864 sizeof(struct copychunk_ioctl_rsp)) {
865 cifs_dbg(VFS, "invalid cchunk response size\n");
866 rc = -EIO;
867 goto cchunk_out;
868 }
869 if (retbuf->TotalBytesWritten == 0) {
870 cifs_dbg(FYI, "no bytes copied\n");
871 rc = -EIO;
872 goto cchunk_out;
873 }
874 /*
875 * Check if server claimed to write more than we asked
876 */
877 if (le32_to_cpu(retbuf->TotalBytesWritten) >
878 le32_to_cpu(pcchunk->Length)) {
879 cifs_dbg(VFS, "invalid copy chunk response\n");
880 rc = -EIO;
881 goto cchunk_out;
882 }
883 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
884 cifs_dbg(VFS, "invalid num chunks written\n");
885 rc = -EIO;
886 goto cchunk_out;
887 }
888 chunks_copied++;
Steve French41c13582013-11-14 00:05:36 -0600889
Sachin Prabhu620d8742017-02-10 16:03:51 +0530890 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
891 src_off += bytes_written;
892 dest_off += bytes_written;
893 len -= bytes_written;
894 total_bytes_written += bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600895
Sachin Prabhu620d8742017-02-10 16:03:51 +0530896 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
Steve French9bf0c9c2013-11-16 18:05:28 -0600897 le32_to_cpu(retbuf->ChunksWritten),
898 le32_to_cpu(retbuf->ChunkBytesWritten),
Sachin Prabhu620d8742017-02-10 16:03:51 +0530899 bytes_written);
Steve French9bf0c9c2013-11-16 18:05:28 -0600900 } else if (rc == -EINVAL) {
901 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
902 goto cchunk_out;
Steve French41c13582013-11-14 00:05:36 -0600903
Steve French9bf0c9c2013-11-16 18:05:28 -0600904 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
905 le32_to_cpu(retbuf->ChunksWritten),
906 le32_to_cpu(retbuf->ChunkBytesWritten),
907 le32_to_cpu(retbuf->TotalBytesWritten));
908
909 /*
910 * Check if this is the first request using these sizes,
911 * (ie check if copy succeed once with original sizes
912 * and check if the server gave us different sizes after
913 * we already updated max sizes on previous request).
914 * if not then why is the server returning an error now
915 */
916 if ((chunks_copied != 0) || chunk_sizes_updated)
917 goto cchunk_out;
918
919 /* Check that server is not asking us to grow size */
920 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
921 tcon->max_bytes_chunk)
922 tcon->max_bytes_chunk =
923 le32_to_cpu(retbuf->ChunkBytesWritten);
924 else
925 goto cchunk_out; /* server gave us bogus size */
926
927 /* No need to change MaxChunks since already set to 1 */
928 chunk_sizes_updated = true;
Sachin Prabhu2477bc52015-02-04 13:10:26 +0000929 } else
930 goto cchunk_out;
Steve French9bf0c9c2013-11-16 18:05:28 -0600931 }
932
933cchunk_out:
Steve French41c13582013-11-14 00:05:36 -0600934 kfree(pcchunk);
Steve French24df1482016-09-29 04:20:23 -0500935 kfree(retbuf);
Sachin Prabhu620d8742017-02-10 16:03:51 +0530936 if (rc)
937 return rc;
938 else
939 return total_bytes_written;
Steve French41c13582013-11-14 00:05:36 -0600940}
941
942static int
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700943smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
944 struct cifs_fid *fid)
945{
946 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
947}
948
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700949static unsigned int
950smb2_read_data_offset(char *buf)
951{
952 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
953 return rsp->DataOffset;
954}
955
956static unsigned int
Long Li74dcf412017-11-22 17:38:46 -0700957smb2_read_data_length(char *buf, bool in_remaining)
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700958{
959 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
Long Li74dcf412017-11-22 17:38:46 -0700960
961 if (in_remaining)
962 return le32_to_cpu(rsp->DataRemaining);
963
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700964 return le32_to_cpu(rsp->DataLength);
965}
966
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700967
968static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500969smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700970 struct cifs_io_parms *parms, unsigned int *bytes_read,
971 char **buf, int *buf_type)
972{
Steve Frenchdb8b6312014-09-22 05:13:55 -0500973 parms->persistent_fid = pfid->persistent_fid;
974 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovskyd8e05032012-09-18 16:20:30 -0700975 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
976}
977
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700978static int
Steve Frenchdb8b6312014-09-22 05:13:55 -0500979smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700980 struct cifs_io_parms *parms, unsigned int *written,
981 struct kvec *iov, unsigned long nr_segs)
982{
983
Steve Frenchdb8b6312014-09-22 05:13:55 -0500984 parms->persistent_fid = pfid->persistent_fid;
985 parms->volatile_fid = pfid->volatile_fid;
Pavel Shilovsky009d3442012-09-18 16:20:30 -0700986 return SMB2_write(xid, parms, written, iov, nr_segs);
987}
988
Steve Frenchd43cc792014-08-13 17:16:29 -0500989/* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
990static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
991 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
992{
993 struct cifsInodeInfo *cifsi;
994 int rc;
995
996 cifsi = CIFS_I(inode);
997
998 /* if file already sparse don't bother setting sparse again */
999 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1000 return true; /* already sparse */
1001
1002 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1003 return true; /* already not sparse */
1004
1005 /*
1006 * Can't check for sparse support on share the usual way via the
1007 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1008 * since Samba server doesn't set the flag on the share, yet
1009 * supports the set sparse FSCTL and returns sparse correctly
1010 * in the file attributes. If we fail setting sparse though we
1011 * mark that server does not support sparse files for this share
1012 * to avoid repeatedly sending the unsupported fsctl to server
1013 * if the file is repeatedly extended.
1014 */
1015 if (tcon->broken_sparse_sup)
1016 return false;
1017
1018 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1019 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001020 true /* is_fctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +01001021 &setsparse, 1, NULL, NULL);
Steve Frenchd43cc792014-08-13 17:16:29 -05001022 if (rc) {
1023 tcon->broken_sparse_sup = true;
1024 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1025 return false;
1026 }
1027
1028 if (setsparse)
1029 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1030 else
1031 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1032
1033 return true;
1034}
1035
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001036static int
1037smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1038 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1039{
1040 __le64 eof = cpu_to_le64(size);
Steve French3d1a3742014-08-11 21:05:25 -05001041 struct inode *inode;
1042
1043 /*
1044 * If extending file more than one page make sparse. Many Linux fs
1045 * make files sparse by default when extending via ftruncate
1046 */
David Howells2b0143b2015-03-17 22:25:59 +00001047 inode = d_inode(cfile->dentry);
Steve French3d1a3742014-08-11 21:05:25 -05001048
1049 if (!set_alloc && (size > inode->i_size + 8192)) {
Steve French3d1a3742014-08-11 21:05:25 -05001050 __u8 set_sparse = 1;
Steve French3d1a3742014-08-11 21:05:25 -05001051
Steve Frenchd43cc792014-08-13 17:16:29 -05001052 /* whether set sparse succeeds or not, extend the file */
1053 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
Steve French3d1a3742014-08-11 21:05:25 -05001054 }
1055
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001056 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Steve Frenchf29ebb42014-07-19 21:44:58 -05001057 cfile->fid.volatile_fid, cfile->pid, &eof, false);
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001058}
1059
Steve French02b16662015-06-27 21:18:36 -07001060static int
1061smb2_duplicate_extents(const unsigned int xid,
1062 struct cifsFileInfo *srcfile,
1063 struct cifsFileInfo *trgtfile, u64 src_off,
1064 u64 len, u64 dest_off)
1065{
1066 int rc;
1067 unsigned int ret_data_len;
Steve French02b16662015-06-27 21:18:36 -07001068 struct duplicate_extents_to_file dup_ext_buf;
1069 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1070
1071 /* server fileays advertise duplicate extent support with this flag */
1072 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1073 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1074 return -EOPNOTSUPP;
1075
1076 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1077 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1078 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1079 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1080 dup_ext_buf.ByteCount = cpu_to_le64(len);
1081 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1082 src_off, dest_off, len);
1083
1084 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1085 if (rc)
1086 goto duplicate_extents_out;
1087
1088 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1089 trgtfile->fid.volatile_fid,
1090 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001091 true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +01001092 (char *)&dup_ext_buf,
Steve French02b16662015-06-27 21:18:36 -07001093 sizeof(struct duplicate_extents_to_file),
Steve French24df1482016-09-29 04:20:23 -05001094 NULL,
Steve French02b16662015-06-27 21:18:36 -07001095 &ret_data_len);
1096
1097 if (ret_data_len > 0)
1098 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1099
1100duplicate_extents_out:
1101 return rc;
1102}
Steve French02b16662015-06-27 21:18:36 -07001103
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001104static int
Steve French64a5cfa2013-10-14 15:31:32 -05001105smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1106 struct cifsFileInfo *cfile)
1107{
1108 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1109 cfile->fid.volatile_fid);
1110}
1111
1112static int
Steve Frenchb3152e22015-06-24 03:17:02 -05001113smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1114 struct cifsFileInfo *cfile)
1115{
1116 struct fsctl_set_integrity_information_req integr_info;
Steve Frenchb3152e22015-06-24 03:17:02 -05001117 unsigned int ret_data_len;
1118
1119 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1120 integr_info.Flags = 0;
1121 integr_info.Reserved = 0;
1122
1123 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1124 cfile->fid.volatile_fid,
1125 FSCTL_SET_INTEGRITY_INFORMATION,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001126 true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +01001127 (char *)&integr_info,
Steve Frenchb3152e22015-06-24 03:17:02 -05001128 sizeof(struct fsctl_set_integrity_information_req),
Steve French24df1482016-09-29 04:20:23 -05001129 NULL,
Steve Frenchb3152e22015-06-24 03:17:02 -05001130 &ret_data_len);
1131
1132}
1133
1134static int
Steve French834170c2016-09-30 21:14:26 -05001135smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1136 struct cifsFileInfo *cfile, void __user *ioc_buf)
1137{
1138 char *retbuf = NULL;
1139 unsigned int ret_data_len = 0;
1140 int rc;
1141 struct smb_snapshot_array snapshot_in;
1142
1143 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1144 cfile->fid.volatile_fid,
1145 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001146 true /* is_fsctl */,
Aurelien Aptel51146622017-02-28 15:08:41 +01001147 NULL, 0 /* no input data */,
Steve French834170c2016-09-30 21:14:26 -05001148 (char **)&retbuf,
1149 &ret_data_len);
1150 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1151 rc, ret_data_len);
1152 if (rc)
1153 return rc;
1154
1155 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1156 /* Fixup buffer */
1157 if (copy_from_user(&snapshot_in, ioc_buf,
1158 sizeof(struct smb_snapshot_array))) {
1159 rc = -EFAULT;
1160 kfree(retbuf);
1161 return rc;
1162 }
1163 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
1164 rc = -ERANGE;
David Disseldorp0e5c7952017-05-03 17:39:09 +02001165 kfree(retbuf);
Steve French834170c2016-09-30 21:14:26 -05001166 return rc;
1167 }
1168
1169 if (ret_data_len > snapshot_in.snapshot_array_size)
1170 ret_data_len = snapshot_in.snapshot_array_size;
1171
1172 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1173 rc = -EFAULT;
1174 }
1175
1176 kfree(retbuf);
1177 return rc;
1178}
1179
1180static int
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001181smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1182 const char *path, struct cifs_sb_info *cifs_sb,
1183 struct cifs_fid *fid, __u16 search_flags,
1184 struct cifs_search_info *srch_inf)
1185{
1186 __le16 *utf16_path;
1187 int rc;
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001188 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001189 struct cifs_open_parms oparms;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001190
1191 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1192 if (!utf16_path)
1193 return -ENOMEM;
1194
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001195 oparms.tcon = tcon;
1196 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1197 oparms.disposition = FILE_OPEN;
1198 oparms.create_options = 0;
1199 oparms.fid = fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001200 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001201
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001202 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001203 kfree(utf16_path);
1204 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -07001205 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001206 return rc;
1207 }
1208
1209 srch_inf->entries_in_buffer = 0;
1210 srch_inf->index_of_last_entry = 0;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001211
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001212 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1213 fid->volatile_fid, 0, srch_inf);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001214 if (rc) {
Pavel Shilovskydcd878382017-06-06 16:58:58 -07001215 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001216 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001217 }
1218 return rc;
1219}
1220
1221static int
1222smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1223 struct cifs_fid *fid, __u16 search_flags,
1224 struct cifs_search_info *srch_inf)
1225{
1226 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1227 fid->volatile_fid, 0, srch_inf);
1228}
1229
1230static int
1231smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1232 struct cifs_fid *fid)
1233{
1234 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1235}
1236
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001237/*
1238* If we negotiate SMB2 protocol and get STATUS_PENDING - update
1239* the number of credits and return true. Otherwise - return false.
1240*/
1241static bool
1242smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1243{
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001244 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001245
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001246 if (shdr->Status != STATUS_PENDING)
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001247 return false;
1248
1249 if (!length) {
1250 spin_lock(&server->req_lock);
Pavel Shilovsky31473fc2016-10-24 15:33:04 -07001251 server->credits += le16_to_cpu(shdr->CreditRequest);
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07001252 spin_unlock(&server->req_lock);
1253 wake_up(&server->request_q);
1254 }
1255
1256 return true;
1257}
1258
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07001259static bool
1260smb2_is_session_expired(char *buf)
1261{
1262 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
1263
1264 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
1265 return false;
1266
1267 cifs_dbg(FYI, "Session expired\n");
1268 return true;
1269}
1270
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001271static int
1272smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1273 struct cifsInodeInfo *cinode)
1274{
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001275 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1276 return SMB2_lease_break(0, tcon, cinode->lease_key,
1277 smb2_get_lease_state(cinode));
1278
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001279 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1280 fid->volatile_fid,
Pavel Shilovsky18cceb62013-09-05 13:01:06 +04001281 CIFS_CACHE_READ(cinode) ? 1 : 0);
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001282}
1283
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001284static int
1285smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1286 struct kstatfs *buf)
1287{
1288 int rc;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001289 __le16 srch_path = 0; /* Null - open root of share */
1290 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001291 struct cifs_open_parms oparms;
1292 struct cifs_fid fid;
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001293
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001294 oparms.tcon = tcon;
1295 oparms.desired_access = FILE_READ_ATTRIBUTES;
1296 oparms.disposition = FILE_OPEN;
1297 oparms.create_options = 0;
1298 oparms.fid = &fid;
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +04001299 oparms.reconnect = false;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001300
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001301 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001302 if (rc)
1303 return rc;
1304 buf->f_type = SMB2_MAGIC_NUMBER;
Pavel Shilovsky064f6042013-07-09 18:20:30 +04001305 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1306 buf);
1307 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001308 return rc;
1309}
1310
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001311static bool
1312smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1313{
1314 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1315 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1316}
1317
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001318static int
1319smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1320 __u64 length, __u32 type, int lock, int unlock, bool wait)
1321{
1322 if (unlock && !lock)
1323 type = SMB2_LOCKFLAG_UNLOCK;
1324 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1325 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1326 current->tgid, length, offset, type, wait);
1327}
1328
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001329static void
1330smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1331{
1332 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1333}
1334
1335static void
1336smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1337{
1338 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1339}
1340
1341static void
1342smb2_new_lease_key(struct cifs_fid *fid)
1343{
Steve Frenchfa70b872016-09-22 00:39:34 -05001344 generate_random_uuid(fid->lease_key);
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07001345}
1346
Aurelien Aptel9d496402017-02-13 16:16:49 +01001347static int
1348smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1349 const char *search_name,
1350 struct dfs_info3_param **target_nodes,
1351 unsigned int *num_of_nodes,
1352 const struct nls_table *nls_codepage, int remap)
1353{
1354 int rc;
1355 __le16 *utf16_path = NULL;
1356 int utf16_path_len = 0;
1357 struct cifs_tcon *tcon;
1358 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1359 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1360 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1361
1362 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1363
1364 /*
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001365 * Try to use the IPC tcon, otherwise just use any
Aurelien Aptel9d496402017-02-13 16:16:49 +01001366 */
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001367 tcon = ses->tcon_ipc;
1368 if (tcon == NULL) {
1369 spin_lock(&cifs_tcp_ses_lock);
1370 tcon = list_first_entry_or_null(&ses->tcon_list,
1371 struct cifs_tcon,
1372 tcon_list);
1373 if (tcon)
1374 tcon->tc_count++;
1375 spin_unlock(&cifs_tcp_ses_lock);
1376 }
Aurelien Aptel9d496402017-02-13 16:16:49 +01001377
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001378 if (tcon == NULL) {
Aurelien Aptel9d496402017-02-13 16:16:49 +01001379 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1380 ses);
1381 rc = -ENOTCONN;
1382 goto out;
1383 }
1384
1385 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1386 &utf16_path_len,
1387 nls_codepage, remap);
1388 if (!utf16_path) {
1389 rc = -ENOMEM;
1390 goto out;
1391 }
1392
1393 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1394 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1395 if (!dfs_req) {
1396 rc = -ENOMEM;
1397 goto out;
1398 }
1399
1400 /* Highest DFS referral version understood */
1401 dfs_req->MaxReferralLevel = DFS_VERSION;
1402
1403 /* Path to resolve in an UTF-16 null-terminated string */
1404 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1405
1406 do {
Aurelien Aptel9d496402017-02-13 16:16:49 +01001407 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1408 FSCTL_DFS_GET_REFERRALS,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001409 true /* is_fsctl */,
Aurelien Aptel9d496402017-02-13 16:16:49 +01001410 (char *)dfs_req, dfs_req_size,
1411 (char **)&dfs_rsp, &dfs_rsp_size);
Aurelien Aptel9d496402017-02-13 16:16:49 +01001412 } while (rc == -EAGAIN);
1413
1414 if (rc) {
Aurelien Aptel57025912017-11-21 14:47:56 +01001415 if (rc != -ENOENT)
1416 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
Aurelien Aptel9d496402017-02-13 16:16:49 +01001417 goto out;
1418 }
1419
1420 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1421 num_of_nodes, target_nodes,
1422 nls_codepage, remap, search_name,
1423 true /* is_unicode */);
1424 if (rc) {
1425 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1426 goto out;
1427 }
1428
1429 out:
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001430 if (tcon && !tcon->ipc) {
1431 /* ipc tcons are not refcounted */
Aurelien Aptel9d496402017-02-13 16:16:49 +01001432 spin_lock(&cifs_tcp_ses_lock);
1433 tcon->tc_count--;
1434 spin_unlock(&cifs_tcp_ses_lock);
1435 }
1436 kfree(utf16_path);
1437 kfree(dfs_req);
1438 kfree(dfs_rsp);
1439 return rc;
1440}
Pavel Shilovsky78932422016-07-24 10:37:38 +03001441#define SMB2_SYMLINK_STRUCT_SIZE \
1442 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1443
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001444static int
1445smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1446 const char *full_path, char **target_path,
1447 struct cifs_sb_info *cifs_sb)
1448{
1449 int rc;
1450 __le16 *utf16_path;
1451 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1452 struct cifs_open_parms oparms;
1453 struct cifs_fid fid;
1454 struct smb2_err_rsp *err_buf = NULL;
1455 struct smb2_symlink_err_rsp *symlink;
Pavel Shilovsky78932422016-07-24 10:37:38 +03001456 unsigned int sub_len;
1457 unsigned int sub_offset;
1458 unsigned int print_len;
1459 unsigned int print_offset;
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001460
1461 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1462
1463 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1464 if (!utf16_path)
1465 return -ENOMEM;
1466
1467 oparms.tcon = tcon;
1468 oparms.desired_access = FILE_READ_ATTRIBUTES;
1469 oparms.disposition = FILE_OPEN;
1470 oparms.create_options = 0;
1471 oparms.fid = &fid;
1472 oparms.reconnect = false;
1473
1474 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1475
1476 if (!rc || !err_buf) {
1477 kfree(utf16_path);
1478 return -ENOENT;
1479 }
Pavel Shilovsky78932422016-07-24 10:37:38 +03001480
1481 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1482 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1483 kfree(utf16_path);
1484 return -ENOENT;
1485 }
1486
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001487 /* open must fail on symlink - reset rc */
1488 rc = 0;
1489 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1490 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1491 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
Pavel Shilovsky78932422016-07-24 10:37:38 +03001492 print_len = le16_to_cpu(symlink->PrintNameLength);
1493 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1494
1495 if (get_rfc1002_length(err_buf) + 4 <
1496 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1497 kfree(utf16_path);
1498 return -ENOENT;
1499 }
1500
1501 if (get_rfc1002_length(err_buf) + 4 <
1502 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1503 kfree(utf16_path);
1504 return -ENOENT;
1505 }
1506
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04001507 *target_path = cifs_strndup_from_utf16(
1508 (char *)symlink->PathBuffer + sub_offset,
1509 sub_len, true, cifs_sb->local_nls);
1510 if (!(*target_path)) {
1511 kfree(utf16_path);
1512 return -ENOMEM;
1513 }
1514 convert_delimiter(*target_path, '/');
1515 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1516 kfree(utf16_path);
1517 return rc;
1518}
1519
Arnd Bergmann84908422017-06-27 17:06:13 +02001520#ifdef CONFIG_CIFS_ACL
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001521static struct cifs_ntsd *
1522get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1523 const struct cifs_fid *cifsfid, u32 *pacllen)
1524{
1525 struct cifs_ntsd *pntsd = NULL;
1526 unsigned int xid;
1527 int rc = -EOPNOTSUPP;
1528 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1529
1530 if (IS_ERR(tlink))
1531 return ERR_CAST(tlink);
1532
1533 xid = get_xid();
1534 cifs_dbg(FYI, "trying to get acl\n");
1535
1536 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1537 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1538 free_xid(xid);
1539
1540 cifs_put_tlink(tlink);
1541
1542 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1543 if (rc)
1544 return ERR_PTR(rc);
1545 return pntsd;
1546
1547}
1548
1549static struct cifs_ntsd *
1550get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1551 const char *path, u32 *pacllen)
1552{
1553 struct cifs_ntsd *pntsd = NULL;
1554 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1555 unsigned int xid;
1556 int rc;
1557 struct cifs_tcon *tcon;
1558 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1559 struct cifs_fid fid;
1560 struct cifs_open_parms oparms;
1561 __le16 *utf16_path;
1562
1563 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1564 if (IS_ERR(tlink))
1565 return ERR_CAST(tlink);
1566
1567 tcon = tlink_tcon(tlink);
1568 xid = get_xid();
1569
1570 if (backup_cred(cifs_sb))
Colin Ian King709340a2017-07-05 13:47:34 +01001571 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001572 else
1573 oparms.create_options = 0;
1574
1575 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1576 if (!utf16_path)
1577 return ERR_PTR(-ENOMEM);
1578
1579 oparms.tcon = tcon;
1580 oparms.desired_access = READ_CONTROL;
1581 oparms.disposition = FILE_OPEN;
1582 oparms.fid = &fid;
1583 oparms.reconnect = false;
1584
1585 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
1586 kfree(utf16_path);
1587 if (!rc) {
1588 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1589 fid.volatile_fid, (void **)&pntsd, pacllen);
1590 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1591 }
1592
1593 cifs_put_tlink(tlink);
1594 free_xid(xid);
1595
1596 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1597 if (rc)
1598 return ERR_PTR(rc);
1599 return pntsd;
1600}
1601
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05001602#ifdef CONFIG_CIFS_ACL
1603static int
1604set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1605 struct inode *inode, const char *path, int aclflag)
1606{
1607 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1608 unsigned int xid;
1609 int rc, access_flags = 0;
1610 struct cifs_tcon *tcon;
1611 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1612 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1613 struct cifs_fid fid;
1614 struct cifs_open_parms oparms;
1615 __le16 *utf16_path;
1616
1617 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
1618 if (IS_ERR(tlink))
1619 return PTR_ERR(tlink);
1620
1621 tcon = tlink_tcon(tlink);
1622 xid = get_xid();
1623
1624 if (backup_cred(cifs_sb))
1625 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1626 else
1627 oparms.create_options = 0;
1628
1629 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
1630 access_flags = WRITE_OWNER;
1631 else
1632 access_flags = WRITE_DAC;
1633
1634 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1635 if (!utf16_path)
1636 return -ENOMEM;
1637
1638 oparms.tcon = tcon;
1639 oparms.desired_access = access_flags;
1640 oparms.disposition = FILE_OPEN;
1641 oparms.path = path;
1642 oparms.fid = &fid;
1643 oparms.reconnect = false;
1644
1645 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
1646 kfree(utf16_path);
1647 if (!rc) {
1648 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1649 fid.volatile_fid, pnntsd, acllen, aclflag);
1650 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1651 }
1652
1653 cifs_put_tlink(tlink);
1654 free_xid(xid);
1655 return rc;
1656}
1657#endif /* CIFS_ACL */
1658
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001659/* Retrieve an ACL from the server */
1660static struct cifs_ntsd *
1661get_smb2_acl(struct cifs_sb_info *cifs_sb,
1662 struct inode *inode, const char *path,
1663 u32 *pacllen)
1664{
1665 struct cifs_ntsd *pntsd = NULL;
1666 struct cifsFileInfo *open_file = NULL;
1667
1668 if (inode)
1669 open_file = find_readable_file(CIFS_I(inode), true);
1670 if (!open_file)
1671 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
1672
1673 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
1674 cifsFileInfo_put(open_file);
1675 return pntsd;
1676}
Arnd Bergmann84908422017-06-27 17:06:13 +02001677#endif
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05001678
Steve French30175622014-08-17 18:16:40 -05001679static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1680 loff_t offset, loff_t len, bool keep_size)
1681{
1682 struct inode *inode;
1683 struct cifsInodeInfo *cifsi;
1684 struct cifsFileInfo *cfile = file->private_data;
1685 struct file_zero_data_information fsctl_buf;
1686 long rc;
1687 unsigned int xid;
1688
1689 xid = get_xid();
1690
David Howells2b0143b2015-03-17 22:25:59 +00001691 inode = d_inode(cfile->dentry);
Steve French30175622014-08-17 18:16:40 -05001692 cifsi = CIFS_I(inode);
1693
1694 /* if file not oplocked can't be sure whether asking to extend size */
1695 if (!CIFS_CACHE_READ(cifsi))
1696 if (keep_size == false)
1697 return -EOPNOTSUPP;
1698
Steve French2bb93d22014-08-20 18:56:29 -05001699 /*
Steve French30175622014-08-17 18:16:40 -05001700 * Must check if file sparse since fallocate -z (zero range) assumes
1701 * non-sparse allocation
1702 */
1703 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1704 return -EOPNOTSUPP;
1705
1706 /*
1707 * need to make sure we are not asked to extend the file since the SMB3
1708 * fsctl does not change the file size. In the future we could change
1709 * this to zero the first part of the range then set the file size
1710 * which for a non sparse file would zero the newly extended range
1711 */
1712 if (keep_size == false)
1713 if (i_size_read(inode) < offset + len)
1714 return -EOPNOTSUPP;
1715
1716 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1717
1718 fsctl_buf.FileOffset = cpu_to_le64(offset);
1719 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1720
1721 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1722 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001723 true /* is_fctl */, (char *)&fsctl_buf,
Steve French30175622014-08-17 18:16:40 -05001724 sizeof(struct file_zero_data_information), NULL, NULL);
1725 free_xid(xid);
1726 return rc;
1727}
1728
Steve French31742c52014-08-17 08:38:47 -05001729static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1730 loff_t offset, loff_t len)
1731{
1732 struct inode *inode;
1733 struct cifsInodeInfo *cifsi;
1734 struct cifsFileInfo *cfile = file->private_data;
1735 struct file_zero_data_information fsctl_buf;
1736 long rc;
1737 unsigned int xid;
1738 __u8 set_sparse = 1;
1739
1740 xid = get_xid();
1741
David Howells2b0143b2015-03-17 22:25:59 +00001742 inode = d_inode(cfile->dentry);
Steve French31742c52014-08-17 08:38:47 -05001743 cifsi = CIFS_I(inode);
1744
1745 /* Need to make file sparse, if not already, before freeing range. */
1746 /* Consider adding equivalent for compressed since it could also work */
1747 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1748 return -EOPNOTSUPP;
1749
1750 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1751
1752 fsctl_buf.FileOffset = cpu_to_le64(offset);
1753 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1754
1755 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1756 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
Aurelien Aptel63a83b82018-01-24 13:46:11 +01001757 true /* is_fctl */, (char *)&fsctl_buf,
Steve French31742c52014-08-17 08:38:47 -05001758 sizeof(struct file_zero_data_information), NULL, NULL);
1759 free_xid(xid);
1760 return rc;
1761}
1762
Steve French9ccf3212014-10-18 17:01:15 -05001763static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1764 loff_t off, loff_t len, bool keep_size)
1765{
1766 struct inode *inode;
1767 struct cifsInodeInfo *cifsi;
1768 struct cifsFileInfo *cfile = file->private_data;
1769 long rc = -EOPNOTSUPP;
1770 unsigned int xid;
1771
1772 xid = get_xid();
1773
David Howells2b0143b2015-03-17 22:25:59 +00001774 inode = d_inode(cfile->dentry);
Steve French9ccf3212014-10-18 17:01:15 -05001775 cifsi = CIFS_I(inode);
1776
1777 /* if file not oplocked can't be sure whether asking to extend size */
1778 if (!CIFS_CACHE_READ(cifsi))
1779 if (keep_size == false)
1780 return -EOPNOTSUPP;
1781
1782 /*
1783 * Files are non-sparse by default so falloc may be a no-op
1784 * Must check if file sparse. If not sparse, and not extending
1785 * then no need to do anything since file already allocated
1786 */
1787 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1788 if (keep_size == true)
1789 return 0;
1790 /* check if extending file */
1791 else if (i_size_read(inode) >= off + len)
1792 /* not extending file and already not sparse */
1793 return 0;
1794 /* BB: in future add else clause to extend file */
1795 else
1796 return -EOPNOTSUPP;
1797 }
1798
1799 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1800 /*
1801 * Check if falloc starts within first few pages of file
1802 * and ends within a few pages of the end of file to
1803 * ensure that most of file is being forced to be
1804 * fallocated now. If so then setting whole file sparse
1805 * ie potentially making a few extra pages at the beginning
1806 * or end of the file non-sparse via set_sparse is harmless.
1807 */
1808 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1809 return -EOPNOTSUPP;
1810
1811 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1812 }
1813 /* BB: else ... in future add code to extend file and set sparse */
1814
1815
1816 free_xid(xid);
1817 return rc;
1818}
1819
1820
Steve French31742c52014-08-17 08:38:47 -05001821static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1822 loff_t off, loff_t len)
1823{
1824 /* KEEP_SIZE already checked for by do_fallocate */
1825 if (mode & FALLOC_FL_PUNCH_HOLE)
1826 return smb3_punch_hole(file, tcon, off, len);
Steve French30175622014-08-17 18:16:40 -05001827 else if (mode & FALLOC_FL_ZERO_RANGE) {
1828 if (mode & FALLOC_FL_KEEP_SIZE)
1829 return smb3_zero_range(file, tcon, off, len, true);
1830 return smb3_zero_range(file, tcon, off, len, false);
Steve French9ccf3212014-10-18 17:01:15 -05001831 } else if (mode == FALLOC_FL_KEEP_SIZE)
1832 return smb3_simple_falloc(file, tcon, off, len, true);
1833 else if (mode == 0)
1834 return smb3_simple_falloc(file, tcon, off, len, false);
Steve French31742c52014-08-17 08:38:47 -05001835
1836 return -EOPNOTSUPP;
1837}
1838
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001839static void
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00001840smb2_downgrade_oplock(struct TCP_Server_Info *server,
1841 struct cifsInodeInfo *cinode, bool set_level2)
1842{
1843 if (set_level2)
1844 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1845 0, NULL);
1846 else
1847 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1848}
1849
1850static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001851smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1852 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001853{
1854 oplock &= 0xFF;
1855 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1856 return;
1857 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001858 cinode->oplock = CIFS_CACHE_RHW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001859 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1860 &cinode->vfs_inode);
1861 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001862 cinode->oplock = CIFS_CACHE_RW_FLG;
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001863 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1864 &cinode->vfs_inode);
1865 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1866 cinode->oplock = CIFS_CACHE_READ_FLG;
1867 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1868 &cinode->vfs_inode);
1869 } else
1870 cinode->oplock = 0;
1871}
1872
1873static void
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001874smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1875 unsigned int epoch, bool *purge_cache)
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001876{
1877 char message[5] = {0};
1878
1879 oplock &= 0xFF;
1880 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1881 return;
1882
1883 cinode->oplock = 0;
1884 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1885 cinode->oplock |= CIFS_CACHE_READ_FLG;
1886 strcat(message, "R");
1887 }
1888 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1889 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1890 strcat(message, "H");
1891 }
1892 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1893 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1894 strcat(message, "W");
1895 }
1896 if (!cinode->oplock)
1897 strcat(message, "None");
1898 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1899 &cinode->vfs_inode);
1900}
1901
Pavel Shilovsky42873b02013-09-05 21:30:16 +04001902static void
1903smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1904 unsigned int epoch, bool *purge_cache)
1905{
1906 unsigned int old_oplock = cinode->oplock;
1907
1908 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1909
1910 if (purge_cache) {
1911 *purge_cache = false;
1912 if (old_oplock == CIFS_CACHE_READ_FLG) {
1913 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1914 (epoch - cinode->epoch > 0))
1915 *purge_cache = true;
1916 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1917 (epoch - cinode->epoch > 1))
1918 *purge_cache = true;
1919 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1920 (epoch - cinode->epoch > 1))
1921 *purge_cache = true;
1922 else if (cinode->oplock == 0 &&
1923 (epoch - cinode->epoch > 0))
1924 *purge_cache = true;
1925 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1926 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1927 (epoch - cinode->epoch > 0))
1928 *purge_cache = true;
1929 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1930 (epoch - cinode->epoch > 1))
1931 *purge_cache = true;
1932 }
1933 cinode->epoch = epoch;
1934 }
1935}
1936
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04001937static bool
1938smb2_is_read_op(__u32 oplock)
1939{
1940 return oplock == SMB2_OPLOCK_LEVEL_II;
1941}
1942
1943static bool
1944smb21_is_read_op(__u32 oplock)
1945{
1946 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1947 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1948}
1949
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001950static __le32
1951map_oplock_to_lease(u8 oplock)
1952{
1953 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1954 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1955 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1956 return SMB2_LEASE_READ_CACHING;
1957 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1958 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1959 SMB2_LEASE_WRITE_CACHING;
1960 return 0;
1961}
1962
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001963static char *
1964smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1965{
1966 struct create_lease *buf;
1967
1968 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1969 if (!buf)
1970 return NULL;
1971
1972 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1973 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001974 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001975
1976 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1977 (struct create_lease, lcontext));
1978 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1979 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1980 (struct create_lease, Name));
1981 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07001982 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04001983 buf->Name[0] = 'R';
1984 buf->Name[1] = 'q';
1985 buf->Name[2] = 'L';
1986 buf->Name[3] = 's';
1987 return (char *)buf;
1988}
1989
Pavel Shilovskyf0473902013-09-04 13:44:05 +04001990static char *
1991smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1992{
1993 struct create_lease_v2 *buf;
1994
1995 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1996 if (!buf)
1997 return NULL;
1998
1999 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
2000 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
2001 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2002
2003 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2004 (struct create_lease_v2, lcontext));
2005 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2006 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2007 (struct create_lease_v2, Name));
2008 buf->ccontext.NameLength = cpu_to_le16(4);
Steve French12197a72014-05-14 05:29:40 -07002009 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002010 buf->Name[0] = 'R';
2011 buf->Name[1] = 'q';
2012 buf->Name[2] = 'L';
2013 buf->Name[3] = 's';
2014 return (char *)buf;
2015}
2016
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002017static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002018smb2_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002019{
2020 struct create_lease *lc = (struct create_lease *)buf;
2021
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002022 *epoch = 0; /* not used */
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002023 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2024 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2025 return le32_to_cpu(lc->lcontext.LeaseState);
2026}
2027
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002028static __u8
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002029smb3_parse_lease_buf(void *buf, unsigned int *epoch)
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002030{
2031 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2032
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002033 *epoch = le16_to_cpu(lc->lcontext.Epoch);
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002034 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2035 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2036 return le32_to_cpu(lc->lcontext.LeaseState);
2037}
2038
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002039static unsigned int
2040smb2_wp_retry_size(struct inode *inode)
2041{
2042 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2043 SMB2_MAX_BUFFER_SIZE);
2044}
2045
Pavel Shilovsky52755802014-08-18 20:49:57 +04002046static bool
2047smb2_dir_needs_close(struct cifsFileInfo *cfile)
2048{
2049 return !cfile->invalidHandle;
2050}
2051
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002052static void
2053fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
2054{
2055 struct smb2_sync_hdr *shdr =
2056 (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base;
2057 unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
2058
2059 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2060 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2061 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2062 tr_hdr->Flags = cpu_to_le16(0x01);
2063 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2064 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2065 inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4);
2066 inc_rfc1001_len(tr_hdr, orig_len);
2067}
2068
Ronnie Sahlberg262916b2018-02-20 12:45:21 +11002069/* We can not use the normal sg_set_buf() as we will sometimes pass a
2070 * stack object as buf.
2071 */
2072static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2073 unsigned int buflen)
2074{
2075 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2076}
2077
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002078static struct scatterlist *
2079init_sg(struct smb_rqst *rqst, u8 *sign)
2080{
2081 unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
2082 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
2083 struct scatterlist *sg;
2084 unsigned int i;
2085 unsigned int j;
2086
2087 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2088 if (!sg)
2089 return NULL;
2090
2091 sg_init_table(sg, sg_len);
Ronnie Sahlberg262916b2018-02-20 12:45:21 +11002092 smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002093 for (i = 1; i < rqst->rq_nvec; i++)
Ronnie Sahlberg262916b2018-02-20 12:45:21 +11002094 smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002095 rqst->rq_iov[i].iov_len);
2096 for (j = 0; i < sg_len - 1; i++, j++) {
2097 unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
2098 : rqst->rq_tailsz;
2099 sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
2100 }
Ronnie Sahlberg262916b2018-02-20 12:45:21 +11002101 smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002102 return sg;
2103}
2104
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002105static int
2106smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2107{
2108 struct cifs_ses *ses;
2109 u8 *ses_enc_key;
2110
2111 spin_lock(&cifs_tcp_ses_lock);
2112 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2113 if (ses->Suid != ses_id)
2114 continue;
2115 ses_enc_key = enc ? ses->smb3encryptionkey :
2116 ses->smb3decryptionkey;
2117 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2118 spin_unlock(&cifs_tcp_ses_lock);
2119 return 0;
2120 }
2121 spin_unlock(&cifs_tcp_ses_lock);
2122
2123 return 1;
2124}
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002125/*
2126 * Encrypt or decrypt @rqst message. @rqst has the following format:
2127 * iov[0] - transform header (associate data),
2128 * iov[1-N] and pages - data to encrypt.
2129 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2130 * untouched.
2131 */
2132static int
2133crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
2134{
2135 struct smb2_transform_hdr *tr_hdr =
2136 (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
2137 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002138 int rc = 0;
2139 struct scatterlist *sg;
2140 u8 sign[SMB2_SIGNATURE_SIZE] = {};
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002141 u8 key[SMB3_SIGN_KEY_SIZE];
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002142 struct aead_request *req;
2143 char *iv;
2144 unsigned int iv_len;
Gilad Ben-Yossefa5186b82017-10-18 08:00:46 +01002145 DECLARE_CRYPTO_WAIT(wait);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002146 struct crypto_aead *tfm;
2147 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2148
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002149 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2150 if (rc) {
2151 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2152 enc ? "en" : "de");
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002153 return 0;
2154 }
2155
2156 rc = smb3_crypto_aead_allocate(server);
2157 if (rc) {
2158 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2159 return rc;
2160 }
2161
2162 tfm = enc ? server->secmech.ccmaesencrypt :
2163 server->secmech.ccmaesdecrypt;
Pavel Shilovsky61cfac6f2017-02-28 16:05:19 -08002164 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002165 if (rc) {
2166 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2167 return rc;
2168 }
2169
2170 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2171 if (rc) {
2172 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2173 return rc;
2174 }
2175
2176 req = aead_request_alloc(tfm, GFP_KERNEL);
2177 if (!req) {
2178 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2179 return -ENOMEM;
2180 }
2181
2182 if (!enc) {
2183 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2184 crypt_len += SMB2_SIGNATURE_SIZE;
2185 }
2186
2187 sg = init_sg(rqst, sign);
2188 if (!sg) {
Christophe Jaillet517a6e42017-06-11 09:12:47 +02002189 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2190 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002191 goto free_req;
2192 }
2193
2194 iv_len = crypto_aead_ivsize(tfm);
2195 iv = kzalloc(iv_len, GFP_KERNEL);
2196 if (!iv) {
2197 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
Christophe Jaillet517a6e42017-06-11 09:12:47 +02002198 rc = -ENOMEM;
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002199 goto free_sg;
2200 }
2201 iv[0] = 3;
2202 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2203
2204 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2205 aead_request_set_ad(req, assoc_data_len);
2206
2207 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossefa5186b82017-10-18 08:00:46 +01002208 crypto_req_done, &wait);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002209
Gilad Ben-Yossefa5186b82017-10-18 08:00:46 +01002210 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2211 : crypto_aead_decrypt(req), &wait);
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002212
2213 if (!rc && enc)
2214 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2215
2216 kfree(iv);
2217free_sg:
2218 kfree(sg);
2219free_req:
2220 kfree(req);
2221 return rc;
2222}
2223
2224static int
2225smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
2226 struct smb_rqst *old_rq)
2227{
2228 struct kvec *iov;
2229 struct page **pages;
2230 struct smb2_transform_hdr *tr_hdr;
2231 unsigned int npages = old_rq->rq_npages;
2232 int i;
2233 int rc = -ENOMEM;
2234
2235 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2236 if (!pages)
2237 return rc;
2238
2239 new_rq->rq_pages = pages;
2240 new_rq->rq_npages = old_rq->rq_npages;
2241 new_rq->rq_pagesz = old_rq->rq_pagesz;
2242 new_rq->rq_tailsz = old_rq->rq_tailsz;
2243
2244 for (i = 0; i < npages; i++) {
2245 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2246 if (!pages[i])
2247 goto err_free_pages;
2248 }
2249
2250 iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL);
2251 if (!iov)
2252 goto err_free_pages;
2253
2254 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2255 memcpy(&iov[1], &old_rq->rq_iov[1],
2256 sizeof(struct kvec) * (old_rq->rq_nvec - 1));
2257 new_rq->rq_iov = iov;
2258 new_rq->rq_nvec = old_rq->rq_nvec;
2259
2260 tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
2261 if (!tr_hdr)
2262 goto err_free_iov;
2263
2264 /* fill the 1st iov with a transform header */
2265 fill_transform_hdr(tr_hdr, old_rq);
2266 new_rq->rq_iov[0].iov_base = tr_hdr;
2267 new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2268
2269 /* copy pages form the old */
2270 for (i = 0; i < npages; i++) {
2271 char *dst = kmap(new_rq->rq_pages[i]);
2272 char *src = kmap(old_rq->rq_pages[i]);
2273 unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz :
2274 new_rq->rq_tailsz;
2275 memcpy(dst, src, len);
2276 kunmap(new_rq->rq_pages[i]);
2277 kunmap(old_rq->rq_pages[i]);
2278 }
2279
2280 rc = crypt_message(server, new_rq, 1);
2281 cifs_dbg(FYI, "encrypt message returned %d", rc);
2282 if (rc)
2283 goto err_free_tr_hdr;
2284
2285 return rc;
2286
2287err_free_tr_hdr:
2288 kfree(tr_hdr);
2289err_free_iov:
2290 kfree(iov);
2291err_free_pages:
2292 for (i = i - 1; i >= 0; i--)
2293 put_page(pages[i]);
2294 kfree(pages);
2295 return rc;
2296}
2297
2298static void
2299smb3_free_transform_rq(struct smb_rqst *rqst)
2300{
2301 int i = rqst->rq_npages - 1;
2302
2303 for (; i >= 0; i--)
2304 put_page(rqst->rq_pages[i]);
2305 kfree(rqst->rq_pages);
2306 /* free transform header */
2307 kfree(rqst->rq_iov[0].iov_base);
2308 kfree(rqst->rq_iov);
2309}
2310
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002311static int
2312smb3_is_transform_hdr(void *buf)
2313{
2314 struct smb2_transform_hdr *trhdr = buf;
2315
2316 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2317}
2318
2319static int
2320decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2321 unsigned int buf_data_size, struct page **pages,
2322 unsigned int npages, unsigned int page_data_size)
2323{
2324 struct kvec iov[2];
2325 struct smb_rqst rqst = {NULL};
2326 struct smb2_hdr *hdr;
2327 int rc;
2328
2329 iov[0].iov_base = buf;
2330 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2331 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2332 iov[1].iov_len = buf_data_size;
2333
2334 rqst.rq_iov = iov;
2335 rqst.rq_nvec = 2;
2336 rqst.rq_pages = pages;
2337 rqst.rq_npages = npages;
2338 rqst.rq_pagesz = PAGE_SIZE;
2339 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2340
2341 rc = crypt_message(server, &rqst, 0);
2342 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2343
2344 if (rc)
2345 return rc;
2346
2347 memmove(buf + 4, iov[1].iov_base, buf_data_size);
2348 hdr = (struct smb2_hdr *)buf;
2349 hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size);
2350 server->total_read = buf_data_size + page_data_size + 4;
2351
2352 return rc;
2353}
2354
2355static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002356read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2357 unsigned int npages, unsigned int len)
2358{
2359 int i;
2360 int length;
2361
2362 for (i = 0; i < npages; i++) {
2363 struct page *page = pages[i];
2364 size_t n;
2365
2366 n = len;
2367 if (len >= PAGE_SIZE) {
2368 /* enough data to fill the page */
2369 n = PAGE_SIZE;
2370 len -= n;
2371 } else {
2372 zero_user(page, len, PAGE_SIZE - len);
2373 len = 0;
2374 }
2375 length = cifs_read_page_from_socket(server, page, n);
2376 if (length < 0)
2377 return length;
2378 server->total_read += length;
2379 }
2380
2381 return 0;
2382}
2383
2384static int
2385init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2386 unsigned int cur_off, struct bio_vec **page_vec)
2387{
2388 struct bio_vec *bvec;
2389 int i;
2390
2391 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2392 if (!bvec)
2393 return -ENOMEM;
2394
2395 for (i = 0; i < npages; i++) {
2396 bvec[i].bv_page = pages[i];
2397 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2398 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2399 data_size -= bvec[i].bv_len;
2400 }
2401
2402 if (data_size != 0) {
2403 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2404 kfree(bvec);
2405 return -EIO;
2406 }
2407
2408 *page_vec = bvec;
2409 return 0;
2410}
2411
2412static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002413handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2414 char *buf, unsigned int buf_len, struct page **pages,
2415 unsigned int npages, unsigned int page_data_size)
2416{
2417 unsigned int data_offset;
2418 unsigned int data_len;
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002419 unsigned int cur_off;
2420 unsigned int cur_page_idx;
2421 unsigned int pad_len;
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002422 struct cifs_readdata *rdata = mid->callback_data;
2423 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
2424 struct bio_vec *bvec = NULL;
2425 struct iov_iter iter;
2426 struct kvec iov;
2427 int length;
Long Li74dcf412017-11-22 17:38:46 -07002428 bool use_rdma_mr = false;
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002429
2430 if (shdr->Command != SMB2_READ) {
2431 cifs_dbg(VFS, "only big read responses are supported\n");
2432 return -ENOTSUPP;
2433 }
2434
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002435 if (server->ops->is_session_expired &&
2436 server->ops->is_session_expired(buf)) {
2437 cifs_reconnect(server);
2438 wake_up(&server->response_q);
2439 return -1;
2440 }
2441
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002442 if (server->ops->is_status_pending &&
2443 server->ops->is_status_pending(buf, server, 0))
2444 return -1;
2445
2446 rdata->result = server->ops->map_error(buf, false);
2447 if (rdata->result != 0) {
2448 cifs_dbg(FYI, "%s: server returned error %d\n",
2449 __func__, rdata->result);
2450 dequeue_mid(mid, rdata->result);
2451 return 0;
2452 }
2453
2454 data_offset = server->ops->read_data_offset(buf) + 4;
Long Li74dcf412017-11-22 17:38:46 -07002455#ifdef CONFIG_CIFS_SMB_DIRECT
2456 use_rdma_mr = rdata->mr;
2457#endif
2458 data_len = server->ops->read_data_length(buf, use_rdma_mr);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002459
2460 if (data_offset < server->vals->read_rsp_size) {
2461 /*
2462 * win2k8 sometimes sends an offset of 0 when the read
2463 * is beyond the EOF. Treat it as if the data starts just after
2464 * the header.
2465 */
2466 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2467 __func__, data_offset);
2468 data_offset = server->vals->read_rsp_size;
2469 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2470 /* data_offset is beyond the end of smallbuf */
2471 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2472 __func__, data_offset);
2473 rdata->result = -EIO;
2474 dequeue_mid(mid, rdata->result);
2475 return 0;
2476 }
2477
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002478 pad_len = data_offset - server->vals->read_rsp_size;
2479
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002480 if (buf_len <= data_offset) {
2481 /* read response payload is in pages */
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002482 cur_page_idx = pad_len / PAGE_SIZE;
2483 cur_off = pad_len % PAGE_SIZE;
2484
2485 if (cur_page_idx != 0) {
2486 /* data offset is beyond the 1st page of response */
2487 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2488 __func__, data_offset);
2489 rdata->result = -EIO;
2490 dequeue_mid(mid, rdata->result);
2491 return 0;
2492 }
2493
2494 if (data_len > page_data_size - pad_len) {
2495 /* data_len is corrupt -- discard frame */
2496 rdata->result = -EIO;
2497 dequeue_mid(mid, rdata->result);
2498 return 0;
2499 }
2500
2501 rdata->result = init_read_bvec(pages, npages, page_data_size,
2502 cur_off, &bvec);
2503 if (rdata->result != 0) {
2504 dequeue_mid(mid, rdata->result);
2505 return 0;
2506 }
2507
2508 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002509 } else if (buf_len >= data_offset + data_len) {
2510 /* read response payload is in buf */
2511 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2512 iov.iov_base = buf + data_offset;
2513 iov.iov_len = data_len;
2514 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2515 } else {
2516 /* read response payload cannot be in both buf and pages */
2517 WARN_ONCE(1, "buf can not contain only a part of read data");
2518 rdata->result = -EIO;
2519 dequeue_mid(mid, rdata->result);
2520 return 0;
2521 }
2522
2523 /* set up first iov for signature check */
2524 rdata->iov[0].iov_base = buf;
2525 rdata->iov[0].iov_len = 4;
2526 rdata->iov[1].iov_base = buf + 4;
2527 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2528 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2529 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2530
2531 length = rdata->copy_into_pages(server, rdata, &iter);
2532
2533 kfree(bvec);
2534
2535 if (length < 0)
2536 return length;
2537
2538 dequeue_mid(mid, false);
2539 return length;
2540}
2541
2542static int
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002543receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2544{
2545 char *buf = server->smallbuf;
2546 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2547 unsigned int npages;
2548 struct page **pages;
2549 unsigned int len;
2550 unsigned int buflen = get_rfc1002_length(buf) + 4;
2551 int rc;
2552 int i = 0;
2553
2554 len = min_t(unsigned int, buflen, server->vals->read_rsp_size - 4 +
2555 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2556
2557 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2558 if (rc < 0)
2559 return rc;
2560 server->total_read += rc;
2561
2562 len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 -
2563 server->vals->read_rsp_size;
2564 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2565
2566 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2567 if (!pages) {
2568 rc = -ENOMEM;
2569 goto discard_data;
2570 }
2571
2572 for (; i < npages; i++) {
2573 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2574 if (!pages[i]) {
2575 rc = -ENOMEM;
2576 goto discard_data;
2577 }
2578 }
2579
2580 /* read read data into pages */
2581 rc = read_data_into_pages(server, pages, npages, len);
2582 if (rc)
2583 goto free_pages;
2584
Pavel Shilovsky350be252017-04-10 10:31:33 -07002585 rc = cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002586 if (rc)
2587 goto free_pages;
2588
2589 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - 4,
2590 pages, npages, len);
2591 if (rc)
2592 goto free_pages;
2593
2594 *mid = smb2_find_mid(server, buf);
2595 if (*mid == NULL)
2596 cifs_dbg(FYI, "mid not found\n");
2597 else {
2598 cifs_dbg(FYI, "mid found\n");
2599 (*mid)->decrypted = true;
2600 rc = handle_read_data(server, *mid, buf,
2601 server->vals->read_rsp_size,
2602 pages, npages, len);
2603 }
2604
2605free_pages:
2606 for (i = i - 1; i >= 0; i--)
2607 put_page(pages[i]);
2608 kfree(pages);
2609 return rc;
2610discard_data:
Pavel Shilovsky350be252017-04-10 10:31:33 -07002611 cifs_discard_remaining_data(server);
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002612 goto free_pages;
2613}
2614
2615static int
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002616receive_encrypted_standard(struct TCP_Server_Info *server,
2617 struct mid_q_entry **mid)
2618{
2619 int length;
2620 char *buf = server->smallbuf;
2621 unsigned int pdu_length = get_rfc1002_length(buf);
2622 unsigned int buf_size;
2623 struct mid_q_entry *mid_entry;
2624
2625 /* switch to large buffer if too big for a small one */
2626 if (pdu_length + 4 > MAX_CIFS_SMALL_BUFFER_SIZE) {
2627 server->large_buf = true;
2628 memcpy(server->bigbuf, buf, server->total_read);
2629 buf = server->bigbuf;
2630 }
2631
2632 /* now read the rest */
2633 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
2634 pdu_length - HEADER_SIZE(server) + 1 + 4);
2635 if (length < 0)
2636 return length;
2637 server->total_read += length;
2638
2639 buf_size = pdu_length + 4 - sizeof(struct smb2_transform_hdr);
2640 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
2641 if (length)
2642 return length;
2643
2644 mid_entry = smb2_find_mid(server, buf);
2645 if (mid_entry == NULL)
2646 cifs_dbg(FYI, "mid not found\n");
2647 else {
2648 cifs_dbg(FYI, "mid found\n");
2649 mid_entry->decrypted = true;
2650 }
2651
2652 *mid = mid_entry;
2653
2654 if (mid_entry && mid_entry->handle)
2655 return mid_entry->handle(server, mid_entry);
2656
2657 return cifs_handle_standard(server, mid_entry);
2658}
2659
2660static int
2661smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2662{
2663 char *buf = server->smallbuf;
2664 unsigned int pdu_length = get_rfc1002_length(buf);
2665 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2666 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2667
2668 if (pdu_length + 4 < sizeof(struct smb2_transform_hdr) +
2669 sizeof(struct smb2_sync_hdr)) {
2670 cifs_dbg(VFS, "Transform message is too small (%u)\n",
2671 pdu_length);
2672 cifs_reconnect(server);
2673 wake_up(&server->response_q);
2674 return -ECONNABORTED;
2675 }
2676
2677 if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
2678 cifs_dbg(VFS, "Transform message is broken\n");
2679 cifs_reconnect(server);
2680 wake_up(&server->response_q);
2681 return -ECONNABORTED;
2682 }
2683
Pavel Shilovskyc42a6ab2016-11-17 16:20:23 -08002684 if (pdu_length + 4 > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
2685 return receive_encrypted_read(server, mid);
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002686
2687 return receive_encrypted_standard(server, mid);
2688}
2689
2690int
2691smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
2692{
2693 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
2694
2695 return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + 4,
2696 NULL, 0, 0);
2697}
2698
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002699struct smb_version_operations smb20_operations = {
2700 .compare_fids = smb2_compare_fids,
2701 .setup_request = smb2_setup_request,
2702 .setup_async_request = smb2_setup_async_request,
2703 .check_receive = smb2_check_receive,
2704 .add_credits = smb2_add_credits,
2705 .set_credits = smb2_set_credits,
2706 .get_credits_field = smb2_get_credits_field,
2707 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002708 .wait_mtu_credits = cifs_wait_mtu_credits,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002709 .get_next_mid = smb2_get_next_mid,
2710 .read_data_offset = smb2_read_data_offset,
2711 .read_data_length = smb2_read_data_length,
2712 .map_error = map_smb2_to_linux_error,
2713 .find_mid = smb2_find_mid,
2714 .check_message = smb2_check_message,
2715 .dump_detail = smb2_dump_detail,
2716 .clear_stats = smb2_clear_stats,
2717 .print_stats = smb2_print_stats,
2718 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002719 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002720 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002721 .need_neg = smb2_need_neg,
2722 .negotiate = smb2_negotiate,
2723 .negotiate_wsize = smb2_negotiate_wsize,
2724 .negotiate_rsize = smb2_negotiate_rsize,
2725 .sess_setup = SMB2_sess_setup,
2726 .logoff = SMB2_logoff,
2727 .tree_connect = SMB2_tcon,
2728 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002729 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002730 .is_path_accessible = smb2_is_path_accessible,
2731 .can_echo = smb2_can_echo,
2732 .echo = SMB2_echo,
2733 .query_path_info = smb2_query_path_info,
2734 .get_srv_inum = smb2_get_srv_inum,
2735 .query_file_info = smb2_query_file_info,
2736 .set_path_size = smb2_set_path_size,
2737 .set_file_size = smb2_set_file_size,
2738 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002739 .set_compression = smb2_set_compression,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002740 .mkdir = smb2_mkdir,
2741 .mkdir_setinfo = smb2_mkdir_setinfo,
2742 .rmdir = smb2_rmdir,
2743 .unlink = smb2_unlink,
2744 .rename = smb2_rename_path,
2745 .create_hardlink = smb2_create_hardlink,
2746 .query_symlink = smb2_query_symlink,
Sachin Prabhu5b23c972016-07-11 16:53:20 +01002747 .query_mf_symlink = smb3_query_mf_symlink,
2748 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002749 .open = smb2_open_file,
2750 .set_fid = smb2_set_fid,
2751 .close = smb2_close_file,
2752 .flush = smb2_flush_file,
2753 .async_readv = smb2_async_readv,
2754 .async_writev = smb2_async_writev,
2755 .sync_read = smb2_sync_read,
2756 .sync_write = smb2_sync_write,
2757 .query_dir_first = smb2_query_dir_first,
2758 .query_dir_next = smb2_query_dir_next,
2759 .close_dir = smb2_close_dir,
2760 .calc_smb_size = smb2_calc_size,
2761 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002762 .is_session_expired = smb2_is_session_expired,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002763 .oplock_response = smb2_oplock_response,
2764 .queryfs = smb2_queryfs,
2765 .mand_lock = smb2_mand_lock,
2766 .mand_unlock_range = smb2_unlock_range,
2767 .push_mand_locks = smb2_push_mandatory_locks,
2768 .get_lease_key = smb2_get_lease_key,
2769 .set_lease_key = smb2_set_lease_key,
2770 .new_lease_key = smb2_new_lease_key,
2771 .calc_signature = smb2_calc_signature,
2772 .is_read_op = smb2_is_read_op,
2773 .set_oplock_level = smb2_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002774 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002775 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002776 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002777 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002778 .dir_needs_close = smb2_dir_needs_close,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002779 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302780 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002781#ifdef CONFIG_CIFS_XATTR
2782 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002783 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002784#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002785#ifdef CONFIG_CIFS_ACL
2786 .get_acl = get_smb2_acl,
2787 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002788 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002789#endif /* CIFS_ACL */
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002790};
2791
Steve French1080ef72011-02-24 18:07:19 +00002792struct smb_version_operations smb21_operations = {
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07002793 .compare_fids = smb2_compare_fids,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002794 .setup_request = smb2_setup_request,
Pavel Shilovskyc95b8ee2012-07-11 14:45:28 +04002795 .setup_async_request = smb2_setup_async_request,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002796 .check_receive = smb2_check_receive,
Pavel Shilovsky28ea5292012-05-23 16:18:00 +04002797 .add_credits = smb2_add_credits,
2798 .set_credits = smb2_set_credits,
2799 .get_credits_field = smb2_get_credits_field,
2800 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002801 .wait_mtu_credits = smb2_wait_mtu_credits,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04002802 .get_next_mid = smb2_get_next_mid,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002803 .read_data_offset = smb2_read_data_offset,
2804 .read_data_length = smb2_read_data_length,
2805 .map_error = map_smb2_to_linux_error,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04002806 .find_mid = smb2_find_mid,
2807 .check_message = smb2_check_message,
2808 .dump_detail = smb2_dump_detail,
Pavel Shilovskyd60622e2012-05-28 15:19:39 +04002809 .clear_stats = smb2_clear_stats,
2810 .print_stats = smb2_print_stats,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002811 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002812 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002813 .downgrade_oplock = smb2_downgrade_oplock,
Pavel Shilovskyec2e4522011-12-27 16:12:43 +04002814 .need_neg = smb2_need_neg,
2815 .negotiate = smb2_negotiate,
Pavel Shilovsky3a3bab52012-09-18 16:20:28 -07002816 .negotiate_wsize = smb2_negotiate_wsize,
2817 .negotiate_rsize = smb2_negotiate_rsize,
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +04002818 .sess_setup = SMB2_sess_setup,
2819 .logoff = SMB2_logoff,
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +04002820 .tree_connect = SMB2_tcon,
2821 .tree_disconnect = SMB2_tdis,
Steve French34f62642013-10-09 02:07:00 -05002822 .qfs_tcon = smb2_qfs_tcon,
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04002823 .is_path_accessible = smb2_is_path_accessible,
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04002824 .can_echo = smb2_can_echo,
2825 .echo = SMB2_echo,
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04002826 .query_path_info = smb2_query_path_info,
2827 .get_srv_inum = smb2_get_srv_inum,
Pavel Shilovskyb7546bc2012-09-18 16:20:27 -07002828 .query_file_info = smb2_query_file_info,
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07002829 .set_path_size = smb2_set_path_size,
2830 .set_file_size = smb2_set_file_size,
Pavel Shilovsky1feeaac2012-09-18 16:20:32 -07002831 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002832 .set_compression = smb2_set_compression,
Pavel Shilovskya0e73182011-07-19 12:56:37 +04002833 .mkdir = smb2_mkdir,
2834 .mkdir_setinfo = smb2_mkdir_setinfo,
Pavel Shilovsky1a500f02012-07-10 16:14:38 +04002835 .rmdir = smb2_rmdir,
Pavel Shilovskycbe6f432012-09-18 16:20:25 -07002836 .unlink = smb2_unlink,
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07002837 .rename = smb2_rename_path,
Pavel Shilovsky568798c2012-09-18 16:20:31 -07002838 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002839 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002840 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002841 .create_mf_symlink = smb3_create_mf_symlink,
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07002842 .open = smb2_open_file,
2843 .set_fid = smb2_set_fid,
2844 .close = smb2_close_file,
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07002845 .flush = smb2_flush_file,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07002846 .async_readv = smb2_async_readv,
Pavel Shilovsky33319142012-09-18 16:20:29 -07002847 .async_writev = smb2_async_writev,
Pavel Shilovskyd8e05032012-09-18 16:20:30 -07002848 .sync_read = smb2_sync_read,
Pavel Shilovsky009d3442012-09-18 16:20:30 -07002849 .sync_write = smb2_sync_write,
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07002850 .query_dir_first = smb2_query_dir_first,
2851 .query_dir_next = smb2_query_dir_next,
2852 .close_dir = smb2_close_dir,
2853 .calc_smb_size = smb2_calc_size,
Pavel Shilovsky2e44b282012-09-18 16:20:33 -07002854 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002855 .is_session_expired = smb2_is_session_expired,
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07002856 .oplock_response = smb2_oplock_response,
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07002857 .queryfs = smb2_queryfs,
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07002858 .mand_lock = smb2_mand_lock,
2859 .mand_unlock_range = smb2_unlock_range,
Pavel Shilovskyb1407992012-09-19 06:22:44 -07002860 .push_mand_locks = smb2_push_mandatory_locks,
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -07002861 .get_lease_key = smb2_get_lease_key,
2862 .set_lease_key = smb2_set_lease_key,
2863 .new_lease_key = smb2_new_lease_key,
Steve French38107d42012-12-08 22:08:06 -06002864 .calc_signature = smb2_calc_signature,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002865 .is_read_op = smb21_is_read_op,
2866 .set_oplock_level = smb21_set_oplock_level,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04002867 .create_lease_buf = smb2_create_lease_buf,
Pavel Shilovskyb5c7cde2013-09-05 20:16:45 +04002868 .parse_lease_buf = smb2_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002869 .copychunk_range = smb2_copychunk_range,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002870 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002871 .dir_needs_close = smb2_dir_needs_close,
Steve French834170c2016-09-30 21:14:26 -05002872 .enum_snapshots = smb3_enum_snapshots,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002873 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302874 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002875#ifdef CONFIG_CIFS_XATTR
2876 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002877 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002878#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002879#ifdef CONFIG_CIFS_ACL
2880 .get_acl = get_smb2_acl,
2881 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002882 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002883#endif /* CIFS_ACL */
Steve French38107d42012-12-08 22:08:06 -06002884};
2885
Steve French38107d42012-12-08 22:08:06 -06002886struct smb_version_operations smb30_operations = {
2887 .compare_fids = smb2_compare_fids,
2888 .setup_request = smb2_setup_request,
2889 .setup_async_request = smb2_setup_async_request,
2890 .check_receive = smb2_check_receive,
2891 .add_credits = smb2_add_credits,
2892 .set_credits = smb2_set_credits,
2893 .get_credits_field = smb2_get_credits_field,
2894 .get_credits = smb2_get_credits,
Pavel Shilovskycb7e9ea2014-06-05 19:03:27 +04002895 .wait_mtu_credits = smb2_wait_mtu_credits,
Steve French38107d42012-12-08 22:08:06 -06002896 .get_next_mid = smb2_get_next_mid,
2897 .read_data_offset = smb2_read_data_offset,
2898 .read_data_length = smb2_read_data_length,
2899 .map_error = map_smb2_to_linux_error,
2900 .find_mid = smb2_find_mid,
2901 .check_message = smb2_check_message,
2902 .dump_detail = smb2_dump_detail,
2903 .clear_stats = smb2_clear_stats,
2904 .print_stats = smb2_print_stats,
Steve French769ee6a2013-06-19 14:15:30 -05002905 .dump_share_caps = smb2_dump_share_caps,
Steve French38107d42012-12-08 22:08:06 -06002906 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08002907 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Sachin Prabhuc11f1df2014-03-11 16:11:47 +00002908 .downgrade_oplock = smb2_downgrade_oplock,
Steve French38107d42012-12-08 22:08:06 -06002909 .need_neg = smb2_need_neg,
2910 .negotiate = smb2_negotiate,
2911 .negotiate_wsize = smb2_negotiate_wsize,
2912 .negotiate_rsize = smb2_negotiate_rsize,
2913 .sess_setup = SMB2_sess_setup,
2914 .logoff = SMB2_logoff,
2915 .tree_connect = SMB2_tcon,
2916 .tree_disconnect = SMB2_tdis,
Steven Frenchaf6a12e2013-10-09 20:55:53 -05002917 .qfs_tcon = smb3_qfs_tcon,
Steve French38107d42012-12-08 22:08:06 -06002918 .is_path_accessible = smb2_is_path_accessible,
2919 .can_echo = smb2_can_echo,
2920 .echo = SMB2_echo,
2921 .query_path_info = smb2_query_path_info,
2922 .get_srv_inum = smb2_get_srv_inum,
2923 .query_file_info = smb2_query_file_info,
2924 .set_path_size = smb2_set_path_size,
2925 .set_file_size = smb2_set_file_size,
2926 .set_file_info = smb2_set_file_info,
Steve French64a5cfa2013-10-14 15:31:32 -05002927 .set_compression = smb2_set_compression,
Steve French38107d42012-12-08 22:08:06 -06002928 .mkdir = smb2_mkdir,
2929 .mkdir_setinfo = smb2_mkdir_setinfo,
2930 .rmdir = smb2_rmdir,
2931 .unlink = smb2_unlink,
2932 .rename = smb2_rename_path,
2933 .create_hardlink = smb2_create_hardlink,
Pavel Shilovskyb42bf882013-08-14 19:25:21 +04002934 .query_symlink = smb2_query_symlink,
Steve Frenchc22870e2014-09-16 07:18:19 -05002935 .query_mf_symlink = smb3_query_mf_symlink,
Steve French5ab97572014-09-15 04:49:28 -05002936 .create_mf_symlink = smb3_create_mf_symlink,
Steve French38107d42012-12-08 22:08:06 -06002937 .open = smb2_open_file,
2938 .set_fid = smb2_set_fid,
2939 .close = smb2_close_file,
2940 .flush = smb2_flush_file,
2941 .async_readv = smb2_async_readv,
2942 .async_writev = smb2_async_writev,
2943 .sync_read = smb2_sync_read,
2944 .sync_write = smb2_sync_write,
2945 .query_dir_first = smb2_query_dir_first,
2946 .query_dir_next = smb2_query_dir_next,
2947 .close_dir = smb2_close_dir,
2948 .calc_smb_size = smb2_calc_size,
2949 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07002950 .is_session_expired = smb2_is_session_expired,
Steve French38107d42012-12-08 22:08:06 -06002951 .oplock_response = smb2_oplock_response,
2952 .queryfs = smb2_queryfs,
2953 .mand_lock = smb2_mand_lock,
2954 .mand_unlock_range = smb2_unlock_range,
2955 .push_mand_locks = smb2_push_mandatory_locks,
2956 .get_lease_key = smb2_get_lease_key,
2957 .set_lease_key = smb2_set_lease_key,
2958 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06002959 .generate_signingkey = generate_smb30signingkey,
Steve French38107d42012-12-08 22:08:06 -06002960 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05002961 .set_integrity = smb3_set_integrity,
Pavel Shilovsky53ef1012013-09-05 16:11:28 +04002962 .is_read_op = smb21_is_read_op,
Pavel Shilovsky42873b02013-09-05 21:30:16 +04002963 .set_oplock_level = smb3_set_oplock_level,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04002964 .create_lease_buf = smb3_create_lease_buf,
2965 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05002966 .copychunk_range = smb2_copychunk_range,
Steve Frenchca9e7a12015-10-01 21:40:10 -05002967 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchff1c0382013-11-19 23:44:46 -06002968 .validate_negotiate = smb3_validate_negotiate,
Pavel Shilovsky7f6c5002014-06-22 11:03:22 +04002969 .wp_retry_size = smb2_wp_retry_size,
Pavel Shilovsky52755802014-08-18 20:49:57 +04002970 .dir_needs_close = smb2_dir_needs_close,
Steve French31742c52014-08-17 08:38:47 -05002971 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05002972 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07002973 .init_transform_rq = smb3_init_transform_rq,
2974 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08002975 .is_transform_hdr = smb3_is_transform_hdr,
2976 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01002977 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05302978 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002979#ifdef CONFIG_CIFS_XATTR
2980 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10002981 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10002982#endif /* CIFS_XATTR */
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002983#ifdef CONFIG_CIFS_ACL
2984 .get_acl = get_smb2_acl,
2985 .get_acl_by_fid = get_smb2_acl_by_fid,
Shirish Pargaonkar366ed842017-06-28 22:37:32 -05002986 .set_acl = set_smb2_acl,
Shirish Pargaonkar2f1afe22017-06-22 22:52:05 -05002987#endif /* CIFS_ACL */
Steve French1080ef72011-02-24 18:07:19 +00002988};
2989
Steve Frenchaab18932015-06-23 23:37:11 -05002990#ifdef CONFIG_CIFS_SMB311
2991struct smb_version_operations smb311_operations = {
2992 .compare_fids = smb2_compare_fids,
2993 .setup_request = smb2_setup_request,
2994 .setup_async_request = smb2_setup_async_request,
2995 .check_receive = smb2_check_receive,
2996 .add_credits = smb2_add_credits,
2997 .set_credits = smb2_set_credits,
2998 .get_credits_field = smb2_get_credits_field,
2999 .get_credits = smb2_get_credits,
3000 .wait_mtu_credits = smb2_wait_mtu_credits,
3001 .get_next_mid = smb2_get_next_mid,
3002 .read_data_offset = smb2_read_data_offset,
3003 .read_data_length = smb2_read_data_length,
3004 .map_error = map_smb2_to_linux_error,
3005 .find_mid = smb2_find_mid,
3006 .check_message = smb2_check_message,
3007 .dump_detail = smb2_dump_detail,
3008 .clear_stats = smb2_clear_stats,
3009 .print_stats = smb2_print_stats,
3010 .dump_share_caps = smb2_dump_share_caps,
3011 .is_oplock_break = smb2_is_valid_oplock_break,
Sachin Prabhu38bd4902017-03-03 15:41:38 -08003012 .handle_cancelled_mid = smb2_handle_cancelled_mid,
Steve Frenchaab18932015-06-23 23:37:11 -05003013 .downgrade_oplock = smb2_downgrade_oplock,
3014 .need_neg = smb2_need_neg,
3015 .negotiate = smb2_negotiate,
3016 .negotiate_wsize = smb2_negotiate_wsize,
3017 .negotiate_rsize = smb2_negotiate_rsize,
3018 .sess_setup = SMB2_sess_setup,
3019 .logoff = SMB2_logoff,
3020 .tree_connect = SMB2_tcon,
3021 .tree_disconnect = SMB2_tdis,
3022 .qfs_tcon = smb3_qfs_tcon,
3023 .is_path_accessible = smb2_is_path_accessible,
3024 .can_echo = smb2_can_echo,
3025 .echo = SMB2_echo,
3026 .query_path_info = smb2_query_path_info,
3027 .get_srv_inum = smb2_get_srv_inum,
3028 .query_file_info = smb2_query_file_info,
3029 .set_path_size = smb2_set_path_size,
3030 .set_file_size = smb2_set_file_size,
3031 .set_file_info = smb2_set_file_info,
3032 .set_compression = smb2_set_compression,
3033 .mkdir = smb2_mkdir,
3034 .mkdir_setinfo = smb2_mkdir_setinfo,
3035 .rmdir = smb2_rmdir,
3036 .unlink = smb2_unlink,
3037 .rename = smb2_rename_path,
3038 .create_hardlink = smb2_create_hardlink,
3039 .query_symlink = smb2_query_symlink,
3040 .query_mf_symlink = smb3_query_mf_symlink,
3041 .create_mf_symlink = smb3_create_mf_symlink,
3042 .open = smb2_open_file,
3043 .set_fid = smb2_set_fid,
3044 .close = smb2_close_file,
3045 .flush = smb2_flush_file,
3046 .async_readv = smb2_async_readv,
3047 .async_writev = smb2_async_writev,
3048 .sync_read = smb2_sync_read,
3049 .sync_write = smb2_sync_write,
3050 .query_dir_first = smb2_query_dir_first,
3051 .query_dir_next = smb2_query_dir_next,
3052 .close_dir = smb2_close_dir,
3053 .calc_smb_size = smb2_calc_size,
3054 .is_status_pending = smb2_is_status_pending,
Pavel Shilovsky511c54a2017-07-08 14:32:00 -07003055 .is_session_expired = smb2_is_session_expired,
Steve Frenchaab18932015-06-23 23:37:11 -05003056 .oplock_response = smb2_oplock_response,
3057 .queryfs = smb2_queryfs,
3058 .mand_lock = smb2_mand_lock,
3059 .mand_unlock_range = smb2_unlock_range,
3060 .push_mand_locks = smb2_push_mandatory_locks,
3061 .get_lease_key = smb2_get_lease_key,
3062 .set_lease_key = smb2_set_lease_key,
3063 .new_lease_key = smb2_new_lease_key,
Steve French373512e2015-12-18 13:05:30 -06003064 .generate_signingkey = generate_smb311signingkey,
Steve Frenchaab18932015-06-23 23:37:11 -05003065 .calc_signature = smb3_calc_signature,
Steve Frenchb3152e22015-06-24 03:17:02 -05003066 .set_integrity = smb3_set_integrity,
Steve Frenchaab18932015-06-23 23:37:11 -05003067 .is_read_op = smb21_is_read_op,
3068 .set_oplock_level = smb3_set_oplock_level,
3069 .create_lease_buf = smb3_create_lease_buf,
3070 .parse_lease_buf = smb3_parse_lease_buf,
Sachin Prabhu312bbc52017-04-04 02:12:04 -05003071 .copychunk_range = smb2_copychunk_range,
Steve French02b16662015-06-27 21:18:36 -07003072 .duplicate_extents = smb2_duplicate_extents,
Steve Frenchaab18932015-06-23 23:37:11 -05003073/* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3074 .wp_retry_size = smb2_wp_retry_size,
3075 .dir_needs_close = smb2_dir_needs_close,
3076 .fallocate = smb3_fallocate,
Steve French834170c2016-09-30 21:14:26 -05003077 .enum_snapshots = smb3_enum_snapshots,
Pavel Shilovsky026e93d2016-11-03 16:47:37 -07003078 .init_transform_rq = smb3_init_transform_rq,
3079 .free_transform_rq = smb3_free_transform_rq,
Pavel Shilovsky4326ed22016-11-17 15:24:46 -08003080 .is_transform_hdr = smb3_is_transform_hdr,
3081 .receive_transform = smb3_receive_transform,
Aurelien Aptel9d496402017-02-13 16:16:49 +01003082 .get_dfs_refer = smb2_get_dfs_refer,
Sachin Prabhuef65aae2017-01-18 15:35:57 +05303083 .select_sectype = smb2_select_sectype,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10003084#ifdef CONFIG_CIFS_XATTR
3085 .query_all_EAs = smb2_query_eas,
Ronnie Sahlberg55175542017-08-24 11:24:56 +10003086 .set_EA = smb2_set_ea,
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10003087#endif /* CIFS_XATTR */
Steve Frenchaab18932015-06-23 23:37:11 -05003088};
3089#endif /* CIFS_SMB311 */
3090
Steve Frenchdd446b12012-11-28 23:21:06 -06003091struct smb_version_values smb20_values = {
3092 .version_string = SMB20_VERSION_STRING,
3093 .protocol_id = SMB20_PROT_ID,
3094 .req_capabilities = 0, /* MBZ */
3095 .large_lock_type = 0,
3096 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3097 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3098 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3099 .header_size = sizeof(struct smb2_hdr),
3100 .max_header_size = MAX_SMB2_HDR_SIZE,
3101 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3102 .lock_cmd = SMB2_LOCK,
3103 .cap_unix = 0,
3104 .cap_nt_find = SMB2_NT_FIND,
3105 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04003106 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3107 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04003108 .create_lease_size = sizeof(struct create_lease),
Steve Frenchdd446b12012-11-28 23:21:06 -06003109};
3110
Steve French1080ef72011-02-24 18:07:19 +00003111struct smb_version_values smb21_values = {
3112 .version_string = SMB21_VERSION_STRING,
Steve Frenche4aa25e2012-10-01 12:26:22 -05003113 .protocol_id = SMB21_PROT_ID,
3114 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3115 .large_lock_type = 0,
3116 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3117 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3118 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3119 .header_size = sizeof(struct smb2_hdr),
3120 .max_header_size = MAX_SMB2_HDR_SIZE,
3121 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3122 .lock_cmd = SMB2_LOCK,
3123 .cap_unix = 0,
3124 .cap_nt_find = SMB2_NT_FIND,
3125 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04003126 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3127 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskya41a28b2013-09-04 13:07:41 +04003128 .create_lease_size = sizeof(struct create_lease),
Steve Frenche4aa25e2012-10-01 12:26:22 -05003129};
3130
Steve French9764c022017-09-17 10:41:35 -05003131struct smb_version_values smb3any_values = {
3132 .version_string = SMB3ANY_VERSION_STRING,
3133 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3134 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3135 .large_lock_type = 0,
3136 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3137 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3138 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3139 .header_size = sizeof(struct smb2_hdr),
3140 .max_header_size = MAX_SMB2_HDR_SIZE,
3141 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3142 .lock_cmd = SMB2_LOCK,
3143 .cap_unix = 0,
3144 .cap_nt_find = SMB2_NT_FIND,
3145 .cap_large_files = SMB2_LARGE_FILES,
3146 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3147 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3148 .create_lease_size = sizeof(struct create_lease_v2),
3149};
3150
3151struct smb_version_values smbdefault_values = {
3152 .version_string = SMBDEFAULT_VERSION_STRING,
3153 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3154 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3155 .large_lock_type = 0,
3156 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3157 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3158 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3159 .header_size = sizeof(struct smb2_hdr),
3160 .max_header_size = MAX_SMB2_HDR_SIZE,
3161 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3162 .lock_cmd = SMB2_LOCK,
3163 .cap_unix = 0,
3164 .cap_nt_find = SMB2_NT_FIND,
3165 .cap_large_files = SMB2_LARGE_FILES,
3166 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3167 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3168 .create_lease_size = sizeof(struct create_lease_v2),
3169};
3170
Steve Frenche4aa25e2012-10-01 12:26:22 -05003171struct smb_version_values smb30_values = {
3172 .version_string = SMB30_VERSION_STRING,
3173 .protocol_id = SMB30_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06003174 .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 -07003175 .large_lock_type = 0,
3176 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3177 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3178 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +04003179 .header_size = sizeof(struct smb2_hdr),
3180 .max_header_size = MAX_SMB2_HDR_SIZE,
Pavel Shilovsky09a47072012-09-18 16:20:29 -07003181 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +04003182 .lock_cmd = SMB2_LOCK,
Pavel Shilovsky29e20f92012-07-13 13:58:14 +04003183 .cap_unix = 0,
3184 .cap_nt_find = SMB2_NT_FIND,
3185 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04003186 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3187 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04003188 .create_lease_size = sizeof(struct create_lease_v2),
Steve French1080ef72011-02-24 18:07:19 +00003189};
Steve French20b6d8b2013-06-12 22:48:41 -05003190
3191struct smb_version_values smb302_values = {
3192 .version_string = SMB302_VERSION_STRING,
3193 .protocol_id = SMB302_PROT_ID,
Steve French373512e2015-12-18 13:05:30 -06003194 .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 -05003195 .large_lock_type = 0,
3196 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3197 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3198 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3199 .header_size = sizeof(struct smb2_hdr),
3200 .max_header_size = MAX_SMB2_HDR_SIZE,
3201 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3202 .lock_cmd = SMB2_LOCK,
3203 .cap_unix = 0,
3204 .cap_nt_find = SMB2_NT_FIND,
3205 .cap_large_files = SMB2_LARGE_FILES,
Jeff Layton50285882013-06-27 12:45:00 -04003206 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3207 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
Pavel Shilovskyf0473902013-09-04 13:44:05 +04003208 .create_lease_size = sizeof(struct create_lease_v2),
Steve French20b6d8b2013-06-12 22:48:41 -05003209};
Steve French5f7fbf72014-12-17 22:52:58 -06003210
3211#ifdef CONFIG_CIFS_SMB311
3212struct smb_version_values smb311_values = {
3213 .version_string = SMB311_VERSION_STRING,
3214 .protocol_id = SMB311_PROT_ID,
Steve French19558802017-06-21 16:50:20 -05003215 .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 -06003216 .large_lock_type = 0,
3217 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3218 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3219 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3220 .header_size = sizeof(struct smb2_hdr),
3221 .max_header_size = MAX_SMB2_HDR_SIZE,
3222 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3223 .lock_cmd = SMB2_LOCK,
3224 .cap_unix = 0,
3225 .cap_nt_find = SMB2_NT_FIND,
3226 .cap_large_files = SMB2_LARGE_FILES,
3227 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3228 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3229 .create_lease_size = sizeof(struct create_lease_v2),
3230};
3231#endif /* SMB311 */