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