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