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