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: |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 112 | cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n"); |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 113 | break; |
| 114 | case 1: |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 115 | cifs_server_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 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); |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 233 | cifs_server_dbg(VFS, "trying to return %d credits to old session\n", |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 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) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 273 | cifs_server_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 | |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 297 | cifs_server_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 | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 300 | cifs_server_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) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 579 | cifs_tcon_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) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1333 | cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1334 | goto req_res_key_exit; |
| 1335 | } |
| 1336 | if (ret_data_len < sizeof(struct resume_key_req)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1337 | cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n"); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 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 | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1372 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1373 | struct kvec close_iov[1]; |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1374 | unsigned int size[2]; |
| 1375 | void *data[2]; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1376 | |
| 1377 | memset(rqst, 0, sizeof(rqst)); |
| 1378 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 1379 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1380 | |
| 1381 | if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) |
| 1382 | return -EFAULT; |
| 1383 | |
| 1384 | if (qi.output_buffer_length > 1024) |
| 1385 | return -EINVAL; |
| 1386 | |
| 1387 | if (!ses || !(ses->server)) |
| 1388 | return -EIO; |
| 1389 | |
| 1390 | if (smb3_encryption_required(tcon)) |
| 1391 | flags |= CIFS_TRANSFORM_REQ; |
| 1392 | |
| 1393 | buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL); |
| 1394 | if (buffer == NULL) |
| 1395 | return -ENOMEM; |
| 1396 | |
| 1397 | if (copy_from_user(buffer, arg + sizeof(struct smb_query_info), |
| 1398 | qi.output_buffer_length)) { |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1399 | rc = -EFAULT; |
| 1400 | goto iqinf_exit; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1401 | } |
| 1402 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1403 | /* Open */ |
| 1404 | memset(&open_iov, 0, sizeof(open_iov)); |
| 1405 | rqst[0].rq_iov = open_iov; |
| 1406 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1407 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1408 | memset(&oparms, 0, sizeof(oparms)); |
| 1409 | oparms.tcon = tcon; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1410 | oparms.disposition = FILE_OPEN; |
| 1411 | if (is_dir) |
| 1412 | oparms.create_options = CREATE_NOT_FILE; |
| 1413 | else |
| 1414 | oparms.create_options = CREATE_NOT_DIR; |
| 1415 | oparms.fid = &fid; |
| 1416 | oparms.reconnect = false; |
| 1417 | |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1418 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1419 | switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) { |
| 1420 | case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS: |
| 1421 | 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] | 1422 | break; |
| 1423 | case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS: |
| 1424 | oparms.desired_access = GENERIC_ALL; |
| 1425 | break; |
| 1426 | case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS: |
| 1427 | oparms.desired_access = GENERIC_READ; |
| 1428 | break; |
| 1429 | case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS: |
| 1430 | oparms.desired_access = GENERIC_WRITE; |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1431 | break; |
| 1432 | } |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1433 | } else if (qi.flags & PASSTHRU_SET_INFO) { |
| 1434 | oparms.desired_access = GENERIC_WRITE; |
| 1435 | } else { |
| 1436 | oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL; |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1437 | } |
| 1438 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1439 | rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path); |
| 1440 | if (rc) |
| 1441 | goto iqinf_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1442 | smb2_set_next_command(tcon, &rqst[0]); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1443 | |
| 1444 | /* Query */ |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1445 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1446 | /* Can eventually relax perm check since server enforces too */ |
| 1447 | if (!capable(CAP_SYS_ADMIN)) |
| 1448 | rc = -EPERM; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1449 | else { |
| 1450 | memset(&io_iov, 0, sizeof(io_iov)); |
| 1451 | rqst[1].rq_iov = io_iov; |
| 1452 | rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; |
| 1453 | |
| 1454 | rc = SMB2_ioctl_init(tcon, &rqst[1], |
| 1455 | COMPOUND_FID, COMPOUND_FID, |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1456 | qi.info_type, true, buffer, |
| 1457 | qi.output_buffer_length, |
| 1458 | CIFSMaxBufSize); |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1459 | } |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1460 | } else if (qi.flags == PASSTHRU_SET_INFO) { |
| 1461 | /* Can eventually relax perm check since server enforces too */ |
| 1462 | if (!capable(CAP_SYS_ADMIN)) |
| 1463 | rc = -EPERM; |
| 1464 | else { |
| 1465 | memset(&si_iov, 0, sizeof(si_iov)); |
| 1466 | rqst[1].rq_iov = si_iov; |
| 1467 | rqst[1].rq_nvec = 1; |
| 1468 | |
| 1469 | size[0] = 8; |
| 1470 | data[0] = buffer; |
| 1471 | |
| 1472 | rc = SMB2_set_info_init(tcon, &rqst[1], |
| 1473 | COMPOUND_FID, COMPOUND_FID, |
| 1474 | current->tgid, |
| 1475 | FILE_END_OF_FILE_INFORMATION, |
| 1476 | SMB2_O_INFO_FILE, 0, data, size); |
| 1477 | } |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1478 | } else if (qi.flags == PASSTHRU_QUERY_INFO) { |
| 1479 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 1480 | rqst[1].rq_iov = qi_iov; |
| 1481 | rqst[1].rq_nvec = 1; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1482 | |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1483 | rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, |
| 1484 | COMPOUND_FID, qi.file_info_class, |
| 1485 | qi.info_type, qi.additional_information, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1486 | qi.input_buffer_length, |
| 1487 | qi.output_buffer_length, buffer); |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1488 | } else { /* unknown flags */ |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1489 | cifs_tcon_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags); |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1490 | rc = -EINVAL; |
| 1491 | } |
| 1492 | |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1493 | if (rc) |
| 1494 | goto iqinf_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1495 | smb2_set_next_command(tcon, &rqst[1]); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1496 | smb2_set_related(&rqst[1]); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1497 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1498 | /* Close */ |
| 1499 | memset(&close_iov, 0, sizeof(close_iov)); |
| 1500 | rqst[2].rq_iov = close_iov; |
| 1501 | rqst[2].rq_nvec = 1; |
| 1502 | |
| 1503 | rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1504 | if (rc) |
| 1505 | goto iqinf_exit; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1506 | smb2_set_related(&rqst[2]); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1507 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1508 | rc = compound_send_recv(xid, ses, flags, 3, rqst, |
| 1509 | resp_buftype, rsp_iov); |
| 1510 | if (rc) |
| 1511 | goto iqinf_exit; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1512 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1513 | pqi = (struct smb_query_info __user *)arg; |
| 1514 | io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base; |
| 1515 | if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) |
| 1516 | qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); |
Ronnie Sahlberg | 5242fcb | 2019-04-15 12:13:52 +1000 | [diff] [blame] | 1517 | if (qi.input_buffer_length > 0 && |
| 1518 | le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length > rsp_iov[1].iov_len) { |
| 1519 | rc = -EFAULT; |
| 1520 | goto iqinf_exit; |
| 1521 | } |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1522 | if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, |
| 1523 | sizeof(qi.input_buffer_length))) { |
| 1524 | rc = -EFAULT; |
| 1525 | goto iqinf_exit; |
| 1526 | } |
Ronnie Sahlberg | 5242fcb | 2019-04-15 12:13:52 +1000 | [diff] [blame] | 1527 | if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info), |
| 1528 | (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset), |
| 1529 | qi.input_buffer_length)) { |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1530 | rc = -EFAULT; |
| 1531 | goto iqinf_exit; |
| 1532 | } |
| 1533 | } else { |
| 1534 | pqi = (struct smb_query_info __user *)arg; |
| 1535 | qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; |
| 1536 | if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) |
| 1537 | qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); |
| 1538 | if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, |
| 1539 | sizeof(qi.input_buffer_length))) { |
| 1540 | rc = -EFAULT; |
| 1541 | goto iqinf_exit; |
| 1542 | } |
| 1543 | if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) { |
| 1544 | rc = -EFAULT; |
| 1545 | goto iqinf_exit; |
| 1546 | } |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | iqinf_exit: |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1550 | kfree(buffer); |
| 1551 | SMB2_open_free(&rqst[0]); |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1552 | if (qi.flags & PASSTHRU_FSCTL) |
| 1553 | SMB2_ioctl_free(&rqst[1]); |
| 1554 | else |
| 1555 | SMB2_query_info_free(&rqst[1]); |
| 1556 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1557 | SMB2_close_free(&rqst[2]); |
| 1558 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 1559 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 1560 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1561 | return rc; |
| 1562 | } |
| 1563 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1564 | static ssize_t |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 1565 | smb2_copychunk_range(const unsigned int xid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1566 | struct cifsFileInfo *srcfile, |
| 1567 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 1568 | u64 len, u64 dest_off) |
| 1569 | { |
| 1570 | int rc; |
| 1571 | unsigned int ret_data_len; |
| 1572 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1573 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 1574 | struct cifs_tcon *tcon; |
| 1575 | int chunks_copied = 0; |
| 1576 | bool chunk_sizes_updated = false; |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1577 | ssize_t bytes_written, total_bytes_written = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1578 | |
| 1579 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 1580 | |
| 1581 | if (pcchunk == NULL) |
| 1582 | return -ENOMEM; |
| 1583 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1584 | cifs_dbg(FYI, "%s: about to call request res key\n", __func__); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1585 | /* Request a key from the server to identify the source of the copy */ |
| 1586 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 1587 | srcfile->fid.persistent_fid, |
| 1588 | srcfile->fid.volatile_fid, pcchunk); |
| 1589 | |
| 1590 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 1591 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1592 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1593 | |
| 1594 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 1595 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1596 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1597 | pcchunk->Reserved2 = 0; |
| 1598 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1599 | tcon = tlink_tcon(trgtfile->tlink); |
| 1600 | |
| 1601 | while (len > 0) { |
| 1602 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 1603 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 1604 | pcchunk->Length = |
| 1605 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 1606 | |
| 1607 | /* Request server copy to target from src identified by key */ |
| 1608 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1609 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1610 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1611 | sizeof(struct copychunk_ioctl), CIFSMaxBufSize, |
| 1612 | (char **)&retbuf, &ret_data_len); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1613 | if (rc == 0) { |
| 1614 | if (ret_data_len != |
| 1615 | sizeof(struct copychunk_ioctl_rsp)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1616 | cifs_tcon_dbg(VFS, "invalid cchunk response size\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1617 | rc = -EIO; |
| 1618 | goto cchunk_out; |
| 1619 | } |
| 1620 | if (retbuf->TotalBytesWritten == 0) { |
| 1621 | cifs_dbg(FYI, "no bytes copied\n"); |
| 1622 | rc = -EIO; |
| 1623 | goto cchunk_out; |
| 1624 | } |
| 1625 | /* |
| 1626 | * Check if server claimed to write more than we asked |
| 1627 | */ |
| 1628 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 1629 | le32_to_cpu(pcchunk->Length)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1630 | cifs_tcon_dbg(VFS, "invalid copy chunk response\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1631 | rc = -EIO; |
| 1632 | goto cchunk_out; |
| 1633 | } |
| 1634 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1635 | cifs_tcon_dbg(VFS, "invalid num chunks written\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1636 | rc = -EIO; |
| 1637 | goto cchunk_out; |
| 1638 | } |
| 1639 | chunks_copied++; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1640 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1641 | bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); |
| 1642 | src_off += bytes_written; |
| 1643 | dest_off += bytes_written; |
| 1644 | len -= bytes_written; |
| 1645 | total_bytes_written += bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1646 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1647 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n", |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1648 | le32_to_cpu(retbuf->ChunksWritten), |
| 1649 | le32_to_cpu(retbuf->ChunkBytesWritten), |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1650 | bytes_written); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1651 | } else if (rc == -EINVAL) { |
| 1652 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 1653 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1654 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1655 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 1656 | le32_to_cpu(retbuf->ChunksWritten), |
| 1657 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 1658 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 1659 | |
| 1660 | /* |
| 1661 | * Check if this is the first request using these sizes, |
| 1662 | * (ie check if copy succeed once with original sizes |
| 1663 | * and check if the server gave us different sizes after |
| 1664 | * we already updated max sizes on previous request). |
| 1665 | * if not then why is the server returning an error now |
| 1666 | */ |
| 1667 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 1668 | goto cchunk_out; |
| 1669 | |
| 1670 | /* Check that server is not asking us to grow size */ |
| 1671 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 1672 | tcon->max_bytes_chunk) |
| 1673 | tcon->max_bytes_chunk = |
| 1674 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 1675 | else |
| 1676 | goto cchunk_out; /* server gave us bogus size */ |
| 1677 | |
| 1678 | /* No need to change MaxChunks since already set to 1 */ |
| 1679 | chunk_sizes_updated = true; |
Sachin Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 1680 | } else |
| 1681 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1685 | kfree(pcchunk); |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1686 | kfree(retbuf); |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1687 | if (rc) |
| 1688 | return rc; |
| 1689 | else |
| 1690 | return total_bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1694 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 1695 | struct cifs_fid *fid) |
| 1696 | { |
| 1697 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 1698 | } |
| 1699 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1700 | static unsigned int |
| 1701 | smb2_read_data_offset(char *buf) |
| 1702 | { |
| 1703 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1704 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1705 | return rsp->DataOffset; |
| 1706 | } |
| 1707 | |
| 1708 | static unsigned int |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1709 | smb2_read_data_length(char *buf, bool in_remaining) |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1710 | { |
| 1711 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1712 | |
| 1713 | if (in_remaining) |
| 1714 | return le32_to_cpu(rsp->DataRemaining); |
| 1715 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1716 | return le32_to_cpu(rsp->DataLength); |
| 1717 | } |
| 1718 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1719 | |
| 1720 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1721 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1722 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 1723 | char **buf, int *buf_type) |
| 1724 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1725 | parms->persistent_fid = pfid->persistent_fid; |
| 1726 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1727 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 1728 | } |
| 1729 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1730 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1731 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1732 | struct cifs_io_parms *parms, unsigned int *written, |
| 1733 | struct kvec *iov, unsigned long nr_segs) |
| 1734 | { |
| 1735 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1736 | parms->persistent_fid = pfid->persistent_fid; |
| 1737 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1738 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 1739 | } |
| 1740 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1741 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 1742 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, |
| 1743 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) |
| 1744 | { |
| 1745 | struct cifsInodeInfo *cifsi; |
| 1746 | int rc; |
| 1747 | |
| 1748 | cifsi = CIFS_I(inode); |
| 1749 | |
| 1750 | /* if file already sparse don't bother setting sparse again */ |
| 1751 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) |
| 1752 | return true; /* already sparse */ |
| 1753 | |
| 1754 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) |
| 1755 | return true; /* already not sparse */ |
| 1756 | |
| 1757 | /* |
| 1758 | * Can't check for sparse support on share the usual way via the |
| 1759 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share |
| 1760 | * since Samba server doesn't set the flag on the share, yet |
| 1761 | * supports the set sparse FSCTL and returns sparse correctly |
| 1762 | * in the file attributes. If we fail setting sparse though we |
| 1763 | * mark that server does not support sparse files for this share |
| 1764 | * to avoid repeatedly sending the unsupported fsctl to server |
| 1765 | * if the file is repeatedly extended. |
| 1766 | */ |
| 1767 | if (tcon->broken_sparse_sup) |
| 1768 | return false; |
| 1769 | |
| 1770 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1771 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1772 | true /* is_fctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1773 | &setsparse, 1, CIFSMaxBufSize, NULL, NULL); |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1774 | if (rc) { |
| 1775 | tcon->broken_sparse_sup = true; |
| 1776 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); |
| 1777 | return false; |
| 1778 | } |
| 1779 | |
| 1780 | if (setsparse) |
| 1781 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; |
| 1782 | else |
| 1783 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); |
| 1784 | |
| 1785 | return true; |
| 1786 | } |
| 1787 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1788 | static int |
| 1789 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 1790 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 1791 | { |
| 1792 | __le64 eof = cpu_to_le64(size); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1793 | struct inode *inode; |
| 1794 | |
| 1795 | /* |
| 1796 | * If extending file more than one page make sparse. Many Linux fs |
| 1797 | * make files sparse by default when extending via ftruncate |
| 1798 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1799 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1800 | |
| 1801 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1802 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1803 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 1804 | /* whether set sparse succeeds or not, extend the file */ |
| 1805 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 1806 | } |
| 1807 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1808 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Ronnie Sahlberg | 3764cbd | 2018-09-03 13:33:47 +1000 | [diff] [blame] | 1809 | cfile->fid.volatile_fid, cfile->pid, &eof); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1812 | static int |
| 1813 | smb2_duplicate_extents(const unsigned int xid, |
| 1814 | struct cifsFileInfo *srcfile, |
| 1815 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 1816 | u64 len, u64 dest_off) |
| 1817 | { |
| 1818 | int rc; |
| 1819 | unsigned int ret_data_len; |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1820 | struct duplicate_extents_to_file dup_ext_buf; |
| 1821 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); |
| 1822 | |
| 1823 | /* server fileays advertise duplicate extent support with this flag */ |
| 1824 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & |
| 1825 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) |
| 1826 | return -EOPNOTSUPP; |
| 1827 | |
| 1828 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; |
| 1829 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; |
| 1830 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); |
| 1831 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); |
| 1832 | dup_ext_buf.ByteCount = cpu_to_le64(len); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1833 | 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] | 1834 | src_off, dest_off, len); |
| 1835 | |
| 1836 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 1837 | if (rc) |
| 1838 | goto duplicate_extents_out; |
| 1839 | |
| 1840 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 1841 | trgtfile->fid.volatile_fid, |
| 1842 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1843 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1844 | (char *)&dup_ext_buf, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1845 | sizeof(struct duplicate_extents_to_file), |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1846 | CIFSMaxBufSize, NULL, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1847 | &ret_data_len); |
| 1848 | |
| 1849 | if (ret_data_len > 0) |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1850 | cifs_dbg(FYI, "Non-zero response length in duplicate extents\n"); |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1851 | |
| 1852 | duplicate_extents_out: |
| 1853 | return rc; |
| 1854 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 1855 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1856 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 1857 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 1858 | struct cifsFileInfo *cfile) |
| 1859 | { |
| 1860 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 1861 | cfile->fid.volatile_fid); |
| 1862 | } |
| 1863 | |
| 1864 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1865 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, |
| 1866 | struct cifsFileInfo *cfile) |
| 1867 | { |
| 1868 | struct fsctl_set_integrity_information_req integr_info; |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1869 | unsigned int ret_data_len; |
| 1870 | |
| 1871 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); |
| 1872 | integr_info.Flags = 0; |
| 1873 | integr_info.Reserved = 0; |
| 1874 | |
| 1875 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1876 | cfile->fid.volatile_fid, |
| 1877 | FSCTL_SET_INTEGRITY_INFORMATION, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1878 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 1879 | (char *)&integr_info, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1880 | sizeof(struct fsctl_set_integrity_information_req), |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1881 | CIFSMaxBufSize, NULL, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1882 | &ret_data_len); |
| 1883 | |
| 1884 | } |
| 1885 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 1886 | /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */ |
| 1887 | #define GMT_TOKEN_SIZE 50 |
| 1888 | |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1889 | #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */ |
| 1890 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 1891 | /* |
| 1892 | * Input buffer contains (empty) struct smb_snapshot array with size filled in |
| 1893 | * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2 |
| 1894 | */ |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 1895 | static int |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1896 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, |
| 1897 | struct cifsFileInfo *cfile, void __user *ioc_buf) |
| 1898 | { |
| 1899 | char *retbuf = NULL; |
| 1900 | unsigned int ret_data_len = 0; |
| 1901 | int rc; |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1902 | u32 max_response_size; |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1903 | struct smb_snapshot_array snapshot_in; |
| 1904 | |
Steve French | 973189a | 2019-04-04 00:41:04 -0500 | [diff] [blame] | 1905 | /* |
| 1906 | * On the first query to enumerate the list of snapshots available |
| 1907 | * for this volume the buffer begins with 0 (number of snapshots |
| 1908 | * which can be returned is zero since at that point we do not know |
| 1909 | * how big the buffer needs to be). On the second query, |
| 1910 | * it (ret_data_len) is set to number of snapshots so we can |
| 1911 | * know to set the maximum response size larger (see below). |
| 1912 | */ |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1913 | if (get_user(ret_data_len, (unsigned int __user *)ioc_buf)) |
| 1914 | return -EFAULT; |
| 1915 | |
| 1916 | /* |
| 1917 | * Note that for snapshot queries that servers like Azure expect that |
| 1918 | * the first query be minimal size (and just used to get the number/size |
| 1919 | * of previous versions) so response size must be specified as EXACTLY |
| 1920 | * sizeof(struct snapshot_array) which is 16 when rounded up to multiple |
| 1921 | * of eight bytes. |
| 1922 | */ |
| 1923 | if (ret_data_len == 0) |
| 1924 | max_response_size = MIN_SNAPSHOT_ARRAY_SIZE; |
| 1925 | else |
| 1926 | max_response_size = CIFSMaxBufSize; |
| 1927 | |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1928 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 1929 | cfile->fid.volatile_fid, |
| 1930 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1931 | true /* is_fsctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1932 | NULL, 0 /* no input data */, max_response_size, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1933 | (char **)&retbuf, |
| 1934 | &ret_data_len); |
| 1935 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", |
| 1936 | rc, ret_data_len); |
| 1937 | if (rc) |
| 1938 | return rc; |
| 1939 | |
| 1940 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { |
| 1941 | /* Fixup buffer */ |
| 1942 | if (copy_from_user(&snapshot_in, ioc_buf, |
| 1943 | sizeof(struct smb_snapshot_array))) { |
| 1944 | rc = -EFAULT; |
| 1945 | kfree(retbuf); |
| 1946 | return rc; |
| 1947 | } |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1948 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 1949 | /* |
| 1950 | * Check for min size, ie not large enough to fit even one GMT |
| 1951 | * token (snapshot). On the first ioctl some users may pass in |
| 1952 | * smaller size (or zero) to simply get the size of the array |
| 1953 | * so the user space caller can allocate sufficient memory |
| 1954 | * and retry the ioctl again with larger array size sufficient |
| 1955 | * to hold all of the snapshot GMT tokens on the second try. |
| 1956 | */ |
| 1957 | if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE) |
| 1958 | ret_data_len = sizeof(struct smb_snapshot_array); |
| 1959 | |
| 1960 | /* |
| 1961 | * We return struct SRV_SNAPSHOT_ARRAY, followed by |
| 1962 | * the snapshot array (of 50 byte GMT tokens) each |
| 1963 | * representing an available previous version of the data |
| 1964 | */ |
| 1965 | if (ret_data_len > (snapshot_in.snapshot_array_size + |
| 1966 | sizeof(struct smb_snapshot_array))) |
| 1967 | ret_data_len = snapshot_in.snapshot_array_size + |
| 1968 | sizeof(struct smb_snapshot_array); |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 1969 | |
| 1970 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) |
| 1971 | rc = -EFAULT; |
| 1972 | } |
| 1973 | |
| 1974 | kfree(retbuf); |
| 1975 | return rc; |
| 1976 | } |
| 1977 | |
| 1978 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1979 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 1980 | const char *path, struct cifs_sb_info *cifs_sb, |
| 1981 | struct cifs_fid *fid, __u16 search_flags, |
| 1982 | struct cifs_search_info *srch_inf) |
| 1983 | { |
| 1984 | __le16 *utf16_path; |
| 1985 | int rc; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1986 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1987 | struct cifs_open_parms oparms; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1988 | |
| 1989 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1990 | if (!utf16_path) |
| 1991 | return -ENOMEM; |
| 1992 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1993 | oparms.tcon = tcon; |
| 1994 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 1995 | oparms.disposition = FILE_OPEN; |
Steve French | 5e19697 | 2018-08-27 17:04:13 -0500 | [diff] [blame] | 1996 | if (backup_cred(cifs_sb)) |
| 1997 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 1998 | else |
| 1999 | oparms.create_options = 0; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2000 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 2001 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2002 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2003 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2004 | kfree(utf16_path); |
| 2005 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 2006 | cifs_dbg(FYI, "open dir failed rc=%d\n", rc); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2007 | return rc; |
| 2008 | } |
| 2009 | |
| 2010 | srch_inf->entries_in_buffer = 0; |
Aurelien Aptel | 0595751 | 2018-05-17 16:35:07 +0200 | [diff] [blame] | 2011 | srch_inf->index_of_last_entry = 2; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2012 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2013 | rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 2014 | fid->volatile_fid, 0, srch_inf); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2015 | if (rc) { |
Pavel Shilovsky | dcd87838 | 2017-06-06 16:58:58 -0700 | [diff] [blame] | 2016 | cifs_dbg(FYI, "query directory failed rc=%d\n", rc); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2017 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2018 | } |
| 2019 | return rc; |
| 2020 | } |
| 2021 | |
| 2022 | static int |
| 2023 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 2024 | struct cifs_fid *fid, __u16 search_flags, |
| 2025 | struct cifs_search_info *srch_inf) |
| 2026 | { |
| 2027 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 2028 | fid->volatile_fid, 0, srch_inf); |
| 2029 | } |
| 2030 | |
| 2031 | static int |
| 2032 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 2033 | struct cifs_fid *fid) |
| 2034 | { |
| 2035 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 2036 | } |
| 2037 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2038 | /* |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2039 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 2040 | * the number of credits and return true. Otherwise - return false. |
| 2041 | */ |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2042 | static bool |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 2043 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2044 | { |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 2045 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2046 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2047 | if (shdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2048 | return false; |
| 2049 | |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 2050 | if (shdr->CreditRequest) { |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2051 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2052 | server->credits += le16_to_cpu(shdr->CreditRequest); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2053 | spin_unlock(&server->req_lock); |
| 2054 | wake_up(&server->request_q); |
| 2055 | } |
| 2056 | |
| 2057 | return true; |
| 2058 | } |
| 2059 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2060 | static bool |
| 2061 | smb2_is_session_expired(char *buf) |
| 2062 | { |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 2063 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2064 | |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 2065 | if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && |
| 2066 | shdr->Status != STATUS_USER_SESSION_DELETED) |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2067 | return false; |
| 2068 | |
Steve French | e68a932 | 2018-07-30 14:23:58 -0500 | [diff] [blame] | 2069 | trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId, |
| 2070 | le16_to_cpu(shdr->Command), |
| 2071 | le64_to_cpu(shdr->MessageId)); |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 2072 | cifs_dbg(FYI, "Session expired or deleted\n"); |
Steve French | e68a932 | 2018-07-30 14:23:58 -0500 | [diff] [blame] | 2073 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2074 | return true; |
| 2075 | } |
| 2076 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2077 | static int |
| 2078 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 2079 | struct cifsInodeInfo *cinode) |
| 2080 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 2081 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 2082 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 2083 | smb2_get_lease_state(cinode)); |
| 2084 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2085 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 2086 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 2087 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2090 | void |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2091 | smb2_set_related(struct smb_rqst *rqst) |
| 2092 | { |
| 2093 | struct smb2_sync_hdr *shdr; |
| 2094 | |
| 2095 | shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 2096 | if (shdr == NULL) { |
| 2097 | cifs_dbg(FYI, "shdr NULL in smb2_set_related\n"); |
| 2098 | return; |
| 2099 | } |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2100 | shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; |
| 2101 | } |
| 2102 | |
| 2103 | char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0}; |
| 2104 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2105 | void |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2106 | smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2107 | { |
| 2108 | struct smb2_sync_hdr *shdr; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2109 | struct cifs_ses *ses = tcon->ses; |
| 2110 | struct TCP_Server_Info *server = ses->server; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2111 | unsigned long len = smb_rqst_len(server, rqst); |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2112 | int i, num_padding; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2113 | |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 2114 | shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); |
| 2115 | if (shdr == NULL) { |
| 2116 | cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n"); |
| 2117 | return; |
| 2118 | } |
| 2119 | |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2120 | /* SMB headers in a compound are 8 byte aligned. */ |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2121 | |
| 2122 | /* No padding needed */ |
| 2123 | if (!(len & 7)) |
| 2124 | goto finished; |
| 2125 | |
| 2126 | num_padding = 8 - (len & 7); |
| 2127 | if (!smb3_encryption_required(tcon)) { |
| 2128 | /* |
| 2129 | * If we do not have encryption then we can just add an extra |
| 2130 | * iov for the padding. |
| 2131 | */ |
| 2132 | rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; |
| 2133 | rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; |
| 2134 | rqst->rq_nvec++; |
| 2135 | len += num_padding; |
| 2136 | } else { |
| 2137 | /* |
| 2138 | * We can not add a small padding iov for the encryption case |
| 2139 | * because the encryption framework can not handle the padding |
| 2140 | * iovs. |
| 2141 | * We have to flatten this into a single buffer and add |
| 2142 | * the padding to it. |
| 2143 | */ |
| 2144 | for (i = 1; i < rqst->rq_nvec; i++) { |
| 2145 | memcpy(rqst->rq_iov[0].iov_base + |
| 2146 | rqst->rq_iov[0].iov_len, |
| 2147 | rqst->rq_iov[i].iov_base, |
| 2148 | rqst->rq_iov[i].iov_len); |
| 2149 | rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; |
Ronnie Sahlberg | 271b9c0 | 2018-12-18 17:49:05 -0600 | [diff] [blame] | 2150 | } |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2151 | memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, |
| 2152 | 0, num_padding); |
| 2153 | rqst->rq_iov[0].iov_len += num_padding; |
| 2154 | len += num_padding; |
| 2155 | rqst->rq_nvec = 1; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2156 | } |
| 2157 | |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2158 | finished: |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2159 | shdr->NextCommand = cpu_to_le32(len); |
| 2160 | } |
| 2161 | |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2162 | /* |
| 2163 | * Passes the query info response back to the caller on success. |
| 2164 | * Caller need to free this with free_rsp_buf(). |
| 2165 | */ |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2166 | int |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2167 | smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, |
| 2168 | __le16 *utf16_path, u32 desired_access, |
| 2169 | u32 class, u32 type, u32 output_len, |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2170 | struct kvec *rsp, int *buftype, |
| 2171 | struct cifs_sb_info *cifs_sb) |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2172 | { |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2173 | struct cifs_ses *ses = tcon->ses; |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2174 | int flags = 0; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2175 | struct smb_rqst rqst[3]; |
| 2176 | int resp_buftype[3]; |
| 2177 | struct kvec rsp_iov[3]; |
Ronnie Sahlberg | 4d8dfaf | 2018-08-21 11:49:21 +1000 | [diff] [blame] | 2178 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2179 | struct kvec qi_iov[1]; |
| 2180 | struct kvec close_iov[1]; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2181 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2182 | struct cifs_open_parms oparms; |
| 2183 | struct cifs_fid fid; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2184 | int rc; |
| 2185 | |
| 2186 | if (smb3_encryption_required(tcon)) |
| 2187 | flags |= CIFS_TRANSFORM_REQ; |
| 2188 | |
| 2189 | memset(rqst, 0, sizeof(rqst)); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2190 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2191 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 2192 | |
| 2193 | memset(&open_iov, 0, sizeof(open_iov)); |
| 2194 | rqst[0].rq_iov = open_iov; |
Ronnie Sahlberg | 4d8dfaf | 2018-08-21 11:49:21 +1000 | [diff] [blame] | 2195 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2196 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2197 | oparms.tcon = tcon; |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2198 | oparms.desired_access = desired_access; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2199 | oparms.disposition = FILE_OPEN; |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2200 | if (cifs_sb && backup_cred(cifs_sb)) |
| 2201 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 2202 | else |
| 2203 | oparms.create_options = 0; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2204 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 2205 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2206 | |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2207 | rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2208 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2209 | goto qic_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2210 | smb2_set_next_command(tcon, &rqst[0]); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2211 | |
| 2212 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 2213 | rqst[1].rq_iov = qi_iov; |
| 2214 | rqst[1].rq_nvec = 1; |
| 2215 | |
| 2216 | rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID, |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2217 | class, type, 0, |
| 2218 | output_len, 0, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 2219 | NULL); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2220 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2221 | goto qic_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2222 | smb2_set_next_command(tcon, &rqst[1]); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2223 | smb2_set_related(&rqst[1]); |
| 2224 | |
| 2225 | memset(&close_iov, 0, sizeof(close_iov)); |
| 2226 | rqst[2].rq_iov = close_iov; |
| 2227 | rqst[2].rq_nvec = 1; |
| 2228 | |
| 2229 | rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID); |
| 2230 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2231 | goto qic_exit; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2232 | smb2_set_related(&rqst[2]); |
| 2233 | |
| 2234 | rc = compound_send_recv(xid, ses, flags, 3, rqst, |
| 2235 | resp_buftype, rsp_iov); |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2236 | if (rc) { |
| 2237 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2238 | goto qic_exit; |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2239 | } |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2240 | *rsp = rsp_iov[1]; |
| 2241 | *buftype = resp_buftype[1]; |
| 2242 | |
| 2243 | qic_exit: |
| 2244 | SMB2_open_free(&rqst[0]); |
| 2245 | SMB2_query_info_free(&rqst[1]); |
| 2246 | SMB2_close_free(&rqst[2]); |
| 2247 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 2248 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
| 2249 | return rc; |
| 2250 | } |
| 2251 | |
| 2252 | static int |
| 2253 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 2254 | struct kstatfs *buf) |
| 2255 | { |
| 2256 | struct smb2_query_info_rsp *rsp; |
| 2257 | struct smb2_fs_full_size_info *info = NULL; |
| 2258 | __le16 utf16_path = 0; /* Null - open root of share */ |
| 2259 | struct kvec rsp_iov = {NULL, 0}; |
| 2260 | int buftype = CIFS_NO_BUFFER; |
| 2261 | int rc; |
| 2262 | |
| 2263 | |
| 2264 | rc = smb2_query_info_compound(xid, tcon, &utf16_path, |
| 2265 | FILE_READ_ATTRIBUTES, |
| 2266 | FS_FULL_SIZE_INFORMATION, |
| 2267 | SMB2_O_INFO_FILESYSTEM, |
| 2268 | sizeof(struct smb2_fs_full_size_info), |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2269 | &rsp_iov, &buftype, NULL); |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2270 | if (rc) |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2271 | goto qfs_exit; |
| 2272 | |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2273 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2274 | buf->f_type = SMB2_MAGIC_NUMBER; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2275 | info = (struct smb2_fs_full_size_info *)( |
| 2276 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); |
| 2277 | rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), |
| 2278 | le32_to_cpu(rsp->OutputBufferLength), |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2279 | &rsp_iov, |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2280 | sizeof(struct smb2_fs_full_size_info)); |
| 2281 | if (!rc) |
| 2282 | smb2_copy_fs_info_to_kstatfs(info, buf); |
| 2283 | |
| 2284 | qfs_exit: |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2285 | free_rsp_buf(buftype, rsp_iov.iov_base); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2286 | return rc; |
| 2287 | } |
| 2288 | |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2289 | static int |
| 2290 | smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
| 2291 | struct kstatfs *buf) |
| 2292 | { |
| 2293 | int rc; |
| 2294 | __le16 srch_path = 0; /* Null - open root of share */ |
| 2295 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2296 | struct cifs_open_parms oparms; |
| 2297 | struct cifs_fid fid; |
| 2298 | |
| 2299 | if (!tcon->posix_extensions) |
| 2300 | return smb2_queryfs(xid, tcon, buf); |
| 2301 | |
| 2302 | oparms.tcon = tcon; |
| 2303 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 2304 | oparms.disposition = FILE_OPEN; |
| 2305 | oparms.create_options = 0; |
| 2306 | oparms.fid = &fid; |
| 2307 | oparms.reconnect = false; |
| 2308 | |
| 2309 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL); |
| 2310 | if (rc) |
| 2311 | return rc; |
| 2312 | |
| 2313 | rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid, |
| 2314 | fid.volatile_fid, buf); |
| 2315 | buf->f_type = SMB2_MAGIC_NUMBER; |
| 2316 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 2317 | return rc; |
| 2318 | } |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2319 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2320 | static bool |
| 2321 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 2322 | { |
| 2323 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 2324 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 2325 | } |
| 2326 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2327 | static int |
| 2328 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 2329 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 2330 | { |
| 2331 | if (unlock && !lock) |
| 2332 | type = SMB2_LOCKFLAG_UNLOCK; |
| 2333 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 2334 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 2335 | current->tgid, length, offset, type, wait); |
| 2336 | } |
| 2337 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2338 | static void |
| 2339 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 2340 | { |
| 2341 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 2342 | } |
| 2343 | |
| 2344 | static void |
| 2345 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 2346 | { |
| 2347 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 2348 | } |
| 2349 | |
| 2350 | static void |
| 2351 | smb2_new_lease_key(struct cifs_fid *fid) |
| 2352 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 2353 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2356 | static int |
| 2357 | smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses, |
| 2358 | const char *search_name, |
| 2359 | struct dfs_info3_param **target_nodes, |
| 2360 | unsigned int *num_of_nodes, |
| 2361 | const struct nls_table *nls_codepage, int remap) |
| 2362 | { |
| 2363 | int rc; |
| 2364 | __le16 *utf16_path = NULL; |
| 2365 | int utf16_path_len = 0; |
| 2366 | struct cifs_tcon *tcon; |
| 2367 | struct fsctl_get_dfs_referral_req *dfs_req = NULL; |
| 2368 | struct get_dfs_referral_rsp *dfs_rsp = NULL; |
| 2369 | u32 dfs_req_size = 0, dfs_rsp_size = 0; |
| 2370 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2371 | cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2372 | |
| 2373 | /* |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2374 | * Try to use the IPC tcon, otherwise just use any |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2375 | */ |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2376 | tcon = ses->tcon_ipc; |
| 2377 | if (tcon == NULL) { |
| 2378 | spin_lock(&cifs_tcp_ses_lock); |
| 2379 | tcon = list_first_entry_or_null(&ses->tcon_list, |
| 2380 | struct cifs_tcon, |
| 2381 | tcon_list); |
| 2382 | if (tcon) |
| 2383 | tcon->tc_count++; |
| 2384 | spin_unlock(&cifs_tcp_ses_lock); |
| 2385 | } |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2386 | |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2387 | if (tcon == NULL) { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2388 | cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", |
| 2389 | ses); |
| 2390 | rc = -ENOTCONN; |
| 2391 | goto out; |
| 2392 | } |
| 2393 | |
| 2394 | utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX, |
| 2395 | &utf16_path_len, |
| 2396 | nls_codepage, remap); |
| 2397 | if (!utf16_path) { |
| 2398 | rc = -ENOMEM; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | |
| 2402 | dfs_req_size = sizeof(*dfs_req) + utf16_path_len; |
| 2403 | dfs_req = kzalloc(dfs_req_size, GFP_KERNEL); |
| 2404 | if (!dfs_req) { |
| 2405 | rc = -ENOMEM; |
| 2406 | goto out; |
| 2407 | } |
| 2408 | |
| 2409 | /* Highest DFS referral version understood */ |
| 2410 | dfs_req->MaxReferralLevel = DFS_VERSION; |
| 2411 | |
| 2412 | /* Path to resolve in an UTF-16 null-terminated string */ |
| 2413 | memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); |
| 2414 | |
| 2415 | do { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2416 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 2417 | FSCTL_DFS_GET_REFERRALS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2418 | true /* is_fsctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2419 | (char *)dfs_req, dfs_req_size, CIFSMaxBufSize, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2420 | (char **)&dfs_rsp, &dfs_rsp_size); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2421 | } while (rc == -EAGAIN); |
| 2422 | |
| 2423 | if (rc) { |
Steve French | 2564f2f | 2018-03-21 23:16:36 -0500 | [diff] [blame] | 2424 | if ((rc != -ENOENT) && (rc != -EOPNOTSUPP)) |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 2425 | cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2426 | goto out; |
| 2427 | } |
| 2428 | |
| 2429 | rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size, |
| 2430 | num_of_nodes, target_nodes, |
| 2431 | nls_codepage, remap, search_name, |
| 2432 | true /* is_unicode */); |
| 2433 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 2434 | cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2435 | goto out; |
| 2436 | } |
| 2437 | |
| 2438 | out: |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2439 | if (tcon && !tcon->ipc) { |
| 2440 | /* ipc tcons are not refcounted */ |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2441 | spin_lock(&cifs_tcp_ses_lock); |
| 2442 | tcon->tc_count--; |
| 2443 | spin_unlock(&cifs_tcp_ses_lock); |
| 2444 | } |
| 2445 | kfree(utf16_path); |
| 2446 | kfree(dfs_req); |
| 2447 | kfree(dfs_rsp); |
| 2448 | return rc; |
| 2449 | } |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2450 | |
| 2451 | static int |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2452 | parse_reparse_posix(struct reparse_posix_data *symlink_buf, |
| 2453 | u32 plen, char **target_path, |
| 2454 | struct cifs_sb_info *cifs_sb) |
| 2455 | { |
| 2456 | unsigned int len; |
| 2457 | |
| 2458 | /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ |
| 2459 | len = le16_to_cpu(symlink_buf->ReparseDataLength); |
| 2460 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2461 | if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) { |
| 2462 | cifs_dbg(VFS, "%lld not a supported symlink type\n", |
| 2463 | le64_to_cpu(symlink_buf->InodeType)); |
| 2464 | return -EOPNOTSUPP; |
| 2465 | } |
| 2466 | |
| 2467 | *target_path = cifs_strndup_from_utf16( |
| 2468 | symlink_buf->PathBuffer, |
| 2469 | len, true, cifs_sb->local_nls); |
| 2470 | if (!(*target_path)) |
| 2471 | return -ENOMEM; |
| 2472 | |
| 2473 | convert_delimiter(*target_path, '/'); |
| 2474 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 2475 | |
| 2476 | return 0; |
| 2477 | } |
| 2478 | |
| 2479 | static int |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2480 | parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf, |
| 2481 | u32 plen, char **target_path, |
| 2482 | struct cifs_sb_info *cifs_sb) |
| 2483 | { |
| 2484 | unsigned int sub_len; |
| 2485 | unsigned int sub_offset; |
| 2486 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2487 | /* 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] | 2488 | |
| 2489 | sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset); |
| 2490 | sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength); |
| 2491 | if (sub_offset + 20 > plen || |
| 2492 | sub_offset + sub_len + 20 > plen) { |
| 2493 | cifs_dbg(VFS, "srv returned malformed symlink buffer\n"); |
| 2494 | return -EIO; |
| 2495 | } |
| 2496 | |
| 2497 | *target_path = cifs_strndup_from_utf16( |
| 2498 | symlink_buf->PathBuffer + sub_offset, |
| 2499 | sub_len, true, cifs_sb->local_nls); |
| 2500 | if (!(*target_path)) |
| 2501 | return -ENOMEM; |
| 2502 | |
| 2503 | convert_delimiter(*target_path, '/'); |
| 2504 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 2505 | |
| 2506 | return 0; |
| 2507 | } |
| 2508 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2509 | static int |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2510 | parse_reparse_point(struct reparse_data_buffer *buf, |
| 2511 | u32 plen, char **target_path, |
| 2512 | struct cifs_sb_info *cifs_sb) |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2513 | { |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2514 | if (plen < sizeof(struct reparse_data_buffer)) { |
| 2515 | cifs_dbg(VFS, "reparse buffer is too small. Must be " |
| 2516 | "at least 8 bytes but was %d\n", plen); |
| 2517 | return -EIO; |
| 2518 | } |
| 2519 | |
| 2520 | if (plen < le16_to_cpu(buf->ReparseDataLength) + |
| 2521 | sizeof(struct reparse_data_buffer)) { |
| 2522 | cifs_dbg(VFS, "srv returned invalid reparse buf " |
| 2523 | "length: %d\n", plen); |
| 2524 | return -EIO; |
| 2525 | } |
| 2526 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2527 | /* See MS-FSCC 2.1.2 */ |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2528 | switch (le32_to_cpu(buf->ReparseTag)) { |
| 2529 | case IO_REPARSE_TAG_NFS: |
| 2530 | return parse_reparse_posix( |
| 2531 | (struct reparse_posix_data *)buf, |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2532 | plen, target_path, cifs_sb); |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2533 | case IO_REPARSE_TAG_SYMLINK: |
| 2534 | return parse_reparse_symlink( |
| 2535 | (struct reparse_symlink_data_buffer *)buf, |
| 2536 | plen, target_path, cifs_sb); |
| 2537 | default: |
| 2538 | cifs_dbg(VFS, "srv returned unknown symlink buffer " |
| 2539 | "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag)); |
| 2540 | return -EOPNOTSUPP; |
| 2541 | } |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2542 | } |
| 2543 | |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2544 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 2545 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 2546 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2547 | static int |
| 2548 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2549 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 2550 | char **target_path, bool is_reparse_point) |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2551 | { |
| 2552 | int rc; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2553 | __le16 *utf16_path = NULL; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2554 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2555 | struct cifs_open_parms oparms; |
| 2556 | struct cifs_fid fid; |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 2557 | struct kvec err_iov = {NULL, 0}; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2558 | struct smb2_err_rsp *err_buf = NULL; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2559 | struct smb2_symlink_err_rsp *symlink; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2560 | unsigned int sub_len; |
| 2561 | unsigned int sub_offset; |
| 2562 | unsigned int print_len; |
| 2563 | unsigned int print_offset; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2564 | int flags = 0; |
| 2565 | struct smb_rqst rqst[3]; |
| 2566 | int resp_buftype[3]; |
| 2567 | struct kvec rsp_iov[3]; |
| 2568 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 2569 | struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; |
| 2570 | struct kvec close_iov[1]; |
| 2571 | struct smb2_create_rsp *create_rsp; |
| 2572 | struct smb2_ioctl_rsp *ioctl_rsp; |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2573 | struct reparse_data_buffer *reparse_buf; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2574 | u32 plen; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2575 | |
| 2576 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 2577 | |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2578 | *target_path = NULL; |
| 2579 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2580 | if (smb3_encryption_required(tcon)) |
| 2581 | flags |= CIFS_TRANSFORM_REQ; |
| 2582 | |
| 2583 | memset(rqst, 0, sizeof(rqst)); |
| 2584 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 2585 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 2586 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2587 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 2588 | if (!utf16_path) |
| 2589 | return -ENOMEM; |
| 2590 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2591 | /* Open */ |
| 2592 | memset(&open_iov, 0, sizeof(open_iov)); |
| 2593 | rqst[0].rq_iov = open_iov; |
| 2594 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 2595 | |
| 2596 | memset(&oparms, 0, sizeof(oparms)); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2597 | oparms.tcon = tcon; |
| 2598 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 2599 | oparms.disposition = FILE_OPEN; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2600 | |
Steve French | 5e19697 | 2018-08-27 17:04:13 -0500 | [diff] [blame] | 2601 | if (backup_cred(cifs_sb)) |
| 2602 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 2603 | else |
| 2604 | oparms.create_options = 0; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2605 | if (is_reparse_point) |
| 2606 | oparms.create_options = OPEN_REPARSE_POINT; |
| 2607 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2608 | oparms.fid = &fid; |
| 2609 | oparms.reconnect = false; |
| 2610 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2611 | rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path); |
| 2612 | if (rc) |
| 2613 | goto querty_exit; |
| 2614 | smb2_set_next_command(tcon, &rqst[0]); |
| 2615 | |
| 2616 | |
| 2617 | /* IOCTL */ |
| 2618 | memset(&io_iov, 0, sizeof(io_iov)); |
| 2619 | rqst[1].rq_iov = io_iov; |
| 2620 | rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; |
| 2621 | |
| 2622 | rc = SMB2_ioctl_init(tcon, &rqst[1], fid.persistent_fid, |
| 2623 | fid.volatile_fid, FSCTL_GET_REPARSE_POINT, |
| 2624 | true /* is_fctl */, NULL, 0, CIFSMaxBufSize); |
| 2625 | if (rc) |
| 2626 | goto querty_exit; |
| 2627 | |
| 2628 | smb2_set_next_command(tcon, &rqst[1]); |
| 2629 | smb2_set_related(&rqst[1]); |
| 2630 | |
| 2631 | |
| 2632 | /* Close */ |
| 2633 | memset(&close_iov, 0, sizeof(close_iov)); |
| 2634 | rqst[2].rq_iov = close_iov; |
| 2635 | rqst[2].rq_nvec = 1; |
| 2636 | |
| 2637 | rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID); |
| 2638 | if (rc) |
| 2639 | goto querty_exit; |
| 2640 | |
| 2641 | smb2_set_related(&rqst[2]); |
| 2642 | |
| 2643 | rc = compound_send_recv(xid, tcon->ses, flags, 3, rqst, |
| 2644 | resp_buftype, rsp_iov); |
| 2645 | |
| 2646 | create_rsp = rsp_iov[0].iov_base; |
| 2647 | if (create_rsp && create_rsp->sync_hdr.Status) |
| 2648 | err_iov = rsp_iov[0]; |
| 2649 | ioctl_rsp = rsp_iov[1].iov_base; |
| 2650 | |
| 2651 | /* |
| 2652 | * Open was successful and we got an ioctl response. |
| 2653 | */ |
| 2654 | if ((rc == 0) && (is_reparse_point)) { |
| 2655 | /* See MS-FSCC 2.3.23 */ |
| 2656 | |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2657 | reparse_buf = (struct reparse_data_buffer *) |
| 2658 | ((char *)ioctl_rsp + |
| 2659 | le32_to_cpu(ioctl_rsp->OutputOffset)); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2660 | plen = le32_to_cpu(ioctl_rsp->OutputCount); |
| 2661 | |
| 2662 | if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > |
| 2663 | rsp_iov[1].iov_len) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 2664 | cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n", |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2665 | plen); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2666 | rc = -EIO; |
| 2667 | goto querty_exit; |
| 2668 | } |
| 2669 | |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2670 | rc = parse_reparse_point(reparse_buf, plen, target_path, |
| 2671 | cifs_sb); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2672 | goto querty_exit; |
| 2673 | } |
| 2674 | |
Gustavo A. R. Silva | 0d568cd | 2018-04-13 10:13:29 -0500 | [diff] [blame] | 2675 | if (!rc || !err_iov.iov_base) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2676 | rc = -ENOENT; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2677 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2678 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2679 | |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 2680 | err_buf = err_iov.iov_base; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2681 | 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] | 2682 | err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) { |
Ronnie Sahlberg | df070af | 2019-07-09 18:41:11 +1000 | [diff] [blame] | 2683 | rc = -EINVAL; |
| 2684 | goto querty_exit; |
| 2685 | } |
| 2686 | |
| 2687 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 2688 | if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG || |
| 2689 | le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) { |
| 2690 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2691 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2692 | } |
| 2693 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2694 | /* open must fail on symlink - reset rc */ |
| 2695 | rc = 0; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2696 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 2697 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2698 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 2699 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 2700 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2701 | 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] | 2702 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2703 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2704 | } |
| 2705 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 2706 | if (err_iov.iov_len < |
| 2707 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
Ronnie Sahlberg | df070af | 2019-07-09 18:41:11 +1000 | [diff] [blame] | 2708 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2709 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 2710 | } |
| 2711 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2712 | *target_path = cifs_strndup_from_utf16( |
| 2713 | (char *)symlink->PathBuffer + sub_offset, |
| 2714 | sub_len, true, cifs_sb->local_nls); |
| 2715 | if (!(*target_path)) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2716 | rc = -ENOMEM; |
| 2717 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2718 | } |
| 2719 | convert_delimiter(*target_path, '/'); |
| 2720 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2721 | |
| 2722 | querty_exit: |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2723 | cifs_dbg(FYI, "query symlink rc %d\n", rc); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2724 | kfree(utf16_path); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 2725 | SMB2_open_free(&rqst[0]); |
| 2726 | SMB2_ioctl_free(&rqst[1]); |
| 2727 | SMB2_close_free(&rqst[2]); |
| 2728 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 2729 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 2730 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 2731 | return rc; |
| 2732 | } |
| 2733 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2734 | static struct cifs_ntsd * |
| 2735 | get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb, |
| 2736 | const struct cifs_fid *cifsfid, u32 *pacllen) |
| 2737 | { |
| 2738 | struct cifs_ntsd *pntsd = NULL; |
| 2739 | unsigned int xid; |
| 2740 | int rc = -EOPNOTSUPP; |
| 2741 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 2742 | |
| 2743 | if (IS_ERR(tlink)) |
| 2744 | return ERR_CAST(tlink); |
| 2745 | |
| 2746 | xid = get_xid(); |
| 2747 | cifs_dbg(FYI, "trying to get acl\n"); |
| 2748 | |
| 2749 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, |
| 2750 | cifsfid->volatile_fid, (void **)&pntsd, pacllen); |
| 2751 | free_xid(xid); |
| 2752 | |
| 2753 | cifs_put_tlink(tlink); |
| 2754 | |
| 2755 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 2756 | if (rc) |
| 2757 | return ERR_PTR(rc); |
| 2758 | return pntsd; |
| 2759 | |
| 2760 | } |
| 2761 | |
| 2762 | static struct cifs_ntsd * |
| 2763 | get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, |
| 2764 | const char *path, u32 *pacllen) |
| 2765 | { |
| 2766 | struct cifs_ntsd *pntsd = NULL; |
| 2767 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2768 | unsigned int xid; |
| 2769 | int rc; |
| 2770 | struct cifs_tcon *tcon; |
| 2771 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 2772 | struct cifs_fid fid; |
| 2773 | struct cifs_open_parms oparms; |
| 2774 | __le16 *utf16_path; |
| 2775 | |
| 2776 | cifs_dbg(FYI, "get smb3 acl for path %s\n", path); |
| 2777 | if (IS_ERR(tlink)) |
| 2778 | return ERR_CAST(tlink); |
| 2779 | |
| 2780 | tcon = tlink_tcon(tlink); |
| 2781 | xid = get_xid(); |
| 2782 | |
| 2783 | if (backup_cred(cifs_sb)) |
Colin Ian King | 709340a | 2017-07-05 13:47:34 +0100 | [diff] [blame] | 2784 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2785 | else |
| 2786 | oparms.create_options = 0; |
| 2787 | |
| 2788 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2789 | if (!utf16_path) { |
| 2790 | rc = -ENOMEM; |
| 2791 | free_xid(xid); |
| 2792 | return ERR_PTR(rc); |
| 2793 | } |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2794 | |
| 2795 | oparms.tcon = tcon; |
| 2796 | oparms.desired_access = READ_CONTROL; |
| 2797 | oparms.disposition = FILE_OPEN; |
| 2798 | oparms.fid = &fid; |
| 2799 | oparms.reconnect = false; |
| 2800 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2801 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2802 | kfree(utf16_path); |
| 2803 | if (!rc) { |
| 2804 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 2805 | fid.volatile_fid, (void **)&pntsd, pacllen); |
| 2806 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 2807 | } |
| 2808 | |
| 2809 | cifs_put_tlink(tlink); |
| 2810 | free_xid(xid); |
| 2811 | |
| 2812 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 2813 | if (rc) |
| 2814 | return ERR_PTR(rc); |
| 2815 | return pntsd; |
| 2816 | } |
| 2817 | |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2818 | static int |
| 2819 | set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 2820 | struct inode *inode, const char *path, int aclflag) |
| 2821 | { |
| 2822 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2823 | unsigned int xid; |
| 2824 | int rc, access_flags = 0; |
| 2825 | struct cifs_tcon *tcon; |
| 2826 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 2827 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 2828 | struct cifs_fid fid; |
| 2829 | struct cifs_open_parms oparms; |
| 2830 | __le16 *utf16_path; |
| 2831 | |
| 2832 | cifs_dbg(FYI, "set smb3 acl for path %s\n", path); |
| 2833 | if (IS_ERR(tlink)) |
| 2834 | return PTR_ERR(tlink); |
| 2835 | |
| 2836 | tcon = tlink_tcon(tlink); |
| 2837 | xid = get_xid(); |
| 2838 | |
| 2839 | if (backup_cred(cifs_sb)) |
| 2840 | oparms.create_options = CREATE_OPEN_BACKUP_INTENT; |
| 2841 | else |
| 2842 | oparms.create_options = 0; |
| 2843 | |
| 2844 | if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP) |
| 2845 | access_flags = WRITE_OWNER; |
| 2846 | else |
| 2847 | access_flags = WRITE_DAC; |
| 2848 | |
| 2849 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2850 | if (!utf16_path) { |
| 2851 | rc = -ENOMEM; |
| 2852 | free_xid(xid); |
| 2853 | return rc; |
| 2854 | } |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2855 | |
| 2856 | oparms.tcon = tcon; |
| 2857 | oparms.desired_access = access_flags; |
| 2858 | oparms.disposition = FILE_OPEN; |
| 2859 | oparms.path = path; |
| 2860 | oparms.fid = &fid; |
| 2861 | oparms.reconnect = false; |
| 2862 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 2863 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL); |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2864 | kfree(utf16_path); |
| 2865 | if (!rc) { |
| 2866 | rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 2867 | fid.volatile_fid, pnntsd, acllen, aclflag); |
| 2868 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 2869 | } |
| 2870 | |
| 2871 | cifs_put_tlink(tlink); |
| 2872 | free_xid(xid); |
| 2873 | return rc; |
| 2874 | } |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 2875 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2876 | /* Retrieve an ACL from the server */ |
| 2877 | static struct cifs_ntsd * |
| 2878 | get_smb2_acl(struct cifs_sb_info *cifs_sb, |
| 2879 | struct inode *inode, const char *path, |
| 2880 | u32 *pacllen) |
| 2881 | { |
| 2882 | struct cifs_ntsd *pntsd = NULL; |
| 2883 | struct cifsFileInfo *open_file = NULL; |
| 2884 | |
| 2885 | if (inode) |
| 2886 | open_file = find_readable_file(CIFS_I(inode), true); |
| 2887 | if (!open_file) |
| 2888 | return get_smb2_acl_by_path(cifs_sb, path, pacllen); |
| 2889 | |
| 2890 | pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); |
| 2891 | cifsFileInfo_put(open_file); |
| 2892 | return pntsd; |
| 2893 | } |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 2894 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2895 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 2896 | loff_t offset, loff_t len, bool keep_size) |
| 2897 | { |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2898 | struct cifs_ses *ses = tcon->ses; |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2899 | struct inode *inode; |
| 2900 | struct cifsInodeInfo *cifsi; |
| 2901 | struct cifsFileInfo *cfile = file->private_data; |
| 2902 | struct file_zero_data_information fsctl_buf; |
| 2903 | long rc; |
| 2904 | unsigned int xid; |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2905 | __le64 eof; |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2906 | |
| 2907 | xid = get_xid(); |
| 2908 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2909 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2910 | cifsi = CIFS_I(inode); |
| 2911 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2912 | trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 2913 | ses->Suid, offset, len); |
| 2914 | |
| 2915 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2916 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 2917 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2918 | if (keep_size == false) { |
| 2919 | rc = -EOPNOTSUPP; |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 2920 | trace_smb3_zero_err(xid, cfile->fid.persistent_fid, |
| 2921 | tcon->tid, ses->Suid, offset, len, rc); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2922 | free_xid(xid); |
| 2923 | return rc; |
| 2924 | } |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2925 | |
Steve French | d1c35af | 2019-05-09 00:09:37 -0500 | [diff] [blame] | 2926 | cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2927 | |
| 2928 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 2929 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 2930 | |
Ronnie Sahlberg | c425014 | 2019-05-02 15:52:57 +1000 | [diff] [blame] | 2931 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 2932 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true, |
| 2933 | (char *)&fsctl_buf, |
| 2934 | sizeof(struct file_zero_data_information), |
| 2935 | 0, NULL, NULL); |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2936 | if (rc) |
| 2937 | goto zero_range_exit; |
| 2938 | |
| 2939 | /* |
| 2940 | * do we also need to change the size of the file? |
| 2941 | */ |
| 2942 | if (keep_size == false && i_size_read(inode) < offset + len) { |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2943 | eof = cpu_to_le64(offset + len); |
Ronnie Sahlberg | c425014 | 2019-05-02 15:52:57 +1000 | [diff] [blame] | 2944 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 2945 | cfile->fid.volatile_fid, cfile->pid, &eof); |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2946 | } |
| 2947 | |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 2948 | zero_range_exit: |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2949 | free_xid(xid); |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 2950 | if (rc) |
| 2951 | trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, |
| 2952 | ses->Suid, offset, len, rc); |
| 2953 | else |
| 2954 | trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid, |
| 2955 | ses->Suid, offset, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 2956 | return rc; |
| 2957 | } |
| 2958 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2959 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 2960 | loff_t offset, loff_t len) |
| 2961 | { |
| 2962 | struct inode *inode; |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2963 | struct cifsFileInfo *cfile = file->private_data; |
| 2964 | struct file_zero_data_information fsctl_buf; |
| 2965 | long rc; |
| 2966 | unsigned int xid; |
| 2967 | __u8 set_sparse = 1; |
| 2968 | |
| 2969 | xid = get_xid(); |
| 2970 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2971 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2972 | |
| 2973 | /* Need to make file sparse, if not already, before freeing range. */ |
| 2974 | /* Consider adding equivalent for compressed since it could also work */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 2975 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { |
| 2976 | rc = -EOPNOTSUPP; |
| 2977 | free_xid(xid); |
| 2978 | return rc; |
| 2979 | } |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2980 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2981 | cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2982 | |
| 2983 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 2984 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 2985 | |
| 2986 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 2987 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2988 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2989 | sizeof(struct file_zero_data_information), |
| 2990 | CIFSMaxBufSize, NULL, NULL); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 2991 | free_xid(xid); |
| 2992 | return rc; |
| 2993 | } |
| 2994 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 2995 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 2996 | loff_t off, loff_t len, bool keep_size) |
| 2997 | { |
| 2998 | struct inode *inode; |
| 2999 | struct cifsInodeInfo *cifsi; |
| 3000 | struct cifsFileInfo *cfile = file->private_data; |
| 3001 | long rc = -EOPNOTSUPP; |
| 3002 | unsigned int xid; |
Ronnie Sahlberg | f169947 | 2019-03-15 00:08:48 +1000 | [diff] [blame] | 3003 | __le64 eof; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3004 | |
| 3005 | xid = get_xid(); |
| 3006 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3007 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3008 | cifsi = CIFS_I(inode); |
| 3009 | |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3010 | trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3011 | tcon->ses->Suid, off, len); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3012 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 3013 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3014 | if (keep_size == false) { |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3015 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, |
| 3016 | tcon->tid, tcon->ses->Suid, off, len, rc); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3017 | free_xid(xid); |
| 3018 | return rc; |
| 3019 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3020 | |
| 3021 | /* |
| 3022 | * Files are non-sparse by default so falloc may be a no-op |
| 3023 | * Must check if file sparse. If not sparse, and not extending |
| 3024 | * then no need to do anything since file already allocated |
| 3025 | */ |
| 3026 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
| 3027 | if (keep_size == true) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3028 | rc = 0; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3029 | /* check if extending file */ |
| 3030 | else if (i_size_read(inode) >= off + len) |
| 3031 | /* not extending file and already not sparse */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3032 | rc = 0; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3033 | /* BB: in future add else clause to extend file */ |
| 3034 | else |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3035 | rc = -EOPNOTSUPP; |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3036 | if (rc) |
| 3037 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, |
| 3038 | tcon->tid, tcon->ses->Suid, off, len, rc); |
| 3039 | else |
| 3040 | trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, |
| 3041 | tcon->tid, tcon->ses->Suid, off, len); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3042 | free_xid(xid); |
| 3043 | return rc; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 3047 | /* |
| 3048 | * Check if falloc starts within first few pages of file |
| 3049 | * and ends within a few pages of the end of file to |
| 3050 | * ensure that most of file is being forced to be |
| 3051 | * fallocated now. If so then setting whole file sparse |
| 3052 | * ie potentially making a few extra pages at the beginning |
| 3053 | * or end of the file non-sparse via set_sparse is harmless. |
| 3054 | */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3055 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) { |
| 3056 | rc = -EOPNOTSUPP; |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3057 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, |
| 3058 | tcon->tid, tcon->ses->Suid, off, len, rc); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3059 | free_xid(xid); |
| 3060 | return rc; |
| 3061 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3062 | |
Ronnie Sahlberg | f169947 | 2019-03-15 00:08:48 +1000 | [diff] [blame] | 3063 | smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 3064 | rc = 0; |
| 3065 | } else { |
| 3066 | smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 3067 | rc = 0; |
| 3068 | if (i_size_read(inode) < off + len) { |
| 3069 | eof = cpu_to_le64(off + len); |
| 3070 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 3071 | cfile->fid.volatile_fid, cfile->pid, |
| 3072 | &eof); |
| 3073 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3074 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3075 | |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3076 | if (rc) |
| 3077 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3078 | tcon->ses->Suid, off, len, rc); |
| 3079 | else |
| 3080 | trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3081 | tcon->ses->Suid, off, len); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3082 | |
| 3083 | free_xid(xid); |
| 3084 | return rc; |
| 3085 | } |
| 3086 | |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 3087 | static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) |
| 3088 | { |
| 3089 | struct cifsFileInfo *wrcfile, *cfile = file->private_data; |
| 3090 | struct cifsInodeInfo *cifsi; |
| 3091 | struct inode *inode; |
| 3092 | int rc = 0; |
| 3093 | struct file_allocated_range_buffer in_data, *out_data = NULL; |
| 3094 | u32 out_data_len; |
| 3095 | unsigned int xid; |
| 3096 | |
| 3097 | if (whence != SEEK_HOLE && whence != SEEK_DATA) |
| 3098 | return generic_file_llseek(file, offset, whence); |
| 3099 | |
| 3100 | inode = d_inode(cfile->dentry); |
| 3101 | cifsi = CIFS_I(inode); |
| 3102 | |
| 3103 | if (offset < 0 || offset >= i_size_read(inode)) |
| 3104 | return -ENXIO; |
| 3105 | |
| 3106 | xid = get_xid(); |
| 3107 | /* |
| 3108 | * We need to be sure that all dirty pages are written as they |
| 3109 | * might fill holes on the server. |
| 3110 | * Note that we also MUST flush any written pages since at least |
| 3111 | * some servers (Windows2016) will not reflect recent writes in |
| 3112 | * QUERY_ALLOCATED_RANGES until SMB2_flush is called. |
| 3113 | */ |
| 3114 | wrcfile = find_writable_file(cifsi, false); |
| 3115 | if (wrcfile) { |
| 3116 | filemap_write_and_wait(inode->i_mapping); |
| 3117 | smb2_flush_file(xid, tcon, &wrcfile->fid); |
| 3118 | cifsFileInfo_put(wrcfile); |
| 3119 | } |
| 3120 | |
| 3121 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { |
| 3122 | if (whence == SEEK_HOLE) |
| 3123 | offset = i_size_read(inode); |
| 3124 | goto lseek_exit; |
| 3125 | } |
| 3126 | |
| 3127 | in_data.file_offset = cpu_to_le64(offset); |
| 3128 | in_data.length = cpu_to_le64(i_size_read(inode)); |
| 3129 | |
| 3130 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3131 | cfile->fid.volatile_fid, |
| 3132 | FSCTL_QUERY_ALLOCATED_RANGES, true, |
| 3133 | (char *)&in_data, sizeof(in_data), |
| 3134 | sizeof(struct file_allocated_range_buffer), |
| 3135 | (char **)&out_data, &out_data_len); |
| 3136 | if (rc == -E2BIG) |
| 3137 | rc = 0; |
| 3138 | if (rc) |
| 3139 | goto lseek_exit; |
| 3140 | |
| 3141 | if (whence == SEEK_HOLE && out_data_len == 0) |
| 3142 | goto lseek_exit; |
| 3143 | |
| 3144 | if (whence == SEEK_DATA && out_data_len == 0) { |
| 3145 | rc = -ENXIO; |
| 3146 | goto lseek_exit; |
| 3147 | } |
| 3148 | |
| 3149 | if (out_data_len < sizeof(struct file_allocated_range_buffer)) { |
| 3150 | rc = -EINVAL; |
| 3151 | goto lseek_exit; |
| 3152 | } |
| 3153 | if (whence == SEEK_DATA) { |
| 3154 | offset = le64_to_cpu(out_data->file_offset); |
| 3155 | goto lseek_exit; |
| 3156 | } |
| 3157 | if (offset < le64_to_cpu(out_data->file_offset)) |
| 3158 | goto lseek_exit; |
| 3159 | |
| 3160 | offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length); |
| 3161 | |
| 3162 | lseek_exit: |
| 3163 | free_xid(xid); |
| 3164 | kfree(out_data); |
| 3165 | if (!rc) |
| 3166 | return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); |
| 3167 | else |
| 3168 | return rc; |
| 3169 | } |
| 3170 | |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 3171 | static int smb3_fiemap(struct cifs_tcon *tcon, |
| 3172 | struct cifsFileInfo *cfile, |
| 3173 | struct fiemap_extent_info *fei, u64 start, u64 len) |
| 3174 | { |
| 3175 | unsigned int xid; |
| 3176 | struct file_allocated_range_buffer in_data, *out_data; |
| 3177 | u32 out_data_len; |
| 3178 | int i, num, rc, flags, last_blob; |
| 3179 | u64 next; |
| 3180 | |
| 3181 | if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC)) |
| 3182 | return -EBADR; |
| 3183 | |
| 3184 | xid = get_xid(); |
| 3185 | again: |
| 3186 | in_data.file_offset = cpu_to_le64(start); |
| 3187 | in_data.length = cpu_to_le64(len); |
| 3188 | |
| 3189 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3190 | cfile->fid.volatile_fid, |
| 3191 | FSCTL_QUERY_ALLOCATED_RANGES, true, |
| 3192 | (char *)&in_data, sizeof(in_data), |
| 3193 | 1024 * sizeof(struct file_allocated_range_buffer), |
| 3194 | (char **)&out_data, &out_data_len); |
| 3195 | if (rc == -E2BIG) { |
| 3196 | last_blob = 0; |
| 3197 | rc = 0; |
| 3198 | } else |
| 3199 | last_blob = 1; |
| 3200 | if (rc) |
| 3201 | goto out; |
| 3202 | |
| 3203 | if (out_data_len < sizeof(struct file_allocated_range_buffer)) { |
| 3204 | rc = -EINVAL; |
| 3205 | goto out; |
| 3206 | } |
| 3207 | if (out_data_len % sizeof(struct file_allocated_range_buffer)) { |
| 3208 | rc = -EINVAL; |
| 3209 | goto out; |
| 3210 | } |
| 3211 | |
| 3212 | num = out_data_len / sizeof(struct file_allocated_range_buffer); |
| 3213 | for (i = 0; i < num; i++) { |
| 3214 | flags = 0; |
| 3215 | if (i == num - 1 && last_blob) |
| 3216 | flags |= FIEMAP_EXTENT_LAST; |
| 3217 | |
| 3218 | rc = fiemap_fill_next_extent(fei, |
| 3219 | le64_to_cpu(out_data[i].file_offset), |
| 3220 | le64_to_cpu(out_data[i].file_offset), |
| 3221 | le64_to_cpu(out_data[i].length), |
| 3222 | flags); |
| 3223 | if (rc < 0) |
| 3224 | goto out; |
| 3225 | if (rc == 1) { |
| 3226 | rc = 0; |
| 3227 | goto out; |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | if (!last_blob) { |
| 3232 | next = le64_to_cpu(out_data[num - 1].file_offset) + |
| 3233 | le64_to_cpu(out_data[num - 1].length); |
| 3234 | len = len - (next - start); |
| 3235 | start = next; |
| 3236 | goto again; |
| 3237 | } |
| 3238 | |
| 3239 | out: |
| 3240 | free_xid(xid); |
| 3241 | kfree(out_data); |
| 3242 | return rc; |
| 3243 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3244 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3245 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 3246 | loff_t off, loff_t len) |
| 3247 | { |
| 3248 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 3249 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 3250 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3251 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 3252 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 3253 | return smb3_zero_range(file, tcon, off, len, true); |
| 3254 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3255 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 3256 | return smb3_simple_falloc(file, tcon, off, len, true); |
| 3257 | else if (mode == 0) |
| 3258 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3259 | |
| 3260 | return -EOPNOTSUPP; |
| 3261 | } |
| 3262 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3263 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 3264 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
| 3265 | struct cifsInodeInfo *cinode, bool set_level2) |
| 3266 | { |
| 3267 | if (set_level2) |
| 3268 | server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II, |
| 3269 | 0, NULL); |
| 3270 | else |
| 3271 | server->ops->set_oplock_level(cinode, 0, 0, NULL); |
| 3272 | } |
| 3273 | |
| 3274 | static void |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 3275 | smb21_downgrade_oplock(struct TCP_Server_Info *server, |
| 3276 | struct cifsInodeInfo *cinode, bool set_level2) |
| 3277 | { |
| 3278 | server->ops->set_oplock_level(cinode, |
| 3279 | set_level2 ? SMB2_LEASE_READ_CACHING_HE : |
| 3280 | 0, 0, NULL); |
| 3281 | } |
| 3282 | |
| 3283 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3284 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 3285 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3286 | { |
| 3287 | oplock &= 0xFF; |
| 3288 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 3289 | return; |
| 3290 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3291 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3292 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 3293 | &cinode->vfs_inode); |
| 3294 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3295 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3296 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 3297 | &cinode->vfs_inode); |
| 3298 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 3299 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 3300 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 3301 | &cinode->vfs_inode); |
| 3302 | } else |
| 3303 | cinode->oplock = 0; |
| 3304 | } |
| 3305 | |
| 3306 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3307 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 3308 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3309 | { |
| 3310 | char message[5] = {0}; |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 3311 | unsigned int new_oplock = 0; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3312 | |
| 3313 | oplock &= 0xFF; |
| 3314 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 3315 | return; |
| 3316 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3317 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 3318 | new_oplock |= CIFS_CACHE_READ_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3319 | strcat(message, "R"); |
| 3320 | } |
| 3321 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 3322 | new_oplock |= CIFS_CACHE_HANDLE_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3323 | strcat(message, "H"); |
| 3324 | } |
| 3325 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 3326 | new_oplock |= CIFS_CACHE_WRITE_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3327 | strcat(message, "W"); |
| 3328 | } |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 3329 | if (!new_oplock) |
| 3330 | strncpy(message, "None", sizeof(message)); |
| 3331 | |
| 3332 | cinode->oplock = new_oplock; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3333 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 3334 | &cinode->vfs_inode); |
| 3335 | } |
| 3336 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3337 | static void |
| 3338 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 3339 | unsigned int epoch, bool *purge_cache) |
| 3340 | { |
| 3341 | unsigned int old_oplock = cinode->oplock; |
| 3342 | |
| 3343 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 3344 | |
| 3345 | if (purge_cache) { |
| 3346 | *purge_cache = false; |
| 3347 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 3348 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 3349 | (epoch - cinode->epoch > 0)) |
| 3350 | *purge_cache = true; |
| 3351 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 3352 | (epoch - cinode->epoch > 1)) |
| 3353 | *purge_cache = true; |
| 3354 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 3355 | (epoch - cinode->epoch > 1)) |
| 3356 | *purge_cache = true; |
| 3357 | else if (cinode->oplock == 0 && |
| 3358 | (epoch - cinode->epoch > 0)) |
| 3359 | *purge_cache = true; |
| 3360 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 3361 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 3362 | (epoch - cinode->epoch > 0)) |
| 3363 | *purge_cache = true; |
| 3364 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 3365 | (epoch - cinode->epoch > 1)) |
| 3366 | *purge_cache = true; |
| 3367 | } |
| 3368 | cinode->epoch = epoch; |
| 3369 | } |
| 3370 | } |
| 3371 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 3372 | static bool |
| 3373 | smb2_is_read_op(__u32 oplock) |
| 3374 | { |
| 3375 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 3376 | } |
| 3377 | |
| 3378 | static bool |
| 3379 | smb21_is_read_op(__u32 oplock) |
| 3380 | { |
| 3381 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 3382 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 3383 | } |
| 3384 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3385 | static __le32 |
| 3386 | map_oplock_to_lease(u8 oplock) |
| 3387 | { |
| 3388 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 3389 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 3390 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 3391 | return SMB2_LEASE_READ_CACHING; |
| 3392 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 3393 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 3394 | SMB2_LEASE_WRITE_CACHING; |
| 3395 | return 0; |
| 3396 | } |
| 3397 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3398 | static char * |
| 3399 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 3400 | { |
| 3401 | struct create_lease *buf; |
| 3402 | |
| 3403 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 3404 | if (!buf) |
| 3405 | return NULL; |
| 3406 | |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 3407 | memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3408 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3409 | |
| 3410 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 3411 | (struct create_lease, lcontext)); |
| 3412 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 3413 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 3414 | (struct create_lease, Name)); |
| 3415 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 3416 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 3417 | buf->Name[0] = 'R'; |
| 3418 | buf->Name[1] = 'q'; |
| 3419 | buf->Name[2] = 'L'; |
| 3420 | buf->Name[3] = 's'; |
| 3421 | return (char *)buf; |
| 3422 | } |
| 3423 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3424 | static char * |
| 3425 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 3426 | { |
| 3427 | struct create_lease_v2 *buf; |
| 3428 | |
| 3429 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 3430 | if (!buf) |
| 3431 | return NULL; |
| 3432 | |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 3433 | memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3434 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 3435 | |
| 3436 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 3437 | (struct create_lease_v2, lcontext)); |
| 3438 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 3439 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 3440 | (struct create_lease_v2, Name)); |
| 3441 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 3442 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3443 | buf->Name[0] = 'R'; |
| 3444 | buf->Name[1] = 'q'; |
| 3445 | buf->Name[2] = 'L'; |
| 3446 | buf->Name[3] = 's'; |
| 3447 | return (char *)buf; |
| 3448 | } |
| 3449 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 3450 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 3451 | smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 3452 | { |
| 3453 | struct create_lease *lc = (struct create_lease *)buf; |
| 3454 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3455 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 3456 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 3457 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 3458 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 3459 | } |
| 3460 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3461 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 3462 | smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3463 | { |
| 3464 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 3465 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 3466 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3467 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 3468 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 3469 | if (lease_key) |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 3470 | memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 3471 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 3472 | } |
| 3473 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 3474 | static unsigned int |
| 3475 | smb2_wp_retry_size(struct inode *inode) |
| 3476 | { |
| 3477 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, |
| 3478 | SMB2_MAX_BUFFER_SIZE); |
| 3479 | } |
| 3480 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 3481 | static bool |
| 3482 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 3483 | { |
| 3484 | return !cfile->invalidHandle; |
| 3485 | } |
| 3486 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3487 | static void |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3488 | 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] | 3489 | struct smb_rqst *old_rq, __le16 cipher_type) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3490 | { |
| 3491 | struct smb2_sync_hdr *shdr = |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3492 | (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3493 | |
| 3494 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); |
| 3495 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; |
| 3496 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); |
| 3497 | tr_hdr->Flags = cpu_to_le16(0x01); |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 3498 | if (cipher_type == SMB2_ENCRYPTION_AES128_GCM) |
| 3499 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE); |
| 3500 | else |
| 3501 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3502 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 3505 | /* We can not use the normal sg_set_buf() as we will sometimes pass a |
| 3506 | * stack object as buf. |
| 3507 | */ |
| 3508 | static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, |
| 3509 | unsigned int buflen) |
| 3510 | { |
Sebastien Tisserant | ee9d661 | 2019-08-01 12:06:08 -0500 | [diff] [blame] | 3511 | void *addr; |
| 3512 | /* |
| 3513 | * VMAP_STACK (at least) puts stack into the vmalloc address space |
| 3514 | */ |
| 3515 | if (is_vmalloc_addr(buf)) |
| 3516 | addr = vmalloc_to_page(buf); |
| 3517 | else |
| 3518 | addr = virt_to_page(buf); |
| 3519 | sg_set_page(sg, addr, buflen, offset_in_page(buf)); |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 3520 | } |
| 3521 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3522 | /* Assumes the first rqst has a transform header as the first iov. |
| 3523 | * I.e. |
| 3524 | * rqst[0].rq_iov[0] is transform header |
| 3525 | * rqst[0].rq_iov[1+] data to be encrypted/decrypted |
| 3526 | * rqst[1+].rq_iov[0+] data to be encrypted/decrypted |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3527 | */ |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3528 | static struct scatterlist * |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3529 | init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3530 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3531 | unsigned int sg_len; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3532 | struct scatterlist *sg; |
| 3533 | unsigned int i; |
| 3534 | unsigned int j; |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3535 | unsigned int idx = 0; |
| 3536 | int skip; |
| 3537 | |
| 3538 | sg_len = 1; |
| 3539 | for (i = 0; i < num_rqst; i++) |
| 3540 | sg_len += rqst[i].rq_nvec + rqst[i].rq_npages; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3541 | |
| 3542 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); |
| 3543 | if (!sg) |
| 3544 | return NULL; |
| 3545 | |
| 3546 | sg_init_table(sg, sg_len); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3547 | for (i = 0; i < num_rqst; i++) { |
| 3548 | for (j = 0; j < rqst[i].rq_nvec; j++) { |
| 3549 | /* |
| 3550 | * The first rqst has a transform header where the |
| 3551 | * first 20 bytes are not part of the encrypted blob |
| 3552 | */ |
| 3553 | skip = (i == 0) && (j == 0) ? 20 : 0; |
| 3554 | smb2_sg_set_buf(&sg[idx++], |
| 3555 | rqst[i].rq_iov[j].iov_base + skip, |
| 3556 | rqst[i].rq_iov[j].iov_len - skip); |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 3557 | } |
Steve French | d5f07fb | 2018-06-05 17:46:24 -0500 | [diff] [blame] | 3558 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3559 | for (j = 0; j < rqst[i].rq_npages; j++) { |
| 3560 | unsigned int len, offset; |
| 3561 | |
| 3562 | rqst_page_get_length(&rqst[i], j, &len, &offset); |
| 3563 | sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset); |
| 3564 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3565 | } |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3566 | smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3567 | return sg; |
| 3568 | } |
| 3569 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 3570 | static int |
| 3571 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) |
| 3572 | { |
| 3573 | struct cifs_ses *ses; |
| 3574 | u8 *ses_enc_key; |
| 3575 | |
| 3576 | spin_lock(&cifs_tcp_ses_lock); |
| 3577 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 3578 | if (ses->Suid != ses_id) |
| 3579 | continue; |
| 3580 | ses_enc_key = enc ? ses->smb3encryptionkey : |
| 3581 | ses->smb3decryptionkey; |
| 3582 | memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE); |
| 3583 | spin_unlock(&cifs_tcp_ses_lock); |
| 3584 | return 0; |
| 3585 | } |
| 3586 | spin_unlock(&cifs_tcp_ses_lock); |
| 3587 | |
| 3588 | return 1; |
| 3589 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3590 | /* |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3591 | * Encrypt or decrypt @rqst message. @rqst[0] has the following format: |
| 3592 | * iov[0] - transform header (associate data), |
| 3593 | * iov[1-N] - SMB2 header and pages - data to encrypt. |
| 3594 | * 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] | 3595 | * untouched. |
| 3596 | */ |
| 3597 | static int |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3598 | crypt_message(struct TCP_Server_Info *server, int num_rqst, |
| 3599 | struct smb_rqst *rqst, int enc) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3600 | { |
| 3601 | struct smb2_transform_hdr *tr_hdr = |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3602 | (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 3603 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3604 | int rc = 0; |
| 3605 | struct scatterlist *sg; |
| 3606 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 3607 | u8 key[SMB3_SIGN_KEY_SIZE]; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3608 | struct aead_request *req; |
| 3609 | char *iv; |
| 3610 | unsigned int iv_len; |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 3611 | DECLARE_CRYPTO_WAIT(wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3612 | struct crypto_aead *tfm; |
| 3613 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 3614 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 3615 | rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); |
| 3616 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3617 | cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__, |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 3618 | enc ? "en" : "de"); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3619 | return 0; |
| 3620 | } |
| 3621 | |
| 3622 | rc = smb3_crypto_aead_allocate(server); |
| 3623 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3624 | cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3625 | return rc; |
| 3626 | } |
| 3627 | |
| 3628 | tfm = enc ? server->secmech.ccmaesencrypt : |
| 3629 | server->secmech.ccmaesdecrypt; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 3630 | rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3631 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3632 | cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3633 | return rc; |
| 3634 | } |
| 3635 | |
| 3636 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); |
| 3637 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3638 | cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3639 | return rc; |
| 3640 | } |
| 3641 | |
| 3642 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 3643 | if (!req) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3644 | cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3645 | return -ENOMEM; |
| 3646 | } |
| 3647 | |
| 3648 | if (!enc) { |
| 3649 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); |
| 3650 | crypt_len += SMB2_SIGNATURE_SIZE; |
| 3651 | } |
| 3652 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3653 | sg = init_sg(num_rqst, rqst, sign); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3654 | if (!sg) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3655 | cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 3656 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3657 | goto free_req; |
| 3658 | } |
| 3659 | |
| 3660 | iv_len = crypto_aead_ivsize(tfm); |
| 3661 | iv = kzalloc(iv_len, GFP_KERNEL); |
| 3662 | if (!iv) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3663 | cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 3664 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3665 | goto free_sg; |
| 3666 | } |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 3667 | |
| 3668 | if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) |
| 3669 | memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE); |
| 3670 | else { |
| 3671 | iv[0] = 3; |
| 3672 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE); |
| 3673 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3674 | |
| 3675 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); |
| 3676 | aead_request_set_ad(req, assoc_data_len); |
| 3677 | |
| 3678 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 3679 | crypto_req_done, &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3680 | |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 3681 | rc = crypto_wait_req(enc ? crypto_aead_encrypt(req) |
| 3682 | : crypto_aead_decrypt(req), &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3683 | |
| 3684 | if (!rc && enc) |
| 3685 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); |
| 3686 | |
| 3687 | kfree(iv); |
| 3688 | free_sg: |
| 3689 | kfree(sg); |
| 3690 | free_req: |
| 3691 | kfree(req); |
| 3692 | return rc; |
| 3693 | } |
| 3694 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3695 | void |
| 3696 | smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3697 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3698 | int i, j; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3699 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3700 | for (i = 0; i < num_rqst; i++) { |
| 3701 | if (rqst[i].rq_pages) { |
| 3702 | for (j = rqst[i].rq_npages - 1; j >= 0; j--) |
| 3703 | put_page(rqst[i].rq_pages[j]); |
| 3704 | kfree(rqst[i].rq_pages); |
| 3705 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3706 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3709 | /* |
| 3710 | * This function will initialize new_rq and encrypt the content. |
| 3711 | * The first entry, new_rq[0], only contains a single iov which contains |
| 3712 | * a smb2_transform_hdr and is pre-allocated by the caller. |
| 3713 | * This function then populates new_rq[1+] with the content from olq_rq[0+]. |
| 3714 | * |
| 3715 | * The end result is an array of smb_rqst structures where the first structure |
| 3716 | * only contains a single iov for the transform header which we then can pass |
| 3717 | * to crypt_message(). |
| 3718 | * |
| 3719 | * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller |
| 3720 | * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests |
| 3721 | */ |
| 3722 | static int |
| 3723 | smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, |
| 3724 | struct smb_rqst *new_rq, struct smb_rqst *old_rq) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3725 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3726 | struct page **pages; |
| 3727 | struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base; |
| 3728 | unsigned int npages; |
| 3729 | unsigned int orig_len = 0; |
| 3730 | int i, j; |
| 3731 | int rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3732 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3733 | for (i = 1; i < num_rqst; i++) { |
| 3734 | npages = old_rq[i - 1].rq_npages; |
| 3735 | pages = kmalloc_array(npages, sizeof(struct page *), |
| 3736 | GFP_KERNEL); |
| 3737 | if (!pages) |
| 3738 | goto err_free; |
| 3739 | |
| 3740 | new_rq[i].rq_pages = pages; |
| 3741 | new_rq[i].rq_npages = npages; |
| 3742 | new_rq[i].rq_offset = old_rq[i - 1].rq_offset; |
| 3743 | new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz; |
| 3744 | new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz; |
| 3745 | new_rq[i].rq_iov = old_rq[i - 1].rq_iov; |
| 3746 | new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec; |
| 3747 | |
| 3748 | orig_len += smb_rqst_len(server, &old_rq[i - 1]); |
| 3749 | |
| 3750 | for (j = 0; j < npages; j++) { |
| 3751 | pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 3752 | if (!pages[j]) |
| 3753 | goto err_free; |
| 3754 | } |
| 3755 | |
| 3756 | /* copy pages form the old */ |
| 3757 | for (j = 0; j < npages; j++) { |
| 3758 | char *dst, *src; |
| 3759 | unsigned int offset, len; |
| 3760 | |
| 3761 | rqst_page_get_length(&new_rq[i], j, &len, &offset); |
| 3762 | |
| 3763 | dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset; |
| 3764 | src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset; |
| 3765 | |
| 3766 | memcpy(dst, src, len); |
| 3767 | kunmap(new_rq[i].rq_pages[j]); |
| 3768 | kunmap(old_rq[i - 1].rq_pages[j]); |
| 3769 | } |
| 3770 | } |
| 3771 | |
| 3772 | /* fill the 1st iov with a transform header */ |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 3773 | fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3774 | |
| 3775 | rc = crypt_message(server, num_rqst, new_rq, 1); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 3776 | cifs_dbg(FYI, "Encrypt message returned %d\n", rc); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3777 | if (rc) |
| 3778 | goto err_free; |
| 3779 | |
| 3780 | return rc; |
| 3781 | |
| 3782 | err_free: |
| 3783 | smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]); |
| 3784 | return rc; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3787 | static int |
| 3788 | smb3_is_transform_hdr(void *buf) |
| 3789 | { |
| 3790 | struct smb2_transform_hdr *trhdr = buf; |
| 3791 | |
| 3792 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; |
| 3793 | } |
| 3794 | |
| 3795 | static int |
| 3796 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, |
| 3797 | unsigned int buf_data_size, struct page **pages, |
| 3798 | unsigned int npages, unsigned int page_data_size) |
| 3799 | { |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3800 | struct kvec iov[2]; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3801 | struct smb_rqst rqst = {NULL}; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3802 | int rc; |
| 3803 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3804 | iov[0].iov_base = buf; |
| 3805 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 3806 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); |
| 3807 | iov[1].iov_len = buf_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3808 | |
| 3809 | rqst.rq_iov = iov; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3810 | rqst.rq_nvec = 2; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3811 | rqst.rq_pages = pages; |
| 3812 | rqst.rq_npages = npages; |
| 3813 | rqst.rq_pagesz = PAGE_SIZE; |
| 3814 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; |
| 3815 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 3816 | rc = crypt_message(server, 1, &rqst, 0); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 3817 | cifs_dbg(FYI, "Decrypt message returned %d\n", rc); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3818 | |
| 3819 | if (rc) |
| 3820 | return rc; |
| 3821 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 3822 | memmove(buf, iov[1].iov_base, buf_data_size); |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 3823 | |
| 3824 | server->total_read = buf_data_size + page_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3825 | |
| 3826 | return rc; |
| 3827 | } |
| 3828 | |
| 3829 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 3830 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, |
| 3831 | unsigned int npages, unsigned int len) |
| 3832 | { |
| 3833 | int i; |
| 3834 | int length; |
| 3835 | |
| 3836 | for (i = 0; i < npages; i++) { |
| 3837 | struct page *page = pages[i]; |
| 3838 | size_t n; |
| 3839 | |
| 3840 | n = len; |
| 3841 | if (len >= PAGE_SIZE) { |
| 3842 | /* enough data to fill the page */ |
| 3843 | n = PAGE_SIZE; |
| 3844 | len -= n; |
| 3845 | } else { |
| 3846 | zero_user(page, len, PAGE_SIZE - len); |
| 3847 | len = 0; |
| 3848 | } |
Long Li | 1dbe346 | 2018-05-30 12:47:55 -0700 | [diff] [blame] | 3849 | length = cifs_read_page_from_socket(server, page, 0, n); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 3850 | if (length < 0) |
| 3851 | return length; |
| 3852 | server->total_read += length; |
| 3853 | } |
| 3854 | |
| 3855 | return 0; |
| 3856 | } |
| 3857 | |
| 3858 | static int |
| 3859 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, |
| 3860 | unsigned int cur_off, struct bio_vec **page_vec) |
| 3861 | { |
| 3862 | struct bio_vec *bvec; |
| 3863 | int i; |
| 3864 | |
| 3865 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); |
| 3866 | if (!bvec) |
| 3867 | return -ENOMEM; |
| 3868 | |
| 3869 | for (i = 0; i < npages; i++) { |
| 3870 | bvec[i].bv_page = pages[i]; |
| 3871 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; |
| 3872 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); |
| 3873 | data_size -= bvec[i].bv_len; |
| 3874 | } |
| 3875 | |
| 3876 | if (data_size != 0) { |
| 3877 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); |
| 3878 | kfree(bvec); |
| 3879 | return -EIO; |
| 3880 | } |
| 3881 | |
| 3882 | *page_vec = bvec; |
| 3883 | return 0; |
| 3884 | } |
| 3885 | |
| 3886 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3887 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 3888 | char *buf, unsigned int buf_len, struct page **pages, |
| 3889 | unsigned int npages, unsigned int page_data_size) |
| 3890 | { |
| 3891 | unsigned int data_offset; |
| 3892 | unsigned int data_len; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 3893 | unsigned int cur_off; |
| 3894 | unsigned int cur_page_idx; |
| 3895 | unsigned int pad_len; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3896 | struct cifs_readdata *rdata = mid->callback_data; |
Ronnie Sahlberg | 49f466b | 2018-06-01 10:53:06 +1000 | [diff] [blame] | 3897 | struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3898 | struct bio_vec *bvec = NULL; |
| 3899 | struct iov_iter iter; |
| 3900 | struct kvec iov; |
| 3901 | int length; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 3902 | bool use_rdma_mr = false; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3903 | |
| 3904 | if (shdr->Command != SMB2_READ) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3905 | cifs_server_dbg(VFS, "only big read responses are supported\n"); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3906 | return -ENOTSUPP; |
| 3907 | } |
| 3908 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 3909 | if (server->ops->is_session_expired && |
| 3910 | server->ops->is_session_expired(buf)) { |
| 3911 | cifs_reconnect(server); |
| 3912 | wake_up(&server->response_q); |
| 3913 | return -1; |
| 3914 | } |
| 3915 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3916 | if (server->ops->is_status_pending && |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 3917 | server->ops->is_status_pending(buf, server)) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3918 | return -1; |
| 3919 | |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 3920 | /* set up first two iov to get credits */ |
| 3921 | rdata->iov[0].iov_base = buf; |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 3922 | rdata->iov[0].iov_len = 0; |
| 3923 | rdata->iov[1].iov_base = buf; |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 3924 | rdata->iov[1].iov_len = |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 3925 | min_t(unsigned int, buf_len, server->vals->read_rsp_size); |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 3926 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 3927 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 3928 | cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", |
| 3929 | rdata->iov[1].iov_base, rdata->iov[1].iov_len); |
| 3930 | |
| 3931 | rdata->result = server->ops->map_error(buf, true); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3932 | if (rdata->result != 0) { |
| 3933 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 3934 | __func__, rdata->result); |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 3935 | /* normal error on read response */ |
| 3936 | dequeue_mid(mid, false); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3937 | return 0; |
| 3938 | } |
| 3939 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 3940 | data_offset = server->ops->read_data_offset(buf); |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 3941 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 3942 | use_rdma_mr = rdata->mr; |
| 3943 | #endif |
| 3944 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3945 | |
| 3946 | if (data_offset < server->vals->read_rsp_size) { |
| 3947 | /* |
| 3948 | * win2k8 sometimes sends an offset of 0 when the read |
| 3949 | * is beyond the EOF. Treat it as if the data starts just after |
| 3950 | * the header. |
| 3951 | */ |
| 3952 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 3953 | __func__, data_offset); |
| 3954 | data_offset = server->vals->read_rsp_size; |
| 3955 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 3956 | /* data_offset is beyond the end of smallbuf */ |
| 3957 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 3958 | __func__, data_offset); |
| 3959 | rdata->result = -EIO; |
| 3960 | dequeue_mid(mid, rdata->result); |
| 3961 | return 0; |
| 3962 | } |
| 3963 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 3964 | pad_len = data_offset - server->vals->read_rsp_size; |
| 3965 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3966 | if (buf_len <= data_offset) { |
| 3967 | /* read response payload is in pages */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 3968 | cur_page_idx = pad_len / PAGE_SIZE; |
| 3969 | cur_off = pad_len % PAGE_SIZE; |
| 3970 | |
| 3971 | if (cur_page_idx != 0) { |
| 3972 | /* data offset is beyond the 1st page of response */ |
| 3973 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", |
| 3974 | __func__, data_offset); |
| 3975 | rdata->result = -EIO; |
| 3976 | dequeue_mid(mid, rdata->result); |
| 3977 | return 0; |
| 3978 | } |
| 3979 | |
| 3980 | if (data_len > page_data_size - pad_len) { |
| 3981 | /* data_len is corrupt -- discard frame */ |
| 3982 | rdata->result = -EIO; |
| 3983 | dequeue_mid(mid, rdata->result); |
| 3984 | return 0; |
| 3985 | } |
| 3986 | |
| 3987 | rdata->result = init_read_bvec(pages, npages, page_data_size, |
| 3988 | cur_off, &bvec); |
| 3989 | if (rdata->result != 0) { |
| 3990 | dequeue_mid(mid, rdata->result); |
| 3991 | return 0; |
| 3992 | } |
| 3993 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 3994 | iov_iter_bvec(&iter, WRITE, bvec, npages, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 3995 | } else if (buf_len >= data_offset + data_len) { |
| 3996 | /* read response payload is in buf */ |
| 3997 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); |
| 3998 | iov.iov_base = buf + data_offset; |
| 3999 | iov.iov_len = data_len; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 4000 | iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4001 | } else { |
| 4002 | /* read response payload cannot be in both buf and pages */ |
| 4003 | WARN_ONCE(1, "buf can not contain only a part of read data"); |
| 4004 | rdata->result = -EIO; |
| 4005 | dequeue_mid(mid, rdata->result); |
| 4006 | return 0; |
| 4007 | } |
| 4008 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4009 | length = rdata->copy_into_pages(server, rdata, &iter); |
| 4010 | |
| 4011 | kfree(bvec); |
| 4012 | |
| 4013 | if (length < 0) |
| 4014 | return length; |
| 4015 | |
| 4016 | dequeue_mid(mid, false); |
| 4017 | return length; |
| 4018 | } |
| 4019 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4020 | struct smb2_decrypt_work { |
| 4021 | struct work_struct decrypt; |
| 4022 | struct TCP_Server_Info *server; |
| 4023 | struct page **ppages; |
| 4024 | char *buf; |
| 4025 | unsigned int npages; |
| 4026 | unsigned int len; |
| 4027 | }; |
| 4028 | |
| 4029 | |
| 4030 | static void smb2_decrypt_offload(struct work_struct *work) |
| 4031 | { |
| 4032 | struct smb2_decrypt_work *dw = container_of(work, |
| 4033 | struct smb2_decrypt_work, decrypt); |
| 4034 | int i, rc; |
| 4035 | struct mid_q_entry *mid; |
| 4036 | |
| 4037 | rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, |
| 4038 | dw->ppages, dw->npages, dw->len); |
| 4039 | if (rc) { |
| 4040 | cifs_dbg(VFS, "error decrypting rc=%d\n", rc); |
| 4041 | goto free_pages; |
| 4042 | } |
| 4043 | |
| 4044 | mid = smb2_find_mid(dw->server, dw->buf); |
| 4045 | if (mid == NULL) |
| 4046 | cifs_dbg(FYI, "mid not found\n"); |
| 4047 | else { |
| 4048 | mid->decrypted = true; |
| 4049 | rc = handle_read_data(dw->server, mid, dw->buf, |
| 4050 | dw->server->vals->read_rsp_size, |
| 4051 | dw->ppages, dw->npages, dw->len); |
| 4052 | } |
| 4053 | |
| 4054 | dw->server->lstrp = jiffies; |
| 4055 | |
| 4056 | mid->callback(mid); |
| 4057 | |
| 4058 | cifs_mid_q_entry_release(mid); |
| 4059 | |
| 4060 | free_pages: |
| 4061 | for (i = dw->npages-1; i >= 0; i--) |
| 4062 | put_page(dw->ppages[i]); |
| 4063 | |
| 4064 | kfree(dw->ppages); |
| 4065 | cifs_small_buf_release(dw->buf); |
| 4066 | } |
| 4067 | |
| 4068 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4069 | static int |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4070 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, |
| 4071 | int *num_mids) |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4072 | { |
| 4073 | char *buf = server->smallbuf; |
| 4074 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 4075 | unsigned int npages; |
| 4076 | struct page **pages; |
| 4077 | unsigned int len; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4078 | unsigned int buflen = server->pdu_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4079 | int rc; |
| 4080 | int i = 0; |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4081 | struct smb2_decrypt_work *dw; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4082 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4083 | *num_mids = 1; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4084 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size + |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4085 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; |
| 4086 | |
| 4087 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); |
| 4088 | if (rc < 0) |
| 4089 | return rc; |
| 4090 | server->total_read += rc; |
| 4091 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4092 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) - |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 4093 | server->vals->read_rsp_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4094 | npages = DIV_ROUND_UP(len, PAGE_SIZE); |
| 4095 | |
| 4096 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 4097 | if (!pages) { |
| 4098 | rc = -ENOMEM; |
| 4099 | goto discard_data; |
| 4100 | } |
| 4101 | |
| 4102 | for (; i < npages; i++) { |
| 4103 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 4104 | if (!pages[i]) { |
| 4105 | rc = -ENOMEM; |
| 4106 | goto discard_data; |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | /* read read data into pages */ |
| 4111 | rc = read_data_into_pages(server, pages, npages, len); |
| 4112 | if (rc) |
| 4113 | goto free_pages; |
| 4114 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 4115 | rc = cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4116 | if (rc) |
| 4117 | goto free_pages; |
| 4118 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4119 | /* |
| 4120 | * For large reads, offload to different thread for better performance, |
| 4121 | * use more cores decrypting which can be expensive |
| 4122 | */ |
| 4123 | |
| 4124 | /* TODO: make the size limit to enable decrypt offload configurable */ |
| 4125 | if (server->pdu_size > (512 * 1024)) { |
| 4126 | dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL); |
| 4127 | if (dw == NULL) |
| 4128 | goto non_offloaded_decrypt; |
| 4129 | |
| 4130 | dw->buf = server->smallbuf; |
| 4131 | server->smallbuf = (char *)cifs_small_buf_get(); |
| 4132 | |
| 4133 | INIT_WORK(&dw->decrypt, smb2_decrypt_offload); |
| 4134 | |
| 4135 | dw->npages = npages; |
| 4136 | dw->server = server; |
| 4137 | dw->ppages = pages; |
| 4138 | dw->len = len; |
| 4139 | queue_work(cifsiod_wq, &dw->decrypt); |
| 4140 | *num_mids = 0; /* worker thread takes care of finding mid */ |
| 4141 | return -1; |
| 4142 | } |
| 4143 | |
| 4144 | non_offloaded_decrypt: |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4145 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4146 | pages, npages, len); |
| 4147 | if (rc) |
| 4148 | goto free_pages; |
| 4149 | |
| 4150 | *mid = smb2_find_mid(server, buf); |
| 4151 | if (*mid == NULL) |
| 4152 | cifs_dbg(FYI, "mid not found\n"); |
| 4153 | else { |
| 4154 | cifs_dbg(FYI, "mid found\n"); |
| 4155 | (*mid)->decrypted = true; |
| 4156 | rc = handle_read_data(server, *mid, buf, |
| 4157 | server->vals->read_rsp_size, |
| 4158 | pages, npages, len); |
| 4159 | } |
| 4160 | |
| 4161 | free_pages: |
| 4162 | for (i = i - 1; i >= 0; i--) |
| 4163 | put_page(pages[i]); |
| 4164 | kfree(pages); |
| 4165 | return rc; |
| 4166 | discard_data: |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 4167 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4168 | goto free_pages; |
| 4169 | } |
| 4170 | |
| 4171 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4172 | receive_encrypted_standard(struct TCP_Server_Info *server, |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4173 | struct mid_q_entry **mids, char **bufs, |
| 4174 | int *num_mids) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4175 | { |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4176 | int ret, length; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4177 | char *buf = server->smallbuf; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4178 | struct smb2_sync_hdr *shdr; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 4179 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4180 | unsigned int buf_size; |
| 4181 | struct mid_q_entry *mid_entry; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4182 | int next_is_large; |
| 4183 | char *next_buffer = NULL; |
| 4184 | |
| 4185 | *num_mids = 0; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4186 | |
| 4187 | /* switch to large buffer if too big for a small one */ |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4188 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4189 | server->large_buf = true; |
| 4190 | memcpy(server->bigbuf, buf, server->total_read); |
| 4191 | buf = server->bigbuf; |
| 4192 | } |
| 4193 | |
| 4194 | /* now read the rest */ |
| 4195 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4196 | pdu_length - HEADER_SIZE(server) + 1); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4197 | if (length < 0) |
| 4198 | return length; |
| 4199 | server->total_read += length; |
| 4200 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4201 | buf_size = pdu_length - sizeof(struct smb2_transform_hdr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4202 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); |
| 4203 | if (length) |
| 4204 | return length; |
| 4205 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4206 | next_is_large = server->large_buf; |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4207 | one_more: |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4208 | shdr = (struct smb2_sync_hdr *)buf; |
| 4209 | if (shdr->NextCommand) { |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4210 | if (next_is_large) |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4211 | next_buffer = (char *)cifs_buf_get(); |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4212 | else |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4213 | next_buffer = (char *)cifs_small_buf_get(); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4214 | memcpy(next_buffer, |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4215 | buf + le32_to_cpu(shdr->NextCommand), |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4216 | pdu_length - le32_to_cpu(shdr->NextCommand)); |
| 4217 | } |
| 4218 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4219 | mid_entry = smb2_find_mid(server, buf); |
| 4220 | if (mid_entry == NULL) |
| 4221 | cifs_dbg(FYI, "mid not found\n"); |
| 4222 | else { |
| 4223 | cifs_dbg(FYI, "mid found\n"); |
| 4224 | mid_entry->decrypted = true; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4225 | mid_entry->resp_buf_size = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4228 | if (*num_mids >= MAX_COMPOUND) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4229 | cifs_server_dbg(VFS, "too many PDUs in compound\n"); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4230 | return -1; |
| 4231 | } |
| 4232 | bufs[*num_mids] = buf; |
| 4233 | mids[(*num_mids)++] = mid_entry; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4234 | |
| 4235 | if (mid_entry && mid_entry->handle) |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4236 | ret = mid_entry->handle(server, mid_entry); |
| 4237 | else |
| 4238 | ret = cifs_handle_standard(server, mid_entry); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4239 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4240 | if (ret == 0 && shdr->NextCommand) { |
| 4241 | pdu_length -= le32_to_cpu(shdr->NextCommand); |
| 4242 | server->large_buf = next_is_large; |
| 4243 | if (next_is_large) |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4244 | server->bigbuf = buf = next_buffer; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4245 | else |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4246 | server->smallbuf = buf = next_buffer; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4247 | goto one_more; |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 4248 | } else if (ret != 0) { |
| 4249 | /* |
| 4250 | * ret != 0 here means that we didn't get to handle_mid() thus |
| 4251 | * server->smallbuf and server->bigbuf are still valid. We need |
| 4252 | * to free next_buffer because it is not going to be used |
| 4253 | * anywhere. |
| 4254 | */ |
| 4255 | if (next_is_large) |
| 4256 | free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer); |
| 4257 | else |
| 4258 | free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | return ret; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | static int |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4265 | smb3_receive_transform(struct TCP_Server_Info *server, |
| 4266 | struct mid_q_entry **mids, char **bufs, int *num_mids) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4267 | { |
| 4268 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 4269 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4270 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 4271 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 4272 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4273 | if (pdu_length < sizeof(struct smb2_transform_hdr) + |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4274 | sizeof(struct smb2_sync_hdr)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4275 | cifs_server_dbg(VFS, "Transform message is too small (%u)\n", |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4276 | pdu_length); |
| 4277 | cifs_reconnect(server); |
| 4278 | wake_up(&server->response_q); |
| 4279 | return -ECONNABORTED; |
| 4280 | } |
| 4281 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4282 | if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4283 | cifs_server_dbg(VFS, "Transform message is broken\n"); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4284 | cifs_reconnect(server); |
| 4285 | wake_up(&server->response_q); |
| 4286 | return -ECONNABORTED; |
| 4287 | } |
| 4288 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4289 | /* TODO: add support for compounds containing READ. */ |
Paul Aurich | 6d2f84e | 2018-12-31 14:13:34 -0800 | [diff] [blame] | 4290 | if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) { |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame^] | 4291 | return receive_encrypted_read(server, &mids[0], num_mids); |
Paul Aurich | 6d2f84e | 2018-12-31 14:13:34 -0800 | [diff] [blame] | 4292 | } |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4293 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 4294 | return receive_encrypted_standard(server, mids, bufs, num_mids); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | int |
| 4298 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 4299 | { |
| 4300 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 4301 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4302 | return handle_read_data(server, mid, buf, server->pdu_size, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4303 | NULL, 0, 0); |
| 4304 | } |
| 4305 | |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 4306 | static int |
| 4307 | smb2_next_header(char *buf) |
| 4308 | { |
| 4309 | struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf; |
| 4310 | struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf; |
| 4311 | |
| 4312 | if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) |
| 4313 | return sizeof(struct smb2_transform_hdr) + |
| 4314 | le32_to_cpu(t_hdr->OriginalMessageSize); |
| 4315 | |
| 4316 | return le32_to_cpu(hdr->NextCommand); |
| 4317 | } |
| 4318 | |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 4319 | static int |
| 4320 | smb2_make_node(unsigned int xid, struct inode *inode, |
| 4321 | struct dentry *dentry, struct cifs_tcon *tcon, |
| 4322 | char *full_path, umode_t mode, dev_t dev) |
| 4323 | { |
| 4324 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 4325 | int rc = -EPERM; |
| 4326 | int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL; |
| 4327 | FILE_ALL_INFO *buf = NULL; |
| 4328 | struct cifs_io_parms io_parms; |
| 4329 | __u32 oplock = 0; |
| 4330 | struct cifs_fid fid; |
| 4331 | struct cifs_open_parms oparms; |
| 4332 | unsigned int bytes_written; |
| 4333 | struct win_dev *pdev; |
| 4334 | struct kvec iov[2]; |
| 4335 | |
| 4336 | /* |
| 4337 | * Check if mounted with mount parm 'sfu' mount parm. |
| 4338 | * SFU emulation should work with all servers, but only |
| 4339 | * supports block and char device (no socket & fifo), |
| 4340 | * and was used by default in earlier versions of Windows |
| 4341 | */ |
| 4342 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) |
| 4343 | goto out; |
| 4344 | |
| 4345 | /* |
| 4346 | * TODO: Add ability to create instead via reparse point. Windows (e.g. |
| 4347 | * their current NFS server) uses this approach to expose special files |
| 4348 | * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions |
| 4349 | */ |
| 4350 | |
| 4351 | if (!S_ISCHR(mode) && !S_ISBLK(mode)) |
| 4352 | goto out; |
| 4353 | |
| 4354 | cifs_dbg(FYI, "sfu compat create special file\n"); |
| 4355 | |
| 4356 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 4357 | if (buf == NULL) { |
| 4358 | rc = -ENOMEM; |
| 4359 | goto out; |
| 4360 | } |
| 4361 | |
| 4362 | if (backup_cred(cifs_sb)) |
| 4363 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
| 4364 | |
| 4365 | oparms.tcon = tcon; |
| 4366 | oparms.cifs_sb = cifs_sb; |
| 4367 | oparms.desired_access = GENERIC_WRITE; |
| 4368 | oparms.create_options = create_options; |
| 4369 | oparms.disposition = FILE_CREATE; |
| 4370 | oparms.path = full_path; |
| 4371 | oparms.fid = &fid; |
| 4372 | oparms.reconnect = false; |
| 4373 | |
| 4374 | if (tcon->ses->server->oplocks) |
| 4375 | oplock = REQ_OPLOCK; |
| 4376 | else |
| 4377 | oplock = 0; |
| 4378 | rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf); |
| 4379 | if (rc) |
| 4380 | goto out; |
| 4381 | |
| 4382 | /* |
| 4383 | * BB Do not bother to decode buf since no local inode yet to put |
| 4384 | * timestamps in, but we can reuse it safely. |
| 4385 | */ |
| 4386 | |
| 4387 | pdev = (struct win_dev *)buf; |
| 4388 | io_parms.pid = current->tgid; |
| 4389 | io_parms.tcon = tcon; |
| 4390 | io_parms.offset = 0; |
| 4391 | io_parms.length = sizeof(struct win_dev); |
| 4392 | iov[1].iov_base = buf; |
| 4393 | iov[1].iov_len = sizeof(struct win_dev); |
| 4394 | if (S_ISCHR(mode)) { |
| 4395 | memcpy(pdev->type, "IntxCHR", 8); |
| 4396 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 4397 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 4398 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 4399 | &bytes_written, iov, 1); |
| 4400 | } else if (S_ISBLK(mode)) { |
| 4401 | memcpy(pdev->type, "IntxBLK", 8); |
| 4402 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 4403 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 4404 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 4405 | &bytes_written, iov, 1); |
| 4406 | } |
| 4407 | tcon->ses->server->ops->close(xid, tcon, &fid); |
| 4408 | d_drop(dentry); |
| 4409 | |
| 4410 | /* FIXME: add code here to set EAs */ |
| 4411 | out: |
| 4412 | kfree(buf); |
| 4413 | return rc; |
| 4414 | } |
| 4415 | |
| 4416 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4417 | struct smb_version_operations smb20_operations = { |
| 4418 | .compare_fids = smb2_compare_fids, |
| 4419 | .setup_request = smb2_setup_request, |
| 4420 | .setup_async_request = smb2_setup_async_request, |
| 4421 | .check_receive = smb2_check_receive, |
| 4422 | .add_credits = smb2_add_credits, |
| 4423 | .set_credits = smb2_set_credits, |
| 4424 | .get_credits_field = smb2_get_credits_field, |
| 4425 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 4426 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4427 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 4428 | .revert_current_mid = smb2_revert_current_mid, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4429 | .read_data_offset = smb2_read_data_offset, |
| 4430 | .read_data_length = smb2_read_data_length, |
| 4431 | .map_error = map_smb2_to_linux_error, |
| 4432 | .find_mid = smb2_find_mid, |
| 4433 | .check_message = smb2_check_message, |
| 4434 | .dump_detail = smb2_dump_detail, |
| 4435 | .clear_stats = smb2_clear_stats, |
| 4436 | .print_stats = smb2_print_stats, |
| 4437 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 4438 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 4439 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4440 | .need_neg = smb2_need_neg, |
| 4441 | .negotiate = smb2_negotiate, |
| 4442 | .negotiate_wsize = smb2_negotiate_wsize, |
| 4443 | .negotiate_rsize = smb2_negotiate_rsize, |
| 4444 | .sess_setup = SMB2_sess_setup, |
| 4445 | .logoff = SMB2_logoff, |
| 4446 | .tree_connect = SMB2_tcon, |
| 4447 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 4448 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4449 | .is_path_accessible = smb2_is_path_accessible, |
| 4450 | .can_echo = smb2_can_echo, |
| 4451 | .echo = SMB2_echo, |
| 4452 | .query_path_info = smb2_query_path_info, |
| 4453 | .get_srv_inum = smb2_get_srv_inum, |
| 4454 | .query_file_info = smb2_query_file_info, |
| 4455 | .set_path_size = smb2_set_path_size, |
| 4456 | .set_file_size = smb2_set_file_size, |
| 4457 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 4458 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4459 | .mkdir = smb2_mkdir, |
| 4460 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 4461 | .rmdir = smb2_rmdir, |
| 4462 | .unlink = smb2_unlink, |
| 4463 | .rename = smb2_rename_path, |
| 4464 | .create_hardlink = smb2_create_hardlink, |
| 4465 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 4466 | .query_mf_symlink = smb3_query_mf_symlink, |
| 4467 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4468 | .open = smb2_open_file, |
| 4469 | .set_fid = smb2_set_fid, |
| 4470 | .close = smb2_close_file, |
| 4471 | .flush = smb2_flush_file, |
| 4472 | .async_readv = smb2_async_readv, |
| 4473 | .async_writev = smb2_async_writev, |
| 4474 | .sync_read = smb2_sync_read, |
| 4475 | .sync_write = smb2_sync_write, |
| 4476 | .query_dir_first = smb2_query_dir_first, |
| 4477 | .query_dir_next = smb2_query_dir_next, |
| 4478 | .close_dir = smb2_close_dir, |
| 4479 | .calc_smb_size = smb2_calc_size, |
| 4480 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4481 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4482 | .oplock_response = smb2_oplock_response, |
| 4483 | .queryfs = smb2_queryfs, |
| 4484 | .mand_lock = smb2_mand_lock, |
| 4485 | .mand_unlock_range = smb2_unlock_range, |
| 4486 | .push_mand_locks = smb2_push_mandatory_locks, |
| 4487 | .get_lease_key = smb2_get_lease_key, |
| 4488 | .set_lease_key = smb2_set_lease_key, |
| 4489 | .new_lease_key = smb2_new_lease_key, |
| 4490 | .calc_signature = smb2_calc_signature, |
| 4491 | .is_read_op = smb2_is_read_op, |
| 4492 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4493 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 4494 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 4495 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 4496 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 4497 | .dir_needs_close = smb2_dir_needs_close, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 4498 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 4499 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4500 | #ifdef CONFIG_CIFS_XATTR |
| 4501 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 4502 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4503 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 4504 | .get_acl = get_smb2_acl, |
| 4505 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 4506 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 4507 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 4508 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 4509 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4510 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 4511 | .llseek = smb3_llseek, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4512 | }; |
| 4513 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 4514 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 4515 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 4516 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 4517 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 4518 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 4519 | .add_credits = smb2_add_credits, |
| 4520 | .set_credits = smb2_set_credits, |
| 4521 | .get_credits_field = smb2_get_credits_field, |
| 4522 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 4523 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 4524 | .adjust_credits = smb2_adjust_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 4525 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 4526 | .revert_current_mid = smb2_revert_current_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 4527 | .read_data_offset = smb2_read_data_offset, |
| 4528 | .read_data_length = smb2_read_data_length, |
| 4529 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 4530 | .find_mid = smb2_find_mid, |
| 4531 | .check_message = smb2_check_message, |
| 4532 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 4533 | .clear_stats = smb2_clear_stats, |
| 4534 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 4535 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 4536 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 4537 | .downgrade_oplock = smb21_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 4538 | .need_neg = smb2_need_neg, |
| 4539 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 4540 | .negotiate_wsize = smb2_negotiate_wsize, |
| 4541 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 4542 | .sess_setup = SMB2_sess_setup, |
| 4543 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 4544 | .tree_connect = SMB2_tcon, |
| 4545 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 4546 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 4547 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 4548 | .can_echo = smb2_can_echo, |
| 4549 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 4550 | .query_path_info = smb2_query_path_info, |
| 4551 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 4552 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 4553 | .set_path_size = smb2_set_path_size, |
| 4554 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 4555 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 4556 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 4557 | .mkdir = smb2_mkdir, |
| 4558 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 4559 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 4560 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 4561 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 4562 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 4563 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 4564 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 4565 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 4566 | .open = smb2_open_file, |
| 4567 | .set_fid = smb2_set_fid, |
| 4568 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 4569 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 4570 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 4571 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 4572 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 4573 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 4574 | .query_dir_first = smb2_query_dir_first, |
| 4575 | .query_dir_next = smb2_query_dir_next, |
| 4576 | .close_dir = smb2_close_dir, |
| 4577 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 4578 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4579 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 4580 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 4581 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 4582 | .mand_lock = smb2_mand_lock, |
| 4583 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 4584 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 4585 | .get_lease_key = smb2_get_lease_key, |
| 4586 | .set_lease_key = smb2_set_lease_key, |
| 4587 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4588 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4589 | .is_read_op = smb21_is_read_op, |
| 4590 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4591 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 4592 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 4593 | .copychunk_range = smb2_copychunk_range, |
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 | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 4596 | .enum_snapshots = smb3_enum_snapshots, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 4597 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 4598 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4599 | #ifdef CONFIG_CIFS_XATTR |
| 4600 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 4601 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4602 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 4603 | .get_acl = get_smb2_acl, |
| 4604 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 4605 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 4606 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 4607 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 4608 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4609 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 4610 | .llseek = smb3_llseek, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4611 | }; |
| 4612 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4613 | struct smb_version_operations smb30_operations = { |
| 4614 | .compare_fids = smb2_compare_fids, |
| 4615 | .setup_request = smb2_setup_request, |
| 4616 | .setup_async_request = smb2_setup_async_request, |
| 4617 | .check_receive = smb2_check_receive, |
| 4618 | .add_credits = smb2_add_credits, |
| 4619 | .set_credits = smb2_set_credits, |
| 4620 | .get_credits_field = smb2_get_credits_field, |
| 4621 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 4622 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 4623 | .adjust_credits = smb2_adjust_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4624 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 4625 | .revert_current_mid = smb2_revert_current_mid, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4626 | .read_data_offset = smb2_read_data_offset, |
| 4627 | .read_data_length = smb2_read_data_length, |
| 4628 | .map_error = map_smb2_to_linux_error, |
| 4629 | .find_mid = smb2_find_mid, |
| 4630 | .check_message = smb2_check_message, |
| 4631 | .dump_detail = smb2_dump_detail, |
| 4632 | .clear_stats = smb2_clear_stats, |
| 4633 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 4634 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4635 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 4636 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 4637 | .downgrade_oplock = smb21_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4638 | .need_neg = smb2_need_neg, |
| 4639 | .negotiate = smb2_negotiate, |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 4640 | .negotiate_wsize = smb3_negotiate_wsize, |
| 4641 | .negotiate_rsize = smb3_negotiate_rsize, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4642 | .sess_setup = SMB2_sess_setup, |
| 4643 | .logoff = SMB2_logoff, |
| 4644 | .tree_connect = SMB2_tcon, |
| 4645 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 4646 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4647 | .is_path_accessible = smb2_is_path_accessible, |
| 4648 | .can_echo = smb2_can_echo, |
| 4649 | .echo = SMB2_echo, |
| 4650 | .query_path_info = smb2_query_path_info, |
| 4651 | .get_srv_inum = smb2_get_srv_inum, |
| 4652 | .query_file_info = smb2_query_file_info, |
| 4653 | .set_path_size = smb2_set_path_size, |
| 4654 | .set_file_size = smb2_set_file_size, |
| 4655 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 4656 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4657 | .mkdir = smb2_mkdir, |
| 4658 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 4659 | .rmdir = smb2_rmdir, |
| 4660 | .unlink = smb2_unlink, |
| 4661 | .rename = smb2_rename_path, |
| 4662 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 4663 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 4664 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 4665 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4666 | .open = smb2_open_file, |
| 4667 | .set_fid = smb2_set_fid, |
| 4668 | .close = smb2_close_file, |
| 4669 | .flush = smb2_flush_file, |
| 4670 | .async_readv = smb2_async_readv, |
| 4671 | .async_writev = smb2_async_writev, |
| 4672 | .sync_read = smb2_sync_read, |
| 4673 | .sync_write = smb2_sync_write, |
| 4674 | .query_dir_first = smb2_query_dir_first, |
| 4675 | .query_dir_next = smb2_query_dir_next, |
| 4676 | .close_dir = smb2_close_dir, |
| 4677 | .calc_smb_size = smb2_calc_size, |
| 4678 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4679 | .is_session_expired = smb2_is_session_expired, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4680 | .oplock_response = smb2_oplock_response, |
| 4681 | .queryfs = smb2_queryfs, |
| 4682 | .mand_lock = smb2_mand_lock, |
| 4683 | .mand_unlock_range = smb2_unlock_range, |
| 4684 | .push_mand_locks = smb2_push_mandatory_locks, |
| 4685 | .get_lease_key = smb2_get_lease_key, |
| 4686 | .set_lease_key = smb2_set_lease_key, |
| 4687 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 4688 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 4689 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 4690 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4691 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4692 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4693 | .create_lease_buf = smb3_create_lease_buf, |
| 4694 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 4695 | .copychunk_range = smb2_copychunk_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 4696 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 4697 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 4698 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 4699 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 4700 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 4701 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4702 | .init_transform_rq = smb3_init_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4703 | .is_transform_hdr = smb3_is_transform_hdr, |
| 4704 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 4705 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 4706 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4707 | #ifdef CONFIG_CIFS_XATTR |
| 4708 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 4709 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4710 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 4711 | .get_acl = get_smb2_acl, |
| 4712 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 4713 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 4714 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 4715 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 4716 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4717 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 4718 | .llseek = smb3_llseek, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 4719 | }; |
| 4720 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4721 | struct smb_version_operations smb311_operations = { |
| 4722 | .compare_fids = smb2_compare_fids, |
| 4723 | .setup_request = smb2_setup_request, |
| 4724 | .setup_async_request = smb2_setup_async_request, |
| 4725 | .check_receive = smb2_check_receive, |
| 4726 | .add_credits = smb2_add_credits, |
| 4727 | .set_credits = smb2_set_credits, |
| 4728 | .get_credits_field = smb2_get_credits_field, |
| 4729 | .get_credits = smb2_get_credits, |
| 4730 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 4731 | .adjust_credits = smb2_adjust_credits, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4732 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 4733 | .revert_current_mid = smb2_revert_current_mid, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4734 | .read_data_offset = smb2_read_data_offset, |
| 4735 | .read_data_length = smb2_read_data_length, |
| 4736 | .map_error = map_smb2_to_linux_error, |
| 4737 | .find_mid = smb2_find_mid, |
| 4738 | .check_message = smb2_check_message, |
| 4739 | .dump_detail = smb2_dump_detail, |
| 4740 | .clear_stats = smb2_clear_stats, |
| 4741 | .print_stats = smb2_print_stats, |
| 4742 | .dump_share_caps = smb2_dump_share_caps, |
| 4743 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 4744 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 4745 | .downgrade_oplock = smb21_downgrade_oplock, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4746 | .need_neg = smb2_need_neg, |
| 4747 | .negotiate = smb2_negotiate, |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 4748 | .negotiate_wsize = smb3_negotiate_wsize, |
| 4749 | .negotiate_rsize = smb3_negotiate_rsize, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4750 | .sess_setup = SMB2_sess_setup, |
| 4751 | .logoff = SMB2_logoff, |
| 4752 | .tree_connect = SMB2_tcon, |
| 4753 | .tree_disconnect = SMB2_tdis, |
| 4754 | .qfs_tcon = smb3_qfs_tcon, |
| 4755 | .is_path_accessible = smb2_is_path_accessible, |
| 4756 | .can_echo = smb2_can_echo, |
| 4757 | .echo = SMB2_echo, |
| 4758 | .query_path_info = smb2_query_path_info, |
| 4759 | .get_srv_inum = smb2_get_srv_inum, |
| 4760 | .query_file_info = smb2_query_file_info, |
| 4761 | .set_path_size = smb2_set_path_size, |
| 4762 | .set_file_size = smb2_set_file_size, |
| 4763 | .set_file_info = smb2_set_file_info, |
| 4764 | .set_compression = smb2_set_compression, |
| 4765 | .mkdir = smb2_mkdir, |
| 4766 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Steve French | bea851b | 2018-06-14 21:56:32 -0500 | [diff] [blame] | 4767 | .posix_mkdir = smb311_posix_mkdir, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4768 | .rmdir = smb2_rmdir, |
| 4769 | .unlink = smb2_unlink, |
| 4770 | .rename = smb2_rename_path, |
| 4771 | .create_hardlink = smb2_create_hardlink, |
| 4772 | .query_symlink = smb2_query_symlink, |
| 4773 | .query_mf_symlink = smb3_query_mf_symlink, |
| 4774 | .create_mf_symlink = smb3_create_mf_symlink, |
| 4775 | .open = smb2_open_file, |
| 4776 | .set_fid = smb2_set_fid, |
| 4777 | .close = smb2_close_file, |
| 4778 | .flush = smb2_flush_file, |
| 4779 | .async_readv = smb2_async_readv, |
| 4780 | .async_writev = smb2_async_writev, |
| 4781 | .sync_read = smb2_sync_read, |
| 4782 | .sync_write = smb2_sync_write, |
| 4783 | .query_dir_first = smb2_query_dir_first, |
| 4784 | .query_dir_next = smb2_query_dir_next, |
| 4785 | .close_dir = smb2_close_dir, |
| 4786 | .calc_smb_size = smb2_calc_size, |
| 4787 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4788 | .is_session_expired = smb2_is_session_expired, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4789 | .oplock_response = smb2_oplock_response, |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 4790 | .queryfs = smb311_queryfs, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4791 | .mand_lock = smb2_mand_lock, |
| 4792 | .mand_unlock_range = smb2_unlock_range, |
| 4793 | .push_mand_locks = smb2_push_mandatory_locks, |
| 4794 | .get_lease_key = smb2_get_lease_key, |
| 4795 | .set_lease_key = smb2_set_lease_key, |
| 4796 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 4797 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4798 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 4799 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4800 | .is_read_op = smb21_is_read_op, |
| 4801 | .set_oplock_level = smb3_set_oplock_level, |
| 4802 | .create_lease_buf = smb3_create_lease_buf, |
| 4803 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 4804 | .copychunk_range = smb2_copychunk_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 4805 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4806 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 4807 | .wp_retry_size = smb2_wp_retry_size, |
| 4808 | .dir_needs_close = smb2_dir_needs_close, |
| 4809 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 4810 | .enum_snapshots = smb3_enum_snapshots, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4811 | .init_transform_rq = smb3_init_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4812 | .is_transform_hdr = smb3_is_transform_hdr, |
| 4813 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 4814 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 4815 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4816 | #ifdef CONFIG_CIFS_XATTR |
| 4817 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 4818 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 4819 | #endif /* CIFS_XATTR */ |
Ronnie Sahlberg | c1777df | 2018-08-10 11:03:55 +1000 | [diff] [blame] | 4820 | .get_acl = get_smb2_acl, |
| 4821 | .get_acl_by_fid = get_smb2_acl_by_fid, |
| 4822 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 4823 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 4824 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 4825 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4826 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 4827 | .llseek = smb3_llseek, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4828 | }; |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 4829 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 4830 | struct smb_version_values smb20_values = { |
| 4831 | .version_string = SMB20_VERSION_STRING, |
| 4832 | .protocol_id = SMB20_PROT_ID, |
| 4833 | .req_capabilities = 0, /* MBZ */ |
| 4834 | .large_lock_type = 0, |
| 4835 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4836 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4837 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4838 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4839 | .header_preamble_size = 0, |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 4840 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4841 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4842 | .lock_cmd = SMB2_LOCK, |
| 4843 | .cap_unix = 0, |
| 4844 | .cap_nt_find = SMB2_NT_FIND, |
| 4845 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 4846 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4847 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4848 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 4849 | }; |
| 4850 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 4851 | struct smb_version_values smb21_values = { |
| 4852 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 4853 | .protocol_id = SMB21_PROT_ID, |
| 4854 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 4855 | .large_lock_type = 0, |
| 4856 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4857 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4858 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4859 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4860 | .header_preamble_size = 0, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 4861 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4862 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4863 | .lock_cmd = SMB2_LOCK, |
| 4864 | .cap_unix = 0, |
| 4865 | .cap_nt_find = SMB2_NT_FIND, |
| 4866 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 4867 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4868 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4869 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 4870 | }; |
| 4871 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 4872 | struct smb_version_values smb3any_values = { |
| 4873 | .version_string = SMB3ANY_VERSION_STRING, |
| 4874 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 4875 | .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] | 4876 | .large_lock_type = 0, |
| 4877 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4878 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4879 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4880 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4881 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 4882 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4883 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4884 | .lock_cmd = SMB2_LOCK, |
| 4885 | .cap_unix = 0, |
| 4886 | .cap_nt_find = SMB2_NT_FIND, |
| 4887 | .cap_large_files = SMB2_LARGE_FILES, |
| 4888 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4889 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4890 | .create_lease_size = sizeof(struct create_lease_v2), |
| 4891 | }; |
| 4892 | |
| 4893 | struct smb_version_values smbdefault_values = { |
| 4894 | .version_string = SMBDEFAULT_VERSION_STRING, |
| 4895 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 4896 | .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] | 4897 | .large_lock_type = 0, |
| 4898 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4899 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4900 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4901 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4902 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 4903 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4904 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4905 | .lock_cmd = SMB2_LOCK, |
| 4906 | .cap_unix = 0, |
| 4907 | .cap_nt_find = SMB2_NT_FIND, |
| 4908 | .cap_large_files = SMB2_LARGE_FILES, |
| 4909 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4910 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4911 | .create_lease_size = sizeof(struct create_lease_v2), |
| 4912 | }; |
| 4913 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 4914 | struct smb_version_values smb30_values = { |
| 4915 | .version_string = SMB30_VERSION_STRING, |
| 4916 | .protocol_id = SMB30_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 4917 | .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] | 4918 | .large_lock_type = 0, |
| 4919 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4920 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4921 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4922 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4923 | .header_preamble_size = 0, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 4924 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 4925 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 4926 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 4927 | .cap_unix = 0, |
| 4928 | .cap_nt_find = SMB2_NT_FIND, |
| 4929 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 4930 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4931 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4932 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 4933 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 4934 | |
| 4935 | struct smb_version_values smb302_values = { |
| 4936 | .version_string = SMB302_VERSION_STRING, |
| 4937 | .protocol_id = SMB302_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 4938 | .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] | 4939 | .large_lock_type = 0, |
| 4940 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4941 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4942 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4943 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4944 | .header_preamble_size = 0, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 4945 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4946 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4947 | .lock_cmd = SMB2_LOCK, |
| 4948 | .cap_unix = 0, |
| 4949 | .cap_nt_find = SMB2_NT_FIND, |
| 4950 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 4951 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4952 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4953 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 4954 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 4955 | |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 4956 | struct smb_version_values smb311_values = { |
| 4957 | .version_string = SMB311_VERSION_STRING, |
| 4958 | .protocol_id = SMB311_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 4959 | .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] | 4960 | .large_lock_type = 0, |
| 4961 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 4962 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 4963 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4964 | .header_size = sizeof(struct smb2_sync_hdr), |
| 4965 | .header_preamble_size = 0, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 4966 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 4967 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 4968 | .lock_cmd = SMB2_LOCK, |
| 4969 | .cap_unix = 0, |
| 4970 | .cap_nt_find = SMB2_NT_FIND, |
| 4971 | .cap_large_files = SMB2_LARGE_FILES, |
| 4972 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4973 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 4974 | .create_lease_size = sizeof(struct create_lease_v2), |
| 4975 | }; |