Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SMB2 version specific operations |
| 3 | * |
| 4 | * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License v2 as published |
| 8 | * by the Free Software Foundation. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public License |
| 16 | * along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 20 | #include <linux/pagemap.h> |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 21 | #include <linux/vfs.h> |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 22 | #include <linux/falloc.h> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 23 | #include <linux/scatterlist.h> |
Tobias Regnery | 4fa8e50 | 2017-03-30 12:34:14 +0200 | [diff] [blame] | 24 | #include <linux/uuid.h> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 25 | #include <crypto/aead.h> |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 26 | #include "cifsglob.h" |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 27 | #include "smb2pdu.h" |
| 28 | #include "smb2proto.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 29 | #include "cifsproto.h" |
| 30 | #include "cifs_debug.h" |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 31 | #include "cifs_unicode.h" |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 32 | #include "smb2status.h" |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 33 | #include "smb2glob.h" |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 34 | #include "cifs_ioctl.h" |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 35 | #include "smbdirect.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 36 | |
| 37 | static int |
| 38 | change_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 Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 48 | cifs_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 49 | break; |
| 50 | case 2: |
| 51 | server->echoes = true; |
| 52 | server->oplocks = false; |
| 53 | server->echo_credits = 1; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 54 | cifs_dbg(FYI, "disabling oplocks\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 55 | break; |
| 56 | default: |
| 57 | server->echoes = true; |
Steve French | e0ddde9 | 2015-09-22 09:29:38 -0500 | [diff] [blame] | 58 | if (enable_oplocks) { |
| 59 | server->oplocks = true; |
| 60 | server->oplock_credits = 1; |
| 61 | } else |
| 62 | server->oplocks = false; |
| 63 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 64 | server->echo_credits = 1; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 65 | } |
| 66 | server->credits -= server->echo_credits + server->oplock_credits; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static void |
| 71 | smb2_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 French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 78 | 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 Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 82 | server->in_flight--; |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 83 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 84 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 85 | /* |
| 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 Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 96 | spin_unlock(&server->req_lock); |
| 97 | wake_up(&server->request_q); |
| 98 | if (rc) |
| 99 | cifs_reconnect(server); |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | smb2_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 | |
| 110 | static int * |
| 111 | smb2_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 | |
| 123 | static unsigned int |
| 124 | smb2_get_credits(struct mid_q_entry *mid) |
| 125 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 126 | struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf); |
| 127 | |
| 128 | return le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 129 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 130 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 131 | static int |
| 132 | smb2_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 Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 178 | static __u64 |
| 179 | smb2_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 French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 188 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 189 | static struct mid_q_entry * |
| 190 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 191 | { |
| 192 | struct mid_q_entry *mid; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 193 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
| 194 | __u64 wire_mid = le64_to_cpu(shdr->MessageId); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 195 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 196 | if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 197 | cifs_dbg(VFS, "encrypted frame parsing not supported yet"); |
| 198 | return NULL; |
| 199 | } |
| 200 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 201 | spin_lock(&GlobalMid_Lock); |
| 202 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
Sachin Prabhu | 9235d09 | 2014-12-09 17:37:00 +0000 | [diff] [blame] | 203 | if ((mid->mid == wire_mid) && |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 204 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 205 | (mid->command == shdr->Command)) { |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 206 | spin_unlock(&GlobalMid_Lock); |
| 207 | return mid; |
| 208 | } |
| 209 | } |
| 210 | spin_unlock(&GlobalMid_Lock); |
| 211 | return NULL; |
| 212 | } |
| 213 | |
| 214 | static void |
| 215 | smb2_dump_detail(void *buf) |
| 216 | { |
| 217 | #ifdef CONFIG_CIFS_DEBUG2 |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 218 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 219 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 220 | cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 221 | 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 Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 224 | #endif |
| 225 | } |
| 226 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 227 | static bool |
| 228 | smb2_need_neg(struct TCP_Server_Info *server) |
| 229 | { |
| 230 | return server->max_read == 0; |
| 231 | } |
| 232 | |
| 233 | static int |
| 234 | smb2_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 Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 245 | static unsigned int |
| 246 | smb2_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 Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 254 | #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 Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 259 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 260 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 261 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 262 | return wsize; |
| 263 | } |
| 264 | |
| 265 | static unsigned int |
| 266 | smb2_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 Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 274 | #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 Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 279 | |
| 280 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 281 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 282 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 283 | return rsize; |
| 284 | } |
| 285 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 286 | #ifdef CONFIG_CIFS_STATS2 |
| 287 | static int |
| 288 | SMB3_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 French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 298 | 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 French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 304 | /* 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 French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 309 | } |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 310 | kfree(out_buf); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 311 | return rc; |
| 312 | } |
| 313 | #endif /* STATS2 */ |
| 314 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 315 | static void |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 316 | smb3_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 French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 335 | #ifdef CONFIG_CIFS_STATS2 |
| 336 | SMB3_request_interfaces(xid, tcon); |
| 337 | #endif /* STATS2 */ |
| 338 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 339 | 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 | |
| 349 | static void |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 350 | smb2_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 French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 369 | 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 French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 373 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 374 | return; |
| 375 | } |
| 376 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 377 | static int |
| 378 | smb2_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 Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 382 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 383 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 384 | struct cifs_open_parms oparms; |
| 385 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 386 | |
| 387 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 388 | if (!utf16_path) |
| 389 | return -ENOMEM; |
| 390 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 391 | 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 Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 396 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 397 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 398 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 399 | if (rc) { |
| 400 | kfree(utf16_path); |
| 401 | return rc; |
| 402 | } |
| 403 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 404 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 405 | kfree(utf16_path); |
| 406 | return rc; |
| 407 | } |
| 408 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 409 | static int |
| 410 | smb2_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 Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 418 | static int |
| 419 | smb2_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 Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 425 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 426 | 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 Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 438 | #ifdef CONFIG_CIFS_XATTR |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 439 | static ssize_t |
| 440 | move_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 | |
| 518 | out: |
| 519 | return (ssize_t)rc; |
| 520 | } |
| 521 | |
| 522 | static ssize_t |
| 523 | smb2_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 Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 534 | int ea_buf_size = SMB2_MIN_EA_BUF; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 535 | |
| 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 Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 554 | 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 Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 578 | } |
| 579 | |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 580 | 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 Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 590 | |
| 591 | static int |
| 592 | smb2_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 Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 645 | #endif |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 646 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 647 | static bool |
| 648 | smb2_can_echo(struct TCP_Server_Info *server) |
| 649 | { |
| 650 | return server->echoes; |
| 651 | } |
| 652 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 653 | static void |
| 654 | smb2_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 | |
| 665 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 666 | smb2_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 French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 681 | 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 French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 690 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 691 | if (tcon->perf_sector_size) |
| 692 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 693 | tcon->perf_sector_size); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 697 | smb2_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 Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 708 | 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 Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 762 | static void |
| 763 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 764 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 765 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 766 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 767 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 768 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 769 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 770 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 771 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 772 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Aurelien Aptel | 94f8737 | 2016-09-22 07:38:50 +0200 | [diff] [blame] | 773 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 776 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 777 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 778 | struct cifs_fid *fid) |
| 779 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 780 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 783 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 784 | SMB2_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 | |
| 808 | req_res_key_exit: |
| 809 | kfree(res_key); |
| 810 | return rc; |
| 811 | } |
| 812 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 813 | static ssize_t |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 814 | smb2_copychunk_range(const unsigned int xid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 815 | 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 French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 822 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 823 | struct cifs_tcon *tcon; |
| 824 | int chunks_copied = 0; |
| 825 | bool chunk_sizes_updated = false; |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 826 | ssize_t bytes_written, total_bytes_written = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 827 | |
| 828 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 829 | |
| 830 | if (pcchunk == NULL) |
| 831 | return -ENOMEM; |
| 832 | |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 833 | cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n"); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 834 | /* 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 French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 841 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 842 | |
| 843 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 844 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 845 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 846 | pcchunk->Reserved2 = 0; |
| 847 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 848 | 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 French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 858 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 859 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 860 | 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 French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 889 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 890 | 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 French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 895 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 896 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n", |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 897 | le32_to_cpu(retbuf->ChunksWritten), |
| 898 | le32_to_cpu(retbuf->ChunkBytesWritten), |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 899 | bytes_written); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 900 | } else if (rc == -EINVAL) { |
| 901 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 902 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 903 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 904 | 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 Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 929 | } else |
| 930 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 934 | kfree(pcchunk); |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 935 | kfree(retbuf); |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 936 | if (rc) |
| 937 | return rc; |
| 938 | else |
| 939 | return total_bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 943 | smb2_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 Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 949 | static unsigned int |
| 950 | smb2_read_data_offset(char *buf) |
| 951 | { |
| 952 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 953 | return rsp->DataOffset; |
| 954 | } |
| 955 | |
| 956 | static unsigned int |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 957 | smb2_read_data_length(char *buf, bool in_remaining) |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 958 | { |
| 959 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 960 | |
| 961 | if (in_remaining) |
| 962 | return le32_to_cpu(rsp->DataRemaining); |
| 963 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 964 | return le32_to_cpu(rsp->DataLength); |
| 965 | } |
| 966 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 967 | |
| 968 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 969 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 970 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 971 | char **buf, int *buf_type) |
| 972 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 973 | parms->persistent_fid = pfid->persistent_fid; |
| 974 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 975 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 976 | } |
| 977 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 978 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 979 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 980 | struct cifs_io_parms *parms, unsigned int *written, |
| 981 | struct kvec *iov, unsigned long nr_segs) |
| 982 | { |
| 983 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 984 | parms->persistent_fid = pfid->persistent_fid; |
| 985 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 986 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 987 | } |
| 988 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 989 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 990 | static 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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1020 | true /* is_fctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1021 | &setsparse, 1, NULL, NULL); |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1022 | 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 Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1036 | static int |
| 1037 | smb2_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 French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1041 | 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 Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1047 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1048 | |
| 1049 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1050 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1051 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1052 | /* whether set sparse succeeds or not, extend the file */ |
| 1053 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1056 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 1057 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1060 | static int |
| 1061 | smb2_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 French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1068 | 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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1091 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1092 | (char *)&dup_ext_buf, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1093 | sizeof(struct duplicate_extents_to_file), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1094 | NULL, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1095 | &ret_data_len); |
| 1096 | |
| 1097 | if (ret_data_len > 0) |
| 1098 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); |
| 1099 | |
| 1100 | duplicate_extents_out: |
| 1101 | return rc; |
| 1102 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1103 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1104 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1105 | smb2_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 | |
| 1112 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1113 | smb3_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 French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1117 | 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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1126 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1127 | (char *)&integr_info, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1128 | sizeof(struct fsctl_set_integrity_information_req), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1129 | NULL, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1130 | &ret_data_len); |
| 1131 | |
| 1132 | } |
| 1133 | |
| 1134 | static int |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1135 | smb3_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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1146 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1147 | NULL, 0 /* no input data */, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1148 | (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 Disseldorp | 0e5c795 | 2017-05-03 17:39:09 +0200 | [diff] [blame] | 1165 | kfree(retbuf); |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1166 | 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 | |
| 1180 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1181 | smb2_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 Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1188 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1189 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1190 | |
| 1191 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1192 | if (!utf16_path) |
| 1193 | return -ENOMEM; |
| 1194 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1195 | 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 Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1200 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1201 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1202 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1203 | kfree(utf16_path); |
| 1204 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 1205 | cifs_dbg(FYI, "open dir failed rc=%d\n", rc); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1206 | return rc; |
| 1207 | } |
| 1208 | |
| 1209 | srch_inf->entries_in_buffer = 0; |
| 1210 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1211 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1212 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 1213 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1214 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 1215 | cifs_dbg(FYI, "query directory failed rc=%d\n", rc); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1216 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1217 | } |
| 1218 | return rc; |
| 1219 | } |
| 1220 | |
| 1221 | static int |
| 1222 | smb2_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 | |
| 1230 | static int |
| 1231 | smb2_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 Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1237 | /* |
| 1238 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 1239 | * the number of credits and return true. Otherwise - return false. |
| 1240 | */ |
| 1241 | static bool |
| 1242 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 1243 | { |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1244 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1245 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1246 | if (shdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1247 | return false; |
| 1248 | |
| 1249 | if (!length) { |
| 1250 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1251 | server->credits += le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1252 | spin_unlock(&server->req_lock); |
| 1253 | wake_up(&server->request_q); |
| 1254 | } |
| 1255 | |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1259 | static bool |
| 1260 | smb2_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 Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1271 | static int |
| 1272 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 1273 | struct cifsInodeInfo *cinode) |
| 1274 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 1275 | 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 Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1279 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 1280 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 1281 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1284 | static int |
| 1285 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 1286 | struct kstatfs *buf) |
| 1287 | { |
| 1288 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1289 | __le16 srch_path = 0; /* Null - open root of share */ |
| 1290 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1291 | struct cifs_open_parms oparms; |
| 1292 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1293 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1294 | 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 Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1299 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1300 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1301 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1302 | if (rc) |
| 1303 | return rc; |
| 1304 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1305 | 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 Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1308 | return rc; |
| 1309 | } |
| 1310 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1311 | static bool |
| 1312 | smb2_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 Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1318 | static int |
| 1319 | smb2_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 Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1329 | static void |
| 1330 | smb2_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 | |
| 1335 | static void |
| 1336 | smb2_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 | |
| 1341 | static void |
| 1342 | smb2_new_lease_key(struct cifs_fid *fid) |
| 1343 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 1344 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1347 | static int |
| 1348 | smb2_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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1365 | * Try to use the IPC tcon, otherwise just use any |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1366 | */ |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1367 | 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 Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1377 | |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1378 | if (tcon == NULL) { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1379 | 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 Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1407 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 1408 | FSCTL_DFS_GET_REFERRALS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1409 | true /* is_fsctl */, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1410 | (char *)dfs_req, dfs_req_size, |
| 1411 | (char **)&dfs_rsp, &dfs_rsp_size); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1412 | } while (rc == -EAGAIN); |
| 1413 | |
| 1414 | if (rc) { |
Steve French | 2564f2f | 2018-03-21 23:16:36 -0500 | [diff] [blame] | 1415 | if ((rc != -ENOENT) && (rc != -EOPNOTSUPP)) |
Aurelien Aptel | 5702591 | 2017-11-21 14:47:56 +0100 | [diff] [blame] | 1416 | cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1417 | 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 Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1430 | if (tcon && !tcon->ipc) { |
| 1431 | /* ipc tcons are not refcounted */ |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1432 | 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 Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1441 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 1442 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 1443 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1444 | static int |
| 1445 | smb2_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 Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1456 | unsigned int sub_len; |
| 1457 | unsigned int sub_offset; |
| 1458 | unsigned int print_len; |
| 1459 | unsigned int print_offset; |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 1460 | struct cifs_ses *ses = tcon->ses; |
| 1461 | struct TCP_Server_Info *server = ses->server; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1462 | |
| 1463 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 1464 | |
| 1465 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 1466 | if (!utf16_path) |
| 1467 | return -ENOMEM; |
| 1468 | |
| 1469 | oparms.tcon = tcon; |
| 1470 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1471 | oparms.disposition = FILE_OPEN; |
| 1472 | oparms.create_options = 0; |
| 1473 | oparms.fid = &fid; |
| 1474 | oparms.reconnect = false; |
| 1475 | |
| 1476 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf); |
| 1477 | |
| 1478 | if (!rc || !err_buf) { |
| 1479 | kfree(utf16_path); |
| 1480 | return -ENOENT; |
| 1481 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1482 | |
| 1483 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 1484 | get_rfc1002_length(err_buf) + server->vals->header_preamble_size < SMB2_SYMLINK_STRUCT_SIZE) { |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1485 | kfree(utf16_path); |
| 1486 | return -ENOENT; |
| 1487 | } |
| 1488 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1489 | /* open must fail on symlink - reset rc */ |
| 1490 | rc = 0; |
| 1491 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 1492 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 1493 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1494 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 1495 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 1496 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 1497 | if (get_rfc1002_length(err_buf) + server->vals->header_preamble_size < |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1498 | SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { |
| 1499 | kfree(utf16_path); |
| 1500 | return -ENOENT; |
| 1501 | } |
| 1502 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 1503 | if (get_rfc1002_length(err_buf) + server->vals->header_preamble_size < |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1504 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
| 1505 | kfree(utf16_path); |
| 1506 | return -ENOENT; |
| 1507 | } |
| 1508 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1509 | *target_path = cifs_strndup_from_utf16( |
| 1510 | (char *)symlink->PathBuffer + sub_offset, |
| 1511 | sub_len, true, cifs_sb->local_nls); |
| 1512 | if (!(*target_path)) { |
| 1513 | kfree(utf16_path); |
| 1514 | return -ENOMEM; |
| 1515 | } |
| 1516 | convert_delimiter(*target_path, '/'); |
| 1517 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 1518 | kfree(utf16_path); |
| 1519 | return rc; |
| 1520 | } |
| 1521 | |
Arnd Bergmann | 8490842 | 2017-06-27 17:06:13 +0200 | [diff] [blame] | 1522 | #ifdef CONFIG_CIFS_ACL |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1523 | static struct cifs_ntsd * |
| 1524 | get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb, |
| 1525 | const struct cifs_fid *cifsfid, u32 *pacllen) |
| 1526 | { |
| 1527 | struct cifs_ntsd *pntsd = NULL; |
| 1528 | unsigned int xid; |
| 1529 | int rc = -EOPNOTSUPP; |
| 1530 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1531 | |
| 1532 | if (IS_ERR(tlink)) |
| 1533 | return ERR_CAST(tlink); |
| 1534 | |
| 1535 | xid = get_xid(); |
| 1536 | cifs_dbg(FYI, "trying to get acl\n"); |
| 1537 | |
| 1538 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, |
| 1539 | cifsfid->volatile_fid, (void **)&pntsd, pacllen); |
| 1540 | free_xid(xid); |
| 1541 | |
| 1542 | cifs_put_tlink(tlink); |
| 1543 | |
| 1544 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 1545 | if (rc) |
| 1546 | return ERR_PTR(rc); |
| 1547 | return pntsd; |
| 1548 | |
| 1549 | } |
| 1550 | |
| 1551 | static struct cifs_ntsd * |
| 1552 | get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, |
| 1553 | const char *path, u32 *pacllen) |
| 1554 | { |
| 1555 | struct cifs_ntsd *pntsd = NULL; |
| 1556 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1557 | unsigned int xid; |
| 1558 | int rc; |
| 1559 | struct cifs_tcon *tcon; |
| 1560 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1561 | struct cifs_fid fid; |
| 1562 | struct cifs_open_parms oparms; |
| 1563 | __le16 *utf16_path; |
| 1564 | |
| 1565 | cifs_dbg(FYI, "get smb3 acl for path %s\n", path); |
| 1566 | if (IS_ERR(tlink)) |
| 1567 | return ERR_CAST(tlink); |
| 1568 | |
| 1569 | tcon = tlink_tcon(tlink); |
| 1570 | xid = get_xid(); |
| 1571 | |
| 1572 | if (backup_cred(cifs_sb)) |
Colin Ian King | 709340a | 2017-07-05 13:47:34 +0100 | [diff] [blame] | 1573 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1574 | else |
| 1575 | oparms.create_options = 0; |
| 1576 | |
| 1577 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1578 | if (!utf16_path) |
| 1579 | return ERR_PTR(-ENOMEM); |
| 1580 | |
| 1581 | oparms.tcon = tcon; |
| 1582 | oparms.desired_access = READ_CONTROL; |
| 1583 | oparms.disposition = FILE_OPEN; |
| 1584 | oparms.fid = &fid; |
| 1585 | oparms.reconnect = false; |
| 1586 | |
| 1587 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
| 1588 | kfree(utf16_path); |
| 1589 | if (!rc) { |
| 1590 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 1591 | fid.volatile_fid, (void **)&pntsd, pacllen); |
| 1592 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 1593 | } |
| 1594 | |
| 1595 | cifs_put_tlink(tlink); |
| 1596 | free_xid(xid); |
| 1597 | |
| 1598 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 1599 | if (rc) |
| 1600 | return ERR_PTR(rc); |
| 1601 | return pntsd; |
| 1602 | } |
| 1603 | |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 1604 | #ifdef CONFIG_CIFS_ACL |
| 1605 | static int |
| 1606 | set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 1607 | struct inode *inode, const char *path, int aclflag) |
| 1608 | { |
| 1609 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1610 | unsigned int xid; |
| 1611 | int rc, access_flags = 0; |
| 1612 | struct cifs_tcon *tcon; |
| 1613 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 1614 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1615 | struct cifs_fid fid; |
| 1616 | struct cifs_open_parms oparms; |
| 1617 | __le16 *utf16_path; |
| 1618 | |
| 1619 | cifs_dbg(FYI, "set smb3 acl for path %s\n", path); |
| 1620 | if (IS_ERR(tlink)) |
| 1621 | return PTR_ERR(tlink); |
| 1622 | |
| 1623 | tcon = tlink_tcon(tlink); |
| 1624 | xid = get_xid(); |
| 1625 | |
| 1626 | if (backup_cred(cifs_sb)) |
| 1627 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 1628 | else |
| 1629 | oparms.create_options = 0; |
| 1630 | |
| 1631 | if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP) |
| 1632 | access_flags = WRITE_OWNER; |
| 1633 | else |
| 1634 | access_flags = WRITE_DAC; |
| 1635 | |
| 1636 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1637 | if (!utf16_path) |
| 1638 | return -ENOMEM; |
| 1639 | |
| 1640 | oparms.tcon = tcon; |
| 1641 | oparms.desired_access = access_flags; |
| 1642 | oparms.disposition = FILE_OPEN; |
| 1643 | oparms.path = path; |
| 1644 | oparms.fid = &fid; |
| 1645 | oparms.reconnect = false; |
| 1646 | |
| 1647 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); |
| 1648 | kfree(utf16_path); |
| 1649 | if (!rc) { |
| 1650 | rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 1651 | fid.volatile_fid, pnntsd, acllen, aclflag); |
| 1652 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 1653 | } |
| 1654 | |
| 1655 | cifs_put_tlink(tlink); |
| 1656 | free_xid(xid); |
| 1657 | return rc; |
| 1658 | } |
| 1659 | #endif /* CIFS_ACL */ |
| 1660 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1661 | /* Retrieve an ACL from the server */ |
| 1662 | static struct cifs_ntsd * |
| 1663 | get_smb2_acl(struct cifs_sb_info *cifs_sb, |
| 1664 | struct inode *inode, const char *path, |
| 1665 | u32 *pacllen) |
| 1666 | { |
| 1667 | struct cifs_ntsd *pntsd = NULL; |
| 1668 | struct cifsFileInfo *open_file = NULL; |
| 1669 | |
| 1670 | if (inode) |
| 1671 | open_file = find_readable_file(CIFS_I(inode), true); |
| 1672 | if (!open_file) |
| 1673 | return get_smb2_acl_by_path(cifs_sb, path, pacllen); |
| 1674 | |
| 1675 | pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); |
| 1676 | cifsFileInfo_put(open_file); |
| 1677 | return pntsd; |
| 1678 | } |
Arnd Bergmann | 8490842 | 2017-06-27 17:06:13 +0200 | [diff] [blame] | 1679 | #endif |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1680 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1681 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 1682 | loff_t offset, loff_t len, bool keep_size) |
| 1683 | { |
| 1684 | struct inode *inode; |
| 1685 | struct cifsInodeInfo *cifsi; |
| 1686 | struct cifsFileInfo *cfile = file->private_data; |
| 1687 | struct file_zero_data_information fsctl_buf; |
| 1688 | long rc; |
| 1689 | unsigned int xid; |
| 1690 | |
| 1691 | xid = get_xid(); |
| 1692 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1693 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1694 | cifsi = CIFS_I(inode); |
| 1695 | |
| 1696 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1697 | if (!CIFS_CACHE_READ(cifsi)) |
| 1698 | if (keep_size == false) |
| 1699 | return -EOPNOTSUPP; |
| 1700 | |
Steve French | 2bb93d2 | 2014-08-20 18:56:29 -0500 | [diff] [blame] | 1701 | /* |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1702 | * Must check if file sparse since fallocate -z (zero range) assumes |
| 1703 | * non-sparse allocation |
| 1704 | */ |
| 1705 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) |
| 1706 | return -EOPNOTSUPP; |
| 1707 | |
| 1708 | /* |
| 1709 | * need to make sure we are not asked to extend the file since the SMB3 |
| 1710 | * fsctl does not change the file size. In the future we could change |
| 1711 | * this to zero the first part of the range then set the file size |
| 1712 | * which for a non sparse file would zero the newly extended range |
| 1713 | */ |
| 1714 | if (keep_size == false) |
| 1715 | if (i_size_read(inode) < offset + len) |
| 1716 | return -EOPNOTSUPP; |
| 1717 | |
| 1718 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1719 | |
| 1720 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1721 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1722 | |
| 1723 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1724 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1725 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1726 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1727 | free_xid(xid); |
| 1728 | return rc; |
| 1729 | } |
| 1730 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1731 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 1732 | loff_t offset, loff_t len) |
| 1733 | { |
| 1734 | struct inode *inode; |
| 1735 | struct cifsInodeInfo *cifsi; |
| 1736 | struct cifsFileInfo *cfile = file->private_data; |
| 1737 | struct file_zero_data_information fsctl_buf; |
| 1738 | long rc; |
| 1739 | unsigned int xid; |
| 1740 | __u8 set_sparse = 1; |
| 1741 | |
| 1742 | xid = get_xid(); |
| 1743 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1744 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1745 | cifsi = CIFS_I(inode); |
| 1746 | |
| 1747 | /* Need to make file sparse, if not already, before freeing range. */ |
| 1748 | /* Consider adding equivalent for compressed since it could also work */ |
| 1749 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) |
| 1750 | return -EOPNOTSUPP; |
| 1751 | |
| 1752 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1753 | |
| 1754 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1755 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1756 | |
| 1757 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1758 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1759 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1760 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1761 | free_xid(xid); |
| 1762 | return rc; |
| 1763 | } |
| 1764 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1765 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 1766 | loff_t off, loff_t len, bool keep_size) |
| 1767 | { |
| 1768 | struct inode *inode; |
| 1769 | struct cifsInodeInfo *cifsi; |
| 1770 | struct cifsFileInfo *cfile = file->private_data; |
| 1771 | long rc = -EOPNOTSUPP; |
| 1772 | unsigned int xid; |
| 1773 | |
| 1774 | xid = get_xid(); |
| 1775 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1776 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1777 | cifsi = CIFS_I(inode); |
| 1778 | |
| 1779 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1780 | if (!CIFS_CACHE_READ(cifsi)) |
| 1781 | if (keep_size == false) |
| 1782 | return -EOPNOTSUPP; |
| 1783 | |
| 1784 | /* |
| 1785 | * Files are non-sparse by default so falloc may be a no-op |
| 1786 | * Must check if file sparse. If not sparse, and not extending |
| 1787 | * then no need to do anything since file already allocated |
| 1788 | */ |
| 1789 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
| 1790 | if (keep_size == true) |
| 1791 | return 0; |
| 1792 | /* check if extending file */ |
| 1793 | else if (i_size_read(inode) >= off + len) |
| 1794 | /* not extending file and already not sparse */ |
| 1795 | return 0; |
| 1796 | /* BB: in future add else clause to extend file */ |
| 1797 | else |
| 1798 | return -EOPNOTSUPP; |
| 1799 | } |
| 1800 | |
| 1801 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 1802 | /* |
| 1803 | * Check if falloc starts within first few pages of file |
| 1804 | * and ends within a few pages of the end of file to |
| 1805 | * ensure that most of file is being forced to be |
| 1806 | * fallocated now. If so then setting whole file sparse |
| 1807 | * ie potentially making a few extra pages at the beginning |
| 1808 | * or end of the file non-sparse via set_sparse is harmless. |
| 1809 | */ |
| 1810 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) |
| 1811 | return -EOPNOTSUPP; |
| 1812 | |
| 1813 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 1814 | } |
| 1815 | /* BB: else ... in future add code to extend file and set sparse */ |
| 1816 | |
| 1817 | |
| 1818 | free_xid(xid); |
| 1819 | return rc; |
| 1820 | } |
| 1821 | |
| 1822 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1823 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 1824 | loff_t off, loff_t len) |
| 1825 | { |
| 1826 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 1827 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 1828 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1829 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 1830 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 1831 | return smb3_zero_range(file, tcon, off, len, true); |
| 1832 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 1833 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 1834 | return smb3_simple_falloc(file, tcon, off, len, true); |
| 1835 | else if (mode == 0) |
| 1836 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1837 | |
| 1838 | return -EOPNOTSUPP; |
| 1839 | } |
| 1840 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1841 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 1842 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 1843 | struct cifsInodeInfo *cinode, bool set_level2) |
| 1844 | { |
| 1845 | if (set_level2) |
| 1846 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 1847 | 0, NULL); |
| 1848 | else |
| 1849 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 1850 | } |
| 1851 | |
| 1852 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1853 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1854 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1855 | { |
| 1856 | oplock &= 0xFF; |
| 1857 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1858 | return; |
| 1859 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1860 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1861 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 1862 | &cinode->vfs_inode); |
| 1863 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1864 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1865 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 1866 | &cinode->vfs_inode); |
| 1867 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 1868 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 1869 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 1870 | &cinode->vfs_inode); |
| 1871 | } else |
| 1872 | cinode->oplock = 0; |
| 1873 | } |
| 1874 | |
| 1875 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1876 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1877 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1878 | { |
| 1879 | char message[5] = {0}; |
| 1880 | |
| 1881 | oplock &= 0xFF; |
| 1882 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 1883 | return; |
| 1884 | |
| 1885 | cinode->oplock = 0; |
| 1886 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 1887 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 1888 | strcat(message, "R"); |
| 1889 | } |
| 1890 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 1891 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 1892 | strcat(message, "H"); |
| 1893 | } |
| 1894 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 1895 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 1896 | strcat(message, "W"); |
| 1897 | } |
| 1898 | if (!cinode->oplock) |
| 1899 | strcat(message, "None"); |
| 1900 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 1901 | &cinode->vfs_inode); |
| 1902 | } |
| 1903 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1904 | static void |
| 1905 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 1906 | unsigned int epoch, bool *purge_cache) |
| 1907 | { |
| 1908 | unsigned int old_oplock = cinode->oplock; |
| 1909 | |
| 1910 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 1911 | |
| 1912 | if (purge_cache) { |
| 1913 | *purge_cache = false; |
| 1914 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 1915 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 1916 | (epoch - cinode->epoch > 0)) |
| 1917 | *purge_cache = true; |
| 1918 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1919 | (epoch - cinode->epoch > 1)) |
| 1920 | *purge_cache = true; |
| 1921 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1922 | (epoch - cinode->epoch > 1)) |
| 1923 | *purge_cache = true; |
| 1924 | else if (cinode->oplock == 0 && |
| 1925 | (epoch - cinode->epoch > 0)) |
| 1926 | *purge_cache = true; |
| 1927 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 1928 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 1929 | (epoch - cinode->epoch > 0)) |
| 1930 | *purge_cache = true; |
| 1931 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 1932 | (epoch - cinode->epoch > 1)) |
| 1933 | *purge_cache = true; |
| 1934 | } |
| 1935 | cinode->epoch = epoch; |
| 1936 | } |
| 1937 | } |
| 1938 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1939 | static bool |
| 1940 | smb2_is_read_op(__u32 oplock) |
| 1941 | { |
| 1942 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 1943 | } |
| 1944 | |
| 1945 | static bool |
| 1946 | smb21_is_read_op(__u32 oplock) |
| 1947 | { |
| 1948 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 1949 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 1950 | } |
| 1951 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1952 | static __le32 |
| 1953 | map_oplock_to_lease(u8 oplock) |
| 1954 | { |
| 1955 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 1956 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 1957 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 1958 | return SMB2_LEASE_READ_CACHING; |
| 1959 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 1960 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 1961 | SMB2_LEASE_WRITE_CACHING; |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1965 | static char * |
| 1966 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1967 | { |
| 1968 | struct create_lease *buf; |
| 1969 | |
| 1970 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 1971 | if (!buf) |
| 1972 | return NULL; |
| 1973 | |
| 1974 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 1975 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1976 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1977 | |
| 1978 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 1979 | (struct create_lease, lcontext)); |
| 1980 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 1981 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 1982 | (struct create_lease, Name)); |
| 1983 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 1984 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 1985 | buf->Name[0] = 'R'; |
| 1986 | buf->Name[1] = 'q'; |
| 1987 | buf->Name[2] = 'L'; |
| 1988 | buf->Name[3] = 's'; |
| 1989 | return (char *)buf; |
| 1990 | } |
| 1991 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 1992 | static char * |
| 1993 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 1994 | { |
| 1995 | struct create_lease_v2 *buf; |
| 1996 | |
| 1997 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 1998 | if (!buf) |
| 1999 | return NULL; |
| 2000 | |
| 2001 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 2002 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 2003 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 2004 | |
| 2005 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 2006 | (struct create_lease_v2, lcontext)); |
| 2007 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 2008 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 2009 | (struct create_lease_v2, Name)); |
| 2010 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 2011 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2012 | buf->Name[0] = 'R'; |
| 2013 | buf->Name[1] = 'q'; |
| 2014 | buf->Name[2] = 'L'; |
| 2015 | buf->Name[3] = 's'; |
| 2016 | return (char *)buf; |
| 2017 | } |
| 2018 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2019 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2020 | smb2_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2021 | { |
| 2022 | struct create_lease *lc = (struct create_lease *)buf; |
| 2023 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2024 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2025 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 2026 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 2027 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 2028 | } |
| 2029 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2030 | static __u8 |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2031 | smb3_parse_lease_buf(void *buf, unsigned int *epoch) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2032 | { |
| 2033 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 2034 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2035 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2036 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 2037 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 2038 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 2039 | } |
| 2040 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2041 | static unsigned int |
| 2042 | smb2_wp_retry_size(struct inode *inode) |
| 2043 | { |
| 2044 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 2045 | SMB2_MAX_BUFFER_SIZE); |
| 2046 | } |
| 2047 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2048 | static bool |
| 2049 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 2050 | { |
| 2051 | return !cfile->invalidHandle; |
| 2052 | } |
| 2053 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2054 | static void |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2055 | fill_transform_hdr(struct TCP_Server_Info *server, |
| 2056 | struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2057 | { |
| 2058 | struct smb2_sync_hdr *shdr = |
| 2059 | (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base; |
| 2060 | unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base); |
| 2061 | |
| 2062 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); |
| 2063 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; |
| 2064 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); |
| 2065 | tr_hdr->Flags = cpu_to_le16(0x01); |
| 2066 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 2067 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2068 | inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - server->vals->header_preamble_size); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2069 | inc_rfc1001_len(tr_hdr, orig_len); |
| 2070 | } |
| 2071 | |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2072 | /* We can not use the normal sg_set_buf() as we will sometimes pass a |
| 2073 | * stack object as buf. |
| 2074 | */ |
| 2075 | static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, |
| 2076 | unsigned int buflen) |
| 2077 | { |
| 2078 | sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); |
| 2079 | } |
| 2080 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2081 | static struct scatterlist * |
| 2082 | init_sg(struct smb_rqst *rqst, u8 *sign) |
| 2083 | { |
| 2084 | unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; |
| 2085 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; |
| 2086 | struct scatterlist *sg; |
| 2087 | unsigned int i; |
| 2088 | unsigned int j; |
| 2089 | |
| 2090 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); |
| 2091 | if (!sg) |
| 2092 | return NULL; |
| 2093 | |
| 2094 | sg_init_table(sg, sg_len); |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2095 | smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2096 | for (i = 1; i < rqst->rq_nvec; i++) |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2097 | smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2098 | rqst->rq_iov[i].iov_len); |
| 2099 | for (j = 0; i < sg_len - 1; i++, j++) { |
| 2100 | unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz |
| 2101 | : rqst->rq_tailsz; |
| 2102 | sg_set_page(&sg[i], rqst->rq_pages[j], len, 0); |
| 2103 | } |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2104 | smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2105 | return sg; |
| 2106 | } |
| 2107 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2108 | static int |
| 2109 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) |
| 2110 | { |
| 2111 | struct cifs_ses *ses; |
| 2112 | u8 *ses_enc_key; |
| 2113 | |
| 2114 | spin_lock(&cifs_tcp_ses_lock); |
| 2115 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 2116 | if (ses->Suid != ses_id) |
| 2117 | continue; |
| 2118 | ses_enc_key = enc ? ses->smb3encryptionkey : |
| 2119 | ses->smb3decryptionkey; |
| 2120 | memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE); |
| 2121 | spin_unlock(&cifs_tcp_ses_lock); |
| 2122 | return 0; |
| 2123 | } |
| 2124 | spin_unlock(&cifs_tcp_ses_lock); |
| 2125 | |
| 2126 | return 1; |
| 2127 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2128 | /* |
| 2129 | * Encrypt or decrypt @rqst message. @rqst has the following format: |
| 2130 | * iov[0] - transform header (associate data), |
| 2131 | * iov[1-N] and pages - data to encrypt. |
| 2132 | * On success return encrypted data in iov[1-N] and pages, leave iov[0] |
| 2133 | * untouched. |
| 2134 | */ |
| 2135 | static int |
| 2136 | crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) |
| 2137 | { |
| 2138 | struct smb2_transform_hdr *tr_hdr = |
| 2139 | (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base; |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2140 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20 - server->vals->header_preamble_size; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2141 | int rc = 0; |
| 2142 | struct scatterlist *sg; |
| 2143 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2144 | u8 key[SMB3_SIGN_KEY_SIZE]; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2145 | struct aead_request *req; |
| 2146 | char *iv; |
| 2147 | unsigned int iv_len; |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2148 | DECLARE_CRYPTO_WAIT(wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2149 | struct crypto_aead *tfm; |
| 2150 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 2151 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2152 | rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); |
| 2153 | if (rc) { |
| 2154 | cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__, |
| 2155 | enc ? "en" : "de"); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2156 | return 0; |
| 2157 | } |
| 2158 | |
| 2159 | rc = smb3_crypto_aead_allocate(server); |
| 2160 | if (rc) { |
| 2161 | cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
| 2162 | return rc; |
| 2163 | } |
| 2164 | |
| 2165 | tfm = enc ? server->secmech.ccmaesencrypt : |
| 2166 | server->secmech.ccmaesdecrypt; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2167 | rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2168 | if (rc) { |
| 2169 | cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); |
| 2170 | return rc; |
| 2171 | } |
| 2172 | |
| 2173 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); |
| 2174 | if (rc) { |
| 2175 | cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc); |
| 2176 | return rc; |
| 2177 | } |
| 2178 | |
| 2179 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 2180 | if (!req) { |
| 2181 | cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__); |
| 2182 | return -ENOMEM; |
| 2183 | } |
| 2184 | |
| 2185 | if (!enc) { |
| 2186 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); |
| 2187 | crypt_len += SMB2_SIGNATURE_SIZE; |
| 2188 | } |
| 2189 | |
| 2190 | sg = init_sg(rqst, sign); |
| 2191 | if (!sg) { |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 2192 | cifs_dbg(VFS, "%s: Failed to init sg", __func__); |
| 2193 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2194 | goto free_req; |
| 2195 | } |
| 2196 | |
| 2197 | iv_len = crypto_aead_ivsize(tfm); |
| 2198 | iv = kzalloc(iv_len, GFP_KERNEL); |
| 2199 | if (!iv) { |
| 2200 | cifs_dbg(VFS, "%s: Failed to alloc IV", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 2201 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2202 | goto free_sg; |
| 2203 | } |
| 2204 | iv[0] = 3; |
| 2205 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 2206 | |
| 2207 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); |
| 2208 | aead_request_set_ad(req, assoc_data_len); |
| 2209 | |
| 2210 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2211 | crypto_req_done, &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2212 | |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2213 | rc = crypto_wait_req(enc ? crypto_aead_encrypt(req) |
| 2214 | : crypto_aead_decrypt(req), &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2215 | |
| 2216 | if (!rc && enc) |
| 2217 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); |
| 2218 | |
| 2219 | kfree(iv); |
| 2220 | free_sg: |
| 2221 | kfree(sg); |
| 2222 | free_req: |
| 2223 | kfree(req); |
| 2224 | return rc; |
| 2225 | } |
| 2226 | |
| 2227 | static int |
| 2228 | smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, |
| 2229 | struct smb_rqst *old_rq) |
| 2230 | { |
| 2231 | struct kvec *iov; |
| 2232 | struct page **pages; |
| 2233 | struct smb2_transform_hdr *tr_hdr; |
| 2234 | unsigned int npages = old_rq->rq_npages; |
| 2235 | int i; |
| 2236 | int rc = -ENOMEM; |
| 2237 | |
| 2238 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 2239 | if (!pages) |
| 2240 | return rc; |
| 2241 | |
| 2242 | new_rq->rq_pages = pages; |
| 2243 | new_rq->rq_npages = old_rq->rq_npages; |
| 2244 | new_rq->rq_pagesz = old_rq->rq_pagesz; |
| 2245 | new_rq->rq_tailsz = old_rq->rq_tailsz; |
| 2246 | |
| 2247 | for (i = 0; i < npages; i++) { |
| 2248 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 2249 | if (!pages[i]) |
| 2250 | goto err_free_pages; |
| 2251 | } |
| 2252 | |
| 2253 | iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL); |
| 2254 | if (!iov) |
| 2255 | goto err_free_pages; |
| 2256 | |
| 2257 | /* copy all iovs from the old except the 1st one (rfc1002 length) */ |
| 2258 | memcpy(&iov[1], &old_rq->rq_iov[1], |
| 2259 | sizeof(struct kvec) * (old_rq->rq_nvec - 1)); |
| 2260 | new_rq->rq_iov = iov; |
| 2261 | new_rq->rq_nvec = old_rq->rq_nvec; |
| 2262 | |
| 2263 | tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); |
| 2264 | if (!tr_hdr) |
| 2265 | goto err_free_iov; |
| 2266 | |
| 2267 | /* fill the 1st iov with a transform header */ |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2268 | fill_transform_hdr(server, tr_hdr, old_rq); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2269 | new_rq->rq_iov[0].iov_base = tr_hdr; |
| 2270 | new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 2271 | |
| 2272 | /* copy pages form the old */ |
| 2273 | for (i = 0; i < npages; i++) { |
| 2274 | char *dst = kmap(new_rq->rq_pages[i]); |
| 2275 | char *src = kmap(old_rq->rq_pages[i]); |
| 2276 | unsigned int len = (i < npages - 1) ? new_rq->rq_pagesz : |
| 2277 | new_rq->rq_tailsz; |
| 2278 | memcpy(dst, src, len); |
| 2279 | kunmap(new_rq->rq_pages[i]); |
| 2280 | kunmap(old_rq->rq_pages[i]); |
| 2281 | } |
| 2282 | |
| 2283 | rc = crypt_message(server, new_rq, 1); |
| 2284 | cifs_dbg(FYI, "encrypt message returned %d", rc); |
| 2285 | if (rc) |
| 2286 | goto err_free_tr_hdr; |
| 2287 | |
| 2288 | return rc; |
| 2289 | |
| 2290 | err_free_tr_hdr: |
| 2291 | kfree(tr_hdr); |
| 2292 | err_free_iov: |
| 2293 | kfree(iov); |
| 2294 | err_free_pages: |
| 2295 | for (i = i - 1; i >= 0; i--) |
| 2296 | put_page(pages[i]); |
| 2297 | kfree(pages); |
| 2298 | return rc; |
| 2299 | } |
| 2300 | |
| 2301 | static void |
| 2302 | smb3_free_transform_rq(struct smb_rqst *rqst) |
| 2303 | { |
| 2304 | int i = rqst->rq_npages - 1; |
| 2305 | |
| 2306 | for (; i >= 0; i--) |
| 2307 | put_page(rqst->rq_pages[i]); |
| 2308 | kfree(rqst->rq_pages); |
| 2309 | /* free transform header */ |
| 2310 | kfree(rqst->rq_iov[0].iov_base); |
| 2311 | kfree(rqst->rq_iov); |
| 2312 | } |
| 2313 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2314 | static int |
| 2315 | smb3_is_transform_hdr(void *buf) |
| 2316 | { |
| 2317 | struct smb2_transform_hdr *trhdr = buf; |
| 2318 | |
| 2319 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; |
| 2320 | } |
| 2321 | |
| 2322 | static int |
| 2323 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, |
| 2324 | unsigned int buf_data_size, struct page **pages, |
| 2325 | unsigned int npages, unsigned int page_data_size) |
| 2326 | { |
| 2327 | struct kvec iov[2]; |
| 2328 | struct smb_rqst rqst = {NULL}; |
| 2329 | struct smb2_hdr *hdr; |
| 2330 | int rc; |
| 2331 | |
| 2332 | iov[0].iov_base = buf; |
| 2333 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 2334 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); |
| 2335 | iov[1].iov_len = buf_data_size; |
| 2336 | |
| 2337 | rqst.rq_iov = iov; |
| 2338 | rqst.rq_nvec = 2; |
| 2339 | rqst.rq_pages = pages; |
| 2340 | rqst.rq_npages = npages; |
| 2341 | rqst.rq_pagesz = PAGE_SIZE; |
| 2342 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; |
| 2343 | |
| 2344 | rc = crypt_message(server, &rqst, 0); |
| 2345 | cifs_dbg(FYI, "decrypt message returned %d\n", rc); |
| 2346 | |
| 2347 | if (rc) |
| 2348 | return rc; |
| 2349 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2350 | memmove(buf + server->vals->header_preamble_size, iov[1].iov_base, buf_data_size); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2351 | hdr = (struct smb2_hdr *)buf; |
| 2352 | hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size); |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2353 | server->total_read = buf_data_size + page_data_size + server->vals->header_preamble_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2354 | |
| 2355 | return rc; |
| 2356 | } |
| 2357 | |
| 2358 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2359 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, |
| 2360 | unsigned int npages, unsigned int len) |
| 2361 | { |
| 2362 | int i; |
| 2363 | int length; |
| 2364 | |
| 2365 | for (i = 0; i < npages; i++) { |
| 2366 | struct page *page = pages[i]; |
| 2367 | size_t n; |
| 2368 | |
| 2369 | n = len; |
| 2370 | if (len >= PAGE_SIZE) { |
| 2371 | /* enough data to fill the page */ |
| 2372 | n = PAGE_SIZE; |
| 2373 | len -= n; |
| 2374 | } else { |
| 2375 | zero_user(page, len, PAGE_SIZE - len); |
| 2376 | len = 0; |
| 2377 | } |
| 2378 | length = cifs_read_page_from_socket(server, page, n); |
| 2379 | if (length < 0) |
| 2380 | return length; |
| 2381 | server->total_read += length; |
| 2382 | } |
| 2383 | |
| 2384 | return 0; |
| 2385 | } |
| 2386 | |
| 2387 | static int |
| 2388 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, |
| 2389 | unsigned int cur_off, struct bio_vec **page_vec) |
| 2390 | { |
| 2391 | struct bio_vec *bvec; |
| 2392 | int i; |
| 2393 | |
| 2394 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); |
| 2395 | if (!bvec) |
| 2396 | return -ENOMEM; |
| 2397 | |
| 2398 | for (i = 0; i < npages; i++) { |
| 2399 | bvec[i].bv_page = pages[i]; |
| 2400 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; |
| 2401 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); |
| 2402 | data_size -= bvec[i].bv_len; |
| 2403 | } |
| 2404 | |
| 2405 | if (data_size != 0) { |
| 2406 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); |
| 2407 | kfree(bvec); |
| 2408 | return -EIO; |
| 2409 | } |
| 2410 | |
| 2411 | *page_vec = bvec; |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2416 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 2417 | char *buf, unsigned int buf_len, struct page **pages, |
| 2418 | unsigned int npages, unsigned int page_data_size) |
| 2419 | { |
| 2420 | unsigned int data_offset; |
| 2421 | unsigned int data_len; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2422 | unsigned int cur_off; |
| 2423 | unsigned int cur_page_idx; |
| 2424 | unsigned int pad_len; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2425 | struct cifs_readdata *rdata = mid->callback_data; |
| 2426 | struct smb2_sync_hdr *shdr = get_sync_hdr(buf); |
| 2427 | struct bio_vec *bvec = NULL; |
| 2428 | struct iov_iter iter; |
| 2429 | struct kvec iov; |
| 2430 | int length; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 2431 | bool use_rdma_mr = false; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2432 | |
| 2433 | if (shdr->Command != SMB2_READ) { |
| 2434 | cifs_dbg(VFS, "only big read responses are supported\n"); |
| 2435 | return -ENOTSUPP; |
| 2436 | } |
| 2437 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2438 | if (server->ops->is_session_expired && |
| 2439 | server->ops->is_session_expired(buf)) { |
| 2440 | cifs_reconnect(server); |
| 2441 | wake_up(&server->response_q); |
| 2442 | return -1; |
| 2443 | } |
| 2444 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2445 | if (server->ops->is_status_pending && |
| 2446 | server->ops->is_status_pending(buf, server, 0)) |
| 2447 | return -1; |
| 2448 | |
| 2449 | rdata->result = server->ops->map_error(buf, false); |
| 2450 | if (rdata->result != 0) { |
| 2451 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 2452 | __func__, rdata->result); |
| 2453 | dequeue_mid(mid, rdata->result); |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2457 | data_offset = server->ops->read_data_offset(buf) + server->vals->header_preamble_size; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 2458 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 2459 | use_rdma_mr = rdata->mr; |
| 2460 | #endif |
| 2461 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2462 | |
| 2463 | if (data_offset < server->vals->read_rsp_size) { |
| 2464 | /* |
| 2465 | * win2k8 sometimes sends an offset of 0 when the read |
| 2466 | * is beyond the EOF. Treat it as if the data starts just after |
| 2467 | * the header. |
| 2468 | */ |
| 2469 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 2470 | __func__, data_offset); |
| 2471 | data_offset = server->vals->read_rsp_size; |
| 2472 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 2473 | /* data_offset is beyond the end of smallbuf */ |
| 2474 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 2475 | __func__, data_offset); |
| 2476 | rdata->result = -EIO; |
| 2477 | dequeue_mid(mid, rdata->result); |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2481 | pad_len = data_offset - server->vals->read_rsp_size; |
| 2482 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2483 | if (buf_len <= data_offset) { |
| 2484 | /* read response payload is in pages */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2485 | cur_page_idx = pad_len / PAGE_SIZE; |
| 2486 | cur_off = pad_len % PAGE_SIZE; |
| 2487 | |
| 2488 | if (cur_page_idx != 0) { |
| 2489 | /* data offset is beyond the 1st page of response */ |
| 2490 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", |
| 2491 | __func__, data_offset); |
| 2492 | rdata->result = -EIO; |
| 2493 | dequeue_mid(mid, rdata->result); |
| 2494 | return 0; |
| 2495 | } |
| 2496 | |
| 2497 | if (data_len > page_data_size - pad_len) { |
| 2498 | /* data_len is corrupt -- discard frame */ |
| 2499 | rdata->result = -EIO; |
| 2500 | dequeue_mid(mid, rdata->result); |
| 2501 | return 0; |
| 2502 | } |
| 2503 | |
| 2504 | rdata->result = init_read_bvec(pages, npages, page_data_size, |
| 2505 | cur_off, &bvec); |
| 2506 | if (rdata->result != 0) { |
| 2507 | dequeue_mid(mid, rdata->result); |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
| 2511 | iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2512 | } else if (buf_len >= data_offset + data_len) { |
| 2513 | /* read response payload is in buf */ |
| 2514 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); |
| 2515 | iov.iov_base = buf + data_offset; |
| 2516 | iov.iov_len = data_len; |
| 2517 | iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len); |
| 2518 | } else { |
| 2519 | /* read response payload cannot be in both buf and pages */ |
| 2520 | WARN_ONCE(1, "buf can not contain only a part of read data"); |
| 2521 | rdata->result = -EIO; |
| 2522 | dequeue_mid(mid, rdata->result); |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | /* set up first iov for signature check */ |
| 2527 | rdata->iov[0].iov_base = buf; |
| 2528 | rdata->iov[0].iov_len = 4; |
| 2529 | rdata->iov[1].iov_base = buf + 4; |
| 2530 | rdata->iov[1].iov_len = server->vals->read_rsp_size - 4; |
| 2531 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 2532 | rdata->iov[0].iov_base, server->vals->read_rsp_size); |
| 2533 | |
| 2534 | length = rdata->copy_into_pages(server, rdata, &iter); |
| 2535 | |
| 2536 | kfree(bvec); |
| 2537 | |
| 2538 | if (length < 0) |
| 2539 | return length; |
| 2540 | |
| 2541 | dequeue_mid(mid, false); |
| 2542 | return length; |
| 2543 | } |
| 2544 | |
| 2545 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2546 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2547 | { |
| 2548 | char *buf = server->smallbuf; |
| 2549 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2550 | unsigned int npages; |
| 2551 | struct page **pages; |
| 2552 | unsigned int len; |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2553 | unsigned int buflen = get_rfc1002_length(buf) + server->vals->header_preamble_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2554 | int rc; |
| 2555 | int i = 0; |
| 2556 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2557 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size - |
| 2558 | server->vals->header_preamble_size + |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2559 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; |
| 2560 | |
| 2561 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); |
| 2562 | if (rc < 0) |
| 2563 | return rc; |
| 2564 | server->total_read += rc; |
| 2565 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2566 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) + |
| 2567 | server->vals->header_preamble_size - |
| 2568 | server->vals->read_rsp_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2569 | npages = DIV_ROUND_UP(len, PAGE_SIZE); |
| 2570 | |
| 2571 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 2572 | if (!pages) { |
| 2573 | rc = -ENOMEM; |
| 2574 | goto discard_data; |
| 2575 | } |
| 2576 | |
| 2577 | for (; i < npages; i++) { |
| 2578 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 2579 | if (!pages[i]) { |
| 2580 | rc = -ENOMEM; |
| 2581 | goto discard_data; |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | /* read read data into pages */ |
| 2586 | rc = read_data_into_pages(server, pages, npages, len); |
| 2587 | if (rc) |
| 2588 | goto free_pages; |
| 2589 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 2590 | rc = cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2591 | if (rc) |
| 2592 | goto free_pages; |
| 2593 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2594 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size - |
| 2595 | server->vals->header_preamble_size, |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2596 | pages, npages, len); |
| 2597 | if (rc) |
| 2598 | goto free_pages; |
| 2599 | |
| 2600 | *mid = smb2_find_mid(server, buf); |
| 2601 | if (*mid == NULL) |
| 2602 | cifs_dbg(FYI, "mid not found\n"); |
| 2603 | else { |
| 2604 | cifs_dbg(FYI, "mid found\n"); |
| 2605 | (*mid)->decrypted = true; |
| 2606 | rc = handle_read_data(server, *mid, buf, |
| 2607 | server->vals->read_rsp_size, |
| 2608 | pages, npages, len); |
| 2609 | } |
| 2610 | |
| 2611 | free_pages: |
| 2612 | for (i = i - 1; i >= 0; i--) |
| 2613 | put_page(pages[i]); |
| 2614 | kfree(pages); |
| 2615 | return rc; |
| 2616 | discard_data: |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 2617 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2618 | goto free_pages; |
| 2619 | } |
| 2620 | |
| 2621 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2622 | receive_encrypted_standard(struct TCP_Server_Info *server, |
| 2623 | struct mid_q_entry **mid) |
| 2624 | { |
| 2625 | int length; |
| 2626 | char *buf = server->smallbuf; |
| 2627 | unsigned int pdu_length = get_rfc1002_length(buf); |
| 2628 | unsigned int buf_size; |
| 2629 | struct mid_q_entry *mid_entry; |
| 2630 | |
| 2631 | /* switch to large buffer if too big for a small one */ |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2632 | if (pdu_length + server->vals->header_preamble_size > MAX_CIFS_SMALL_BUFFER_SIZE) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2633 | server->large_buf = true; |
| 2634 | memcpy(server->bigbuf, buf, server->total_read); |
| 2635 | buf = server->bigbuf; |
| 2636 | } |
| 2637 | |
| 2638 | /* now read the rest */ |
| 2639 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2640 | pdu_length - HEADER_SIZE(server) + 1 + |
| 2641 | server->vals->header_preamble_size); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2642 | if (length < 0) |
| 2643 | return length; |
| 2644 | server->total_read += length; |
| 2645 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2646 | buf_size = pdu_length + server->vals->header_preamble_size - sizeof(struct smb2_transform_hdr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2647 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); |
| 2648 | if (length) |
| 2649 | return length; |
| 2650 | |
| 2651 | mid_entry = smb2_find_mid(server, buf); |
| 2652 | if (mid_entry == NULL) |
| 2653 | cifs_dbg(FYI, "mid not found\n"); |
| 2654 | else { |
| 2655 | cifs_dbg(FYI, "mid found\n"); |
| 2656 | mid_entry->decrypted = true; |
| 2657 | } |
| 2658 | |
| 2659 | *mid = mid_entry; |
| 2660 | |
| 2661 | if (mid_entry && mid_entry->handle) |
| 2662 | return mid_entry->handle(server, mid_entry); |
| 2663 | |
| 2664 | return cifs_handle_standard(server, mid_entry); |
| 2665 | } |
| 2666 | |
| 2667 | static int |
| 2668 | smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2669 | { |
| 2670 | char *buf = server->smallbuf; |
| 2671 | unsigned int pdu_length = get_rfc1002_length(buf); |
| 2672 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2673 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 2674 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2675 | if (pdu_length + server->vals->header_preamble_size < sizeof(struct smb2_transform_hdr) + |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2676 | sizeof(struct smb2_sync_hdr)) { |
| 2677 | cifs_dbg(VFS, "Transform message is too small (%u)\n", |
| 2678 | pdu_length); |
| 2679 | cifs_reconnect(server); |
| 2680 | wake_up(&server->response_q); |
| 2681 | return -ECONNABORTED; |
| 2682 | } |
| 2683 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2684 | if (pdu_length + server->vals->header_preamble_size < orig_len + sizeof(struct smb2_transform_hdr)) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2685 | cifs_dbg(VFS, "Transform message is broken\n"); |
| 2686 | cifs_reconnect(server); |
| 2687 | wake_up(&server->response_q); |
| 2688 | return -ECONNABORTED; |
| 2689 | } |
| 2690 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2691 | if (pdu_length + server->vals->header_preamble_size > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2692 | return receive_encrypted_read(server, mid); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2693 | |
| 2694 | return receive_encrypted_standard(server, mid); |
| 2695 | } |
| 2696 | |
| 2697 | int |
| 2698 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 2699 | { |
| 2700 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 2701 | |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 2702 | return handle_read_data(server, mid, buf, get_rfc1002_length(buf) + |
| 2703 | server->vals->header_preamble_size, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2704 | NULL, 0, 0); |
| 2705 | } |
| 2706 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2707 | struct smb_version_operations smb20_operations = { |
| 2708 | .compare_fids = smb2_compare_fids, |
| 2709 | .setup_request = smb2_setup_request, |
| 2710 | .setup_async_request = smb2_setup_async_request, |
| 2711 | .check_receive = smb2_check_receive, |
| 2712 | .add_credits = smb2_add_credits, |
| 2713 | .set_credits = smb2_set_credits, |
| 2714 | .get_credits_field = smb2_get_credits_field, |
| 2715 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2716 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2717 | .get_next_mid = smb2_get_next_mid, |
| 2718 | .read_data_offset = smb2_read_data_offset, |
| 2719 | .read_data_length = smb2_read_data_length, |
| 2720 | .map_error = map_smb2_to_linux_error, |
| 2721 | .find_mid = smb2_find_mid, |
| 2722 | .check_message = smb2_check_message, |
| 2723 | .dump_detail = smb2_dump_detail, |
| 2724 | .clear_stats = smb2_clear_stats, |
| 2725 | .print_stats = smb2_print_stats, |
| 2726 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 2727 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2728 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2729 | .need_neg = smb2_need_neg, |
| 2730 | .negotiate = smb2_negotiate, |
| 2731 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2732 | .negotiate_rsize = smb2_negotiate_rsize, |
| 2733 | .sess_setup = SMB2_sess_setup, |
| 2734 | .logoff = SMB2_logoff, |
| 2735 | .tree_connect = SMB2_tcon, |
| 2736 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 2737 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2738 | .is_path_accessible = smb2_is_path_accessible, |
| 2739 | .can_echo = smb2_can_echo, |
| 2740 | .echo = SMB2_echo, |
| 2741 | .query_path_info = smb2_query_path_info, |
| 2742 | .get_srv_inum = smb2_get_srv_inum, |
| 2743 | .query_file_info = smb2_query_file_info, |
| 2744 | .set_path_size = smb2_set_path_size, |
| 2745 | .set_file_size = smb2_set_file_size, |
| 2746 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2747 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2748 | .mkdir = smb2_mkdir, |
| 2749 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 2750 | .rmdir = smb2_rmdir, |
| 2751 | .unlink = smb2_unlink, |
| 2752 | .rename = smb2_rename_path, |
| 2753 | .create_hardlink = smb2_create_hardlink, |
| 2754 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 2755 | .query_mf_symlink = smb3_query_mf_symlink, |
| 2756 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2757 | .open = smb2_open_file, |
| 2758 | .set_fid = smb2_set_fid, |
| 2759 | .close = smb2_close_file, |
| 2760 | .flush = smb2_flush_file, |
| 2761 | .async_readv = smb2_async_readv, |
| 2762 | .async_writev = smb2_async_writev, |
| 2763 | .sync_read = smb2_sync_read, |
| 2764 | .sync_write = smb2_sync_write, |
| 2765 | .query_dir_first = smb2_query_dir_first, |
| 2766 | .query_dir_next = smb2_query_dir_next, |
| 2767 | .close_dir = smb2_close_dir, |
| 2768 | .calc_smb_size = smb2_calc_size, |
| 2769 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2770 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2771 | .oplock_response = smb2_oplock_response, |
| 2772 | .queryfs = smb2_queryfs, |
| 2773 | .mand_lock = smb2_mand_lock, |
| 2774 | .mand_unlock_range = smb2_unlock_range, |
| 2775 | .push_mand_locks = smb2_push_mandatory_locks, |
| 2776 | .get_lease_key = smb2_get_lease_key, |
| 2777 | .set_lease_key = smb2_set_lease_key, |
| 2778 | .new_lease_key = smb2_new_lease_key, |
| 2779 | .calc_signature = smb2_calc_signature, |
| 2780 | .is_read_op = smb2_is_read_op, |
| 2781 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2782 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2783 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 2784 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2785 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2786 | .dir_needs_close = smb2_dir_needs_close, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2787 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 2788 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2789 | #ifdef CONFIG_CIFS_XATTR |
| 2790 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 2791 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2792 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2793 | #ifdef CONFIG_CIFS_ACL |
| 2794 | .get_acl = get_smb2_acl, |
| 2795 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2796 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2797 | #endif /* CIFS_ACL */ |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2798 | }; |
| 2799 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2800 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2801 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2802 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 2803 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2804 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 2805 | .add_credits = smb2_add_credits, |
| 2806 | .set_credits = smb2_set_credits, |
| 2807 | .get_credits_field = smb2_get_credits_field, |
| 2808 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2809 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 2810 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2811 | .read_data_offset = smb2_read_data_offset, |
| 2812 | .read_data_length = smb2_read_data_length, |
| 2813 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 2814 | .find_mid = smb2_find_mid, |
| 2815 | .check_message = smb2_check_message, |
| 2816 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 2817 | .clear_stats = smb2_clear_stats, |
| 2818 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2819 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 2820 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2821 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 2822 | .need_neg = smb2_need_neg, |
| 2823 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2824 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2825 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 2826 | .sess_setup = SMB2_sess_setup, |
| 2827 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 2828 | .tree_connect = SMB2_tcon, |
| 2829 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 2830 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 2831 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 2832 | .can_echo = smb2_can_echo, |
| 2833 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 2834 | .query_path_info = smb2_query_path_info, |
| 2835 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 2836 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2837 | .set_path_size = smb2_set_path_size, |
| 2838 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2839 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2840 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 2841 | .mkdir = smb2_mkdir, |
| 2842 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 2843 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 2844 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2845 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 2846 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2847 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 2848 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 2849 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 2850 | .open = smb2_open_file, |
| 2851 | .set_fid = smb2_set_fid, |
| 2852 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 2853 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2854 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 2855 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2856 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2857 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2858 | .query_dir_first = smb2_query_dir_first, |
| 2859 | .query_dir_next = smb2_query_dir_next, |
| 2860 | .close_dir = smb2_close_dir, |
| 2861 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2862 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2863 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2864 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2865 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2866 | .mand_lock = smb2_mand_lock, |
| 2867 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2868 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2869 | .get_lease_key = smb2_get_lease_key, |
| 2870 | .set_lease_key = smb2_set_lease_key, |
| 2871 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2872 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2873 | .is_read_op = smb21_is_read_op, |
| 2874 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2875 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2876 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 2877 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2878 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2879 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2880 | .enum_snapshots = smb3_enum_snapshots, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2881 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 2882 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2883 | #ifdef CONFIG_CIFS_XATTR |
| 2884 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 2885 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2886 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2887 | #ifdef CONFIG_CIFS_ACL |
| 2888 | .get_acl = get_smb2_acl, |
| 2889 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2890 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2891 | #endif /* CIFS_ACL */ |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2892 | }; |
| 2893 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2894 | struct smb_version_operations smb30_operations = { |
| 2895 | .compare_fids = smb2_compare_fids, |
| 2896 | .setup_request = smb2_setup_request, |
| 2897 | .setup_async_request = smb2_setup_async_request, |
| 2898 | .check_receive = smb2_check_receive, |
| 2899 | .add_credits = smb2_add_credits, |
| 2900 | .set_credits = smb2_set_credits, |
| 2901 | .get_credits_field = smb2_get_credits_field, |
| 2902 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2903 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2904 | .get_next_mid = smb2_get_next_mid, |
| 2905 | .read_data_offset = smb2_read_data_offset, |
| 2906 | .read_data_length = smb2_read_data_length, |
| 2907 | .map_error = map_smb2_to_linux_error, |
| 2908 | .find_mid = smb2_find_mid, |
| 2909 | .check_message = smb2_check_message, |
| 2910 | .dump_detail = smb2_dump_detail, |
| 2911 | .clear_stats = smb2_clear_stats, |
| 2912 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 2913 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2914 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 2915 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2916 | .downgrade_oplock = smb2_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2917 | .need_neg = smb2_need_neg, |
| 2918 | .negotiate = smb2_negotiate, |
| 2919 | .negotiate_wsize = smb2_negotiate_wsize, |
| 2920 | .negotiate_rsize = smb2_negotiate_rsize, |
| 2921 | .sess_setup = SMB2_sess_setup, |
| 2922 | .logoff = SMB2_logoff, |
| 2923 | .tree_connect = SMB2_tcon, |
| 2924 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 2925 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2926 | .is_path_accessible = smb2_is_path_accessible, |
| 2927 | .can_echo = smb2_can_echo, |
| 2928 | .echo = SMB2_echo, |
| 2929 | .query_path_info = smb2_query_path_info, |
| 2930 | .get_srv_inum = smb2_get_srv_inum, |
| 2931 | .query_file_info = smb2_query_file_info, |
| 2932 | .set_path_size = smb2_set_path_size, |
| 2933 | .set_file_size = smb2_set_file_size, |
| 2934 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2935 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2936 | .mkdir = smb2_mkdir, |
| 2937 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 2938 | .rmdir = smb2_rmdir, |
| 2939 | .unlink = smb2_unlink, |
| 2940 | .rename = smb2_rename_path, |
| 2941 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2942 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 2943 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 2944 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2945 | .open = smb2_open_file, |
| 2946 | .set_fid = smb2_set_fid, |
| 2947 | .close = smb2_close_file, |
| 2948 | .flush = smb2_flush_file, |
| 2949 | .async_readv = smb2_async_readv, |
| 2950 | .async_writev = smb2_async_writev, |
| 2951 | .sync_read = smb2_sync_read, |
| 2952 | .sync_write = smb2_sync_write, |
| 2953 | .query_dir_first = smb2_query_dir_first, |
| 2954 | .query_dir_next = smb2_query_dir_next, |
| 2955 | .close_dir = smb2_close_dir, |
| 2956 | .calc_smb_size = smb2_calc_size, |
| 2957 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2958 | .is_session_expired = smb2_is_session_expired, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2959 | .oplock_response = smb2_oplock_response, |
| 2960 | .queryfs = smb2_queryfs, |
| 2961 | .mand_lock = smb2_mand_lock, |
| 2962 | .mand_unlock_range = smb2_unlock_range, |
| 2963 | .push_mand_locks = smb2_push_mandatory_locks, |
| 2964 | .get_lease_key = smb2_get_lease_key, |
| 2965 | .set_lease_key = smb2_set_lease_key, |
| 2966 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 2967 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 2968 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2969 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2970 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2971 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2972 | .create_lease_buf = smb3_create_lease_buf, |
| 2973 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 2974 | .copychunk_range = smb2_copychunk_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 2975 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 2976 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2977 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2978 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2979 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2980 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2981 | .init_transform_rq = smb3_init_transform_rq, |
| 2982 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2983 | .is_transform_hdr = smb3_is_transform_hdr, |
| 2984 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2985 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 2986 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2987 | #ifdef CONFIG_CIFS_XATTR |
| 2988 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 2989 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 2990 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2991 | #ifdef CONFIG_CIFS_ACL |
| 2992 | .get_acl = get_smb2_acl, |
| 2993 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2994 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2995 | #endif /* CIFS_ACL */ |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2996 | }; |
| 2997 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 2998 | #ifdef CONFIG_CIFS_SMB311 |
| 2999 | struct smb_version_operations smb311_operations = { |
| 3000 | .compare_fids = smb2_compare_fids, |
| 3001 | .setup_request = smb2_setup_request, |
| 3002 | .setup_async_request = smb2_setup_async_request, |
| 3003 | .check_receive = smb2_check_receive, |
| 3004 | .add_credits = smb2_add_credits, |
| 3005 | .set_credits = smb2_set_credits, |
| 3006 | .get_credits_field = smb2_get_credits_field, |
| 3007 | .get_credits = smb2_get_credits, |
| 3008 | .wait_mtu_credits = smb2_wait_mtu_credits, |
| 3009 | .get_next_mid = smb2_get_next_mid, |
| 3010 | .read_data_offset = smb2_read_data_offset, |
| 3011 | .read_data_length = smb2_read_data_length, |
| 3012 | .map_error = map_smb2_to_linux_error, |
| 3013 | .find_mid = smb2_find_mid, |
| 3014 | .check_message = smb2_check_message, |
| 3015 | .dump_detail = smb2_dump_detail, |
| 3016 | .clear_stats = smb2_clear_stats, |
| 3017 | .print_stats = smb2_print_stats, |
| 3018 | .dump_share_caps = smb2_dump_share_caps, |
| 3019 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 3020 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3021 | .downgrade_oplock = smb2_downgrade_oplock, |
| 3022 | .need_neg = smb2_need_neg, |
| 3023 | .negotiate = smb2_negotiate, |
| 3024 | .negotiate_wsize = smb2_negotiate_wsize, |
| 3025 | .negotiate_rsize = smb2_negotiate_rsize, |
| 3026 | .sess_setup = SMB2_sess_setup, |
| 3027 | .logoff = SMB2_logoff, |
| 3028 | .tree_connect = SMB2_tcon, |
| 3029 | .tree_disconnect = SMB2_tdis, |
| 3030 | .qfs_tcon = smb3_qfs_tcon, |
| 3031 | .is_path_accessible = smb2_is_path_accessible, |
| 3032 | .can_echo = smb2_can_echo, |
| 3033 | .echo = SMB2_echo, |
| 3034 | .query_path_info = smb2_query_path_info, |
| 3035 | .get_srv_inum = smb2_get_srv_inum, |
| 3036 | .query_file_info = smb2_query_file_info, |
| 3037 | .set_path_size = smb2_set_path_size, |
| 3038 | .set_file_size = smb2_set_file_size, |
| 3039 | .set_file_info = smb2_set_file_info, |
| 3040 | .set_compression = smb2_set_compression, |
| 3041 | .mkdir = smb2_mkdir, |
| 3042 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 3043 | .rmdir = smb2_rmdir, |
| 3044 | .unlink = smb2_unlink, |
| 3045 | .rename = smb2_rename_path, |
| 3046 | .create_hardlink = smb2_create_hardlink, |
| 3047 | .query_symlink = smb2_query_symlink, |
| 3048 | .query_mf_symlink = smb3_query_mf_symlink, |
| 3049 | .create_mf_symlink = smb3_create_mf_symlink, |
| 3050 | .open = smb2_open_file, |
| 3051 | .set_fid = smb2_set_fid, |
| 3052 | .close = smb2_close_file, |
| 3053 | .flush = smb2_flush_file, |
| 3054 | .async_readv = smb2_async_readv, |
| 3055 | .async_writev = smb2_async_writev, |
| 3056 | .sync_read = smb2_sync_read, |
| 3057 | .sync_write = smb2_sync_write, |
| 3058 | .query_dir_first = smb2_query_dir_first, |
| 3059 | .query_dir_next = smb2_query_dir_next, |
| 3060 | .close_dir = smb2_close_dir, |
| 3061 | .calc_smb_size = smb2_calc_size, |
| 3062 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3063 | .is_session_expired = smb2_is_session_expired, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3064 | .oplock_response = smb2_oplock_response, |
| 3065 | .queryfs = smb2_queryfs, |
| 3066 | .mand_lock = smb2_mand_lock, |
| 3067 | .mand_unlock_range = smb2_unlock_range, |
| 3068 | .push_mand_locks = smb2_push_mandatory_locks, |
| 3069 | .get_lease_key = smb2_get_lease_key, |
| 3070 | .set_lease_key = smb2_set_lease_key, |
| 3071 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3072 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3073 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 3074 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3075 | .is_read_op = smb21_is_read_op, |
| 3076 | .set_oplock_level = smb3_set_oplock_level, |
| 3077 | .create_lease_buf = smb3_create_lease_buf, |
| 3078 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 3079 | .copychunk_range = smb2_copychunk_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 3080 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3081 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 3082 | .wp_retry_size = smb2_wp_retry_size, |
| 3083 | .dir_needs_close = smb2_dir_needs_close, |
| 3084 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 3085 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3086 | .init_transform_rq = smb3_init_transform_rq, |
| 3087 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3088 | .is_transform_hdr = smb3_is_transform_hdr, |
| 3089 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 3090 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 3091 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3092 | #ifdef CONFIG_CIFS_XATTR |
| 3093 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 3094 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3095 | #endif /* CIFS_XATTR */ |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3096 | }; |
| 3097 | #endif /* CIFS_SMB311 */ |
| 3098 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3099 | struct smb_version_values smb20_values = { |
| 3100 | .version_string = SMB20_VERSION_STRING, |
| 3101 | .protocol_id = SMB20_PROT_ID, |
| 3102 | .req_capabilities = 0, /* MBZ */ |
| 3103 | .large_lock_type = 0, |
| 3104 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3105 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3106 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3107 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3108 | .header_preamble_size = 4, |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3109 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3110 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3111 | .lock_cmd = SMB2_LOCK, |
| 3112 | .cap_unix = 0, |
| 3113 | .cap_nt_find = SMB2_NT_FIND, |
| 3114 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3115 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3116 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3117 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3118 | }; |
| 3119 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3120 | struct smb_version_values smb21_values = { |
| 3121 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3122 | .protocol_id = SMB21_PROT_ID, |
| 3123 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 3124 | .large_lock_type = 0, |
| 3125 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3126 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3127 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3128 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3129 | .header_preamble_size = 4, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3130 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3131 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3132 | .lock_cmd = SMB2_LOCK, |
| 3133 | .cap_unix = 0, |
| 3134 | .cap_nt_find = SMB2_NT_FIND, |
| 3135 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3136 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3137 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3138 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3139 | }; |
| 3140 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3141 | struct smb_version_values smb3any_values = { |
| 3142 | .version_string = SMB3ANY_VERSION_STRING, |
| 3143 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
| 3144 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
| 3145 | .large_lock_type = 0, |
| 3146 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3147 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3148 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3149 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3150 | .header_preamble_size = 4, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3151 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3152 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3153 | .lock_cmd = SMB2_LOCK, |
| 3154 | .cap_unix = 0, |
| 3155 | .cap_nt_find = SMB2_NT_FIND, |
| 3156 | .cap_large_files = SMB2_LARGE_FILES, |
| 3157 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3158 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3159 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3160 | }; |
| 3161 | |
| 3162 | struct smb_version_values smbdefault_values = { |
| 3163 | .version_string = SMBDEFAULT_VERSION_STRING, |
| 3164 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
| 3165 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
| 3166 | .large_lock_type = 0, |
| 3167 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3168 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3169 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3170 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3171 | .header_preamble_size = 4, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3172 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3173 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3174 | .lock_cmd = SMB2_LOCK, |
| 3175 | .cap_unix = 0, |
| 3176 | .cap_nt_find = SMB2_NT_FIND, |
| 3177 | .cap_large_files = SMB2_LARGE_FILES, |
| 3178 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3179 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3180 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3181 | }; |
| 3182 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3183 | struct smb_version_values smb30_values = { |
| 3184 | .version_string = SMB30_VERSION_STRING, |
| 3185 | .protocol_id = SMB30_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3186 | .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 Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3187 | .large_lock_type = 0, |
| 3188 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3189 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3190 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 3191 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3192 | .header_preamble_size = 4, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 3193 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 3194 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 3195 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 3196 | .cap_unix = 0, |
| 3197 | .cap_nt_find = SMB2_NT_FIND, |
| 3198 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3199 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3200 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3201 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3202 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3203 | |
| 3204 | struct smb_version_values smb302_values = { |
| 3205 | .version_string = SMB302_VERSION_STRING, |
| 3206 | .protocol_id = SMB302_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3207 | .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 French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3208 | .large_lock_type = 0, |
| 3209 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3210 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3211 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3212 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3213 | .header_preamble_size = 4, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3214 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3215 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3216 | .lock_cmd = SMB2_LOCK, |
| 3217 | .cap_unix = 0, |
| 3218 | .cap_nt_find = SMB2_NT_FIND, |
| 3219 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3220 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3221 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3222 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3223 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 3224 | |
| 3225 | #ifdef CONFIG_CIFS_SMB311 |
| 3226 | struct smb_version_values smb311_values = { |
| 3227 | .version_string = SMB311_VERSION_STRING, |
| 3228 | .protocol_id = SMB311_PROT_ID, |
Steve French | 1955880 | 2017-06-21 16:50:20 -0500 | [diff] [blame] | 3229 | .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 French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 3230 | .large_lock_type = 0, |
| 3231 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3232 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3233 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
| 3234 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame^] | 3235 | .header_preamble_size = 4, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 3236 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3237 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3238 | .lock_cmd = SMB2_LOCK, |
| 3239 | .cap_unix = 0, |
| 3240 | .cap_nt_find = SMB2_NT_FIND, |
| 3241 | .cap_large_files = SMB2_LARGE_FILES, |
| 3242 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3243 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3244 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3245 | }; |
| 3246 | #endif /* SMB311 */ |