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