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