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 | { |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 126 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 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; |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 193 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 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 |
Ronnie Sahlberg | 14547f7 | 2018-04-22 14:45:53 -0600 | [diff] [blame] | 215 | smb2_dump_detail(void *buf, struct TCP_Server_Info *server) |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 216 | { |
| 217 | #ifdef CONFIG_CIFS_DEBUG2 |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 218 | struct smb2_sync_hdr *shdr = (struct smb2_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); |
Ronnie Sahlberg | 14547f7 | 2018-04-22 14:45:53 -0600 | [diff] [blame] | 223 | cifs_dbg(VFS, "smb buf %p len %u\n", buf, |
Steve French | 71992e62 | 2018-05-06 15:58:51 -0500 | [diff] [blame] | 224 | server->ops->calc_smb_size(buf, server)); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 225 | #endif |
| 226 | } |
| 227 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 228 | static bool |
| 229 | smb2_need_neg(struct TCP_Server_Info *server) |
| 230 | { |
| 231 | return server->max_read == 0; |
| 232 | } |
| 233 | |
| 234 | static int |
| 235 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 236 | { |
| 237 | int rc; |
| 238 | ses->server->CurrentMid = 0; |
| 239 | rc = SMB2_negotiate(xid, ses); |
| 240 | /* BB we probably don't need to retry with modern servers */ |
| 241 | if (rc == -EAGAIN) |
| 242 | rc = -EHOSTDOWN; |
| 243 | return rc; |
| 244 | } |
| 245 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 246 | static unsigned int |
| 247 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 248 | { |
| 249 | struct TCP_Server_Info *server = tcon->ses->server; |
| 250 | unsigned int wsize; |
| 251 | |
| 252 | /* start with specified wsize, or default */ |
| 253 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; |
| 254 | wsize = min_t(unsigned int, wsize, server->max_write); |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 255 | #ifdef CONFIG_CIFS_SMB_DIRECT |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 256 | if (server->rdma) { |
| 257 | if (server->sign) |
| 258 | wsize = min_t(unsigned int, |
| 259 | wsize, server->smbd_conn->max_fragmented_send_size); |
| 260 | else |
| 261 | wsize = min_t(unsigned int, |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 262 | wsize, server->smbd_conn->max_readwrite_size); |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 263 | } |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 264 | #endif |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 265 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 266 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 267 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 268 | return wsize; |
| 269 | } |
| 270 | |
| 271 | static unsigned int |
| 272 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
| 273 | { |
| 274 | struct TCP_Server_Info *server = tcon->ses->server; |
| 275 | unsigned int rsize; |
| 276 | |
| 277 | /* start with specified rsize, or default */ |
| 278 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; |
| 279 | rsize = min_t(unsigned int, rsize, server->max_read); |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 280 | #ifdef CONFIG_CIFS_SMB_DIRECT |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 281 | if (server->rdma) { |
| 282 | if (server->sign) |
| 283 | rsize = min_t(unsigned int, |
| 284 | rsize, server->smbd_conn->max_fragmented_recv_size); |
| 285 | else |
| 286 | rsize = min_t(unsigned int, |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 287 | rsize, server->smbd_conn->max_readwrite_size); |
Long Li | bb4c041 | 2018-04-17 12:17:08 -0700 | [diff] [blame] | 288 | } |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 289 | #endif |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 290 | |
| 291 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 292 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 293 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 294 | return rsize; |
| 295 | } |
| 296 | |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 297 | |
| 298 | static int |
| 299 | parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf, |
| 300 | size_t buf_len, |
| 301 | struct cifs_server_iface **iface_list, |
| 302 | size_t *iface_count) |
| 303 | { |
| 304 | struct network_interface_info_ioctl_rsp *p; |
| 305 | struct sockaddr_in *addr4; |
| 306 | struct sockaddr_in6 *addr6; |
| 307 | struct iface_info_ipv4 *p4; |
| 308 | struct iface_info_ipv6 *p6; |
| 309 | struct cifs_server_iface *info; |
| 310 | ssize_t bytes_left; |
| 311 | size_t next = 0; |
| 312 | int nb_iface = 0; |
| 313 | int rc = 0; |
| 314 | |
| 315 | *iface_list = NULL; |
| 316 | *iface_count = 0; |
| 317 | |
| 318 | /* |
| 319 | * Fist pass: count and sanity check |
| 320 | */ |
| 321 | |
| 322 | bytes_left = buf_len; |
| 323 | p = buf; |
| 324 | while (bytes_left >= sizeof(*p)) { |
| 325 | nb_iface++; |
| 326 | next = le32_to_cpu(p->Next); |
| 327 | if (!next) { |
| 328 | bytes_left -= sizeof(*p); |
| 329 | break; |
| 330 | } |
| 331 | p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next); |
| 332 | bytes_left -= next; |
| 333 | } |
| 334 | |
| 335 | if (!nb_iface) { |
| 336 | cifs_dbg(VFS, "%s: malformed interface info\n", __func__); |
| 337 | rc = -EINVAL; |
| 338 | goto out; |
| 339 | } |
| 340 | |
| 341 | if (bytes_left || p->Next) |
| 342 | cifs_dbg(VFS, "%s: incomplete interface info\n", __func__); |
| 343 | |
| 344 | |
| 345 | /* |
| 346 | * Second pass: extract info to internal structure |
| 347 | */ |
| 348 | |
| 349 | *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL); |
| 350 | if (!*iface_list) { |
| 351 | rc = -ENOMEM; |
| 352 | goto out; |
| 353 | } |
| 354 | |
| 355 | info = *iface_list; |
| 356 | bytes_left = buf_len; |
| 357 | p = buf; |
| 358 | while (bytes_left >= sizeof(*p)) { |
| 359 | info->speed = le64_to_cpu(p->LinkSpeed); |
| 360 | info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE); |
| 361 | info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE); |
| 362 | |
| 363 | cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count); |
| 364 | cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed); |
| 365 | cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__, |
| 366 | le32_to_cpu(p->Capability)); |
| 367 | |
| 368 | switch (p->Family) { |
| 369 | /* |
| 370 | * The kernel and wire socket structures have the same |
| 371 | * layout and use network byte order but make the |
| 372 | * conversion explicit in case either one changes. |
| 373 | */ |
| 374 | case INTERNETWORK: |
| 375 | addr4 = (struct sockaddr_in *)&info->sockaddr; |
| 376 | p4 = (struct iface_info_ipv4 *)p->Buffer; |
| 377 | addr4->sin_family = AF_INET; |
| 378 | memcpy(&addr4->sin_addr, &p4->IPv4Address, 4); |
| 379 | |
| 380 | /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */ |
| 381 | addr4->sin_port = cpu_to_be16(CIFS_PORT); |
| 382 | |
| 383 | cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__, |
| 384 | &addr4->sin_addr); |
| 385 | break; |
| 386 | case INTERNETWORKV6: |
| 387 | addr6 = (struct sockaddr_in6 *)&info->sockaddr; |
| 388 | p6 = (struct iface_info_ipv6 *)p->Buffer; |
| 389 | addr6->sin6_family = AF_INET6; |
| 390 | memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16); |
| 391 | |
| 392 | /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */ |
| 393 | addr6->sin6_flowinfo = 0; |
| 394 | addr6->sin6_scope_id = 0; |
| 395 | addr6->sin6_port = cpu_to_be16(CIFS_PORT); |
| 396 | |
| 397 | cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__, |
| 398 | &addr6->sin6_addr); |
| 399 | break; |
| 400 | default: |
| 401 | cifs_dbg(VFS, |
| 402 | "%s: skipping unsupported socket family\n", |
| 403 | __func__); |
| 404 | goto next_iface; |
| 405 | } |
| 406 | |
| 407 | (*iface_count)++; |
| 408 | info++; |
| 409 | next_iface: |
| 410 | next = le32_to_cpu(p->Next); |
| 411 | if (!next) |
| 412 | break; |
| 413 | p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next); |
| 414 | bytes_left -= next; |
| 415 | } |
| 416 | |
| 417 | if (!*iface_count) { |
| 418 | rc = -EINVAL; |
| 419 | goto out; |
| 420 | } |
| 421 | |
| 422 | out: |
| 423 | if (rc) { |
| 424 | kfree(*iface_list); |
| 425 | *iface_count = 0; |
| 426 | *iface_list = NULL; |
| 427 | } |
| 428 | return rc; |
| 429 | } |
| 430 | |
| 431 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 432 | static int |
| 433 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) |
| 434 | { |
| 435 | int rc; |
| 436 | unsigned int ret_data_len = 0; |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 437 | struct network_interface_info_ioctl_rsp *out_buf = NULL; |
| 438 | struct cifs_server_iface *iface_list; |
| 439 | size_t iface_count; |
| 440 | struct cifs_ses *ses = tcon->ses; |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 441 | |
| 442 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 443 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, |
| 444 | NULL /* no data input */, 0 /* no data input */, |
| 445 | (char **)&out_buf, &ret_data_len); |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 446 | if (rc != 0) { |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 447 | cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc); |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 448 | goto out; |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 449 | } |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 450 | |
| 451 | rc = parse_server_interfaces(out_buf, ret_data_len, |
| 452 | &iface_list, &iface_count); |
| 453 | if (rc) |
| 454 | goto out; |
| 455 | |
| 456 | spin_lock(&ses->iface_lock); |
| 457 | kfree(ses->iface_list); |
| 458 | ses->iface_list = iface_list; |
| 459 | ses->iface_count = iface_count; |
| 460 | ses->iface_last_update = jiffies; |
| 461 | spin_unlock(&ses->iface_lock); |
| 462 | |
| 463 | out: |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 464 | kfree(out_buf); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 465 | return rc; |
| 466 | } |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 467 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 468 | void |
| 469 | smb2_cached_lease_break(struct work_struct *work) |
| 470 | { |
| 471 | struct cached_fid *cfid = container_of(work, |
| 472 | struct cached_fid, lease_break); |
| 473 | mutex_lock(&cfid->fid_mutex); |
| 474 | if (cfid->is_valid) { |
| 475 | cifs_dbg(FYI, "clear cached root file handle\n"); |
| 476 | SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, |
| 477 | cfid->fid->volatile_fid); |
| 478 | cfid->is_valid = false; |
| 479 | } |
| 480 | mutex_unlock(&cfid->fid_mutex); |
| 481 | } |
| 482 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 483 | /* |
| 484 | * Open the directory at the root of a share |
| 485 | */ |
| 486 | int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid) |
| 487 | { |
| 488 | struct cifs_open_parms oparams; |
| 489 | int rc; |
| 490 | __le16 srch_path = 0; /* Null - since an open of top of share */ |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 491 | u8 oplock = SMB2_OPLOCK_LEVEL_II; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 492 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 493 | mutex_lock(&tcon->crfid.fid_mutex); |
| 494 | if (tcon->crfid.is_valid) { |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 495 | cifs_dbg(FYI, "found a cached root file handle\n"); |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 496 | memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid)); |
| 497 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | oparams.tcon = tcon; |
| 502 | oparams.create_options = 0; |
| 503 | oparams.desired_access = FILE_READ_ATTRIBUTES; |
| 504 | oparams.disposition = FILE_OPEN; |
| 505 | oparams.fid = pfid; |
| 506 | oparams.reconnect = false; |
| 507 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 508 | rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 509 | if (rc == 0) { |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 510 | memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid)); |
| 511 | tcon->crfid.tcon = tcon; |
| 512 | tcon->crfid.is_valid = true; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 513 | } |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 514 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 515 | return rc; |
| 516 | } |
| 517 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 518 | static void |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 519 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 520 | { |
| 521 | int rc; |
| 522 | __le16 srch_path = 0; /* Null - open root of share */ |
| 523 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 524 | struct cifs_open_parms oparms; |
| 525 | struct cifs_fid fid; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 526 | bool no_cached_open = tcon->nohandlecache; |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 527 | |
| 528 | oparms.tcon = tcon; |
| 529 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 530 | oparms.disposition = FILE_OPEN; |
| 531 | oparms.create_options = 0; |
| 532 | oparms.fid = &fid; |
| 533 | oparms.reconnect = false; |
| 534 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 535 | if (no_cached_open) |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 536 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, |
| 537 | NULL); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 538 | else |
| 539 | rc = open_shroot(xid, tcon, &fid); |
| 540 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 541 | if (rc) |
| 542 | return; |
| 543 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 544 | SMB3_request_interfaces(xid, tcon); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 545 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 546 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 547 | FS_ATTRIBUTE_INFORMATION); |
| 548 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 549 | FS_DEVICE_INFORMATION); |
| 550 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 551 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 552 | if (no_cached_open) |
| 553 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 554 | return; |
| 555 | } |
| 556 | |
| 557 | static void |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 558 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
| 559 | { |
| 560 | int rc; |
| 561 | __le16 srch_path = 0; /* Null - open root of share */ |
| 562 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 563 | struct cifs_open_parms oparms; |
| 564 | struct cifs_fid fid; |
| 565 | |
| 566 | oparms.tcon = tcon; |
| 567 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 568 | oparms.disposition = FILE_OPEN; |
| 569 | oparms.create_options = 0; |
| 570 | oparms.fid = &fid; |
| 571 | oparms.reconnect = false; |
| 572 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 573 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 574 | if (rc) |
| 575 | return; |
| 576 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 577 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 578 | FS_ATTRIBUTE_INFORMATION); |
| 579 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 580 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 581 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 582 | return; |
| 583 | } |
| 584 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 585 | static int |
| 586 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 587 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 588 | { |
| 589 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 590 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 591 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 592 | struct cifs_open_parms oparms; |
| 593 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 594 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 595 | if ((*full_path == 0) && tcon->crfid.is_valid) |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 596 | return 0; |
| 597 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 598 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 599 | if (!utf16_path) |
| 600 | return -ENOMEM; |
| 601 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 602 | oparms.tcon = tcon; |
| 603 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 604 | oparms.disposition = FILE_OPEN; |
| 605 | oparms.create_options = 0; |
| 606 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 607 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 608 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 609 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 610 | if (rc) { |
| 611 | kfree(utf16_path); |
| 612 | return rc; |
| 613 | } |
| 614 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 615 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 616 | kfree(utf16_path); |
| 617 | return rc; |
| 618 | } |
| 619 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 620 | static int |
| 621 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 622 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 623 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 624 | { |
| 625 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 626 | return 0; |
| 627 | } |
| 628 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 629 | static int |
| 630 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 631 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 632 | { |
| 633 | int rc; |
| 634 | struct smb2_file_all_info *smb2_data; |
| 635 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 636 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 637 | GFP_KERNEL); |
| 638 | if (smb2_data == NULL) |
| 639 | return -ENOMEM; |
| 640 | |
| 641 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 642 | smb2_data); |
| 643 | if (!rc) |
| 644 | move_smb2_info_to_cifs(data, smb2_data); |
| 645 | kfree(smb2_data); |
| 646 | return rc; |
| 647 | } |
| 648 | |
Arnd Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 649 | #ifdef CONFIG_CIFS_XATTR |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 650 | static ssize_t |
| 651 | move_smb2_ea_to_cifs(char *dst, size_t dst_size, |
| 652 | struct smb2_file_full_ea_info *src, size_t src_size, |
| 653 | const unsigned char *ea_name) |
| 654 | { |
| 655 | int rc = 0; |
| 656 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
| 657 | char *name, *value; |
| 658 | size_t name_len, value_len, user_name_len; |
| 659 | |
| 660 | while (src_size > 0) { |
| 661 | name = &src->ea_data[0]; |
| 662 | name_len = (size_t)src->ea_name_length; |
| 663 | value = &src->ea_data[src->ea_name_length + 1]; |
| 664 | value_len = (size_t)le16_to_cpu(src->ea_value_length); |
| 665 | |
| 666 | if (name_len == 0) { |
| 667 | break; |
| 668 | } |
| 669 | |
| 670 | if (src_size < 8 + name_len + 1 + value_len) { |
| 671 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
| 672 | rc = -EIO; |
| 673 | goto out; |
| 674 | } |
| 675 | |
| 676 | if (ea_name) { |
| 677 | if (ea_name_len == name_len && |
| 678 | memcmp(ea_name, name, name_len) == 0) { |
| 679 | rc = value_len; |
| 680 | if (dst_size == 0) |
| 681 | goto out; |
| 682 | if (dst_size < value_len) { |
| 683 | rc = -ERANGE; |
| 684 | goto out; |
| 685 | } |
| 686 | memcpy(dst, value, value_len); |
| 687 | goto out; |
| 688 | } |
| 689 | } else { |
| 690 | /* 'user.' plus a terminating null */ |
| 691 | user_name_len = 5 + 1 + name_len; |
| 692 | |
| 693 | rc += user_name_len; |
| 694 | |
| 695 | if (dst_size >= user_name_len) { |
| 696 | dst_size -= user_name_len; |
| 697 | memcpy(dst, "user.", 5); |
| 698 | dst += 5; |
| 699 | memcpy(dst, src->ea_data, name_len); |
| 700 | dst += name_len; |
| 701 | *dst = 0; |
| 702 | ++dst; |
| 703 | } else if (dst_size == 0) { |
| 704 | /* skip copy - calc size only */ |
| 705 | } else { |
| 706 | /* stop before overrun buffer */ |
| 707 | rc = -ERANGE; |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | if (!src->next_entry_offset) |
| 713 | break; |
| 714 | |
| 715 | if (src_size < le32_to_cpu(src->next_entry_offset)) { |
| 716 | /* stop before overrun buffer */ |
| 717 | rc = -ERANGE; |
| 718 | break; |
| 719 | } |
| 720 | src_size -= le32_to_cpu(src->next_entry_offset); |
| 721 | src = (void *)((char *)src + |
| 722 | le32_to_cpu(src->next_entry_offset)); |
| 723 | } |
| 724 | |
| 725 | /* didn't find the named attribute */ |
| 726 | if (ea_name) |
| 727 | rc = -ENODATA; |
| 728 | |
| 729 | out: |
| 730 | return (ssize_t)rc; |
| 731 | } |
| 732 | |
| 733 | static ssize_t |
| 734 | smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon, |
| 735 | const unsigned char *path, const unsigned char *ea_name, |
| 736 | char *ea_data, size_t buf_size, |
| 737 | struct cifs_sb_info *cifs_sb) |
| 738 | { |
| 739 | int rc; |
| 740 | __le16 *utf16_path; |
| 741 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 742 | struct cifs_open_parms oparms; |
| 743 | struct cifs_fid fid; |
| 744 | struct smb2_file_full_ea_info *smb2_data; |
Ronnie Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 745 | int ea_buf_size = SMB2_MIN_EA_BUF; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 746 | |
| 747 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 748 | if (!utf16_path) |
| 749 | return -ENOMEM; |
| 750 | |
| 751 | oparms.tcon = tcon; |
| 752 | oparms.desired_access = FILE_READ_EA; |
| 753 | oparms.disposition = FILE_OPEN; |
| 754 | oparms.create_options = 0; |
| 755 | oparms.fid = &fid; |
| 756 | oparms.reconnect = false; |
| 757 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 758 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 759 | kfree(utf16_path); |
| 760 | if (rc) { |
| 761 | cifs_dbg(FYI, "open failed rc=%d\n", rc); |
| 762 | return rc; |
| 763 | } |
| 764 | |
Ronnie Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 765 | while (1) { |
| 766 | smb2_data = kzalloc(ea_buf_size, GFP_KERNEL); |
| 767 | if (smb2_data == NULL) { |
| 768 | SMB2_close(xid, tcon, fid.persistent_fid, |
| 769 | fid.volatile_fid); |
| 770 | return -ENOMEM; |
| 771 | } |
| 772 | |
| 773 | rc = SMB2_query_eas(xid, tcon, fid.persistent_fid, |
| 774 | fid.volatile_fid, |
| 775 | ea_buf_size, smb2_data); |
| 776 | |
| 777 | if (rc != -E2BIG) |
| 778 | break; |
| 779 | |
| 780 | kfree(smb2_data); |
| 781 | ea_buf_size <<= 1; |
| 782 | |
| 783 | if (ea_buf_size > SMB2_MAX_EA_BUF) { |
| 784 | cifs_dbg(VFS, "EA size is too large\n"); |
| 785 | SMB2_close(xid, tcon, fid.persistent_fid, |
| 786 | fid.volatile_fid); |
| 787 | return -ENOMEM; |
| 788 | } |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 789 | } |
| 790 | |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 791 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 792 | |
Paulo Alcantara | ae2cd7f | 2018-05-04 11:25:26 -0300 | [diff] [blame] | 793 | /* |
| 794 | * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's |
| 795 | * not an error. Otherwise, the specified ea_name was not found. |
| 796 | */ |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 797 | if (!rc) |
| 798 | rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data, |
| 799 | SMB2_MAX_EA_BUF, ea_name); |
Paulo Alcantara | ae2cd7f | 2018-05-04 11:25:26 -0300 | [diff] [blame] | 800 | else if (!ea_name && rc == -ENODATA) |
| 801 | rc = 0; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 802 | |
| 803 | kfree(smb2_data); |
| 804 | return rc; |
| 805 | } |
| 806 | |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 807 | |
| 808 | static int |
| 809 | smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, |
| 810 | const char *path, const char *ea_name, const void *ea_value, |
| 811 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 812 | struct cifs_sb_info *cifs_sb) |
| 813 | { |
| 814 | int rc; |
| 815 | __le16 *utf16_path; |
| 816 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 817 | struct cifs_open_parms oparms; |
| 818 | struct cifs_fid fid; |
| 819 | struct smb2_file_full_ea_info *ea; |
| 820 | int ea_name_len = strlen(ea_name); |
| 821 | int len; |
| 822 | |
| 823 | if (ea_name_len > 255) |
| 824 | return -EINVAL; |
| 825 | |
| 826 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 827 | if (!utf16_path) |
| 828 | return -ENOMEM; |
| 829 | |
| 830 | oparms.tcon = tcon; |
| 831 | oparms.desired_access = FILE_WRITE_EA; |
| 832 | oparms.disposition = FILE_OPEN; |
| 833 | oparms.create_options = 0; |
| 834 | oparms.fid = &fid; |
| 835 | oparms.reconnect = false; |
| 836 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 837 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 838 | kfree(utf16_path); |
| 839 | if (rc) { |
| 840 | cifs_dbg(FYI, "open failed rc=%d\n", rc); |
| 841 | return rc; |
| 842 | } |
| 843 | |
| 844 | len = sizeof(ea) + ea_name_len + ea_value_len + 1; |
| 845 | ea = kzalloc(len, GFP_KERNEL); |
| 846 | if (ea == NULL) { |
| 847 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 848 | return -ENOMEM; |
| 849 | } |
| 850 | |
| 851 | ea->ea_name_length = ea_name_len; |
| 852 | ea->ea_value_length = cpu_to_le16(ea_value_len); |
| 853 | memcpy(ea->ea_data, ea_name, ea_name_len + 1); |
| 854 | memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len); |
| 855 | |
| 856 | rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea, |
| 857 | len); |
| 858 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 859 | |
| 860 | return rc; |
| 861 | } |
Arnd Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 862 | #endif |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 863 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 864 | static bool |
| 865 | smb2_can_echo(struct TCP_Server_Info *server) |
| 866 | { |
| 867 | return server->echoes; |
| 868 | } |
| 869 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 870 | static void |
| 871 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 872 | { |
| 873 | #ifdef CONFIG_CIFS_STATS |
| 874 | int i; |
| 875 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 876 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 877 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 878 | } |
| 879 | #endif |
| 880 | } |
| 881 | |
| 882 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 883 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 884 | { |
| 885 | seq_puts(m, "\n\tShare Capabilities:"); |
| 886 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 887 | seq_puts(m, " DFS,"); |
| 888 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 889 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 890 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 891 | seq_puts(m, " SCALEOUT,"); |
| 892 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 893 | seq_puts(m, " CLUSTER,"); |
| 894 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 895 | seq_puts(m, " ASYMMETRIC,"); |
| 896 | if (tcon->capabilities == 0) |
| 897 | seq_puts(m, " None"); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 898 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
| 899 | seq_puts(m, " Aligned,"); |
| 900 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) |
| 901 | seq_puts(m, " Partition Aligned,"); |
| 902 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) |
| 903 | seq_puts(m, " SSD,"); |
| 904 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) |
| 905 | seq_puts(m, " TRIM-support,"); |
| 906 | |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 907 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steve French | e0386e4 | 2018-05-20 01:27:03 -0500 | [diff] [blame] | 908 | seq_printf(m, "\n\ttid: 0x%x", tcon->tid); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 909 | if (tcon->perf_sector_size) |
| 910 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 911 | tcon->perf_sector_size); |
Steve French | e0386e4 | 2018-05-20 01:27:03 -0500 | [diff] [blame] | 912 | seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 916 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 917 | { |
| 918 | #ifdef CONFIG_CIFS_STATS |
| 919 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 920 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
| 921 | seq_printf(m, "\nNegotiates: %d sent %d failed", |
| 922 | atomic_read(&sent[SMB2_NEGOTIATE_HE]), |
| 923 | atomic_read(&failed[SMB2_NEGOTIATE_HE])); |
| 924 | seq_printf(m, "\nSessionSetups: %d sent %d failed", |
| 925 | atomic_read(&sent[SMB2_SESSION_SETUP_HE]), |
| 926 | atomic_read(&failed[SMB2_SESSION_SETUP_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 927 | seq_printf(m, "\nLogoffs: %d sent %d failed", |
| 928 | atomic_read(&sent[SMB2_LOGOFF_HE]), |
| 929 | atomic_read(&failed[SMB2_LOGOFF_HE])); |
| 930 | seq_printf(m, "\nTreeConnects: %d sent %d failed", |
| 931 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 932 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
| 933 | seq_printf(m, "\nTreeDisconnects: %d sent %d failed", |
| 934 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 935 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
| 936 | seq_printf(m, "\nCreates: %d sent %d failed", |
| 937 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 938 | atomic_read(&failed[SMB2_CREATE_HE])); |
| 939 | seq_printf(m, "\nCloses: %d sent %d failed", |
| 940 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 941 | atomic_read(&failed[SMB2_CLOSE_HE])); |
| 942 | seq_printf(m, "\nFlushes: %d sent %d failed", |
| 943 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 944 | atomic_read(&failed[SMB2_FLUSH_HE])); |
| 945 | seq_printf(m, "\nReads: %d sent %d failed", |
| 946 | atomic_read(&sent[SMB2_READ_HE]), |
| 947 | atomic_read(&failed[SMB2_READ_HE])); |
| 948 | seq_printf(m, "\nWrites: %d sent %d failed", |
| 949 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 950 | atomic_read(&failed[SMB2_WRITE_HE])); |
| 951 | seq_printf(m, "\nLocks: %d sent %d failed", |
| 952 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 953 | atomic_read(&failed[SMB2_LOCK_HE])); |
| 954 | seq_printf(m, "\nIOCTLs: %d sent %d failed", |
| 955 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 956 | atomic_read(&failed[SMB2_IOCTL_HE])); |
| 957 | seq_printf(m, "\nCancels: %d sent %d failed", |
| 958 | atomic_read(&sent[SMB2_CANCEL_HE]), |
| 959 | atomic_read(&failed[SMB2_CANCEL_HE])); |
| 960 | seq_printf(m, "\nEchos: %d sent %d failed", |
| 961 | atomic_read(&sent[SMB2_ECHO_HE]), |
| 962 | atomic_read(&failed[SMB2_ECHO_HE])); |
| 963 | seq_printf(m, "\nQueryDirectories: %d sent %d failed", |
| 964 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 965 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
| 966 | seq_printf(m, "\nChangeNotifies: %d sent %d failed", |
| 967 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 968 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
| 969 | seq_printf(m, "\nQueryInfos: %d sent %d failed", |
| 970 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 971 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
| 972 | seq_printf(m, "\nSetInfos: %d sent %d failed", |
| 973 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 974 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 975 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 976 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 977 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
| 978 | #endif |
| 979 | } |
| 980 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 981 | static void |
| 982 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 983 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 984 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 985 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 986 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 987 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 988 | cfile->fid.volatile_fid = fid->volatile_fid; |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 989 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 990 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 991 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Aurelien Aptel | 94f8737 | 2016-09-22 07:38:50 +0200 | [diff] [blame] | 992 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 995 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 996 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 997 | struct cifs_fid *fid) |
| 998 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 999 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1002 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1003 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, |
| 1004 | u64 persistent_fid, u64 volatile_fid, |
| 1005 | struct copychunk_ioctl *pcchunk) |
| 1006 | { |
| 1007 | int rc; |
| 1008 | unsigned int ret_data_len; |
| 1009 | struct resume_key_req *res_key; |
| 1010 | |
| 1011 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 1012 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, |
| 1013 | NULL, 0 /* no input */, |
| 1014 | (char **)&res_key, &ret_data_len); |
| 1015 | |
| 1016 | if (rc) { |
| 1017 | cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); |
| 1018 | goto req_res_key_exit; |
| 1019 | } |
| 1020 | if (ret_data_len < sizeof(struct resume_key_req)) { |
| 1021 | cifs_dbg(VFS, "Invalid refcopy resume key length\n"); |
| 1022 | rc = -EINVAL; |
| 1023 | goto req_res_key_exit; |
| 1024 | } |
| 1025 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 1026 | |
| 1027 | req_res_key_exit: |
| 1028 | kfree(res_key); |
| 1029 | return rc; |
| 1030 | } |
| 1031 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1032 | static ssize_t |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 1033 | smb2_copychunk_range(const unsigned int xid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1034 | struct cifsFileInfo *srcfile, |
| 1035 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 1036 | u64 len, u64 dest_off) |
| 1037 | { |
| 1038 | int rc; |
| 1039 | unsigned int ret_data_len; |
| 1040 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1041 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 1042 | struct cifs_tcon *tcon; |
| 1043 | int chunks_copied = 0; |
| 1044 | bool chunk_sizes_updated = false; |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1045 | ssize_t bytes_written, total_bytes_written = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1046 | |
| 1047 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 1048 | |
| 1049 | if (pcchunk == NULL) |
| 1050 | return -ENOMEM; |
| 1051 | |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 1052 | 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] | 1053 | /* Request a key from the server to identify the source of the copy */ |
| 1054 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 1055 | srcfile->fid.persistent_fid, |
| 1056 | srcfile->fid.volatile_fid, pcchunk); |
| 1057 | |
| 1058 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 1059 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1060 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1061 | |
| 1062 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 1063 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1064 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1065 | pcchunk->Reserved2 = 0; |
| 1066 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1067 | tcon = tlink_tcon(trgtfile->tlink); |
| 1068 | |
| 1069 | while (len > 0) { |
| 1070 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 1071 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 1072 | pcchunk->Length = |
| 1073 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 1074 | |
| 1075 | /* Request server copy to target from src identified by key */ |
| 1076 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1077 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1078 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1079 | sizeof(struct copychunk_ioctl), (char **)&retbuf, |
| 1080 | &ret_data_len); |
| 1081 | if (rc == 0) { |
| 1082 | if (ret_data_len != |
| 1083 | sizeof(struct copychunk_ioctl_rsp)) { |
| 1084 | cifs_dbg(VFS, "invalid cchunk response size\n"); |
| 1085 | rc = -EIO; |
| 1086 | goto cchunk_out; |
| 1087 | } |
| 1088 | if (retbuf->TotalBytesWritten == 0) { |
| 1089 | cifs_dbg(FYI, "no bytes copied\n"); |
| 1090 | rc = -EIO; |
| 1091 | goto cchunk_out; |
| 1092 | } |
| 1093 | /* |
| 1094 | * Check if server claimed to write more than we asked |
| 1095 | */ |
| 1096 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 1097 | le32_to_cpu(pcchunk->Length)) { |
| 1098 | cifs_dbg(VFS, "invalid copy chunk response\n"); |
| 1099 | rc = -EIO; |
| 1100 | goto cchunk_out; |
| 1101 | } |
| 1102 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
| 1103 | cifs_dbg(VFS, "invalid num chunks written\n"); |
| 1104 | rc = -EIO; |
| 1105 | goto cchunk_out; |
| 1106 | } |
| 1107 | chunks_copied++; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1108 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1109 | bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); |
| 1110 | src_off += bytes_written; |
| 1111 | dest_off += bytes_written; |
| 1112 | len -= bytes_written; |
| 1113 | total_bytes_written += bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1114 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1115 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n", |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1116 | le32_to_cpu(retbuf->ChunksWritten), |
| 1117 | le32_to_cpu(retbuf->ChunkBytesWritten), |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1118 | bytes_written); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1119 | } else if (rc == -EINVAL) { |
| 1120 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 1121 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1122 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1123 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 1124 | le32_to_cpu(retbuf->ChunksWritten), |
| 1125 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 1126 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 1127 | |
| 1128 | /* |
| 1129 | * Check if this is the first request using these sizes, |
| 1130 | * (ie check if copy succeed once with original sizes |
| 1131 | * and check if the server gave us different sizes after |
| 1132 | * we already updated max sizes on previous request). |
| 1133 | * if not then why is the server returning an error now |
| 1134 | */ |
| 1135 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 1136 | goto cchunk_out; |
| 1137 | |
| 1138 | /* Check that server is not asking us to grow size */ |
| 1139 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 1140 | tcon->max_bytes_chunk) |
| 1141 | tcon->max_bytes_chunk = |
| 1142 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 1143 | else |
| 1144 | goto cchunk_out; /* server gave us bogus size */ |
| 1145 | |
| 1146 | /* No need to change MaxChunks since already set to 1 */ |
| 1147 | chunk_sizes_updated = true; |
Sachin Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 1148 | } else |
| 1149 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1153 | kfree(pcchunk); |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1154 | kfree(retbuf); |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1155 | if (rc) |
| 1156 | return rc; |
| 1157 | else |
| 1158 | return total_bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1162 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 1163 | struct cifs_fid *fid) |
| 1164 | { |
| 1165 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 1166 | } |
| 1167 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1168 | static unsigned int |
| 1169 | smb2_read_data_offset(char *buf) |
| 1170 | { |
| 1171 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
| 1172 | return rsp->DataOffset; |
| 1173 | } |
| 1174 | |
| 1175 | static unsigned int |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1176 | smb2_read_data_length(char *buf, bool in_remaining) |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1177 | { |
| 1178 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1179 | |
| 1180 | if (in_remaining) |
| 1181 | return le32_to_cpu(rsp->DataRemaining); |
| 1182 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1183 | return le32_to_cpu(rsp->DataLength); |
| 1184 | } |
| 1185 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1186 | |
| 1187 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1188 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1189 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 1190 | char **buf, int *buf_type) |
| 1191 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1192 | parms->persistent_fid = pfid->persistent_fid; |
| 1193 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1194 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 1195 | } |
| 1196 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1197 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1198 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1199 | struct cifs_io_parms *parms, unsigned int *written, |
| 1200 | struct kvec *iov, unsigned long nr_segs) |
| 1201 | { |
| 1202 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1203 | parms->persistent_fid = pfid->persistent_fid; |
| 1204 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1205 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 1206 | } |
| 1207 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1208 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 1209 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, |
| 1210 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) |
| 1211 | { |
| 1212 | struct cifsInodeInfo *cifsi; |
| 1213 | int rc; |
| 1214 | |
| 1215 | cifsi = CIFS_I(inode); |
| 1216 | |
| 1217 | /* if file already sparse don't bother setting sparse again */ |
| 1218 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) |
| 1219 | return true; /* already sparse */ |
| 1220 | |
| 1221 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) |
| 1222 | return true; /* already not sparse */ |
| 1223 | |
| 1224 | /* |
| 1225 | * Can't check for sparse support on share the usual way via the |
| 1226 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share |
| 1227 | * since Samba server doesn't set the flag on the share, yet |
| 1228 | * supports the set sparse FSCTL and returns sparse correctly |
| 1229 | * in the file attributes. If we fail setting sparse though we |
| 1230 | * mark that server does not support sparse files for this share |
| 1231 | * to avoid repeatedly sending the unsupported fsctl to server |
| 1232 | * if the file is repeatedly extended. |
| 1233 | */ |
| 1234 | if (tcon->broken_sparse_sup) |
| 1235 | return false; |
| 1236 | |
| 1237 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1238 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1239 | true /* is_fctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1240 | &setsparse, 1, NULL, NULL); |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1241 | if (rc) { |
| 1242 | tcon->broken_sparse_sup = true; |
| 1243 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | if (setsparse) |
| 1248 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; |
| 1249 | else |
| 1250 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); |
| 1251 | |
| 1252 | return true; |
| 1253 | } |
| 1254 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1255 | static int |
| 1256 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 1257 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 1258 | { |
| 1259 | __le64 eof = cpu_to_le64(size); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1260 | struct inode *inode; |
| 1261 | |
| 1262 | /* |
| 1263 | * If extending file more than one page make sparse. Many Linux fs |
| 1264 | * make files sparse by default when extending via ftruncate |
| 1265 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1266 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1267 | |
| 1268 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1269 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1270 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1271 | /* whether set sparse succeeds or not, extend the file */ |
| 1272 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1273 | } |
| 1274 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1275 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 1276 | cfile->fid.volatile_fid, cfile->pid, &eof, false); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1279 | static int |
| 1280 | smb2_duplicate_extents(const unsigned int xid, |
| 1281 | struct cifsFileInfo *srcfile, |
| 1282 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 1283 | u64 len, u64 dest_off) |
| 1284 | { |
| 1285 | int rc; |
| 1286 | unsigned int ret_data_len; |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1287 | struct duplicate_extents_to_file dup_ext_buf; |
| 1288 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); |
| 1289 | |
| 1290 | /* server fileays advertise duplicate extent support with this flag */ |
| 1291 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & |
| 1292 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) |
| 1293 | return -EOPNOTSUPP; |
| 1294 | |
| 1295 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; |
| 1296 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; |
| 1297 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); |
| 1298 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); |
| 1299 | dup_ext_buf.ByteCount = cpu_to_le64(len); |
| 1300 | cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld", |
| 1301 | src_off, dest_off, len); |
| 1302 | |
| 1303 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 1304 | if (rc) |
| 1305 | goto duplicate_extents_out; |
| 1306 | |
| 1307 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 1308 | trgtfile->fid.volatile_fid, |
| 1309 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1310 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1311 | (char *)&dup_ext_buf, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1312 | sizeof(struct duplicate_extents_to_file), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1313 | NULL, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1314 | &ret_data_len); |
| 1315 | |
| 1316 | if (ret_data_len > 0) |
| 1317 | cifs_dbg(FYI, "non-zero response length in duplicate extents"); |
| 1318 | |
| 1319 | duplicate_extents_out: |
| 1320 | return rc; |
| 1321 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1322 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1323 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1324 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 1325 | struct cifsFileInfo *cfile) |
| 1326 | { |
| 1327 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 1328 | cfile->fid.volatile_fid); |
| 1329 | } |
| 1330 | |
| 1331 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1332 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, |
| 1333 | struct cifsFileInfo *cfile) |
| 1334 | { |
| 1335 | struct fsctl_set_integrity_information_req integr_info; |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1336 | unsigned int ret_data_len; |
| 1337 | |
| 1338 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); |
| 1339 | integr_info.Flags = 0; |
| 1340 | integr_info.Reserved = 0; |
| 1341 | |
| 1342 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1343 | cfile->fid.volatile_fid, |
| 1344 | FSCTL_SET_INTEGRITY_INFORMATION, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1345 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1346 | (char *)&integr_info, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1347 | sizeof(struct fsctl_set_integrity_information_req), |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1348 | NULL, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1349 | &ret_data_len); |
| 1350 | |
| 1351 | } |
| 1352 | |
| 1353 | static int |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1354 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, |
| 1355 | struct cifsFileInfo *cfile, void __user *ioc_buf) |
| 1356 | { |
| 1357 | char *retbuf = NULL; |
| 1358 | unsigned int ret_data_len = 0; |
| 1359 | int rc; |
| 1360 | struct smb_snapshot_array snapshot_in; |
| 1361 | |
| 1362 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1363 | cfile->fid.volatile_fid, |
| 1364 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1365 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1366 | NULL, 0 /* no input data */, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1367 | (char **)&retbuf, |
| 1368 | &ret_data_len); |
| 1369 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", |
| 1370 | rc, ret_data_len); |
| 1371 | if (rc) |
| 1372 | return rc; |
| 1373 | |
| 1374 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { |
| 1375 | /* Fixup buffer */ |
| 1376 | if (copy_from_user(&snapshot_in, ioc_buf, |
| 1377 | sizeof(struct smb_snapshot_array))) { |
| 1378 | rc = -EFAULT; |
| 1379 | kfree(retbuf); |
| 1380 | return rc; |
| 1381 | } |
| 1382 | if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) { |
| 1383 | rc = -ERANGE; |
David Disseldorp | 0e5c795 | 2017-05-03 17:39:09 +0200 | [diff] [blame] | 1384 | kfree(retbuf); |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1385 | return rc; |
| 1386 | } |
| 1387 | |
| 1388 | if (ret_data_len > snapshot_in.snapshot_array_size) |
| 1389 | ret_data_len = snapshot_in.snapshot_array_size; |
| 1390 | |
| 1391 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) |
| 1392 | rc = -EFAULT; |
| 1393 | } |
| 1394 | |
| 1395 | kfree(retbuf); |
| 1396 | return rc; |
| 1397 | } |
| 1398 | |
| 1399 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1400 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 1401 | const char *path, struct cifs_sb_info *cifs_sb, |
| 1402 | struct cifs_fid *fid, __u16 search_flags, |
| 1403 | struct cifs_search_info *srch_inf) |
| 1404 | { |
| 1405 | __le16 *utf16_path; |
| 1406 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1407 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1408 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1409 | |
| 1410 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1411 | if (!utf16_path) |
| 1412 | return -ENOMEM; |
| 1413 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1414 | oparms.tcon = tcon; |
| 1415 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 1416 | oparms.disposition = FILE_OPEN; |
| 1417 | oparms.create_options = 0; |
| 1418 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1419 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1420 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1421 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1422 | kfree(utf16_path); |
| 1423 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 1424 | cifs_dbg(FYI, "open dir failed rc=%d\n", rc); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1425 | return rc; |
| 1426 | } |
| 1427 | |
| 1428 | srch_inf->entries_in_buffer = 0; |
| 1429 | srch_inf->index_of_last_entry = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1430 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1431 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 1432 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1433 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 1434 | cifs_dbg(FYI, "query directory failed rc=%d\n", rc); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1435 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1436 | } |
| 1437 | return rc; |
| 1438 | } |
| 1439 | |
| 1440 | static int |
| 1441 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 1442 | struct cifs_fid *fid, __u16 search_flags, |
| 1443 | struct cifs_search_info *srch_inf) |
| 1444 | { |
| 1445 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 1446 | fid->volatile_fid, 0, srch_inf); |
| 1447 | } |
| 1448 | |
| 1449 | static int |
| 1450 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 1451 | struct cifs_fid *fid) |
| 1452 | { |
| 1453 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 1454 | } |
| 1455 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1456 | /* |
| 1457 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 1458 | * the number of credits and return true. Otherwise - return false. |
| 1459 | */ |
| 1460 | static bool |
| 1461 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) |
| 1462 | { |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 1463 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1464 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1465 | if (shdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1466 | return false; |
| 1467 | |
| 1468 | if (!length) { |
| 1469 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 1470 | server->credits += le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1471 | spin_unlock(&server->req_lock); |
| 1472 | wake_up(&server->request_q); |
| 1473 | } |
| 1474 | |
| 1475 | return true; |
| 1476 | } |
| 1477 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1478 | static bool |
| 1479 | smb2_is_session_expired(char *buf) |
| 1480 | { |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 1481 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1482 | |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 1483 | if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && |
| 1484 | shdr->Status != STATUS_USER_SESSION_DELETED) |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1485 | return false; |
| 1486 | |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 1487 | cifs_dbg(FYI, "Session expired or deleted\n"); |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 1488 | return true; |
| 1489 | } |
| 1490 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1491 | static int |
| 1492 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 1493 | struct cifsInodeInfo *cinode) |
| 1494 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 1495 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 1496 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 1497 | smb2_get_lease_state(cinode)); |
| 1498 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1499 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 1500 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 1501 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1504 | static int |
| 1505 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 1506 | struct kstatfs *buf) |
| 1507 | { |
| 1508 | int rc; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1509 | __le16 srch_path = 0; /* Null - open root of share */ |
| 1510 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1511 | struct cifs_open_parms oparms; |
| 1512 | struct cifs_fid fid; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1513 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1514 | oparms.tcon = tcon; |
| 1515 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1516 | oparms.disposition = FILE_OPEN; |
| 1517 | oparms.create_options = 0; |
| 1518 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1519 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1520 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1521 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1522 | if (rc) |
| 1523 | return rc; |
| 1524 | buf->f_type = SMB2_MAGIC_NUMBER; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1525 | rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 1526 | buf); |
| 1527 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 1528 | return rc; |
| 1529 | } |
| 1530 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1531 | static bool |
| 1532 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 1533 | { |
| 1534 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 1535 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 1536 | } |
| 1537 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 1538 | static int |
| 1539 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 1540 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 1541 | { |
| 1542 | if (unlock && !lock) |
| 1543 | type = SMB2_LOCKFLAG_UNLOCK; |
| 1544 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 1545 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 1546 | current->tgid, length, offset, type, wait); |
| 1547 | } |
| 1548 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1549 | static void |
| 1550 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1551 | { |
| 1552 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1553 | } |
| 1554 | |
| 1555 | static void |
| 1556 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 1557 | { |
| 1558 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 1559 | } |
| 1560 | |
| 1561 | static void |
| 1562 | smb2_new_lease_key(struct cifs_fid *fid) |
| 1563 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 1564 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1567 | static int |
| 1568 | smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses, |
| 1569 | const char *search_name, |
| 1570 | struct dfs_info3_param **target_nodes, |
| 1571 | unsigned int *num_of_nodes, |
| 1572 | const struct nls_table *nls_codepage, int remap) |
| 1573 | { |
| 1574 | int rc; |
| 1575 | __le16 *utf16_path = NULL; |
| 1576 | int utf16_path_len = 0; |
| 1577 | struct cifs_tcon *tcon; |
| 1578 | struct fsctl_get_dfs_referral_req *dfs_req = NULL; |
| 1579 | struct get_dfs_referral_rsp *dfs_rsp = NULL; |
| 1580 | u32 dfs_req_size = 0, dfs_rsp_size = 0; |
| 1581 | |
| 1582 | cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name); |
| 1583 | |
| 1584 | /* |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1585 | * Try to use the IPC tcon, otherwise just use any |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1586 | */ |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1587 | tcon = ses->tcon_ipc; |
| 1588 | if (tcon == NULL) { |
| 1589 | spin_lock(&cifs_tcp_ses_lock); |
| 1590 | tcon = list_first_entry_or_null(&ses->tcon_list, |
| 1591 | struct cifs_tcon, |
| 1592 | tcon_list); |
| 1593 | if (tcon) |
| 1594 | tcon->tc_count++; |
| 1595 | spin_unlock(&cifs_tcp_ses_lock); |
| 1596 | } |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1597 | |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1598 | if (tcon == NULL) { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1599 | cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", |
| 1600 | ses); |
| 1601 | rc = -ENOTCONN; |
| 1602 | goto out; |
| 1603 | } |
| 1604 | |
| 1605 | utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX, |
| 1606 | &utf16_path_len, |
| 1607 | nls_codepage, remap); |
| 1608 | if (!utf16_path) { |
| 1609 | rc = -ENOMEM; |
| 1610 | goto out; |
| 1611 | } |
| 1612 | |
| 1613 | dfs_req_size = sizeof(*dfs_req) + utf16_path_len; |
| 1614 | dfs_req = kzalloc(dfs_req_size, GFP_KERNEL); |
| 1615 | if (!dfs_req) { |
| 1616 | rc = -ENOMEM; |
| 1617 | goto out; |
| 1618 | } |
| 1619 | |
| 1620 | /* Highest DFS referral version understood */ |
| 1621 | dfs_req->MaxReferralLevel = DFS_VERSION; |
| 1622 | |
| 1623 | /* Path to resolve in an UTF-16 null-terminated string */ |
| 1624 | memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); |
| 1625 | |
| 1626 | do { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1627 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 1628 | FSCTL_DFS_GET_REFERRALS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1629 | true /* is_fsctl */, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1630 | (char *)dfs_req, dfs_req_size, |
| 1631 | (char **)&dfs_rsp, &dfs_rsp_size); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1632 | } while (rc == -EAGAIN); |
| 1633 | |
| 1634 | if (rc) { |
Steve French | 2564f2f | 2018-03-21 23:16:36 -0500 | [diff] [blame] | 1635 | if ((rc != -ENOENT) && (rc != -EOPNOTSUPP)) |
Aurelien Aptel | 5702591 | 2017-11-21 14:47:56 +0100 | [diff] [blame] | 1636 | 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] | 1637 | goto out; |
| 1638 | } |
| 1639 | |
| 1640 | rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size, |
| 1641 | num_of_nodes, target_nodes, |
| 1642 | nls_codepage, remap, search_name, |
| 1643 | true /* is_unicode */); |
| 1644 | if (rc) { |
| 1645 | cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc); |
| 1646 | goto out; |
| 1647 | } |
| 1648 | |
| 1649 | out: |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1650 | if (tcon && !tcon->ipc) { |
| 1651 | /* ipc tcons are not refcounted */ |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 1652 | spin_lock(&cifs_tcp_ses_lock); |
| 1653 | tcon->tc_count--; |
| 1654 | spin_unlock(&cifs_tcp_ses_lock); |
| 1655 | } |
| 1656 | kfree(utf16_path); |
| 1657 | kfree(dfs_req); |
| 1658 | kfree(dfs_rsp); |
| 1659 | return rc; |
| 1660 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1661 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 1662 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 1663 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1664 | static int |
| 1665 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 1666 | const char *full_path, char **target_path, |
| 1667 | struct cifs_sb_info *cifs_sb) |
| 1668 | { |
| 1669 | int rc; |
| 1670 | __le16 *utf16_path; |
| 1671 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1672 | struct cifs_open_parms oparms; |
| 1673 | struct cifs_fid fid; |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 1674 | struct kvec err_iov = {NULL, 0}; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1675 | struct smb2_err_rsp *err_buf = NULL; |
| 1676 | int resp_buftype; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1677 | struct smb2_symlink_err_rsp *symlink; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1678 | unsigned int sub_len; |
| 1679 | unsigned int sub_offset; |
| 1680 | unsigned int print_len; |
| 1681 | unsigned int print_offset; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1682 | |
| 1683 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 1684 | |
| 1685 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 1686 | if (!utf16_path) |
| 1687 | return -ENOMEM; |
| 1688 | |
| 1689 | oparms.tcon = tcon; |
| 1690 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1691 | oparms.disposition = FILE_OPEN; |
| 1692 | oparms.create_options = 0; |
| 1693 | oparms.fid = &fid; |
| 1694 | oparms.reconnect = false; |
| 1695 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1696 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov, |
| 1697 | &resp_buftype); |
Gustavo A. R. Silva | 0d568cd | 2018-04-13 10:13:29 -0500 | [diff] [blame] | 1698 | if (!rc || !err_iov.iov_base) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1699 | rc = -ENOENT; |
| 1700 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1701 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1702 | |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 1703 | err_buf = err_iov.iov_base; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1704 | if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 1705 | err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1706 | rc = -ENOENT; |
| 1707 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1708 | } |
| 1709 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1710 | /* open must fail on symlink - reset rc */ |
| 1711 | rc = 0; |
| 1712 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 1713 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 1714 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1715 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 1716 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 1717 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 1718 | if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1719 | rc = -ENOENT; |
| 1720 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1721 | } |
| 1722 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 1723 | if (err_iov.iov_len < |
| 1724 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1725 | rc = -ENOENT; |
| 1726 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 1727 | } |
| 1728 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1729 | *target_path = cifs_strndup_from_utf16( |
| 1730 | (char *)symlink->PathBuffer + sub_offset, |
| 1731 | sub_len, true, cifs_sb->local_nls); |
| 1732 | if (!(*target_path)) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1733 | rc = -ENOMEM; |
| 1734 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1735 | } |
| 1736 | convert_delimiter(*target_path, '/'); |
| 1737 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1738 | |
| 1739 | querty_exit: |
| 1740 | free_rsp_buf(resp_buftype, err_buf); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 1741 | kfree(utf16_path); |
| 1742 | return rc; |
| 1743 | } |
| 1744 | |
Arnd Bergmann | 8490842 | 2017-06-27 17:06:13 +0200 | [diff] [blame] | 1745 | #ifdef CONFIG_CIFS_ACL |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1746 | static struct cifs_ntsd * |
| 1747 | get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb, |
| 1748 | const struct cifs_fid *cifsfid, u32 *pacllen) |
| 1749 | { |
| 1750 | struct cifs_ntsd *pntsd = NULL; |
| 1751 | unsigned int xid; |
| 1752 | int rc = -EOPNOTSUPP; |
| 1753 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1754 | |
| 1755 | if (IS_ERR(tlink)) |
| 1756 | return ERR_CAST(tlink); |
| 1757 | |
| 1758 | xid = get_xid(); |
| 1759 | cifs_dbg(FYI, "trying to get acl\n"); |
| 1760 | |
| 1761 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, |
| 1762 | cifsfid->volatile_fid, (void **)&pntsd, pacllen); |
| 1763 | free_xid(xid); |
| 1764 | |
| 1765 | cifs_put_tlink(tlink); |
| 1766 | |
| 1767 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 1768 | if (rc) |
| 1769 | return ERR_PTR(rc); |
| 1770 | return pntsd; |
| 1771 | |
| 1772 | } |
| 1773 | |
| 1774 | static struct cifs_ntsd * |
| 1775 | get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, |
| 1776 | const char *path, u32 *pacllen) |
| 1777 | { |
| 1778 | struct cifs_ntsd *pntsd = NULL; |
| 1779 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1780 | unsigned int xid; |
| 1781 | int rc; |
| 1782 | struct cifs_tcon *tcon; |
| 1783 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1784 | struct cifs_fid fid; |
| 1785 | struct cifs_open_parms oparms; |
| 1786 | __le16 *utf16_path; |
| 1787 | |
| 1788 | cifs_dbg(FYI, "get smb3 acl for path %s\n", path); |
| 1789 | if (IS_ERR(tlink)) |
| 1790 | return ERR_CAST(tlink); |
| 1791 | |
| 1792 | tcon = tlink_tcon(tlink); |
| 1793 | xid = get_xid(); |
| 1794 | |
| 1795 | if (backup_cred(cifs_sb)) |
Colin Ian King | 709340a | 2017-07-05 13:47:34 +0100 | [diff] [blame] | 1796 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1797 | else |
| 1798 | oparms.create_options = 0; |
| 1799 | |
| 1800 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1801 | if (!utf16_path) { |
| 1802 | rc = -ENOMEM; |
| 1803 | free_xid(xid); |
| 1804 | return ERR_PTR(rc); |
| 1805 | } |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1806 | |
| 1807 | oparms.tcon = tcon; |
| 1808 | oparms.desired_access = READ_CONTROL; |
| 1809 | oparms.disposition = FILE_OPEN; |
| 1810 | oparms.fid = &fid; |
| 1811 | oparms.reconnect = false; |
| 1812 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1813 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1814 | kfree(utf16_path); |
| 1815 | if (!rc) { |
| 1816 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 1817 | fid.volatile_fid, (void **)&pntsd, pacllen); |
| 1818 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 1819 | } |
| 1820 | |
| 1821 | cifs_put_tlink(tlink); |
| 1822 | free_xid(xid); |
| 1823 | |
| 1824 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 1825 | if (rc) |
| 1826 | return ERR_PTR(rc); |
| 1827 | return pntsd; |
| 1828 | } |
| 1829 | |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 1830 | #ifdef CONFIG_CIFS_ACL |
| 1831 | static int |
| 1832 | set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 1833 | struct inode *inode, const char *path, int aclflag) |
| 1834 | { |
| 1835 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1836 | unsigned int xid; |
| 1837 | int rc, access_flags = 0; |
| 1838 | struct cifs_tcon *tcon; |
| 1839 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 1840 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 1841 | struct cifs_fid fid; |
| 1842 | struct cifs_open_parms oparms; |
| 1843 | __le16 *utf16_path; |
| 1844 | |
| 1845 | cifs_dbg(FYI, "set smb3 acl for path %s\n", path); |
| 1846 | if (IS_ERR(tlink)) |
| 1847 | return PTR_ERR(tlink); |
| 1848 | |
| 1849 | tcon = tlink_tcon(tlink); |
| 1850 | xid = get_xid(); |
| 1851 | |
| 1852 | if (backup_cred(cifs_sb)) |
| 1853 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 1854 | else |
| 1855 | oparms.create_options = 0; |
| 1856 | |
| 1857 | if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP) |
| 1858 | access_flags = WRITE_OWNER; |
| 1859 | else |
| 1860 | access_flags = WRITE_DAC; |
| 1861 | |
| 1862 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1863 | if (!utf16_path) { |
| 1864 | rc = -ENOMEM; |
| 1865 | free_xid(xid); |
| 1866 | return rc; |
| 1867 | } |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 1868 | |
| 1869 | oparms.tcon = tcon; |
| 1870 | oparms.desired_access = access_flags; |
| 1871 | oparms.disposition = FILE_OPEN; |
| 1872 | oparms.path = path; |
| 1873 | oparms.fid = &fid; |
| 1874 | oparms.reconnect = false; |
| 1875 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 1876 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 1877 | kfree(utf16_path); |
| 1878 | if (!rc) { |
| 1879 | rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 1880 | fid.volatile_fid, pnntsd, acllen, aclflag); |
| 1881 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 1882 | } |
| 1883 | |
| 1884 | cifs_put_tlink(tlink); |
| 1885 | free_xid(xid); |
| 1886 | return rc; |
| 1887 | } |
| 1888 | #endif /* CIFS_ACL */ |
| 1889 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1890 | /* Retrieve an ACL from the server */ |
| 1891 | static struct cifs_ntsd * |
| 1892 | get_smb2_acl(struct cifs_sb_info *cifs_sb, |
| 1893 | struct inode *inode, const char *path, |
| 1894 | u32 *pacllen) |
| 1895 | { |
| 1896 | struct cifs_ntsd *pntsd = NULL; |
| 1897 | struct cifsFileInfo *open_file = NULL; |
| 1898 | |
| 1899 | if (inode) |
| 1900 | open_file = find_readable_file(CIFS_I(inode), true); |
| 1901 | if (!open_file) |
| 1902 | return get_smb2_acl_by_path(cifs_sb, path, pacllen); |
| 1903 | |
| 1904 | pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); |
| 1905 | cifsFileInfo_put(open_file); |
| 1906 | return pntsd; |
| 1907 | } |
Arnd Bergmann | 8490842 | 2017-06-27 17:06:13 +0200 | [diff] [blame] | 1908 | #endif |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 1909 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1910 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 1911 | loff_t offset, loff_t len, bool keep_size) |
| 1912 | { |
| 1913 | struct inode *inode; |
| 1914 | struct cifsInodeInfo *cifsi; |
| 1915 | struct cifsFileInfo *cfile = file->private_data; |
| 1916 | struct file_zero_data_information fsctl_buf; |
| 1917 | long rc; |
| 1918 | unsigned int xid; |
| 1919 | |
| 1920 | xid = get_xid(); |
| 1921 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1922 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1923 | cifsi = CIFS_I(inode); |
| 1924 | |
| 1925 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 1926 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1927 | if (keep_size == false) { |
| 1928 | rc = -EOPNOTSUPP; |
| 1929 | free_xid(xid); |
| 1930 | return rc; |
| 1931 | } |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1932 | |
Steve French | 2bb93d2 | 2014-08-20 18:56:29 -0500 | [diff] [blame] | 1933 | /* |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1934 | * Must check if file sparse since fallocate -z (zero range) assumes |
| 1935 | * non-sparse allocation |
| 1936 | */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1937 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { |
| 1938 | rc = -EOPNOTSUPP; |
| 1939 | free_xid(xid); |
| 1940 | return rc; |
| 1941 | } |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1942 | |
| 1943 | /* |
| 1944 | * need to make sure we are not asked to extend the file since the SMB3 |
| 1945 | * fsctl does not change the file size. In the future we could change |
| 1946 | * this to zero the first part of the range then set the file size |
| 1947 | * which for a non sparse file would zero the newly extended range |
| 1948 | */ |
| 1949 | if (keep_size == false) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1950 | if (i_size_read(inode) < offset + len) { |
| 1951 | rc = -EOPNOTSUPP; |
| 1952 | free_xid(xid); |
| 1953 | return rc; |
| 1954 | } |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1955 | |
| 1956 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1957 | |
| 1958 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1959 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1960 | |
| 1961 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1962 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1963 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 1964 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 1965 | free_xid(xid); |
| 1966 | return rc; |
| 1967 | } |
| 1968 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1969 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 1970 | loff_t offset, loff_t len) |
| 1971 | { |
| 1972 | struct inode *inode; |
| 1973 | struct cifsInodeInfo *cifsi; |
| 1974 | struct cifsFileInfo *cfile = file->private_data; |
| 1975 | struct file_zero_data_information fsctl_buf; |
| 1976 | long rc; |
| 1977 | unsigned int xid; |
| 1978 | __u8 set_sparse = 1; |
| 1979 | |
| 1980 | xid = get_xid(); |
| 1981 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1982 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1983 | cifsi = CIFS_I(inode); |
| 1984 | |
| 1985 | /* Need to make file sparse, if not already, before freeing range. */ |
| 1986 | /* Consider adding equivalent for compressed since it could also work */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 1987 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { |
| 1988 | rc = -EOPNOTSUPP; |
| 1989 | free_xid(xid); |
| 1990 | return rc; |
| 1991 | } |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 1992 | |
| 1993 | cifs_dbg(FYI, "offset %lld len %lld", offset, len); |
| 1994 | |
| 1995 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 1996 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 1997 | |
| 1998 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1999 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2000 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2001 | sizeof(struct file_zero_data_information), NULL, NULL); |
| 2002 | free_xid(xid); |
| 2003 | return rc; |
| 2004 | } |
| 2005 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2006 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 2007 | loff_t off, loff_t len, bool keep_size) |
| 2008 | { |
| 2009 | struct inode *inode; |
| 2010 | struct cifsInodeInfo *cifsi; |
| 2011 | struct cifsFileInfo *cfile = file->private_data; |
| 2012 | long rc = -EOPNOTSUPP; |
| 2013 | unsigned int xid; |
| 2014 | |
| 2015 | xid = get_xid(); |
| 2016 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2017 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2018 | cifsi = CIFS_I(inode); |
| 2019 | |
| 2020 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 2021 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2022 | if (keep_size == false) { |
| 2023 | free_xid(xid); |
| 2024 | return rc; |
| 2025 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2026 | |
| 2027 | /* |
| 2028 | * Files are non-sparse by default so falloc may be a no-op |
| 2029 | * Must check if file sparse. If not sparse, and not extending |
| 2030 | * then no need to do anything since file already allocated |
| 2031 | */ |
| 2032 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
| 2033 | if (keep_size == true) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2034 | rc = 0; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2035 | /* check if extending file */ |
| 2036 | else if (i_size_read(inode) >= off + len) |
| 2037 | /* not extending file and already not sparse */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2038 | rc = 0; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2039 | /* BB: in future add else clause to extend file */ |
| 2040 | else |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2041 | rc = -EOPNOTSUPP; |
| 2042 | free_xid(xid); |
| 2043 | return rc; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 2047 | /* |
| 2048 | * Check if falloc starts within first few pages of file |
| 2049 | * and ends within a few pages of the end of file to |
| 2050 | * ensure that most of file is being forced to be |
| 2051 | * fallocated now. If so then setting whole file sparse |
| 2052 | * ie potentially making a few extra pages at the beginning |
| 2053 | * or end of the file non-sparse via set_sparse is harmless. |
| 2054 | */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2055 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) { |
| 2056 | rc = -EOPNOTSUPP; |
| 2057 | free_xid(xid); |
| 2058 | return rc; |
| 2059 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2060 | |
| 2061 | rc = smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 2062 | } |
| 2063 | /* BB: else ... in future add code to extend file and set sparse */ |
| 2064 | |
| 2065 | |
| 2066 | free_xid(xid); |
| 2067 | return rc; |
| 2068 | } |
| 2069 | |
| 2070 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2071 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 2072 | loff_t off, loff_t len) |
| 2073 | { |
| 2074 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 2075 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 2076 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2077 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 2078 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 2079 | return smb3_zero_range(file, tcon, off, len, true); |
| 2080 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2081 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 2082 | return smb3_simple_falloc(file, tcon, off, len, true); |
| 2083 | else if (mode == 0) |
| 2084 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2085 | |
| 2086 | return -EOPNOTSUPP; |
| 2087 | } |
| 2088 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2089 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2090 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 2091 | struct cifsInodeInfo *cinode, bool set_level2) |
| 2092 | { |
| 2093 | if (set_level2) |
| 2094 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 2095 | 0, NULL); |
| 2096 | else |
| 2097 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 2098 | } |
| 2099 | |
| 2100 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2101 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 2102 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2103 | { |
| 2104 | oplock &= 0xFF; |
| 2105 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 2106 | return; |
| 2107 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2108 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2109 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 2110 | &cinode->vfs_inode); |
| 2111 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2112 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2113 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 2114 | &cinode->vfs_inode); |
| 2115 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 2116 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 2117 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 2118 | &cinode->vfs_inode); |
| 2119 | } else |
| 2120 | cinode->oplock = 0; |
| 2121 | } |
| 2122 | |
| 2123 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2124 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 2125 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2126 | { |
| 2127 | char message[5] = {0}; |
| 2128 | |
| 2129 | oplock &= 0xFF; |
| 2130 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 2131 | return; |
| 2132 | |
| 2133 | cinode->oplock = 0; |
| 2134 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
| 2135 | cinode->oplock |= CIFS_CACHE_READ_FLG; |
| 2136 | strcat(message, "R"); |
| 2137 | } |
| 2138 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
| 2139 | cinode->oplock |= CIFS_CACHE_HANDLE_FLG; |
| 2140 | strcat(message, "H"); |
| 2141 | } |
| 2142 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
| 2143 | cinode->oplock |= CIFS_CACHE_WRITE_FLG; |
| 2144 | strcat(message, "W"); |
| 2145 | } |
| 2146 | if (!cinode->oplock) |
| 2147 | strcat(message, "None"); |
| 2148 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 2149 | &cinode->vfs_inode); |
| 2150 | } |
| 2151 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2152 | static void |
| 2153 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 2154 | unsigned int epoch, bool *purge_cache) |
| 2155 | { |
| 2156 | unsigned int old_oplock = cinode->oplock; |
| 2157 | |
| 2158 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 2159 | |
| 2160 | if (purge_cache) { |
| 2161 | *purge_cache = false; |
| 2162 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 2163 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 2164 | (epoch - cinode->epoch > 0)) |
| 2165 | *purge_cache = true; |
| 2166 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 2167 | (epoch - cinode->epoch > 1)) |
| 2168 | *purge_cache = true; |
| 2169 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 2170 | (epoch - cinode->epoch > 1)) |
| 2171 | *purge_cache = true; |
| 2172 | else if (cinode->oplock == 0 && |
| 2173 | (epoch - cinode->epoch > 0)) |
| 2174 | *purge_cache = true; |
| 2175 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 2176 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 2177 | (epoch - cinode->epoch > 0)) |
| 2178 | *purge_cache = true; |
| 2179 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 2180 | (epoch - cinode->epoch > 1)) |
| 2181 | *purge_cache = true; |
| 2182 | } |
| 2183 | cinode->epoch = epoch; |
| 2184 | } |
| 2185 | } |
| 2186 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2187 | static bool |
| 2188 | smb2_is_read_op(__u32 oplock) |
| 2189 | { |
| 2190 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 2191 | } |
| 2192 | |
| 2193 | static bool |
| 2194 | smb21_is_read_op(__u32 oplock) |
| 2195 | { |
| 2196 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 2197 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 2198 | } |
| 2199 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2200 | static __le32 |
| 2201 | map_oplock_to_lease(u8 oplock) |
| 2202 | { |
| 2203 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 2204 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 2205 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 2206 | return SMB2_LEASE_READ_CACHING; |
| 2207 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 2208 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 2209 | SMB2_LEASE_WRITE_CACHING; |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2213 | static char * |
| 2214 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 2215 | { |
| 2216 | struct create_lease *buf; |
| 2217 | |
| 2218 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 2219 | if (!buf) |
| 2220 | return NULL; |
| 2221 | |
| 2222 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 2223 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2224 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2225 | |
| 2226 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 2227 | (struct create_lease, lcontext)); |
| 2228 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 2229 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 2230 | (struct create_lease, Name)); |
| 2231 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 2232 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 2233 | buf->Name[0] = 'R'; |
| 2234 | buf->Name[1] = 'q'; |
| 2235 | buf->Name[2] = 'L'; |
| 2236 | buf->Name[3] = 's'; |
| 2237 | return (char *)buf; |
| 2238 | } |
| 2239 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2240 | static char * |
| 2241 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 2242 | { |
| 2243 | struct create_lease_v2 *buf; |
| 2244 | |
| 2245 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 2246 | if (!buf) |
| 2247 | return NULL; |
| 2248 | |
| 2249 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); |
| 2250 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); |
| 2251 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 2252 | |
| 2253 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 2254 | (struct create_lease_v2, lcontext)); |
| 2255 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 2256 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 2257 | (struct create_lease_v2, Name)); |
| 2258 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 2259 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2260 | buf->Name[0] = 'R'; |
| 2261 | buf->Name[1] = 'q'; |
| 2262 | buf->Name[2] = 'L'; |
| 2263 | buf->Name[3] = 's'; |
| 2264 | return (char *)buf; |
| 2265 | } |
| 2266 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2267 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 2268 | smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2269 | { |
| 2270 | struct create_lease *lc = (struct create_lease *)buf; |
| 2271 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2272 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 2273 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 2274 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 2275 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 2276 | } |
| 2277 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2278 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 2279 | smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2280 | { |
| 2281 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 2282 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 2283 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2284 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 2285 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 2286 | if (lease_key) |
| 2287 | memcpy(lease_key, &lc->lcontext.LeaseKeyLow, |
| 2288 | SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 2289 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 2290 | } |
| 2291 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 2292 | static unsigned int |
| 2293 | smb2_wp_retry_size(struct inode *inode) |
| 2294 | { |
| 2295 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 2296 | SMB2_MAX_BUFFER_SIZE); |
| 2297 | } |
| 2298 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 2299 | static bool |
| 2300 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 2301 | { |
| 2302 | return !cfile->invalidHandle; |
| 2303 | } |
| 2304 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2305 | static void |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2306 | fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len, |
| 2307 | struct smb_rqst *old_rq) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2308 | { |
| 2309 | struct smb2_sync_hdr *shdr = |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2310 | (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2311 | |
| 2312 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); |
| 2313 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; |
| 2314 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); |
| 2315 | tr_hdr->Flags = cpu_to_le16(0x01); |
| 2316 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 2317 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2320 | /* We can not use the normal sg_set_buf() as we will sometimes pass a |
| 2321 | * stack object as buf. |
| 2322 | */ |
| 2323 | static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, |
| 2324 | unsigned int buflen) |
| 2325 | { |
| 2326 | sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); |
| 2327 | } |
| 2328 | |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2329 | /* Assumes: |
Paulo Alcantara | cd2dca6 | 2018-06-13 13:54:14 -0300 | [diff] [blame] | 2330 | * rqst->rq_iov[0] is transform header |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2331 | * rqst->rq_iov[1+] data to be encrypted/decrypted |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2332 | */ |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2333 | static struct scatterlist * |
| 2334 | init_sg(struct smb_rqst *rqst, u8 *sign) |
| 2335 | { |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2336 | unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2337 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2338 | struct scatterlist *sg; |
| 2339 | unsigned int i; |
| 2340 | unsigned int j; |
| 2341 | |
| 2342 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); |
| 2343 | if (!sg) |
| 2344 | return NULL; |
| 2345 | |
| 2346 | sg_init_table(sg, sg_len); |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2347 | smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 20, assoc_data_len); |
| 2348 | for (i = 1; i < rqst->rq_nvec; i++) |
| 2349 | smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, |
| 2350 | rqst->rq_iov[i].iov_len); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2351 | for (j = 0; i < sg_len - 1; i++, j++) { |
Steve French | d5f07fb | 2018-06-05 17:46:24 -0500 | [diff] [blame] | 2352 | unsigned int len, offset; |
| 2353 | |
| 2354 | rqst_page_get_length(rqst, j, &len, &offset); |
| 2355 | sg_set_page(&sg[i], rqst->rq_pages[j], len, offset); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2356 | } |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 2357 | smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2358 | return sg; |
| 2359 | } |
| 2360 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2361 | static int |
| 2362 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) |
| 2363 | { |
| 2364 | struct cifs_ses *ses; |
| 2365 | u8 *ses_enc_key; |
| 2366 | |
| 2367 | spin_lock(&cifs_tcp_ses_lock); |
| 2368 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 2369 | if (ses->Suid != ses_id) |
| 2370 | continue; |
| 2371 | ses_enc_key = enc ? ses->smb3encryptionkey : |
| 2372 | ses->smb3decryptionkey; |
| 2373 | memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE); |
| 2374 | spin_unlock(&cifs_tcp_ses_lock); |
| 2375 | return 0; |
| 2376 | } |
| 2377 | spin_unlock(&cifs_tcp_ses_lock); |
| 2378 | |
| 2379 | return 1; |
| 2380 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2381 | /* |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2382 | * Encrypt or decrypt @rqst message. @rqst[0] has the following format: |
| 2383 | * iov[0] - transform header (associate data), |
| 2384 | * iov[1-N] - SMB2 header and pages - data to encrypt. |
| 2385 | * On success return encrypted data in iov[1-N] and pages, leave iov[0] |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2386 | * untouched. |
| 2387 | */ |
| 2388 | static int |
| 2389 | crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) |
| 2390 | { |
| 2391 | struct smb2_transform_hdr *tr_hdr = |
Paulo Alcantara | cd2dca6 | 2018-06-13 13:54:14 -0300 | [diff] [blame] | 2392 | (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2393 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2394 | int rc = 0; |
| 2395 | struct scatterlist *sg; |
| 2396 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2397 | u8 key[SMB3_SIGN_KEY_SIZE]; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2398 | struct aead_request *req; |
| 2399 | char *iv; |
| 2400 | unsigned int iv_len; |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2401 | DECLARE_CRYPTO_WAIT(wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2402 | struct crypto_aead *tfm; |
| 2403 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 2404 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2405 | rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); |
| 2406 | if (rc) { |
| 2407 | cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__, |
| 2408 | enc ? "en" : "de"); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | rc = smb3_crypto_aead_allocate(server); |
| 2413 | if (rc) { |
| 2414 | cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
| 2415 | return rc; |
| 2416 | } |
| 2417 | |
| 2418 | tfm = enc ? server->secmech.ccmaesencrypt : |
| 2419 | server->secmech.ccmaesdecrypt; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 2420 | rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2421 | if (rc) { |
| 2422 | cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); |
| 2423 | return rc; |
| 2424 | } |
| 2425 | |
| 2426 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); |
| 2427 | if (rc) { |
| 2428 | cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc); |
| 2429 | return rc; |
| 2430 | } |
| 2431 | |
| 2432 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 2433 | if (!req) { |
| 2434 | cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__); |
| 2435 | return -ENOMEM; |
| 2436 | } |
| 2437 | |
| 2438 | if (!enc) { |
| 2439 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); |
| 2440 | crypt_len += SMB2_SIGNATURE_SIZE; |
| 2441 | } |
| 2442 | |
| 2443 | sg = init_sg(rqst, sign); |
| 2444 | if (!sg) { |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 2445 | cifs_dbg(VFS, "%s: Failed to init sg", __func__); |
| 2446 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2447 | goto free_req; |
| 2448 | } |
| 2449 | |
| 2450 | iv_len = crypto_aead_ivsize(tfm); |
| 2451 | iv = kzalloc(iv_len, GFP_KERNEL); |
| 2452 | if (!iv) { |
| 2453 | cifs_dbg(VFS, "%s: Failed to alloc IV", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 2454 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2455 | goto free_sg; |
| 2456 | } |
| 2457 | iv[0] = 3; |
| 2458 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE); |
| 2459 | |
| 2460 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); |
| 2461 | aead_request_set_ad(req, assoc_data_len); |
| 2462 | |
| 2463 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2464 | crypto_req_done, &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2465 | |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 2466 | rc = crypto_wait_req(enc ? crypto_aead_encrypt(req) |
| 2467 | : crypto_aead_decrypt(req), &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2468 | |
| 2469 | if (!rc && enc) |
| 2470 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); |
| 2471 | |
| 2472 | kfree(iv); |
| 2473 | free_sg: |
| 2474 | kfree(sg); |
| 2475 | free_req: |
| 2476 | kfree(req); |
| 2477 | return rc; |
| 2478 | } |
| 2479 | |
| 2480 | static int |
| 2481 | smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, |
| 2482 | struct smb_rqst *old_rq) |
| 2483 | { |
| 2484 | struct kvec *iov; |
| 2485 | struct page **pages; |
| 2486 | struct smb2_transform_hdr *tr_hdr; |
| 2487 | unsigned int npages = old_rq->rq_npages; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2488 | unsigned int orig_len = 0; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2489 | int i; |
| 2490 | int rc = -ENOMEM; |
| 2491 | |
| 2492 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 2493 | if (!pages) |
| 2494 | return rc; |
| 2495 | |
| 2496 | new_rq->rq_pages = pages; |
Steve French | d5f07fb | 2018-06-05 17:46:24 -0500 | [diff] [blame] | 2497 | new_rq->rq_offset = old_rq->rq_offset; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2498 | new_rq->rq_npages = old_rq->rq_npages; |
| 2499 | new_rq->rq_pagesz = old_rq->rq_pagesz; |
| 2500 | new_rq->rq_tailsz = old_rq->rq_tailsz; |
| 2501 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2502 | for (i = 0; i < old_rq->rq_nvec; i++) |
| 2503 | orig_len += old_rq->rq_iov[i].iov_len; |
| 2504 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2505 | for (i = 0; i < npages; i++) { |
| 2506 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 2507 | if (!pages[i]) |
| 2508 | goto err_free_pages; |
| 2509 | } |
| 2510 | |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2511 | iov = kmalloc_array(old_rq->rq_nvec + 1, sizeof(struct kvec), |
| 2512 | GFP_KERNEL); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2513 | if (!iov) |
| 2514 | goto err_free_pages; |
| 2515 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2516 | /* copy all iovs from the old */ |
| 2517 | memcpy(&iov[1], &old_rq->rq_iov[0], |
| 2518 | sizeof(struct kvec) * old_rq->rq_nvec); |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2519 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2520 | new_rq->rq_iov = iov; |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2521 | new_rq->rq_nvec = old_rq->rq_nvec + 1; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2522 | |
| 2523 | tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); |
| 2524 | if (!tr_hdr) |
| 2525 | goto err_free_iov; |
| 2526 | |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2527 | /* fill the 2nd iov with a transform header */ |
| 2528 | fill_transform_hdr(tr_hdr, orig_len, old_rq); |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2529 | new_rq->rq_iov[0].iov_base = tr_hdr; |
| 2530 | new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2531 | |
| 2532 | /* copy pages form the old */ |
| 2533 | for (i = 0; i < npages; i++) { |
Steve French | d5f07fb | 2018-06-05 17:46:24 -0500 | [diff] [blame] | 2534 | char *dst, *src; |
| 2535 | unsigned int offset, len; |
| 2536 | |
| 2537 | rqst_page_get_length(new_rq, i, &len, &offset); |
| 2538 | |
| 2539 | dst = (char *) kmap(new_rq->rq_pages[i]) + offset; |
| 2540 | src = (char *) kmap(old_rq->rq_pages[i]) + offset; |
| 2541 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2542 | memcpy(dst, src, len); |
| 2543 | kunmap(new_rq->rq_pages[i]); |
| 2544 | kunmap(old_rq->rq_pages[i]); |
| 2545 | } |
| 2546 | |
| 2547 | rc = crypt_message(server, new_rq, 1); |
| 2548 | cifs_dbg(FYI, "encrypt message returned %d", rc); |
| 2549 | if (rc) |
| 2550 | goto err_free_tr_hdr; |
| 2551 | |
| 2552 | return rc; |
| 2553 | |
| 2554 | err_free_tr_hdr: |
| 2555 | kfree(tr_hdr); |
| 2556 | err_free_iov: |
| 2557 | kfree(iov); |
| 2558 | err_free_pages: |
| 2559 | for (i = i - 1; i >= 0; i--) |
| 2560 | put_page(pages[i]); |
| 2561 | kfree(pages); |
| 2562 | return rc; |
| 2563 | } |
| 2564 | |
| 2565 | static void |
| 2566 | smb3_free_transform_rq(struct smb_rqst *rqst) |
| 2567 | { |
| 2568 | int i = rqst->rq_npages - 1; |
| 2569 | |
| 2570 | for (; i >= 0; i--) |
| 2571 | put_page(rqst->rq_pages[i]); |
| 2572 | kfree(rqst->rq_pages); |
| 2573 | /* free transform header */ |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2574 | kfree(rqst->rq_iov[0].iov_base); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2575 | kfree(rqst->rq_iov); |
| 2576 | } |
| 2577 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2578 | static int |
| 2579 | smb3_is_transform_hdr(void *buf) |
| 2580 | { |
| 2581 | struct smb2_transform_hdr *trhdr = buf; |
| 2582 | |
| 2583 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; |
| 2584 | } |
| 2585 | |
| 2586 | static int |
| 2587 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, |
| 2588 | unsigned int buf_data_size, struct page **pages, |
| 2589 | unsigned int npages, unsigned int page_data_size) |
| 2590 | { |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2591 | struct kvec iov[2]; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2592 | struct smb_rqst rqst = {NULL}; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2593 | int rc; |
| 2594 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2595 | iov[0].iov_base = buf; |
| 2596 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 2597 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); |
| 2598 | iov[1].iov_len = buf_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2599 | |
| 2600 | rqst.rq_iov = iov; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2601 | rqst.rq_nvec = 2; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2602 | rqst.rq_pages = pages; |
| 2603 | rqst.rq_npages = npages; |
| 2604 | rqst.rq_pagesz = PAGE_SIZE; |
| 2605 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; |
| 2606 | |
| 2607 | rc = crypt_message(server, &rqst, 0); |
| 2608 | cifs_dbg(FYI, "decrypt message returned %d\n", rc); |
| 2609 | |
| 2610 | if (rc) |
| 2611 | return rc; |
| 2612 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 2613 | memmove(buf, iov[1].iov_base, buf_data_size); |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 2614 | |
| 2615 | server->total_read = buf_data_size + page_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2616 | |
| 2617 | return rc; |
| 2618 | } |
| 2619 | |
| 2620 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2621 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, |
| 2622 | unsigned int npages, unsigned int len) |
| 2623 | { |
| 2624 | int i; |
| 2625 | int length; |
| 2626 | |
| 2627 | for (i = 0; i < npages; i++) { |
| 2628 | struct page *page = pages[i]; |
| 2629 | size_t n; |
| 2630 | |
| 2631 | n = len; |
| 2632 | if (len >= PAGE_SIZE) { |
| 2633 | /* enough data to fill the page */ |
| 2634 | n = PAGE_SIZE; |
| 2635 | len -= n; |
| 2636 | } else { |
| 2637 | zero_user(page, len, PAGE_SIZE - len); |
| 2638 | len = 0; |
| 2639 | } |
Long Li | 1dbe346 | 2018-05-30 12:47:55 -0700 | [diff] [blame] | 2640 | length = cifs_read_page_from_socket(server, page, 0, n); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2641 | if (length < 0) |
| 2642 | return length; |
| 2643 | server->total_read += length; |
| 2644 | } |
| 2645 | |
| 2646 | return 0; |
| 2647 | } |
| 2648 | |
| 2649 | static int |
| 2650 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, |
| 2651 | unsigned int cur_off, struct bio_vec **page_vec) |
| 2652 | { |
| 2653 | struct bio_vec *bvec; |
| 2654 | int i; |
| 2655 | |
| 2656 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); |
| 2657 | if (!bvec) |
| 2658 | return -ENOMEM; |
| 2659 | |
| 2660 | for (i = 0; i < npages; i++) { |
| 2661 | bvec[i].bv_page = pages[i]; |
| 2662 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; |
| 2663 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); |
| 2664 | data_size -= bvec[i].bv_len; |
| 2665 | } |
| 2666 | |
| 2667 | if (data_size != 0) { |
| 2668 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); |
| 2669 | kfree(bvec); |
| 2670 | return -EIO; |
| 2671 | } |
| 2672 | |
| 2673 | *page_vec = bvec; |
| 2674 | return 0; |
| 2675 | } |
| 2676 | |
| 2677 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2678 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 2679 | char *buf, unsigned int buf_len, struct page **pages, |
| 2680 | unsigned int npages, unsigned int page_data_size) |
| 2681 | { |
| 2682 | unsigned int data_offset; |
| 2683 | unsigned int data_len; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2684 | unsigned int cur_off; |
| 2685 | unsigned int cur_page_idx; |
| 2686 | unsigned int pad_len; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2687 | struct cifs_readdata *rdata = mid->callback_data; |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 2688 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2689 | struct bio_vec *bvec = NULL; |
| 2690 | struct iov_iter iter; |
| 2691 | struct kvec iov; |
| 2692 | int length; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 2693 | bool use_rdma_mr = false; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2694 | |
| 2695 | if (shdr->Command != SMB2_READ) { |
| 2696 | cifs_dbg(VFS, "only big read responses are supported\n"); |
| 2697 | return -ENOTSUPP; |
| 2698 | } |
| 2699 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2700 | if (server->ops->is_session_expired && |
| 2701 | server->ops->is_session_expired(buf)) { |
| 2702 | cifs_reconnect(server); |
| 2703 | wake_up(&server->response_q); |
| 2704 | return -1; |
| 2705 | } |
| 2706 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2707 | if (server->ops->is_status_pending && |
| 2708 | server->ops->is_status_pending(buf, server, 0)) |
| 2709 | return -1; |
| 2710 | |
| 2711 | rdata->result = server->ops->map_error(buf, false); |
| 2712 | if (rdata->result != 0) { |
| 2713 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 2714 | __func__, rdata->result); |
| 2715 | dequeue_mid(mid, rdata->result); |
| 2716 | return 0; |
| 2717 | } |
| 2718 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2719 | data_offset = server->ops->read_data_offset(buf); |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 2720 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 2721 | use_rdma_mr = rdata->mr; |
| 2722 | #endif |
| 2723 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2724 | |
| 2725 | if (data_offset < server->vals->read_rsp_size) { |
| 2726 | /* |
| 2727 | * win2k8 sometimes sends an offset of 0 when the read |
| 2728 | * is beyond the EOF. Treat it as if the data starts just after |
| 2729 | * the header. |
| 2730 | */ |
| 2731 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 2732 | __func__, data_offset); |
| 2733 | data_offset = server->vals->read_rsp_size; |
| 2734 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 2735 | /* data_offset is beyond the end of smallbuf */ |
| 2736 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 2737 | __func__, data_offset); |
| 2738 | rdata->result = -EIO; |
| 2739 | dequeue_mid(mid, rdata->result); |
| 2740 | return 0; |
| 2741 | } |
| 2742 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2743 | pad_len = data_offset - server->vals->read_rsp_size; |
| 2744 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2745 | if (buf_len <= data_offset) { |
| 2746 | /* read response payload is in pages */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2747 | cur_page_idx = pad_len / PAGE_SIZE; |
| 2748 | cur_off = pad_len % PAGE_SIZE; |
| 2749 | |
| 2750 | if (cur_page_idx != 0) { |
| 2751 | /* data offset is beyond the 1st page of response */ |
| 2752 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", |
| 2753 | __func__, data_offset); |
| 2754 | rdata->result = -EIO; |
| 2755 | dequeue_mid(mid, rdata->result); |
| 2756 | return 0; |
| 2757 | } |
| 2758 | |
| 2759 | if (data_len > page_data_size - pad_len) { |
| 2760 | /* data_len is corrupt -- discard frame */ |
| 2761 | rdata->result = -EIO; |
| 2762 | dequeue_mid(mid, rdata->result); |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
| 2766 | rdata->result = init_read_bvec(pages, npages, page_data_size, |
| 2767 | cur_off, &bvec); |
| 2768 | if (rdata->result != 0) { |
| 2769 | dequeue_mid(mid, rdata->result); |
| 2770 | return 0; |
| 2771 | } |
| 2772 | |
| 2773 | iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2774 | } else if (buf_len >= data_offset + data_len) { |
| 2775 | /* read response payload is in buf */ |
| 2776 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); |
| 2777 | iov.iov_base = buf + data_offset; |
| 2778 | iov.iov_len = data_len; |
| 2779 | iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len); |
| 2780 | } else { |
| 2781 | /* read response payload cannot be in both buf and pages */ |
| 2782 | WARN_ONCE(1, "buf can not contain only a part of read data"); |
| 2783 | rdata->result = -EIO; |
| 2784 | dequeue_mid(mid, rdata->result); |
| 2785 | return 0; |
| 2786 | } |
| 2787 | |
| 2788 | /* set up first iov for signature check */ |
| 2789 | rdata->iov[0].iov_base = buf; |
| 2790 | rdata->iov[0].iov_len = 4; |
| 2791 | rdata->iov[1].iov_base = buf + 4; |
| 2792 | rdata->iov[1].iov_len = server->vals->read_rsp_size - 4; |
| 2793 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 2794 | rdata->iov[0].iov_base, server->vals->read_rsp_size); |
| 2795 | |
| 2796 | length = rdata->copy_into_pages(server, rdata, &iter); |
| 2797 | |
| 2798 | kfree(bvec); |
| 2799 | |
| 2800 | if (length < 0) |
| 2801 | return length; |
| 2802 | |
| 2803 | dequeue_mid(mid, false); |
| 2804 | return length; |
| 2805 | } |
| 2806 | |
| 2807 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2808 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2809 | { |
| 2810 | char *buf = server->smallbuf; |
| 2811 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2812 | unsigned int npages; |
| 2813 | struct page **pages; |
| 2814 | unsigned int len; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2815 | unsigned int buflen = server->pdu_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2816 | int rc; |
| 2817 | int i = 0; |
| 2818 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2819 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size + |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2820 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; |
| 2821 | |
| 2822 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); |
| 2823 | if (rc < 0) |
| 2824 | return rc; |
| 2825 | server->total_read += rc; |
| 2826 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2827 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) - |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 2828 | server->vals->read_rsp_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2829 | npages = DIV_ROUND_UP(len, PAGE_SIZE); |
| 2830 | |
| 2831 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 2832 | if (!pages) { |
| 2833 | rc = -ENOMEM; |
| 2834 | goto discard_data; |
| 2835 | } |
| 2836 | |
| 2837 | for (; i < npages; i++) { |
| 2838 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 2839 | if (!pages[i]) { |
| 2840 | rc = -ENOMEM; |
| 2841 | goto discard_data; |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | /* read read data into pages */ |
| 2846 | rc = read_data_into_pages(server, pages, npages, len); |
| 2847 | if (rc) |
| 2848 | goto free_pages; |
| 2849 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 2850 | rc = cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2851 | if (rc) |
| 2852 | goto free_pages; |
| 2853 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2854 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2855 | pages, npages, len); |
| 2856 | if (rc) |
| 2857 | goto free_pages; |
| 2858 | |
| 2859 | *mid = smb2_find_mid(server, buf); |
| 2860 | if (*mid == NULL) |
| 2861 | cifs_dbg(FYI, "mid not found\n"); |
| 2862 | else { |
| 2863 | cifs_dbg(FYI, "mid found\n"); |
| 2864 | (*mid)->decrypted = true; |
| 2865 | rc = handle_read_data(server, *mid, buf, |
| 2866 | server->vals->read_rsp_size, |
| 2867 | pages, npages, len); |
| 2868 | } |
| 2869 | |
| 2870 | free_pages: |
| 2871 | for (i = i - 1; i >= 0; i--) |
| 2872 | put_page(pages[i]); |
| 2873 | kfree(pages); |
| 2874 | return rc; |
| 2875 | discard_data: |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 2876 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2877 | goto free_pages; |
| 2878 | } |
| 2879 | |
| 2880 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2881 | receive_encrypted_standard(struct TCP_Server_Info *server, |
| 2882 | struct mid_q_entry **mid) |
| 2883 | { |
| 2884 | int length; |
| 2885 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 2886 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2887 | unsigned int buf_size; |
| 2888 | struct mid_q_entry *mid_entry; |
| 2889 | |
| 2890 | /* switch to large buffer if too big for a small one */ |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2891 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2892 | server->large_buf = true; |
| 2893 | memcpy(server->bigbuf, buf, server->total_read); |
| 2894 | buf = server->bigbuf; |
| 2895 | } |
| 2896 | |
| 2897 | /* now read the rest */ |
| 2898 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2899 | pdu_length - HEADER_SIZE(server) + 1); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2900 | if (length < 0) |
| 2901 | return length; |
| 2902 | server->total_read += length; |
| 2903 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2904 | buf_size = pdu_length - sizeof(struct smb2_transform_hdr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2905 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); |
| 2906 | if (length) |
| 2907 | return length; |
| 2908 | |
| 2909 | mid_entry = smb2_find_mid(server, buf); |
| 2910 | if (mid_entry == NULL) |
| 2911 | cifs_dbg(FYI, "mid not found\n"); |
| 2912 | else { |
| 2913 | cifs_dbg(FYI, "mid found\n"); |
| 2914 | mid_entry->decrypted = true; |
| 2915 | } |
| 2916 | |
| 2917 | *mid = mid_entry; |
| 2918 | |
| 2919 | if (mid_entry && mid_entry->handle) |
| 2920 | return mid_entry->handle(server, mid_entry); |
| 2921 | |
| 2922 | return cifs_handle_standard(server, mid_entry); |
| 2923 | } |
| 2924 | |
| 2925 | static int |
| 2926 | smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid) |
| 2927 | { |
| 2928 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 2929 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2930 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 2931 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 2932 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2933 | if (pdu_length < sizeof(struct smb2_transform_hdr) + |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2934 | sizeof(struct smb2_sync_hdr)) { |
| 2935 | cifs_dbg(VFS, "Transform message is too small (%u)\n", |
| 2936 | pdu_length); |
| 2937 | cifs_reconnect(server); |
| 2938 | wake_up(&server->response_q); |
| 2939 | return -ECONNABORTED; |
| 2940 | } |
| 2941 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2942 | if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2943 | cifs_dbg(VFS, "Transform message is broken\n"); |
| 2944 | cifs_reconnect(server); |
| 2945 | wake_up(&server->response_q); |
| 2946 | return -ECONNABORTED; |
| 2947 | } |
| 2948 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2949 | if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 2950 | return receive_encrypted_read(server, mid); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2951 | |
| 2952 | return receive_encrypted_standard(server, mid); |
| 2953 | } |
| 2954 | |
| 2955 | int |
| 2956 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 2957 | { |
| 2958 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 2959 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2960 | return handle_read_data(server, mid, buf, server->pdu_size, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 2961 | NULL, 0, 0); |
| 2962 | } |
| 2963 | |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 2964 | static int |
| 2965 | smb2_next_header(char *buf) |
| 2966 | { |
| 2967 | struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf; |
| 2968 | struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf; |
| 2969 | |
| 2970 | if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) |
| 2971 | return sizeof(struct smb2_transform_hdr) + |
| 2972 | le32_to_cpu(t_hdr->OriginalMessageSize); |
| 2973 | |
| 2974 | return le32_to_cpu(hdr->NextCommand); |
| 2975 | } |
| 2976 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2977 | struct smb_version_operations smb20_operations = { |
| 2978 | .compare_fids = smb2_compare_fids, |
| 2979 | .setup_request = smb2_setup_request, |
| 2980 | .setup_async_request = smb2_setup_async_request, |
| 2981 | .check_receive = smb2_check_receive, |
| 2982 | .add_credits = smb2_add_credits, |
| 2983 | .set_credits = smb2_set_credits, |
| 2984 | .get_credits_field = smb2_get_credits_field, |
| 2985 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 2986 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2987 | .get_next_mid = smb2_get_next_mid, |
| 2988 | .read_data_offset = smb2_read_data_offset, |
| 2989 | .read_data_length = smb2_read_data_length, |
| 2990 | .map_error = map_smb2_to_linux_error, |
| 2991 | .find_mid = smb2_find_mid, |
| 2992 | .check_message = smb2_check_message, |
| 2993 | .dump_detail = smb2_dump_detail, |
| 2994 | .clear_stats = smb2_clear_stats, |
| 2995 | .print_stats = smb2_print_stats, |
| 2996 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 2997 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 2998 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 2999 | .need_neg = smb2_need_neg, |
| 3000 | .negotiate = smb2_negotiate, |
| 3001 | .negotiate_wsize = smb2_negotiate_wsize, |
| 3002 | .negotiate_rsize = smb2_negotiate_rsize, |
| 3003 | .sess_setup = SMB2_sess_setup, |
| 3004 | .logoff = SMB2_logoff, |
| 3005 | .tree_connect = SMB2_tcon, |
| 3006 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3007 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3008 | .is_path_accessible = smb2_is_path_accessible, |
| 3009 | .can_echo = smb2_can_echo, |
| 3010 | .echo = SMB2_echo, |
| 3011 | .query_path_info = smb2_query_path_info, |
| 3012 | .get_srv_inum = smb2_get_srv_inum, |
| 3013 | .query_file_info = smb2_query_file_info, |
| 3014 | .set_path_size = smb2_set_path_size, |
| 3015 | .set_file_size = smb2_set_file_size, |
| 3016 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 3017 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3018 | .mkdir = smb2_mkdir, |
| 3019 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 3020 | .rmdir = smb2_rmdir, |
| 3021 | .unlink = smb2_unlink, |
| 3022 | .rename = smb2_rename_path, |
| 3023 | .create_hardlink = smb2_create_hardlink, |
| 3024 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 3025 | .query_mf_symlink = smb3_query_mf_symlink, |
| 3026 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3027 | .open = smb2_open_file, |
| 3028 | .set_fid = smb2_set_fid, |
| 3029 | .close = smb2_close_file, |
| 3030 | .flush = smb2_flush_file, |
| 3031 | .async_readv = smb2_async_readv, |
| 3032 | .async_writev = smb2_async_writev, |
| 3033 | .sync_read = smb2_sync_read, |
| 3034 | .sync_write = smb2_sync_write, |
| 3035 | .query_dir_first = smb2_query_dir_first, |
| 3036 | .query_dir_next = smb2_query_dir_next, |
| 3037 | .close_dir = smb2_close_dir, |
| 3038 | .calc_smb_size = smb2_calc_size, |
| 3039 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3040 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3041 | .oplock_response = smb2_oplock_response, |
| 3042 | .queryfs = smb2_queryfs, |
| 3043 | .mand_lock = smb2_mand_lock, |
| 3044 | .mand_unlock_range = smb2_unlock_range, |
| 3045 | .push_mand_locks = smb2_push_mandatory_locks, |
| 3046 | .get_lease_key = smb2_get_lease_key, |
| 3047 | .set_lease_key = smb2_set_lease_key, |
| 3048 | .new_lease_key = smb2_new_lease_key, |
| 3049 | .calc_signature = smb2_calc_signature, |
| 3050 | .is_read_op = smb2_is_read_op, |
| 3051 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3052 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 3053 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 3054 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 3055 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 3056 | .dir_needs_close = smb2_dir_needs_close, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 3057 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 3058 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3059 | #ifdef CONFIG_CIFS_XATTR |
| 3060 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 3061 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3062 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3063 | #ifdef CONFIG_CIFS_ACL |
| 3064 | .get_acl = get_smb2_acl, |
| 3065 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3066 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3067 | #endif /* CIFS_ACL */ |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 3068 | .next_header = smb2_next_header, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3069 | }; |
| 3070 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3071 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3072 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 3073 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 3074 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 3075 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 3076 | .add_credits = smb2_add_credits, |
| 3077 | .set_credits = smb2_set_credits, |
| 3078 | .get_credits_field = smb2_get_credits_field, |
| 3079 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 3080 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 3081 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 3082 | .read_data_offset = smb2_read_data_offset, |
| 3083 | .read_data_length = smb2_read_data_length, |
| 3084 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 3085 | .find_mid = smb2_find_mid, |
| 3086 | .check_message = smb2_check_message, |
| 3087 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 3088 | .clear_stats = smb2_clear_stats, |
| 3089 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3090 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 3091 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 3092 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 3093 | .need_neg = smb2_need_neg, |
| 3094 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 3095 | .negotiate_wsize = smb2_negotiate_wsize, |
| 3096 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 3097 | .sess_setup = SMB2_sess_setup, |
| 3098 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 3099 | .tree_connect = SMB2_tcon, |
| 3100 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 3101 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 3102 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 3103 | .can_echo = smb2_can_echo, |
| 3104 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 3105 | .query_path_info = smb2_query_path_info, |
| 3106 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 3107 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3108 | .set_path_size = smb2_set_path_size, |
| 3109 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 3110 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 3111 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 3112 | .mkdir = smb2_mkdir, |
| 3113 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 3114 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 3115 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3116 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 3117 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3118 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 3119 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 3120 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 3121 | .open = smb2_open_file, |
| 3122 | .set_fid = smb2_set_fid, |
| 3123 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 3124 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 3125 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 3126 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 3127 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 3128 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3129 | .query_dir_first = smb2_query_dir_first, |
| 3130 | .query_dir_next = smb2_query_dir_next, |
| 3131 | .close_dir = smb2_close_dir, |
| 3132 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3133 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3134 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 3135 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 3136 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 3137 | .mand_lock = smb2_mand_lock, |
| 3138 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 3139 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 3140 | .get_lease_key = smb2_get_lease_key, |
| 3141 | .set_lease_key = smb2_set_lease_key, |
| 3142 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3143 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3144 | .is_read_op = smb21_is_read_op, |
| 3145 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3146 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 3147 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 3148 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 3149 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 3150 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 3151 | .enum_snapshots = smb3_enum_snapshots, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 3152 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 3153 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3154 | #ifdef CONFIG_CIFS_XATTR |
| 3155 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 3156 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3157 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3158 | #ifdef CONFIG_CIFS_ACL |
| 3159 | .get_acl = get_smb2_acl, |
| 3160 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3161 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3162 | #endif /* CIFS_ACL */ |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 3163 | .next_header = smb2_next_header, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3164 | }; |
| 3165 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3166 | struct smb_version_operations smb30_operations = { |
| 3167 | .compare_fids = smb2_compare_fids, |
| 3168 | .setup_request = smb2_setup_request, |
| 3169 | .setup_async_request = smb2_setup_async_request, |
| 3170 | .check_receive = smb2_check_receive, |
| 3171 | .add_credits = smb2_add_credits, |
| 3172 | .set_credits = smb2_set_credits, |
| 3173 | .get_credits_field = smb2_get_credits_field, |
| 3174 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 3175 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3176 | .get_next_mid = smb2_get_next_mid, |
| 3177 | .read_data_offset = smb2_read_data_offset, |
| 3178 | .read_data_length = smb2_read_data_length, |
| 3179 | .map_error = map_smb2_to_linux_error, |
| 3180 | .find_mid = smb2_find_mid, |
| 3181 | .check_message = smb2_check_message, |
| 3182 | .dump_detail = smb2_dump_detail, |
| 3183 | .clear_stats = smb2_clear_stats, |
| 3184 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 3185 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3186 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 3187 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 3188 | .downgrade_oplock = smb2_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3189 | .need_neg = smb2_need_neg, |
| 3190 | .negotiate = smb2_negotiate, |
| 3191 | .negotiate_wsize = smb2_negotiate_wsize, |
| 3192 | .negotiate_rsize = smb2_negotiate_rsize, |
| 3193 | .sess_setup = SMB2_sess_setup, |
| 3194 | .logoff = SMB2_logoff, |
| 3195 | .tree_connect = SMB2_tcon, |
| 3196 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 3197 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3198 | .is_path_accessible = smb2_is_path_accessible, |
| 3199 | .can_echo = smb2_can_echo, |
| 3200 | .echo = SMB2_echo, |
| 3201 | .query_path_info = smb2_query_path_info, |
| 3202 | .get_srv_inum = smb2_get_srv_inum, |
| 3203 | .query_file_info = smb2_query_file_info, |
| 3204 | .set_path_size = smb2_set_path_size, |
| 3205 | .set_file_size = smb2_set_file_size, |
| 3206 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 3207 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3208 | .mkdir = smb2_mkdir, |
| 3209 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 3210 | .rmdir = smb2_rmdir, |
| 3211 | .unlink = smb2_unlink, |
| 3212 | .rename = smb2_rename_path, |
| 3213 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3214 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 3215 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 3216 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3217 | .open = smb2_open_file, |
| 3218 | .set_fid = smb2_set_fid, |
| 3219 | .close = smb2_close_file, |
| 3220 | .flush = smb2_flush_file, |
| 3221 | .async_readv = smb2_async_readv, |
| 3222 | .async_writev = smb2_async_writev, |
| 3223 | .sync_read = smb2_sync_read, |
| 3224 | .sync_write = smb2_sync_write, |
| 3225 | .query_dir_first = smb2_query_dir_first, |
| 3226 | .query_dir_next = smb2_query_dir_next, |
| 3227 | .close_dir = smb2_close_dir, |
| 3228 | .calc_smb_size = smb2_calc_size, |
| 3229 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3230 | .is_session_expired = smb2_is_session_expired, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3231 | .oplock_response = smb2_oplock_response, |
| 3232 | .queryfs = smb2_queryfs, |
| 3233 | .mand_lock = smb2_mand_lock, |
| 3234 | .mand_unlock_range = smb2_unlock_range, |
| 3235 | .push_mand_locks = smb2_push_mandatory_locks, |
| 3236 | .get_lease_key = smb2_get_lease_key, |
| 3237 | .set_lease_key = smb2_set_lease_key, |
| 3238 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3239 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 3240 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 3241 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3242 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3243 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3244 | .create_lease_buf = smb3_create_lease_buf, |
| 3245 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 3246 | .copychunk_range = smb2_copychunk_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 3247 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 3248 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 3249 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 3250 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3251 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 3252 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3253 | .init_transform_rq = smb3_init_transform_rq, |
| 3254 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3255 | .is_transform_hdr = smb3_is_transform_hdr, |
| 3256 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 3257 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 3258 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3259 | #ifdef CONFIG_CIFS_XATTR |
| 3260 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 3261 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3262 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3263 | #ifdef CONFIG_CIFS_ACL |
| 3264 | .get_acl = get_smb2_acl, |
| 3265 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3266 | .set_acl = set_smb2_acl, |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3267 | #endif /* CIFS_ACL */ |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 3268 | .next_header = smb2_next_header, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3269 | }; |
| 3270 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3271 | #ifdef CONFIG_CIFS_SMB311 |
| 3272 | struct smb_version_operations smb311_operations = { |
| 3273 | .compare_fids = smb2_compare_fids, |
| 3274 | .setup_request = smb2_setup_request, |
| 3275 | .setup_async_request = smb2_setup_async_request, |
| 3276 | .check_receive = smb2_check_receive, |
| 3277 | .add_credits = smb2_add_credits, |
| 3278 | .set_credits = smb2_set_credits, |
| 3279 | .get_credits_field = smb2_get_credits_field, |
| 3280 | .get_credits = smb2_get_credits, |
| 3281 | .wait_mtu_credits = smb2_wait_mtu_credits, |
| 3282 | .get_next_mid = smb2_get_next_mid, |
| 3283 | .read_data_offset = smb2_read_data_offset, |
| 3284 | .read_data_length = smb2_read_data_length, |
| 3285 | .map_error = map_smb2_to_linux_error, |
| 3286 | .find_mid = smb2_find_mid, |
| 3287 | .check_message = smb2_check_message, |
| 3288 | .dump_detail = smb2_dump_detail, |
| 3289 | .clear_stats = smb2_clear_stats, |
| 3290 | .print_stats = smb2_print_stats, |
| 3291 | .dump_share_caps = smb2_dump_share_caps, |
| 3292 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 3293 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3294 | .downgrade_oplock = smb2_downgrade_oplock, |
| 3295 | .need_neg = smb2_need_neg, |
| 3296 | .negotiate = smb2_negotiate, |
| 3297 | .negotiate_wsize = smb2_negotiate_wsize, |
| 3298 | .negotiate_rsize = smb2_negotiate_rsize, |
| 3299 | .sess_setup = SMB2_sess_setup, |
| 3300 | .logoff = SMB2_logoff, |
| 3301 | .tree_connect = SMB2_tcon, |
| 3302 | .tree_disconnect = SMB2_tdis, |
| 3303 | .qfs_tcon = smb3_qfs_tcon, |
| 3304 | .is_path_accessible = smb2_is_path_accessible, |
| 3305 | .can_echo = smb2_can_echo, |
| 3306 | .echo = SMB2_echo, |
| 3307 | .query_path_info = smb2_query_path_info, |
| 3308 | .get_srv_inum = smb2_get_srv_inum, |
| 3309 | .query_file_info = smb2_query_file_info, |
| 3310 | .set_path_size = smb2_set_path_size, |
| 3311 | .set_file_size = smb2_set_file_size, |
| 3312 | .set_file_info = smb2_set_file_info, |
| 3313 | .set_compression = smb2_set_compression, |
| 3314 | .mkdir = smb2_mkdir, |
| 3315 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Steve French | bea851b | 2018-06-14 21:56:32 -0500 | [diff] [blame^] | 3316 | .posix_mkdir = smb311_posix_mkdir, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3317 | .rmdir = smb2_rmdir, |
| 3318 | .unlink = smb2_unlink, |
| 3319 | .rename = smb2_rename_path, |
| 3320 | .create_hardlink = smb2_create_hardlink, |
| 3321 | .query_symlink = smb2_query_symlink, |
| 3322 | .query_mf_symlink = smb3_query_mf_symlink, |
| 3323 | .create_mf_symlink = smb3_create_mf_symlink, |
| 3324 | .open = smb2_open_file, |
| 3325 | .set_fid = smb2_set_fid, |
| 3326 | .close = smb2_close_file, |
| 3327 | .flush = smb2_flush_file, |
| 3328 | .async_readv = smb2_async_readv, |
| 3329 | .async_writev = smb2_async_writev, |
| 3330 | .sync_read = smb2_sync_read, |
| 3331 | .sync_write = smb2_sync_write, |
| 3332 | .query_dir_first = smb2_query_dir_first, |
| 3333 | .query_dir_next = smb2_query_dir_next, |
| 3334 | .close_dir = smb2_close_dir, |
| 3335 | .calc_smb_size = smb2_calc_size, |
| 3336 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3337 | .is_session_expired = smb2_is_session_expired, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3338 | .oplock_response = smb2_oplock_response, |
| 3339 | .queryfs = smb2_queryfs, |
| 3340 | .mand_lock = smb2_mand_lock, |
| 3341 | .mand_unlock_range = smb2_unlock_range, |
| 3342 | .push_mand_locks = smb2_push_mandatory_locks, |
| 3343 | .get_lease_key = smb2_get_lease_key, |
| 3344 | .set_lease_key = smb2_set_lease_key, |
| 3345 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3346 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3347 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 3348 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3349 | .is_read_op = smb21_is_read_op, |
| 3350 | .set_oplock_level = smb3_set_oplock_level, |
| 3351 | .create_lease_buf = smb3_create_lease_buf, |
| 3352 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 3353 | .copychunk_range = smb2_copychunk_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 3354 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3355 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 3356 | .wp_retry_size = smb2_wp_retry_size, |
| 3357 | .dir_needs_close = smb2_dir_needs_close, |
| 3358 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 3359 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3360 | .init_transform_rq = smb3_init_transform_rq, |
| 3361 | .free_transform_rq = smb3_free_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3362 | .is_transform_hdr = smb3_is_transform_hdr, |
| 3363 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 3364 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 3365 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3366 | #ifdef CONFIG_CIFS_XATTR |
| 3367 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 3368 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 3369 | #endif /* CIFS_XATTR */ |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 3370 | .next_header = smb2_next_header, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 3371 | }; |
| 3372 | #endif /* CIFS_SMB311 */ |
| 3373 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3374 | struct smb_version_values smb20_values = { |
| 3375 | .version_string = SMB20_VERSION_STRING, |
| 3376 | .protocol_id = SMB20_PROT_ID, |
| 3377 | .req_capabilities = 0, /* MBZ */ |
| 3378 | .large_lock_type = 0, |
| 3379 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3380 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3381 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3382 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3383 | .header_preamble_size = 0, |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3384 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3385 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3386 | .lock_cmd = SMB2_LOCK, |
| 3387 | .cap_unix = 0, |
| 3388 | .cap_nt_find = SMB2_NT_FIND, |
| 3389 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3390 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3391 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3392 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 3393 | }; |
| 3394 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3395 | struct smb_version_values smb21_values = { |
| 3396 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3397 | .protocol_id = SMB21_PROT_ID, |
| 3398 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 3399 | .large_lock_type = 0, |
| 3400 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3401 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3402 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3403 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3404 | .header_preamble_size = 0, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3405 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3406 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3407 | .lock_cmd = SMB2_LOCK, |
| 3408 | .cap_unix = 0, |
| 3409 | .cap_nt_find = SMB2_NT_FIND, |
| 3410 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3411 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3412 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3413 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3414 | }; |
| 3415 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3416 | struct smb_version_values smb3any_values = { |
| 3417 | .version_string = SMB3ANY_VERSION_STRING, |
| 3418 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
| 3419 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
| 3420 | .large_lock_type = 0, |
| 3421 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3422 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3423 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3424 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3425 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3426 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3427 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3428 | .lock_cmd = SMB2_LOCK, |
| 3429 | .cap_unix = 0, |
| 3430 | .cap_nt_find = SMB2_NT_FIND, |
| 3431 | .cap_large_files = SMB2_LARGE_FILES, |
| 3432 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3433 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3434 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3435 | }; |
| 3436 | |
| 3437 | struct smb_version_values smbdefault_values = { |
| 3438 | .version_string = SMBDEFAULT_VERSION_STRING, |
| 3439 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
| 3440 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION, |
| 3441 | .large_lock_type = 0, |
| 3442 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3443 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3444 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3445 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3446 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 3447 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3448 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3449 | .lock_cmd = SMB2_LOCK, |
| 3450 | .cap_unix = 0, |
| 3451 | .cap_nt_find = SMB2_NT_FIND, |
| 3452 | .cap_large_files = SMB2_LARGE_FILES, |
| 3453 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3454 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3455 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3456 | }; |
| 3457 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 3458 | struct smb_version_values smb30_values = { |
| 3459 | .version_string = SMB30_VERSION_STRING, |
| 3460 | .protocol_id = SMB30_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3461 | .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] | 3462 | .large_lock_type = 0, |
| 3463 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3464 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3465 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3466 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3467 | .header_preamble_size = 0, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 3468 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 3469 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 3470 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 3471 | .cap_unix = 0, |
| 3472 | .cap_nt_find = SMB2_NT_FIND, |
| 3473 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3474 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3475 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3476 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 3477 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3478 | |
| 3479 | struct smb_version_values smb302_values = { |
| 3480 | .version_string = SMB302_VERSION_STRING, |
| 3481 | .protocol_id = SMB302_PROT_ID, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 3482 | .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] | 3483 | .large_lock_type = 0, |
| 3484 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3485 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3486 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3487 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3488 | .header_preamble_size = 0, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3489 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3490 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3491 | .lock_cmd = SMB2_LOCK, |
| 3492 | .cap_unix = 0, |
| 3493 | .cap_nt_find = SMB2_NT_FIND, |
| 3494 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 3495 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3496 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3497 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 3498 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 3499 | |
| 3500 | #ifdef CONFIG_CIFS_SMB311 |
| 3501 | struct smb_version_values smb311_values = { |
| 3502 | .version_string = SMB311_VERSION_STRING, |
| 3503 | .protocol_id = SMB311_PROT_ID, |
Steve French | 1955880 | 2017-06-21 16:50:20 -0500 | [diff] [blame] | 3504 | .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] | 3505 | .large_lock_type = 0, |
| 3506 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 3507 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 3508 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3509 | .header_size = sizeof(struct smb2_sync_hdr), |
| 3510 | .header_preamble_size = 0, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 3511 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 3512 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 3513 | .lock_cmd = SMB2_LOCK, |
| 3514 | .cap_unix = 0, |
| 3515 | .cap_nt_find = SMB2_NT_FIND, |
| 3516 | .cap_large_files = SMB2_LARGE_FILES, |
| 3517 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3518 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 3519 | .create_lease_size = sizeof(struct create_lease_v2), |
| 3520 | }; |
| 3521 | #endif /* SMB311 */ |