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