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