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