Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 2 | /* |
| 3 | * SMB2 version specific operations |
| 4 | * |
| 5 | * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com> |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 8 | #include <linux/pagemap.h> |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 9 | #include <linux/vfs.h> |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 10 | #include <linux/falloc.h> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 11 | #include <linux/scatterlist.h> |
Tobias Regnery | 4fa8e50 | 2017-03-30 12:34:14 +0200 | [diff] [blame] | 12 | #include <linux/uuid.h> |
Aurelien Aptel | 35adffe | 2019-09-20 06:29:39 +0200 | [diff] [blame] | 13 | #include <linux/sort.h> |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 14 | #include <crypto/aead.h> |
Christoph Hellwig | 10c5db2 | 2020-05-23 09:30:11 +0200 | [diff] [blame] | 15 | #include <linux/fiemap.h> |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 16 | #include "cifsfs.h" |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 17 | #include "cifsglob.h" |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 18 | #include "smb2pdu.h" |
| 19 | #include "smb2proto.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 20 | #include "cifsproto.h" |
| 21 | #include "cifs_debug.h" |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 22 | #include "cifs_unicode.h" |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 23 | #include "smb2status.h" |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 24 | #include "smb2glob.h" |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 25 | #include "cifs_ioctl.h" |
Long Li | 09902f8 | 2017-11-22 17:38:39 -0700 | [diff] [blame] | 26 | #include "smbdirect.h" |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 27 | #include "fs_context.h" |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 28 | |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 29 | /* Change credits for different ops and return the total number of credits */ |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 30 | static int |
| 31 | change_conf(struct TCP_Server_Info *server) |
| 32 | { |
| 33 | server->credits += server->echo_credits + server->oplock_credits; |
| 34 | server->oplock_credits = server->echo_credits = 0; |
| 35 | switch (server->credits) { |
| 36 | case 0: |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 37 | return 0; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 38 | case 1: |
| 39 | server->echoes = false; |
| 40 | server->oplocks = false; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 41 | break; |
| 42 | case 2: |
| 43 | server->echoes = true; |
| 44 | server->oplocks = false; |
| 45 | server->echo_credits = 1; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 46 | break; |
| 47 | default: |
| 48 | server->echoes = true; |
Steve French | e0ddde9 | 2015-09-22 09:29:38 -0500 | [diff] [blame] | 49 | if (enable_oplocks) { |
| 50 | server->oplocks = true; |
| 51 | server->oplock_credits = 1; |
| 52 | } else |
| 53 | server->oplocks = false; |
| 54 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 55 | server->echo_credits = 1; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 56 | } |
| 57 | server->credits -= server->echo_credits + server->oplock_credits; |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 58 | return server->credits + server->echo_credits + server->oplock_credits; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static void |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 62 | smb2_add_credits(struct TCP_Server_Info *server, |
| 63 | const struct cifs_credits *credits, const int optype) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 64 | { |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 65 | int *val, rc = -1; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 66 | int scredits, in_flight; |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 67 | unsigned int add = credits->value; |
| 68 | unsigned int instance = credits->instance; |
| 69 | bool reconnect_detected = false; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 70 | bool reconnect_with_invalid_credits = false; |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 71 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 72 | spin_lock(&server->req_lock); |
| 73 | val = server->ops->get_credits_field(server, optype); |
Steve French | b340a4d | 2018-09-01 01:10:17 -0500 | [diff] [blame] | 74 | |
| 75 | /* eg found case where write overlapping reconnect messed up credits */ |
| 76 | if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0)) |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 77 | reconnect_with_invalid_credits = true; |
| 78 | |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 79 | if ((instance == 0) || (instance == server->reconnect_instance)) |
| 80 | *val += add; |
| 81 | else |
| 82 | reconnect_detected = true; |
Steve French | b340a4d | 2018-09-01 01:10:17 -0500 | [diff] [blame] | 83 | |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 84 | if (*val > 65000) { |
| 85 | *val = 65000; /* Don't get near 64K credits, avoid srv bugs */ |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 86 | pr_warn_once("server overflowed SMB3 credits\n"); |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 87 | } |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 88 | server->in_flight--; |
Shyam Prasad N | 0f56db8 | 2021-02-03 22:49:52 -0800 | [diff] [blame] | 89 | if (server->in_flight == 0 && |
| 90 | ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) && |
| 91 | ((optype & CIFS_OP_MASK) != CIFS_SESS_OP)) |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 92 | rc = change_conf(server); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 93 | /* |
| 94 | * Sometimes server returns 0 credits on oplock break ack - we need to |
| 95 | * rebalance credits in this case. |
| 96 | */ |
| 97 | else if (server->in_flight > 0 && server->oplock_credits == 0 && |
| 98 | server->oplocks) { |
| 99 | if (server->credits > 1) { |
| 100 | server->credits--; |
| 101 | server->oplock_credits++; |
| 102 | } |
| 103 | } |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 104 | scredits = *val; |
| 105 | in_flight = server->in_flight; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 106 | spin_unlock(&server->req_lock); |
| 107 | wake_up(&server->request_q); |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 108 | |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 109 | if (reconnect_detected) { |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 110 | trace_smb3_reconnect_detected(server->CurrentMid, |
| 111 | server->conn_id, server->hostname, scredits, add, in_flight); |
| 112 | |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 113 | cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n", |
| 114 | add, instance); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 115 | } |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 116 | |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 117 | if (reconnect_with_invalid_credits) { |
| 118 | trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, |
| 119 | server->conn_id, server->hostname, scredits, add, in_flight); |
| 120 | cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n", |
| 121 | optype, scredits, add); |
| 122 | } |
| 123 | |
Pavel Shilovsky | 82e0457 | 2019-01-25 10:56:41 -0800 | [diff] [blame] | 124 | if (server->tcpStatus == CifsNeedReconnect |
| 125 | || server->tcpStatus == CifsExiting) |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 126 | return; |
| 127 | |
| 128 | switch (rc) { |
| 129 | case -1: |
| 130 | /* change_conf hasn't been executed */ |
| 131 | break; |
| 132 | case 0: |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 133 | cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n"); |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 134 | break; |
| 135 | case 1: |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 136 | cifs_server_dbg(VFS, "disabling echoes and oplocks\n"); |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 137 | break; |
| 138 | case 2: |
| 139 | cifs_dbg(FYI, "disabling oplocks\n"); |
| 140 | break; |
| 141 | default: |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 142 | /* change_conf rebalanced credits for different types */ |
| 143 | break; |
Pavel Shilovsky | ef68e83 | 2019-01-18 17:25:36 -0800 | [diff] [blame] | 144 | } |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 145 | |
| 146 | trace_smb3_add_credits(server->CurrentMid, |
| 147 | server->conn_id, server->hostname, scredits, add, in_flight); |
| 148 | cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void |
| 152 | smb2_set_credits(struct TCP_Server_Info *server, const int val) |
| 153 | { |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 154 | int scredits, in_flight; |
| 155 | |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 156 | spin_lock(&server->req_lock); |
| 157 | server->credits = val; |
Steve French | 9e1a37d | 2018-09-19 02:38:17 -0500 | [diff] [blame] | 158 | if (val == 1) |
| 159 | server->reconnect_instance++; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 160 | scredits = server->credits; |
| 161 | in_flight = server->in_flight; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 162 | spin_unlock(&server->req_lock); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 163 | |
| 164 | trace_smb3_set_credits(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 165 | server->conn_id, server->hostname, scredits, val, in_flight); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 166 | cifs_dbg(FYI, "%s: set %u credits\n", __func__, val); |
| 167 | |
Steve French | 6e4d3bb | 2018-09-22 11:25:04 -0500 | [diff] [blame] | 168 | /* don't log while holding the lock */ |
| 169 | if (val == 1) |
| 170 | cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n"); |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static int * |
| 174 | smb2_get_credits_field(struct TCP_Server_Info *server, const int optype) |
| 175 | { |
| 176 | switch (optype) { |
| 177 | case CIFS_ECHO_OP: |
| 178 | return &server->echo_credits; |
| 179 | case CIFS_OBREAK_OP: |
| 180 | return &server->oplock_credits; |
| 181 | default: |
| 182 | return &server->credits; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | static unsigned int |
| 187 | smb2_get_credits(struct mid_q_entry *mid) |
| 188 | { |
Pavel Shilovsky | 86a7964 | 2019-11-21 11:35:13 -0800 | [diff] [blame] | 189 | return mid->credits_received; |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 190 | } |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 191 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 192 | static int |
| 193 | smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size, |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 194 | unsigned int *num, struct cifs_credits *credits) |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 195 | { |
| 196 | int rc = 0; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 197 | unsigned int scredits, in_flight; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 198 | |
| 199 | spin_lock(&server->req_lock); |
| 200 | while (1) { |
| 201 | if (server->credits <= 0) { |
| 202 | spin_unlock(&server->req_lock); |
| 203 | cifs_num_waiters_inc(server); |
| 204 | rc = wait_event_killable(server->request_q, |
Ronnie Sahlberg | b227d21 | 2019-03-08 12:58:20 +1000 | [diff] [blame] | 205 | has_credits(server, &server->credits, 1)); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 206 | cifs_num_waiters_dec(server); |
| 207 | if (rc) |
| 208 | return rc; |
| 209 | spin_lock(&server->req_lock); |
| 210 | } else { |
| 211 | if (server->tcpStatus == CifsExiting) { |
| 212 | spin_unlock(&server->req_lock); |
| 213 | return -ENOENT; |
| 214 | } |
| 215 | |
| 216 | scredits = server->credits; |
| 217 | /* can deadlock with reopen */ |
Pavel Shilovsky | acc58d0 | 2019-01-17 08:21:24 -0800 | [diff] [blame] | 218 | if (scredits <= 8) { |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 219 | *num = SMB2_MAX_BUFFER_SIZE; |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 220 | credits->value = 0; |
| 221 | credits->instance = 0; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | |
Pavel Shilovsky | acc58d0 | 2019-01-17 08:21:24 -0800 | [diff] [blame] | 225 | /* leave some credits for reopen and other ops */ |
| 226 | scredits -= 8; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 227 | *num = min_t(unsigned int, size, |
| 228 | scredits * SMB2_MAX_BUFFER_SIZE); |
| 229 | |
Pavel Shilovsky | 335b7b6 | 2019-01-16 11:12:41 -0800 | [diff] [blame] | 230 | credits->value = |
| 231 | DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE); |
| 232 | credits->instance = server->reconnect_instance; |
| 233 | server->credits -= credits->value; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 234 | server->in_flight++; |
Steve French | 1b63f18 | 2019-09-09 22:57:11 -0500 | [diff] [blame] | 235 | if (server->in_flight > server->max_in_flight) |
| 236 | server->max_in_flight = server->in_flight; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | } |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 240 | scredits = server->credits; |
| 241 | in_flight = server->in_flight; |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 242 | spin_unlock(&server->req_lock); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 243 | |
| 244 | trace_smb3_add_credits(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 245 | server->conn_id, server->hostname, scredits, -(credits->value), in_flight); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 246 | cifs_dbg(FYI, "%s: removed %u credits total=%d\n", |
| 247 | __func__, credits->value, scredits); |
| 248 | |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 249 | return rc; |
| 250 | } |
| 251 | |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 252 | static int |
| 253 | smb2_adjust_credits(struct TCP_Server_Info *server, |
| 254 | struct cifs_credits *credits, |
| 255 | const unsigned int payload_size) |
| 256 | { |
| 257 | int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE); |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 258 | int scredits, in_flight; |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 259 | |
| 260 | if (!credits->value || credits->value == new_val) |
| 261 | return 0; |
| 262 | |
| 263 | if (credits->value < new_val) { |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 264 | trace_smb3_too_many_credits(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 265 | server->conn_id, server->hostname, 0, credits->value - new_val, 0); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 266 | cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)", |
| 267 | credits->value, new_val); |
| 268 | |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 269 | return -ENOTSUPP; |
| 270 | } |
| 271 | |
| 272 | spin_lock(&server->req_lock); |
| 273 | |
| 274 | if (server->reconnect_instance != credits->instance) { |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 275 | scredits = server->credits; |
| 276 | in_flight = server->in_flight; |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 277 | spin_unlock(&server->req_lock); |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 278 | |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 279 | trace_smb3_reconnect_detected(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 280 | server->conn_id, server->hostname, scredits, |
| 281 | credits->value - new_val, in_flight); |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 282 | 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] | 283 | credits->value - new_val); |
| 284 | return -EAGAIN; |
| 285 | } |
| 286 | |
| 287 | server->credits += credits->value - new_val; |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 288 | scredits = server->credits; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 289 | in_flight = server->in_flight; |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 290 | spin_unlock(&server->req_lock); |
| 291 | wake_up(&server->request_q); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 292 | |
| 293 | trace_smb3_add_credits(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 294 | server->conn_id, server->hostname, scredits, |
| 295 | credits->value - new_val, in_flight); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 296 | cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n", |
| 297 | __func__, credits->value - new_val, scredits); |
| 298 | |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 299 | credits->value = new_val; |
| 300 | |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 304 | static __u64 |
| 305 | smb2_get_next_mid(struct TCP_Server_Info *server) |
| 306 | { |
| 307 | __u64 mid; |
| 308 | /* for SMB2 we need the current value */ |
| 309 | spin_lock(&GlobalMid_Lock); |
| 310 | mid = server->CurrentMid++; |
| 311 | spin_unlock(&GlobalMid_Lock); |
| 312 | return mid; |
| 313 | } |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 314 | |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 315 | static void |
| 316 | smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val) |
| 317 | { |
| 318 | spin_lock(&GlobalMid_Lock); |
| 319 | if (server->CurrentMid >= val) |
| 320 | server->CurrentMid -= val; |
| 321 | spin_unlock(&GlobalMid_Lock); |
| 322 | } |
| 323 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 324 | static struct mid_q_entry * |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 325 | __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue) |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 326 | { |
| 327 | struct mid_q_entry *mid; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 328 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 329 | __u64 wire_mid = le64_to_cpu(shdr->MessageId); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 330 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 331 | if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 332 | cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n"); |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 333 | return NULL; |
| 334 | } |
| 335 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 336 | spin_lock(&GlobalMid_Lock); |
| 337 | list_for_each_entry(mid, &server->pending_mid_q, qhead) { |
Sachin Prabhu | 9235d09 | 2014-12-09 17:37:00 +0000 | [diff] [blame] | 338 | if ((mid->mid == wire_mid) && |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 339 | (mid->mid_state == MID_REQUEST_SUBMITTED) && |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 340 | (mid->command == shdr->Command)) { |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 341 | kref_get(&mid->refcount); |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 342 | if (dequeue) { |
| 343 | list_del_init(&mid->qhead); |
| 344 | mid->mid_flags |= MID_DELETED; |
| 345 | } |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 346 | spin_unlock(&GlobalMid_Lock); |
| 347 | return mid; |
| 348 | } |
| 349 | } |
| 350 | spin_unlock(&GlobalMid_Lock); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 354 | static struct mid_q_entry * |
| 355 | smb2_find_mid(struct TCP_Server_Info *server, char *buf) |
| 356 | { |
| 357 | return __smb2_find_mid(server, buf, false); |
| 358 | } |
| 359 | |
| 360 | static struct mid_q_entry * |
| 361 | smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf) |
| 362 | { |
| 363 | return __smb2_find_mid(server, buf, true); |
| 364 | } |
| 365 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 366 | static void |
Ronnie Sahlberg | 14547f7 | 2018-04-22 14:45:53 -0600 | [diff] [blame] | 367 | smb2_dump_detail(void *buf, struct TCP_Server_Info *server) |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 368 | { |
| 369 | #ifdef CONFIG_CIFS_DEBUG2 |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 370 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 371 | |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 372 | 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] | 373 | shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 374 | shdr->Id.SyncId.ProcessId); |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 375 | cifs_server_dbg(VFS, "smb buf %p len %u\n", buf, |
Steve French | 71992e62 | 2018-05-06 15:58:51 -0500 | [diff] [blame] | 376 | server->ops->calc_smb_size(buf, server)); |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 377 | #endif |
| 378 | } |
| 379 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 380 | static bool |
| 381 | smb2_need_neg(struct TCP_Server_Info *server) |
| 382 | { |
| 383 | return server->max_read == 0; |
| 384 | } |
| 385 | |
| 386 | static int |
| 387 | smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) |
| 388 | { |
| 389 | int rc; |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 390 | |
Steve French | 0fa757b | 2021-06-25 13:54:32 -0500 | [diff] [blame] | 391 | spin_lock(&GlobalMid_Lock); |
Aurelien Aptel | f6a6bf7 | 2019-09-20 06:22:14 +0200 | [diff] [blame] | 392 | cifs_ses_server(ses)->CurrentMid = 0; |
Steve French | 0fa757b | 2021-06-25 13:54:32 -0500 | [diff] [blame] | 393 | spin_unlock(&GlobalMid_Lock); |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 394 | rc = SMB2_negotiate(xid, ses); |
| 395 | /* BB we probably don't need to retry with modern servers */ |
| 396 | if (rc == -EAGAIN) |
| 397 | rc = -EHOSTDOWN; |
| 398 | return rc; |
| 399 | } |
| 400 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 401 | static unsigned int |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 402 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 403 | { |
| 404 | struct TCP_Server_Info *server = tcon->ses->server; |
| 405 | unsigned int wsize; |
| 406 | |
| 407 | /* start with specified wsize, or default */ |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 408 | wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE; |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 409 | wsize = min_t(unsigned int, wsize, server->max_write); |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 410 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 411 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 412 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 413 | return wsize; |
| 414 | } |
| 415 | |
| 416 | static unsigned int |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 417 | smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 418 | { |
| 419 | struct TCP_Server_Info *server = tcon->ses->server; |
| 420 | unsigned int wsize; |
| 421 | |
| 422 | /* start with specified wsize, or default */ |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 423 | wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE; |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 424 | wsize = min_t(unsigned int, wsize, server->max_write); |
| 425 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 426 | if (server->rdma) { |
| 427 | if (server->sign) |
Long Li | f7950cb | 2020-03-26 19:42:24 -0700 | [diff] [blame] | 428 | /* |
| 429 | * Account for SMB2 data transfer packet header and |
| 430 | * possible encryption header |
| 431 | */ |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 432 | wsize = min_t(unsigned int, |
Long Li | f7950cb | 2020-03-26 19:42:24 -0700 | [diff] [blame] | 433 | wsize, |
| 434 | server->smbd_conn->max_fragmented_send_size - |
| 435 | SMB2_READWRITE_PDU_HEADER_SIZE - |
| 436 | sizeof(struct smb2_transform_hdr)); |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 437 | else |
| 438 | wsize = min_t(unsigned int, |
| 439 | wsize, server->smbd_conn->max_readwrite_size); |
| 440 | } |
| 441 | #endif |
| 442 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 443 | wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE); |
| 444 | |
| 445 | return wsize; |
| 446 | } |
| 447 | |
| 448 | static unsigned int |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 449 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 450 | { |
| 451 | struct TCP_Server_Info *server = tcon->ses->server; |
| 452 | unsigned int rsize; |
| 453 | |
| 454 | /* start with specified rsize, or default */ |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 455 | rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE; |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 456 | rsize = min_t(unsigned int, rsize, server->max_read); |
Pavel Shilovsky | bed9da0 | 2014-06-25 11:28:57 +0400 | [diff] [blame] | 457 | |
| 458 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 459 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 460 | |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 461 | return rsize; |
| 462 | } |
| 463 | |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 464 | static unsigned int |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 465 | smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 466 | { |
| 467 | struct TCP_Server_Info *server = tcon->ses->server; |
| 468 | unsigned int rsize; |
| 469 | |
| 470 | /* start with specified rsize, or default */ |
Ronnie Sahlberg | 3fa1c6d | 2020-12-09 23:07:12 -0600 | [diff] [blame] | 471 | rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE; |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 472 | rsize = min_t(unsigned int, rsize, server->max_read); |
| 473 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 474 | if (server->rdma) { |
| 475 | if (server->sign) |
Long Li | f7950cb | 2020-03-26 19:42:24 -0700 | [diff] [blame] | 476 | /* |
| 477 | * Account for SMB2 data transfer packet header and |
| 478 | * possible encryption header |
| 479 | */ |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 480 | rsize = min_t(unsigned int, |
Long Li | f7950cb | 2020-03-26 19:42:24 -0700 | [diff] [blame] | 481 | rsize, |
| 482 | server->smbd_conn->max_fragmented_recv_size - |
| 483 | SMB2_READWRITE_PDU_HEADER_SIZE - |
| 484 | sizeof(struct smb2_transform_hdr)); |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 485 | else |
| 486 | rsize = min_t(unsigned int, |
| 487 | rsize, server->smbd_conn->max_readwrite_size); |
| 488 | } |
| 489 | #endif |
| 490 | |
| 491 | if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) |
| 492 | rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE); |
| 493 | |
| 494 | return rsize; |
| 495 | } |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 496 | |
| 497 | static int |
| 498 | parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf, |
| 499 | size_t buf_len, |
| 500 | struct cifs_server_iface **iface_list, |
| 501 | size_t *iface_count) |
| 502 | { |
| 503 | struct network_interface_info_ioctl_rsp *p; |
| 504 | struct sockaddr_in *addr4; |
| 505 | struct sockaddr_in6 *addr6; |
| 506 | struct iface_info_ipv4 *p4; |
| 507 | struct iface_info_ipv6 *p6; |
| 508 | struct cifs_server_iface *info; |
| 509 | ssize_t bytes_left; |
| 510 | size_t next = 0; |
| 511 | int nb_iface = 0; |
| 512 | int rc = 0; |
| 513 | |
| 514 | *iface_list = NULL; |
| 515 | *iface_count = 0; |
| 516 | |
| 517 | /* |
| 518 | * Fist pass: count and sanity check |
| 519 | */ |
| 520 | |
| 521 | bytes_left = buf_len; |
| 522 | p = buf; |
| 523 | while (bytes_left >= sizeof(*p)) { |
| 524 | nb_iface++; |
| 525 | next = le32_to_cpu(p->Next); |
| 526 | if (!next) { |
| 527 | bytes_left -= sizeof(*p); |
| 528 | break; |
| 529 | } |
| 530 | p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next); |
| 531 | bytes_left -= next; |
| 532 | } |
| 533 | |
| 534 | if (!nb_iface) { |
| 535 | cifs_dbg(VFS, "%s: malformed interface info\n", __func__); |
| 536 | rc = -EINVAL; |
| 537 | goto out; |
| 538 | } |
| 539 | |
Steve French | ebcd6de | 2020-12-08 21:13:31 -0600 | [diff] [blame] | 540 | /* Azure rounds the buffer size up 8, to a 16 byte boundary */ |
| 541 | if ((bytes_left > 8) || p->Next) |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 542 | cifs_dbg(VFS, "%s: incomplete interface info\n", __func__); |
| 543 | |
| 544 | |
| 545 | /* |
| 546 | * Second pass: extract info to internal structure |
| 547 | */ |
| 548 | |
| 549 | *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL); |
| 550 | if (!*iface_list) { |
| 551 | rc = -ENOMEM; |
| 552 | goto out; |
| 553 | } |
| 554 | |
| 555 | info = *iface_list; |
| 556 | bytes_left = buf_len; |
| 557 | p = buf; |
| 558 | while (bytes_left >= sizeof(*p)) { |
| 559 | info->speed = le64_to_cpu(p->LinkSpeed); |
Hyunchul Lee | c9c9c68 | 2021-07-12 19:34:02 +0900 | [diff] [blame] | 560 | info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0; |
| 561 | info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0; |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 562 | |
| 563 | cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count); |
| 564 | cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed); |
| 565 | cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__, |
| 566 | le32_to_cpu(p->Capability)); |
| 567 | |
| 568 | switch (p->Family) { |
| 569 | /* |
| 570 | * The kernel and wire socket structures have the same |
| 571 | * layout and use network byte order but make the |
| 572 | * conversion explicit in case either one changes. |
| 573 | */ |
| 574 | case INTERNETWORK: |
| 575 | addr4 = (struct sockaddr_in *)&info->sockaddr; |
| 576 | p4 = (struct iface_info_ipv4 *)p->Buffer; |
| 577 | addr4->sin_family = AF_INET; |
| 578 | memcpy(&addr4->sin_addr, &p4->IPv4Address, 4); |
| 579 | |
| 580 | /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */ |
| 581 | addr4->sin_port = cpu_to_be16(CIFS_PORT); |
| 582 | |
| 583 | cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__, |
| 584 | &addr4->sin_addr); |
| 585 | break; |
| 586 | case INTERNETWORKV6: |
| 587 | addr6 = (struct sockaddr_in6 *)&info->sockaddr; |
| 588 | p6 = (struct iface_info_ipv6 *)p->Buffer; |
| 589 | addr6->sin6_family = AF_INET6; |
| 590 | memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16); |
| 591 | |
| 592 | /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */ |
| 593 | addr6->sin6_flowinfo = 0; |
| 594 | addr6->sin6_scope_id = 0; |
| 595 | addr6->sin6_port = cpu_to_be16(CIFS_PORT); |
| 596 | |
| 597 | cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__, |
| 598 | &addr6->sin6_addr); |
| 599 | break; |
| 600 | default: |
| 601 | cifs_dbg(VFS, |
| 602 | "%s: skipping unsupported socket family\n", |
| 603 | __func__); |
| 604 | goto next_iface; |
| 605 | } |
| 606 | |
| 607 | (*iface_count)++; |
| 608 | info++; |
| 609 | next_iface: |
| 610 | next = le32_to_cpu(p->Next); |
| 611 | if (!next) |
| 612 | break; |
| 613 | p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next); |
| 614 | bytes_left -= next; |
| 615 | } |
| 616 | |
| 617 | if (!*iface_count) { |
| 618 | rc = -EINVAL; |
| 619 | goto out; |
| 620 | } |
| 621 | |
| 622 | out: |
| 623 | if (rc) { |
| 624 | kfree(*iface_list); |
| 625 | *iface_count = 0; |
| 626 | *iface_list = NULL; |
| 627 | } |
| 628 | return rc; |
| 629 | } |
| 630 | |
Aurelien Aptel | 35adffe | 2019-09-20 06:29:39 +0200 | [diff] [blame] | 631 | static int compare_iface(const void *ia, const void *ib) |
| 632 | { |
| 633 | const struct cifs_server_iface *a = (struct cifs_server_iface *)ia; |
| 634 | const struct cifs_server_iface *b = (struct cifs_server_iface *)ib; |
| 635 | |
| 636 | return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1); |
| 637 | } |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 638 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 639 | static int |
| 640 | SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) |
| 641 | { |
| 642 | int rc; |
| 643 | unsigned int ret_data_len = 0; |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 644 | struct network_interface_info_ioctl_rsp *out_buf = NULL; |
| 645 | struct cifs_server_iface *iface_list; |
| 646 | size_t iface_count; |
| 647 | struct cifs_ses *ses = tcon->ses; |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 648 | |
| 649 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 650 | FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */, |
| 651 | NULL /* no data input */, 0 /* no data input */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 652 | CIFSMaxBufSize, (char **)&out_buf, &ret_data_len); |
Steve French | c3ed440 | 2018-06-28 22:53:39 -0500 | [diff] [blame] | 653 | if (rc == -EOPNOTSUPP) { |
| 654 | cifs_dbg(FYI, |
| 655 | "server does not support query network interfaces\n"); |
| 656 | goto out; |
| 657 | } else if (rc != 0) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 658 | 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] | 659 | goto out; |
Steve French | 9ffc541 | 2014-10-16 15:13:14 -0500 | [diff] [blame] | 660 | } |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 661 | |
| 662 | rc = parse_server_interfaces(out_buf, ret_data_len, |
| 663 | &iface_list, &iface_count); |
| 664 | if (rc) |
| 665 | goto out; |
| 666 | |
Aurelien Aptel | 35adffe | 2019-09-20 06:29:39 +0200 | [diff] [blame] | 667 | /* sort interfaces from fastest to slowest */ |
| 668 | sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL); |
| 669 | |
Aurelien Aptel | fe856be | 2018-06-14 17:04:51 +0200 | [diff] [blame] | 670 | spin_lock(&ses->iface_lock); |
| 671 | kfree(ses->iface_list); |
| 672 | ses->iface_list = iface_list; |
| 673 | ses->iface_count = iface_count; |
| 674 | ses->iface_last_update = jiffies; |
| 675 | spin_unlock(&ses->iface_lock); |
| 676 | |
| 677 | out: |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 678 | kfree(out_buf); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 679 | return rc; |
| 680 | } |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 681 | |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 682 | static void |
| 683 | smb2_close_cached_fid(struct kref *ref) |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 684 | { |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 685 | struct cached_fid *cfid = container_of(ref, struct cached_fid, |
| 686 | refcount); |
| 687 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 688 | if (cfid->is_valid) { |
| 689 | cifs_dbg(FYI, "clear cached root file handle\n"); |
| 690 | SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, |
| 691 | cfid->fid->volatile_fid); |
Enzo Matsumiya | 9351590 | 2021-09-09 18:46:45 -0300 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /* |
| 695 | * We only check validity above to send SMB2_close, |
| 696 | * but we still need to invalidate these entries |
| 697 | * when this function is called |
| 698 | */ |
| 699 | cfid->is_valid = false; |
| 700 | cfid->file_all_info_is_valid = false; |
| 701 | cfid->has_lease = false; |
| 702 | if (cfid->dentry) { |
| 703 | dput(cfid->dentry); |
| 704 | cfid->dentry = NULL; |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 705 | } |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 706 | } |
| 707 | |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 708 | void close_cached_dir(struct cached_fid *cfid) |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 709 | { |
| 710 | mutex_lock(&cfid->fid_mutex); |
| 711 | kref_put(&cfid->refcount, smb2_close_cached_fid); |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 712 | mutex_unlock(&cfid->fid_mutex); |
| 713 | } |
| 714 | |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 715 | void close_cached_dir_lease_locked(struct cached_fid *cfid) |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 716 | { |
| 717 | if (cfid->has_lease) { |
| 718 | cfid->has_lease = false; |
| 719 | kref_put(&cfid->refcount, smb2_close_cached_fid); |
| 720 | } |
| 721 | } |
| 722 | |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 723 | void close_cached_dir_lease(struct cached_fid *cfid) |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 724 | { |
| 725 | mutex_lock(&cfid->fid_mutex); |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 726 | close_cached_dir_lease_locked(cfid); |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 727 | mutex_unlock(&cfid->fid_mutex); |
| 728 | } |
| 729 | |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 730 | void |
| 731 | smb2_cached_lease_break(struct work_struct *work) |
| 732 | { |
| 733 | struct cached_fid *cfid = container_of(work, |
| 734 | struct cached_fid, lease_break); |
| 735 | |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 736 | close_cached_dir_lease(cfid); |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 737 | } |
| 738 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 739 | /* |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 740 | * Open the and cache a directory handle. |
| 741 | * Only supported for the root handle. |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 742 | */ |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 743 | int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, |
Ronnie Sahlberg | e6eb195 | 2021-03-09 09:07:28 +1000 | [diff] [blame] | 744 | const char *path, |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 745 | struct cifs_sb_info *cifs_sb, |
| 746 | struct cached_fid **cfid) |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 747 | { |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 748 | struct cifs_ses *ses = tcon->ses; |
| 749 | struct TCP_Server_Info *server = ses->server; |
| 750 | struct cifs_open_parms oparms; |
| 751 | struct smb2_create_rsp *o_rsp = NULL; |
| 752 | struct smb2_query_info_rsp *qi_rsp = NULL; |
| 753 | int resp_buftype[2]; |
| 754 | struct smb_rqst rqst[2]; |
| 755 | struct kvec rsp_iov[2]; |
| 756 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 757 | struct kvec qi_iov[1]; |
| 758 | int rc, flags = 0; |
| 759 | __le16 utf16_path = 0; /* Null - since an open of top of share */ |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 760 | u8 oplock = SMB2_OPLOCK_LEVEL_II; |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 761 | struct cifs_fid *pfid; |
Ronnie Sahlberg | 5e9c89d | 2021-03-09 09:07:31 +1000 | [diff] [blame] | 762 | struct dentry *dentry; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 763 | |
Ronnie Sahlberg | 4df3d97 | 2021-03-09 09:07:27 +1000 | [diff] [blame] | 764 | if (tcon->nohandlecache) |
| 765 | return -ENOTSUPP; |
| 766 | |
Ronnie Sahlberg | 269f67e | 2021-03-09 09:07:30 +1000 | [diff] [blame] | 767 | if (cifs_sb->root == NULL) |
| 768 | return -ENOENT; |
| 769 | |
Ronnie Sahlberg | e6eb195 | 2021-03-09 09:07:28 +1000 | [diff] [blame] | 770 | if (strlen(path)) |
Ronnie Sahlberg | 269f67e | 2021-03-09 09:07:30 +1000 | [diff] [blame] | 771 | return -ENOENT; |
Ronnie Sahlberg | e6eb195 | 2021-03-09 09:07:28 +1000 | [diff] [blame] | 772 | |
Ronnie Sahlberg | 5e9c89d | 2021-03-09 09:07:31 +1000 | [diff] [blame] | 773 | dentry = cifs_sb->root; |
| 774 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 775 | mutex_lock(&tcon->crfid.fid_mutex); |
| 776 | if (tcon->crfid.is_valid) { |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 777 | cifs_dbg(FYI, "found a cached root file handle\n"); |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 778 | *cfid = &tcon->crfid; |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 779 | kref_get(&tcon->crfid.refcount); |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 780 | mutex_unlock(&tcon->crfid.fid_mutex); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 781 | return 0; |
| 782 | } |
| 783 | |
Steve French | 96d9f7e | 2019-09-12 17:52:54 -0500 | [diff] [blame] | 784 | /* |
| 785 | * We do not hold the lock for the open because in case |
| 786 | * SMB2_open needs to reconnect, it will end up calling |
| 787 | * cifs_mark_open_files_invalid() which takes the lock again |
| 788 | * thus causing a deadlock |
| 789 | */ |
| 790 | |
| 791 | mutex_unlock(&tcon->crfid.fid_mutex); |
| 792 | |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 793 | if (smb3_encryption_required(tcon)) |
| 794 | flags |= CIFS_TRANSFORM_REQ; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 795 | |
Paulo Alcantara | 0fe0781 | 2020-04-20 23:44:24 -0300 | [diff] [blame] | 796 | if (!server->ops->new_lease_key) |
| 797 | return -EIO; |
| 798 | |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 799 | pfid = tcon->crfid.fid; |
Paulo Alcantara | 0fe0781 | 2020-04-20 23:44:24 -0300 | [diff] [blame] | 800 | server->ops->new_lease_key(pfid); |
| 801 | |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 802 | memset(rqst, 0, sizeof(rqst)); |
| 803 | resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER; |
| 804 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 805 | |
| 806 | /* Open */ |
| 807 | memset(&open_iov, 0, sizeof(open_iov)); |
| 808 | rqst[0].rq_iov = open_iov; |
| 809 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 810 | |
| 811 | oparms.tcon = tcon; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 812 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 813 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 814 | oparms.disposition = FILE_OPEN; |
| 815 | oparms.fid = pfid; |
| 816 | oparms.reconnect = false; |
| 817 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 818 | rc = SMB2_open_init(tcon, server, |
| 819 | &rqst[0], &oplock, &oparms, &utf16_path); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 820 | if (rc) |
Steve French | 96d9f7e | 2019-09-12 17:52:54 -0500 | [diff] [blame] | 821 | goto oshr_free; |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 822 | smb2_set_next_command(tcon, &rqst[0]); |
| 823 | |
| 824 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 825 | rqst[1].rq_iov = qi_iov; |
| 826 | rqst[1].rq_nvec = 1; |
| 827 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 828 | rc = SMB2_query_info_init(tcon, server, |
| 829 | &rqst[1], COMPOUND_FID, |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 830 | COMPOUND_FID, FILE_ALL_INFORMATION, |
| 831 | SMB2_O_INFO_FILE, 0, |
| 832 | sizeof(struct smb2_file_all_info) + |
| 833 | PATH_MAX * 2, 0, NULL); |
| 834 | if (rc) |
Steve French | 96d9f7e | 2019-09-12 17:52:54 -0500 | [diff] [blame] | 835 | goto oshr_free; |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 836 | |
| 837 | smb2_set_related(&rqst[1]); |
| 838 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 839 | rc = compound_send_recv(xid, ses, server, |
| 840 | flags, 2, rqst, |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 841 | resp_buftype, rsp_iov); |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 842 | mutex_lock(&tcon->crfid.fid_mutex); |
| 843 | |
| 844 | /* |
| 845 | * Now we need to check again as the cached root might have |
| 846 | * been successfully re-opened from a concurrent process |
| 847 | */ |
| 848 | |
| 849 | if (tcon->crfid.is_valid) { |
| 850 | /* work was already done */ |
| 851 | |
| 852 | /* stash fids for close() later */ |
| 853 | struct cifs_fid fid = { |
| 854 | .persistent_fid = pfid->persistent_fid, |
| 855 | .volatile_fid = pfid->volatile_fid, |
| 856 | }; |
| 857 | |
| 858 | /* |
Muhammad Usama Anjum | ad7567b | 2021-04-15 20:24:09 +0500 | [diff] [blame] | 859 | * caller expects this func to set the fid in crfid to valid |
| 860 | * cached root, so increment the refcount. |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 861 | */ |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 862 | kref_get(&tcon->crfid.refcount); |
| 863 | |
| 864 | mutex_unlock(&tcon->crfid.fid_mutex); |
| 865 | |
| 866 | if (rc == 0) { |
| 867 | /* close extra handle outside of crit sec */ |
| 868 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 869 | } |
Xiyu Yang | 77577de | 2020-06-13 20:27:09 +0800 | [diff] [blame] | 870 | rc = 0; |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 871 | goto oshr_free; |
| 872 | } |
| 873 | |
| 874 | /* Cached root is still invalid, continue normaly */ |
| 875 | |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 876 | if (rc) { |
| 877 | if (rc == -EREMCHG) { |
| 878 | tcon->need_reconnect = true; |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 879 | pr_warn_once("server share %s deleted\n", |
| 880 | tcon->treeName); |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 881 | } |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 882 | goto oshr_exit; |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 883 | } |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 884 | |
Steve French | d2f1542 | 2019-09-22 00:55:46 -0500 | [diff] [blame] | 885 | atomic_inc(&tcon->num_remote_opens); |
| 886 | |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 887 | o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base; |
Ronnie Sahlberg | c462870 | 2021-09-08 12:10:15 +1000 | [diff] [blame] | 888 | oparms.fid->persistent_fid = le64_to_cpu(o_rsp->PersistentFileId); |
| 889 | oparms.fid->volatile_fid = le64_to_cpu(o_rsp->VolatileFileId); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 890 | #ifdef CONFIG_CIFS_DEBUG2 |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 891 | oparms.fid->mid = le64_to_cpu(o_rsp->hdr.MessageId); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 892 | #endif /* CIFS_DEBUG2 */ |
| 893 | |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 894 | tcon->crfid.tcon = tcon; |
| 895 | tcon->crfid.is_valid = true; |
Ronnie Sahlberg | 5e9c89d | 2021-03-09 09:07:31 +1000 | [diff] [blame] | 896 | tcon->crfid.dentry = dentry; |
| 897 | dget(dentry); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 898 | kref_init(&tcon->crfid.refcount); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 899 | |
Steve French | 89a5bfa | 2019-07-18 17:22:18 -0500 | [diff] [blame] | 900 | /* 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] | 901 | if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) { |
Muhammad Usama Anjum | ad7567b | 2021-04-15 20:24:09 +0500 | [diff] [blame] | 902 | /* |
| 903 | * See commit 2f94a3125b87. Increment the refcount when we |
| 904 | * get a lease for root, release it if lease break occurs |
| 905 | */ |
Ronnie Sahlberg | 2f94a312 | 2019-03-28 11:20:02 +1000 | [diff] [blame] | 906 | kref_get(&tcon->crfid.refcount); |
Pavel Shilovsky | d919131 | 2019-12-10 11:44:52 -0800 | [diff] [blame] | 907 | tcon->crfid.has_lease = true; |
Steve French | 89a5bfa | 2019-07-18 17:22:18 -0500 | [diff] [blame] | 908 | smb2_parse_contexts(server, o_rsp, |
| 909 | &oparms.fid->epoch, |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 910 | oparms.fid->lease_key, &oplock, |
| 911 | NULL, NULL); |
Ronnie Sahlberg | 2f94a312 | 2019-03-28 11:20:02 +1000 | [diff] [blame] | 912 | } else |
| 913 | goto oshr_exit; |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 914 | |
| 915 | qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; |
| 916 | if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) |
| 917 | goto oshr_exit; |
Ronnie Sahlberg | 4811e30 | 2019-04-01 09:53:44 +1000 | [diff] [blame] | 918 | if (!smb2_validate_and_copy_iov( |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 919 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 920 | sizeof(struct smb2_file_all_info), |
| 921 | &rsp_iov[1], sizeof(struct smb2_file_all_info), |
Ronnie Sahlberg | 4811e30 | 2019-04-01 09:53:44 +1000 | [diff] [blame] | 922 | (char *)&tcon->crfid.file_all_info)) |
zhengbin | 720aec0 | 2019-12-25 11:30:20 +0800 | [diff] [blame] | 923 | tcon->crfid.file_all_info_is_valid = true; |
Ronnie Sahlberg | ed20f54 | 2021-03-09 09:07:33 +1000 | [diff] [blame] | 924 | tcon->crfid.time = jiffies; |
| 925 | |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 926 | |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 927 | oshr_exit: |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 928 | mutex_unlock(&tcon->crfid.fid_mutex); |
Aurelien Aptel | 7e5a70a | 2019-07-17 12:46:28 +0200 | [diff] [blame] | 929 | oshr_free: |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 930 | SMB2_open_free(&rqst[0]); |
| 931 | SMB2_query_info_free(&rqst[1]); |
| 932 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 933 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 934 | if (rc == 0) |
| 935 | *cfid = &tcon->crfid; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 936 | return rc; |
| 937 | } |
| 938 | |
Ronnie Sahlberg | 6ef4e9c | 2021-03-09 09:07:32 +1000 | [diff] [blame] | 939 | int open_cached_dir_by_dentry(struct cifs_tcon *tcon, |
| 940 | struct dentry *dentry, |
| 941 | struct cached_fid **cfid) |
| 942 | { |
| 943 | mutex_lock(&tcon->crfid.fid_mutex); |
| 944 | if (tcon->crfid.dentry == dentry) { |
| 945 | cifs_dbg(FYI, "found a cached root file handle by dentry\n"); |
| 946 | *cfid = &tcon->crfid; |
| 947 | kref_get(&tcon->crfid.refcount); |
| 948 | mutex_unlock(&tcon->crfid.fid_mutex); |
| 949 | return 0; |
| 950 | } |
| 951 | mutex_unlock(&tcon->crfid.fid_mutex); |
| 952 | return -ENOENT; |
| 953 | } |
| 954 | |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 955 | static void |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 956 | smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, |
| 957 | struct cifs_sb_info *cifs_sb) |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 958 | { |
| 959 | int rc; |
| 960 | __le16 srch_path = 0; /* Null - open root of share */ |
| 961 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 962 | struct cifs_open_parms oparms; |
| 963 | struct cifs_fid fid; |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 964 | struct cached_fid *cfid = NULL; |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 965 | |
| 966 | oparms.tcon = tcon; |
| 967 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 968 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 969 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 970 | oparms.fid = &fid; |
| 971 | oparms.reconnect = false; |
| 972 | |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 973 | rc = open_cached_dir(xid, tcon, "", cifs_sb, &cfid); |
Ronnie Sahlberg | 4df3d97 | 2021-03-09 09:07:27 +1000 | [diff] [blame] | 974 | if (rc == 0) |
| 975 | memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); |
| 976 | else |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 977 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 978 | NULL, NULL); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 979 | if (rc) |
| 980 | return; |
| 981 | |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 982 | SMB3_request_interfaces(xid, tcon); |
Steve French | c481e9f | 2013-10-14 01:21:53 -0500 | [diff] [blame] | 983 | |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 984 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 985 | FS_ATTRIBUTE_INFORMATION); |
| 986 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 987 | FS_DEVICE_INFORMATION); |
| 988 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
Steve French | 21ba384 | 2018-06-24 23:18:52 -0500 | [diff] [blame] | 989 | FS_VOLUME_INFORMATION); |
| 990 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 991 | FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */ |
Ronnie Sahlberg | 4df3d97 | 2021-03-09 09:07:27 +1000 | [diff] [blame] | 992 | if (cfid == NULL) |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 993 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 994 | else |
Ronnie Sahlberg | 45c0f1a | 2021-03-09 09:07:29 +1000 | [diff] [blame] | 995 | close_cached_dir(cfid); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static void |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 999 | smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, |
| 1000 | struct cifs_sb_info *cifs_sb) |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1001 | { |
| 1002 | int rc; |
| 1003 | __le16 srch_path = 0; /* Null - open root of share */ |
| 1004 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1005 | struct cifs_open_parms oparms; |
| 1006 | struct cifs_fid fid; |
| 1007 | |
| 1008 | oparms.tcon = tcon; |
| 1009 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1010 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1011 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1012 | oparms.fid = &fid; |
| 1013 | oparms.reconnect = false; |
| 1014 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 1015 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, |
| 1016 | NULL, NULL); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1017 | if (rc) |
| 1018 | return; |
| 1019 | |
Steven French | 2167114 | 2013-10-09 13:36:35 -0500 | [diff] [blame] | 1020 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 1021 | FS_ATTRIBUTE_INFORMATION); |
| 1022 | SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 1023 | FS_DEVICE_INFORMATION); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1024 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 1025 | } |
| 1026 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1027 | static int |
| 1028 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
| 1029 | struct cifs_sb_info *cifs_sb, const char *full_path) |
| 1030 | { |
| 1031 | int rc; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1032 | __le16 *utf16_path; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 1033 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1034 | struct cifs_open_parms oparms; |
| 1035 | struct cifs_fid fid; |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1036 | |
Ronnie Sahlberg | a93864d | 2018-06-14 06:48:35 +1000 | [diff] [blame] | 1037 | if ((*full_path == 0) && tcon->crfid.is_valid) |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 1038 | return 0; |
| 1039 | |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1040 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 1041 | if (!utf16_path) |
| 1042 | return -ENOMEM; |
| 1043 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1044 | oparms.tcon = tcon; |
| 1045 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 1046 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1047 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1048 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 1049 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1050 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 1051 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL, |
| 1052 | NULL); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1053 | if (rc) { |
| 1054 | kfree(utf16_path); |
| 1055 | return rc; |
| 1056 | } |
| 1057 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 1058 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 1059 | kfree(utf16_path); |
| 1060 | return rc; |
| 1061 | } |
| 1062 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 1063 | static int |
| 1064 | smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, |
| 1065 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 1066 | u64 *uniqueid, FILE_ALL_INFO *data) |
| 1067 | { |
| 1068 | *uniqueid = le64_to_cpu(data->IndexNumber); |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 1072 | static int |
| 1073 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 1074 | struct cifs_fid *fid, FILE_ALL_INFO *data) |
| 1075 | { |
| 1076 | int rc; |
| 1077 | struct smb2_file_all_info *smb2_data; |
| 1078 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 1079 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 1080 | GFP_KERNEL); |
| 1081 | if (smb2_data == NULL) |
| 1082 | return -ENOMEM; |
| 1083 | |
| 1084 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, |
| 1085 | smb2_data); |
| 1086 | if (!rc) |
| 1087 | move_smb2_info_to_cifs(data, smb2_data); |
| 1088 | kfree(smb2_data); |
| 1089 | return rc; |
| 1090 | } |
| 1091 | |
Arnd Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 1092 | #ifdef CONFIG_CIFS_XATTR |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1093 | static ssize_t |
| 1094 | move_smb2_ea_to_cifs(char *dst, size_t dst_size, |
| 1095 | struct smb2_file_full_ea_info *src, size_t src_size, |
| 1096 | const unsigned char *ea_name) |
| 1097 | { |
| 1098 | int rc = 0; |
| 1099 | unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0; |
| 1100 | char *name, *value; |
Ronnie Sahlberg | 0c5d6cb | 2018-10-25 15:43:36 +1000 | [diff] [blame] | 1101 | size_t buf_size = dst_size; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1102 | size_t name_len, value_len, user_name_len; |
| 1103 | |
| 1104 | while (src_size > 0) { |
| 1105 | name = &src->ea_data[0]; |
| 1106 | name_len = (size_t)src->ea_name_length; |
| 1107 | value = &src->ea_data[src->ea_name_length + 1]; |
| 1108 | value_len = (size_t)le16_to_cpu(src->ea_value_length); |
| 1109 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1110 | if (name_len == 0) |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1111 | break; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1112 | |
| 1113 | if (src_size < 8 + name_len + 1 + value_len) { |
| 1114 | cifs_dbg(FYI, "EA entry goes beyond length of list\n"); |
| 1115 | rc = -EIO; |
| 1116 | goto out; |
| 1117 | } |
| 1118 | |
| 1119 | if (ea_name) { |
| 1120 | if (ea_name_len == name_len && |
| 1121 | memcmp(ea_name, name, name_len) == 0) { |
| 1122 | rc = value_len; |
| 1123 | if (dst_size == 0) |
| 1124 | goto out; |
| 1125 | if (dst_size < value_len) { |
| 1126 | rc = -ERANGE; |
| 1127 | goto out; |
| 1128 | } |
| 1129 | memcpy(dst, value, value_len); |
| 1130 | goto out; |
| 1131 | } |
| 1132 | } else { |
| 1133 | /* 'user.' plus a terminating null */ |
| 1134 | user_name_len = 5 + 1 + name_len; |
| 1135 | |
Ronnie Sahlberg | 0c5d6cb | 2018-10-25 15:43:36 +1000 | [diff] [blame] | 1136 | if (buf_size == 0) { |
| 1137 | /* skip copy - calc size only */ |
| 1138 | rc += user_name_len; |
| 1139 | } else if (dst_size >= user_name_len) { |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1140 | dst_size -= user_name_len; |
| 1141 | memcpy(dst, "user.", 5); |
| 1142 | dst += 5; |
| 1143 | memcpy(dst, src->ea_data, name_len); |
| 1144 | dst += name_len; |
| 1145 | *dst = 0; |
| 1146 | ++dst; |
Ronnie Sahlberg | 0c5d6cb | 2018-10-25 15:43:36 +1000 | [diff] [blame] | 1147 | rc += user_name_len; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1148 | } else { |
| 1149 | /* stop before overrun buffer */ |
| 1150 | rc = -ERANGE; |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (!src->next_entry_offset) |
| 1156 | break; |
| 1157 | |
| 1158 | if (src_size < le32_to_cpu(src->next_entry_offset)) { |
| 1159 | /* stop before overrun buffer */ |
| 1160 | rc = -ERANGE; |
| 1161 | break; |
| 1162 | } |
| 1163 | src_size -= le32_to_cpu(src->next_entry_offset); |
| 1164 | src = (void *)((char *)src + |
| 1165 | le32_to_cpu(src->next_entry_offset)); |
| 1166 | } |
| 1167 | |
| 1168 | /* didn't find the named attribute */ |
| 1169 | if (ea_name) |
| 1170 | rc = -ENODATA; |
| 1171 | |
| 1172 | out: |
| 1173 | return (ssize_t)rc; |
| 1174 | } |
| 1175 | |
| 1176 | static ssize_t |
| 1177 | smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon, |
| 1178 | const unsigned char *path, const unsigned char *ea_name, |
| 1179 | char *ea_data, size_t buf_size, |
| 1180 | struct cifs_sb_info *cifs_sb) |
| 1181 | { |
| 1182 | int rc; |
| 1183 | __le16 *utf16_path; |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1184 | struct kvec rsp_iov = {NULL, 0}; |
| 1185 | int buftype = CIFS_NO_BUFFER; |
| 1186 | struct smb2_query_info_rsp *rsp; |
| 1187 | struct smb2_file_full_ea_info *info = NULL; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1188 | |
| 1189 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1190 | if (!utf16_path) |
| 1191 | return -ENOMEM; |
| 1192 | |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1193 | rc = smb2_query_info_compound(xid, tcon, utf16_path, |
| 1194 | FILE_READ_EA, |
| 1195 | FILE_FULL_EA_INFORMATION, |
| 1196 | SMB2_O_INFO_FILE, |
Ronnie Sahlberg | c4627e6 | 2019-01-29 12:46:17 +1000 | [diff] [blame] | 1197 | CIFSMaxBufSize - |
| 1198 | MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 1199 | MAX_SMB2_CLOSE_RESPONSE_SIZE, |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1200 | &rsp_iov, &buftype, cifs_sb); |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1201 | if (rc) { |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1202 | /* |
| 1203 | * If ea_name is NULL (listxattr) and there are no EAs, |
| 1204 | * return 0 as it's not an error. Otherwise, the specified |
| 1205 | * ea_name was not found. |
| 1206 | */ |
| 1207 | if (!ea_name && rc == -ENODATA) |
| 1208 | rc = 0; |
| 1209 | goto qeas_exit; |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1210 | } |
| 1211 | |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1212 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
| 1213 | rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), |
| 1214 | le32_to_cpu(rsp->OutputBufferLength), |
| 1215 | &rsp_iov, |
| 1216 | sizeof(struct smb2_file_full_ea_info)); |
| 1217 | if (rc) |
| 1218 | goto qeas_exit; |
Ronnie Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 1219 | |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1220 | info = (struct smb2_file_full_ea_info *)( |
| 1221 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); |
| 1222 | rc = move_smb2_ea_to_cifs(ea_data, buf_size, info, |
| 1223 | le32_to_cpu(rsp->OutputBufferLength), ea_name); |
Ronnie Sahlberg | 7cb3def | 2017-09-28 09:39:58 +1000 | [diff] [blame] | 1224 | |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 1225 | qeas_exit: |
| 1226 | kfree(utf16_path); |
| 1227 | free_rsp_buf(buftype, rsp_iov.iov_base); |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 1228 | return rc; |
| 1229 | } |
| 1230 | |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1231 | |
| 1232 | static int |
| 1233 | smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, |
| 1234 | const char *path, const char *ea_name, const void *ea_value, |
| 1235 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 1236 | struct cifs_sb_info *cifs_sb) |
| 1237 | { |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1238 | struct cifs_ses *ses = tcon->ses; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1239 | struct TCP_Server_Info *server = cifs_pick_channel(ses); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1240 | __le16 *utf16_path = NULL; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1241 | int ea_name_len = strlen(ea_name); |
Paulo Alcantara | 04ad69c | 2021-03-08 12:00:50 -0300 | [diff] [blame] | 1242 | int flags = CIFS_CP_CREATE_CLOSE_OP; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1243 | int len; |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1244 | struct smb_rqst rqst[3]; |
| 1245 | int resp_buftype[3]; |
| 1246 | struct kvec rsp_iov[3]; |
| 1247 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 1248 | struct cifs_open_parms oparms; |
| 1249 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1250 | struct cifs_fid fid; |
| 1251 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
| 1252 | unsigned int size[1]; |
| 1253 | void *data[1]; |
| 1254 | struct smb2_file_full_ea_info *ea = NULL; |
| 1255 | struct kvec close_iov[1]; |
Ronnie Sahlberg | 85db6b7 | 2020-02-13 12:14:47 +1000 | [diff] [blame] | 1256 | struct smb2_query_info_rsp *rsp; |
| 1257 | int rc, used_len = 0; |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1258 | |
| 1259 | if (smb3_encryption_required(tcon)) |
| 1260 | flags |= CIFS_TRANSFORM_REQ; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1261 | |
| 1262 | if (ea_name_len > 255) |
| 1263 | return -EINVAL; |
| 1264 | |
| 1265 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 1266 | if (!utf16_path) |
| 1267 | return -ENOMEM; |
| 1268 | |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1269 | memset(rqst, 0, sizeof(rqst)); |
| 1270 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 1271 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 1272 | |
Ronnie Sahlberg | 2109464 | 2019-02-07 15:48:44 +1000 | [diff] [blame] | 1273 | if (ses->server->ops->query_all_EAs) { |
| 1274 | if (!ea_value) { |
| 1275 | rc = ses->server->ops->query_all_EAs(xid, tcon, path, |
| 1276 | ea_name, NULL, 0, |
| 1277 | cifs_sb); |
| 1278 | if (rc == -ENODATA) |
| 1279 | goto sea_exit; |
Ronnie Sahlberg | 85db6b7 | 2020-02-13 12:14:47 +1000 | [diff] [blame] | 1280 | } else { |
| 1281 | /* If we are adding a attribute we should first check |
| 1282 | * if there will be enough space available to store |
| 1283 | * the new EA. If not we should not add it since we |
| 1284 | * would not be able to even read the EAs back. |
| 1285 | */ |
| 1286 | rc = smb2_query_info_compound(xid, tcon, utf16_path, |
| 1287 | FILE_READ_EA, |
| 1288 | FILE_FULL_EA_INFORMATION, |
| 1289 | SMB2_O_INFO_FILE, |
| 1290 | CIFSMaxBufSize - |
| 1291 | MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 1292 | MAX_SMB2_CLOSE_RESPONSE_SIZE, |
| 1293 | &rsp_iov[1], &resp_buftype[1], cifs_sb); |
| 1294 | if (rc == 0) { |
| 1295 | rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; |
| 1296 | used_len = le32_to_cpu(rsp->OutputBufferLength); |
| 1297 | } |
| 1298 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 1299 | resp_buftype[1] = CIFS_NO_BUFFER; |
| 1300 | memset(&rsp_iov[1], 0, sizeof(rsp_iov[1])); |
| 1301 | rc = 0; |
| 1302 | |
| 1303 | /* Use a fudge factor of 256 bytes in case we collide |
| 1304 | * with a different set_EAs command. |
| 1305 | */ |
| 1306 | if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 1307 | MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 < |
| 1308 | used_len + ea_name_len + ea_value_len + 1) { |
| 1309 | rc = -ENOSPC; |
| 1310 | goto sea_exit; |
| 1311 | } |
Ronnie Sahlberg | 2109464 | 2019-02-07 15:48:44 +1000 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1315 | /* Open */ |
| 1316 | memset(&open_iov, 0, sizeof(open_iov)); |
| 1317 | rqst[0].rq_iov = open_iov; |
| 1318 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 1319 | |
| 1320 | memset(&oparms, 0, sizeof(oparms)); |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1321 | oparms.tcon = tcon; |
| 1322 | oparms.desired_access = FILE_WRITE_EA; |
| 1323 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1324 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1325 | oparms.fid = &fid; |
| 1326 | oparms.reconnect = false; |
| 1327 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1328 | rc = SMB2_open_init(tcon, server, |
| 1329 | &rqst[0], &oplock, &oparms, utf16_path); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1330 | if (rc) |
| 1331 | goto sea_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1332 | smb2_set_next_command(tcon, &rqst[0]); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1333 | |
| 1334 | |
| 1335 | /* Set Info */ |
| 1336 | memset(&si_iov, 0, sizeof(si_iov)); |
| 1337 | rqst[1].rq_iov = si_iov; |
| 1338 | rqst[1].rq_nvec = 1; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1339 | |
Vladimir Zapolskiy | 64b7f67 | 2020-10-10 21:25:54 +0300 | [diff] [blame] | 1340 | len = sizeof(*ea) + ea_name_len + ea_value_len + 1; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1341 | ea = kzalloc(len, GFP_KERNEL); |
| 1342 | if (ea == NULL) { |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1343 | rc = -ENOMEM; |
| 1344 | goto sea_exit; |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | ea->ea_name_length = ea_name_len; |
| 1348 | ea->ea_value_length = cpu_to_le16(ea_value_len); |
| 1349 | memcpy(ea->ea_data, ea_name, ea_name_len + 1); |
| 1350 | memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len); |
| 1351 | |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1352 | size[0] = len; |
| 1353 | data[0] = ea; |
| 1354 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1355 | rc = SMB2_set_info_init(tcon, server, |
| 1356 | &rqst[1], COMPOUND_FID, |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1357 | COMPOUND_FID, current->tgid, |
| 1358 | FILE_FULL_EA_INFORMATION, |
| 1359 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1360 | smb2_set_next_command(tcon, &rqst[1]); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1361 | smb2_set_related(&rqst[1]); |
| 1362 | |
| 1363 | |
| 1364 | /* Close */ |
| 1365 | memset(&close_iov, 0, sizeof(close_iov)); |
| 1366 | rqst[2].rq_iov = close_iov; |
| 1367 | rqst[2].rq_nvec = 1; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1368 | rc = SMB2_close_init(tcon, server, |
| 1369 | &rqst[2], COMPOUND_FID, COMPOUND_FID, false); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1370 | smb2_set_related(&rqst[2]); |
| 1371 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1372 | rc = compound_send_recv(xid, ses, server, |
| 1373 | flags, 3, rqst, |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1374 | resp_buftype, rsp_iov); |
Steve French | d2f1542 | 2019-09-22 00:55:46 -0500 | [diff] [blame] | 1375 | /* no need to bump num_remote_opens because handle immediately closed */ |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1376 | |
| 1377 | sea_exit: |
Paulo Alcantara | 6aa0c11 | 2018-07-04 14:16:16 -0300 | [diff] [blame] | 1378 | kfree(ea); |
Ronnie Sahlberg | 0967e54 | 2018-11-06 22:52:43 +1000 | [diff] [blame] | 1379 | kfree(utf16_path); |
| 1380 | SMB2_open_free(&rqst[0]); |
| 1381 | SMB2_set_info_free(&rqst[1]); |
| 1382 | SMB2_close_free(&rqst[2]); |
| 1383 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 1384 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 1385 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1386 | return rc; |
| 1387 | } |
Arnd Bergmann | 1368f15 | 2017-09-05 11:24:15 +0200 | [diff] [blame] | 1388 | #endif |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 1389 | |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 1390 | static bool |
| 1391 | smb2_can_echo(struct TCP_Server_Info *server) |
| 1392 | { |
| 1393 | return server->echoes; |
| 1394 | } |
| 1395 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1396 | static void |
| 1397 | smb2_clear_stats(struct cifs_tcon *tcon) |
| 1398 | { |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1399 | int i; |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1400 | |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1401 | for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) { |
| 1402 | atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); |
| 1403 | atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); |
| 1404 | } |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | static void |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1408 | smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) |
| 1409 | { |
| 1410 | seq_puts(m, "\n\tShare Capabilities:"); |
| 1411 | if (tcon->capabilities & SMB2_SHARE_CAP_DFS) |
| 1412 | seq_puts(m, " DFS,"); |
| 1413 | if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 1414 | seq_puts(m, " CONTINUOUS AVAILABILITY,"); |
| 1415 | if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) |
| 1416 | seq_puts(m, " SCALEOUT,"); |
| 1417 | if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) |
| 1418 | seq_puts(m, " CLUSTER,"); |
| 1419 | if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) |
| 1420 | seq_puts(m, " ASYMMETRIC,"); |
| 1421 | if (tcon->capabilities == 0) |
| 1422 | seq_puts(m, " None"); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 1423 | if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) |
| 1424 | seq_puts(m, " Aligned,"); |
| 1425 | if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) |
| 1426 | seq_puts(m, " Partition Aligned,"); |
| 1427 | if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) |
| 1428 | seq_puts(m, " SSD,"); |
| 1429 | if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) |
| 1430 | seq_puts(m, " TRIM-support,"); |
| 1431 | |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1432 | seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); |
Steve French | e0386e4 | 2018-05-20 01:27:03 -0500 | [diff] [blame] | 1433 | seq_printf(m, "\n\ttid: 0x%x", tcon->tid); |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 1434 | if (tcon->perf_sector_size) |
| 1435 | seq_printf(m, "\tOptimal sector size: 0x%x", |
| 1436 | tcon->perf_sector_size); |
Steve French | e0386e4 | 2018-05-20 01:27:03 -0500 | [diff] [blame] | 1437 | seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access); |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static void |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1441 | smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) |
| 1442 | { |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1443 | atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; |
| 1444 | atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1445 | |
| 1446 | /* |
| 1447 | * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO |
| 1448 | * totals (requests sent) since those SMBs are per-session not per tcon |
| 1449 | */ |
Steve French | 52ce1ac | 2018-07-31 01:46:47 -0500 | [diff] [blame] | 1450 | seq_printf(m, "\nBytes read: %llu Bytes written: %llu", |
| 1451 | (long long)(tcon->bytes_read), |
| 1452 | (long long)(tcon->bytes_written)); |
Steve French | fae8044 | 2018-10-19 17:14:32 -0500 | [diff] [blame] | 1453 | seq_printf(m, "\nOpen files: %d total (local), %d open on server", |
| 1454 | atomic_read(&tcon->num_local_opens), |
| 1455 | atomic_read(&tcon->num_remote_opens)); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1456 | seq_printf(m, "\nTreeConnects: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1457 | atomic_read(&sent[SMB2_TREE_CONNECT_HE]), |
| 1458 | atomic_read(&failed[SMB2_TREE_CONNECT_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1459 | seq_printf(m, "\nTreeDisconnects: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1460 | atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]), |
| 1461 | atomic_read(&failed[SMB2_TREE_DISCONNECT_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1462 | seq_printf(m, "\nCreates: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1463 | atomic_read(&sent[SMB2_CREATE_HE]), |
| 1464 | atomic_read(&failed[SMB2_CREATE_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1465 | seq_printf(m, "\nCloses: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1466 | atomic_read(&sent[SMB2_CLOSE_HE]), |
| 1467 | atomic_read(&failed[SMB2_CLOSE_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1468 | seq_printf(m, "\nFlushes: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1469 | atomic_read(&sent[SMB2_FLUSH_HE]), |
| 1470 | atomic_read(&failed[SMB2_FLUSH_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1471 | seq_printf(m, "\nReads: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1472 | atomic_read(&sent[SMB2_READ_HE]), |
| 1473 | atomic_read(&failed[SMB2_READ_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1474 | seq_printf(m, "\nWrites: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1475 | atomic_read(&sent[SMB2_WRITE_HE]), |
| 1476 | atomic_read(&failed[SMB2_WRITE_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1477 | seq_printf(m, "\nLocks: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1478 | atomic_read(&sent[SMB2_LOCK_HE]), |
| 1479 | atomic_read(&failed[SMB2_LOCK_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1480 | seq_printf(m, "\nIOCTLs: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1481 | atomic_read(&sent[SMB2_IOCTL_HE]), |
| 1482 | atomic_read(&failed[SMB2_IOCTL_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1483 | seq_printf(m, "\nQueryDirectories: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1484 | atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]), |
| 1485 | atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1486 | seq_printf(m, "\nChangeNotifies: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1487 | atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]), |
| 1488 | atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1489 | seq_printf(m, "\nQueryInfos: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1490 | atomic_read(&sent[SMB2_QUERY_INFO_HE]), |
| 1491 | atomic_read(&failed[SMB2_QUERY_INFO_HE])); |
Steve French | 1995d28 | 2018-07-27 15:14:04 -0500 | [diff] [blame] | 1492 | seq_printf(m, "\nSetInfos: %d total %d failed", |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1493 | atomic_read(&sent[SMB2_SET_INFO_HE]), |
| 1494 | atomic_read(&failed[SMB2_SET_INFO_HE])); |
| 1495 | seq_printf(m, "\nOplockBreaks: %d sent %d failed", |
| 1496 | atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]), |
| 1497 | atomic_read(&failed[SMB2_OPLOCK_BREAK_HE])); |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 1498 | } |
| 1499 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1500 | static void |
| 1501 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) |
| 1502 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1503 | struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1504 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
| 1505 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1506 | cfile->fid.persistent_fid = fid->persistent_fid; |
| 1507 | cfile->fid.volatile_fid = fid->volatile_fid; |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 1508 | cfile->fid.access = fid->access; |
Steve French | dfe33f9 | 2018-10-30 19:50:31 -0500 | [diff] [blame] | 1509 | #ifdef CONFIG_CIFS_DEBUG2 |
| 1510 | cfile->fid.mid = fid->mid; |
| 1511 | #endif /* CIFS_DEBUG2 */ |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 1512 | server->ops->set_oplock_level(cinode, oplock, fid->epoch, |
| 1513 | &fid->purge_cache); |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 1514 | cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); |
Aurelien Aptel | 94f8737 | 2016-09-22 07:38:50 +0200 | [diff] [blame] | 1515 | memcpy(cfile->fid.create_guid, fid->create_guid, 16); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 1518 | static void |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1519 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 1520 | struct cifs_fid *fid) |
| 1521 | { |
Pavel Shilovsky | 760ad0c | 2012-09-25 11:00:07 +0400 | [diff] [blame] | 1522 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Steve French | 43f8a6a | 2019-12-02 21:46:54 -0600 | [diff] [blame] | 1525 | static void |
| 1526 | smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon, |
| 1527 | struct cifsFileInfo *cfile) |
| 1528 | { |
| 1529 | struct smb2_file_network_open_info file_inf; |
| 1530 | struct inode *inode; |
| 1531 | int rc; |
| 1532 | |
| 1533 | rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid, |
| 1534 | cfile->fid.volatile_fid, &file_inf); |
| 1535 | if (rc) |
| 1536 | return; |
| 1537 | |
| 1538 | inode = d_inode(cfile->dentry); |
| 1539 | |
| 1540 | spin_lock(&inode->i_lock); |
| 1541 | CIFS_I(inode)->time = jiffies; |
| 1542 | |
| 1543 | /* Creation time should not need to be updated on close */ |
| 1544 | if (file_inf.LastWriteTime) |
| 1545 | inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime); |
| 1546 | if (file_inf.ChangeTime) |
| 1547 | inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime); |
| 1548 | if (file_inf.LastAccessTime) |
| 1549 | inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime); |
| 1550 | |
| 1551 | /* |
| 1552 | * i_blocks is not related to (i_size / i_blksize), |
| 1553 | * but instead 512 byte (2**9) size is required for |
| 1554 | * calculating num blocks. |
| 1555 | */ |
| 1556 | if (le64_to_cpu(file_inf.AllocationSize) > 4096) |
| 1557 | inode->i_blocks = |
| 1558 | (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9; |
| 1559 | |
| 1560 | /* End of file and Attributes should not have to be updated on close */ |
| 1561 | spin_unlock(&inode->i_lock); |
| 1562 | } |
| 1563 | |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1564 | static int |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1565 | SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, |
| 1566 | u64 persistent_fid, u64 volatile_fid, |
| 1567 | struct copychunk_ioctl *pcchunk) |
| 1568 | { |
| 1569 | int rc; |
| 1570 | unsigned int ret_data_len; |
| 1571 | struct resume_key_req *res_key; |
| 1572 | |
| 1573 | rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, |
| 1574 | FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1575 | NULL, 0 /* no input */, CIFSMaxBufSize, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1576 | (char **)&res_key, &ret_data_len); |
| 1577 | |
Steve French | 423333b | 2021-04-19 23:22:37 -0500 | [diff] [blame] | 1578 | if (rc == -EOPNOTSUPP) { |
| 1579 | pr_warn_once("Server share %s does not support copy range\n", tcon->treeName); |
| 1580 | goto req_res_key_exit; |
| 1581 | } else if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1582 | 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] | 1583 | goto req_res_key_exit; |
| 1584 | } |
| 1585 | if (ret_data_len < sizeof(struct resume_key_req)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 1586 | cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n"); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1587 | rc = -EINVAL; |
| 1588 | goto req_res_key_exit; |
| 1589 | } |
| 1590 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 1591 | |
| 1592 | req_res_key_exit: |
| 1593 | kfree(res_key); |
| 1594 | return rc; |
| 1595 | } |
| 1596 | |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1597 | struct iqi_vars { |
| 1598 | struct smb_rqst rqst[3]; |
| 1599 | struct kvec rsp_iov[3]; |
| 1600 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 1601 | struct kvec qi_iov[1]; |
| 1602 | struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; |
| 1603 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
| 1604 | struct kvec close_iov[1]; |
| 1605 | }; |
| 1606 | |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1607 | static int |
| 1608 | smb2_ioctl_query_info(const unsigned int xid, |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1609 | struct cifs_tcon *tcon, |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1610 | struct cifs_sb_info *cifs_sb, |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1611 | __le16 *path, int is_dir, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1612 | unsigned long p) |
| 1613 | { |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1614 | struct iqi_vars *vars; |
| 1615 | struct smb_rqst *rqst; |
| 1616 | struct kvec *rsp_iov; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1617 | struct cifs_ses *ses = tcon->ses; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1618 | struct TCP_Server_Info *server = cifs_pick_channel(ses); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1619 | char __user *arg = (char __user *)p; |
| 1620 | struct smb_query_info qi; |
| 1621 | struct smb_query_info __user *pqi; |
| 1622 | int rc = 0; |
Paulo Alcantara | 04ad69c | 2021-03-08 12:00:50 -0300 | [diff] [blame] | 1623 | int flags = CIFS_CP_CREATE_CLOSE_OP; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1624 | struct smb2_query_info_rsp *qi_rsp = NULL; |
| 1625 | struct smb2_ioctl_rsp *io_rsp = NULL; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1626 | void *buffer = NULL; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1627 | int resp_buftype[3]; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1628 | struct cifs_open_parms oparms; |
| 1629 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 1630 | struct cifs_fid fid; |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1631 | unsigned int size[2]; |
| 1632 | void *data[2]; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1633 | int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1634 | |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1635 | vars = kzalloc(sizeof(*vars), GFP_ATOMIC); |
| 1636 | if (vars == NULL) |
| 1637 | return -ENOMEM; |
| 1638 | rqst = &vars->rqst[0]; |
| 1639 | rsp_iov = &vars->rsp_iov[0]; |
| 1640 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1641 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1642 | |
| 1643 | if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1644 | goto e_fault; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1645 | |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1646 | if (qi.output_buffer_length > 1024) { |
| 1647 | kfree(vars); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1648 | return -EINVAL; |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1649 | } |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1650 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1651 | if (!ses || !server) { |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1652 | kfree(vars); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1653 | return -EIO; |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1654 | } |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1655 | |
| 1656 | if (smb3_encryption_required(tcon)) |
| 1657 | flags |= CIFS_TRANSFORM_REQ; |
| 1658 | |
Markus Elfring | cfaa118 | 2019-11-05 21:30:25 +0100 | [diff] [blame] | 1659 | buffer = memdup_user(arg + sizeof(struct smb_query_info), |
| 1660 | qi.output_buffer_length); |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1661 | if (IS_ERR(buffer)) { |
| 1662 | kfree(vars); |
Markus Elfring | cfaa118 | 2019-11-05 21:30:25 +0100 | [diff] [blame] | 1663 | return PTR_ERR(buffer); |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1664 | } |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1665 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1666 | /* Open */ |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1667 | rqst[0].rq_iov = &vars->open_iov[0]; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1668 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1669 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1670 | memset(&oparms, 0, sizeof(oparms)); |
| 1671 | oparms.tcon = tcon; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1672 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 1673 | oparms.create_options = cifs_create_options(cifs_sb, create_options); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1674 | oparms.fid = &fid; |
| 1675 | oparms.reconnect = false; |
| 1676 | |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1677 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1678 | switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) { |
| 1679 | case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS: |
| 1680 | 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] | 1681 | break; |
| 1682 | case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS: |
| 1683 | oparms.desired_access = GENERIC_ALL; |
| 1684 | break; |
| 1685 | case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS: |
| 1686 | oparms.desired_access = GENERIC_READ; |
| 1687 | break; |
| 1688 | case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS: |
| 1689 | oparms.desired_access = GENERIC_WRITE; |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1690 | break; |
| 1691 | } |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1692 | } else if (qi.flags & PASSTHRU_SET_INFO) { |
| 1693 | oparms.desired_access = GENERIC_WRITE; |
| 1694 | } else { |
| 1695 | oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL; |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1696 | } |
| 1697 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1698 | rc = SMB2_open_init(tcon, server, |
| 1699 | &rqst[0], &oplock, &oparms, path); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1700 | if (rc) |
| 1701 | goto iqinf_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1702 | smb2_set_next_command(tcon, &rqst[0]); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1703 | |
| 1704 | /* Query */ |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1705 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1706 | /* Can eventually relax perm check since server enforces too */ |
| 1707 | if (!capable(CAP_SYS_ADMIN)) |
| 1708 | rc = -EPERM; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1709 | else { |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1710 | rqst[1].rq_iov = &vars->io_iov[0]; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1711 | rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; |
| 1712 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1713 | rc = SMB2_ioctl_init(tcon, server, |
| 1714 | &rqst[1], |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1715 | COMPOUND_FID, COMPOUND_FID, |
Ronnie Sahlberg | efac779 | 2019-04-11 12:20:17 +1000 | [diff] [blame] | 1716 | qi.info_type, true, buffer, |
| 1717 | qi.output_buffer_length, |
Ronnie Sahlberg | 731b82b | 2020-01-08 13:08:07 +1000 | [diff] [blame] | 1718 | CIFSMaxBufSize - |
| 1719 | MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 1720 | MAX_SMB2_CLOSE_RESPONSE_SIZE); |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1721 | } |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1722 | } else if (qi.flags == PASSTHRU_SET_INFO) { |
| 1723 | /* Can eventually relax perm check since server enforces too */ |
| 1724 | if (!capable(CAP_SYS_ADMIN)) |
| 1725 | rc = -EPERM; |
| 1726 | else { |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1727 | rqst[1].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1728 | rqst[1].rq_nvec = 1; |
| 1729 | |
| 1730 | size[0] = 8; |
| 1731 | data[0] = buffer; |
| 1732 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1733 | rc = SMB2_set_info_init(tcon, server, |
| 1734 | &rqst[1], |
Ronnie Sahlberg | 0e90696 | 2019-07-25 13:08:43 +1000 | [diff] [blame] | 1735 | COMPOUND_FID, COMPOUND_FID, |
| 1736 | current->tgid, |
| 1737 | FILE_END_OF_FILE_INFORMATION, |
| 1738 | SMB2_O_INFO_FILE, 0, data, size); |
| 1739 | } |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1740 | } else if (qi.flags == PASSTHRU_QUERY_INFO) { |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1741 | rqst[1].rq_iov = &vars->qi_iov[0]; |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1742 | rqst[1].rq_nvec = 1; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1743 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1744 | rc = SMB2_query_info_init(tcon, server, |
| 1745 | &rqst[1], COMPOUND_FID, |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1746 | COMPOUND_FID, qi.file_info_class, |
| 1747 | qi.info_type, qi.additional_information, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1748 | qi.input_buffer_length, |
| 1749 | qi.output_buffer_length, buffer); |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1750 | } else { /* unknown flags */ |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 1751 | cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n", |
| 1752 | qi.flags); |
Steve French | 31ba433 | 2019-03-13 02:40:07 -0500 | [diff] [blame] | 1753 | rc = -EINVAL; |
| 1754 | } |
| 1755 | |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1756 | if (rc) |
| 1757 | goto iqinf_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 1758 | smb2_set_next_command(tcon, &rqst[1]); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1759 | smb2_set_related(&rqst[1]); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1760 | |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1761 | /* Close */ |
Ronnie Sahlberg | b2ca6c2 | 2020-05-21 15:03:15 +1000 | [diff] [blame] | 1762 | rqst[2].rq_iov = &vars->close_iov[0]; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1763 | rqst[2].rq_nvec = 1; |
| 1764 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1765 | rc = SMB2_close_init(tcon, server, |
| 1766 | &rqst[2], COMPOUND_FID, COMPOUND_FID, false); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1767 | if (rc) |
| 1768 | goto iqinf_exit; |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1769 | smb2_set_related(&rqst[2]); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1770 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 1771 | rc = compound_send_recv(xid, ses, server, |
| 1772 | flags, 3, rqst, |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1773 | resp_buftype, rsp_iov); |
| 1774 | if (rc) |
| 1775 | goto iqinf_exit; |
Steve French | d2f1542 | 2019-09-22 00:55:46 -0500 | [diff] [blame] | 1776 | |
| 1777 | /* No need to bump num_remote_opens since handle immediately closed */ |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1778 | if (qi.flags & PASSTHRU_FSCTL) { |
| 1779 | pqi = (struct smb_query_info __user *)arg; |
| 1780 | io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base; |
| 1781 | if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) |
| 1782 | qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); |
Ronnie Sahlberg | 5242fcb | 2019-04-15 12:13:52 +1000 | [diff] [blame] | 1783 | if (qi.input_buffer_length > 0 && |
Markus Elfring | 2b1116b | 2019-11-05 22:26:53 +0100 | [diff] [blame] | 1784 | le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length |
| 1785 | > rsp_iov[1].iov_len) |
| 1786 | goto e_fault; |
| 1787 | |
| 1788 | if (copy_to_user(&pqi->input_buffer_length, |
| 1789 | &qi.input_buffer_length, |
| 1790 | sizeof(qi.input_buffer_length))) |
| 1791 | goto e_fault; |
| 1792 | |
Ronnie Sahlberg | 5242fcb | 2019-04-15 12:13:52 +1000 | [diff] [blame] | 1793 | if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info), |
| 1794 | (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset), |
Markus Elfring | 2b1116b | 2019-11-05 22:26:53 +0100 | [diff] [blame] | 1795 | qi.input_buffer_length)) |
| 1796 | goto e_fault; |
Ronnie Sahlberg | f5778c3 | 2019-03-15 09:07:22 +1000 | [diff] [blame] | 1797 | } else { |
| 1798 | pqi = (struct smb_query_info __user *)arg; |
| 1799 | qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; |
| 1800 | if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) |
| 1801 | qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); |
Markus Elfring | 2b1116b | 2019-11-05 22:26:53 +0100 | [diff] [blame] | 1802 | if (copy_to_user(&pqi->input_buffer_length, |
| 1803 | &qi.input_buffer_length, |
| 1804 | sizeof(qi.input_buffer_length))) |
| 1805 | goto e_fault; |
| 1806 | |
| 1807 | if (copy_to_user(pqi + 1, qi_rsp->Buffer, |
| 1808 | qi.input_buffer_length)) |
| 1809 | goto e_fault; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | iqinf_exit: |
Aurelien Aptel | ccd48ec | 2021-04-09 15:47:01 +0200 | [diff] [blame] | 1813 | cifs_small_buf_release(rqst[0].rq_iov[0].iov_base); |
| 1814 | cifs_small_buf_release(rqst[1].rq_iov[0].iov_base); |
| 1815 | cifs_small_buf_release(rqst[2].rq_iov[0].iov_base); |
Ronnie Sahlberg | 8d8b26e | 2018-10-17 05:47:58 +1000 | [diff] [blame] | 1816 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 1817 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 1818 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Aurelien Aptel | ccd48ec | 2021-04-09 15:47:01 +0200 | [diff] [blame] | 1819 | kfree(vars); |
| 1820 | kfree(buffer); |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1821 | return rc; |
Markus Elfring | 2b1116b | 2019-11-05 22:26:53 +0100 | [diff] [blame] | 1822 | |
| 1823 | e_fault: |
| 1824 | rc = -EFAULT; |
| 1825 | goto iqinf_exit; |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 1826 | } |
| 1827 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1828 | static ssize_t |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 1829 | smb2_copychunk_range(const unsigned int xid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1830 | struct cifsFileInfo *srcfile, |
| 1831 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 1832 | u64 len, u64 dest_off) |
| 1833 | { |
| 1834 | int rc; |
| 1835 | unsigned int ret_data_len; |
| 1836 | struct copychunk_ioctl *pcchunk; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1837 | struct copychunk_ioctl_rsp *retbuf = NULL; |
| 1838 | struct cifs_tcon *tcon; |
| 1839 | int chunks_copied = 0; |
| 1840 | bool chunk_sizes_updated = false; |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1841 | ssize_t bytes_written, total_bytes_written = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1842 | |
| 1843 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 1844 | |
| 1845 | if (pcchunk == NULL) |
| 1846 | return -ENOMEM; |
| 1847 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1848 | cifs_dbg(FYI, "%s: about to call request res key\n", __func__); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1849 | /* Request a key from the server to identify the source of the copy */ |
| 1850 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 1851 | srcfile->fid.persistent_fid, |
| 1852 | srcfile->fid.volatile_fid, pcchunk); |
| 1853 | |
| 1854 | /* Note: request_res_key sets res_key null only if rc !=0 */ |
| 1855 | if (rc) |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1856 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1857 | |
| 1858 | /* For now array only one chunk long, will make more flexible later */ |
Fabian Frederick | bc09d14 | 2014-12-10 15:41:15 -0800 | [diff] [blame] | 1859 | pcchunk->ChunkCount = cpu_to_le32(1); |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1860 | pcchunk->Reserved = 0; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1861 | pcchunk->Reserved2 = 0; |
| 1862 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1863 | tcon = tlink_tcon(trgtfile->tlink); |
| 1864 | |
| 1865 | while (len > 0) { |
| 1866 | pcchunk->SourceOffset = cpu_to_le64(src_off); |
| 1867 | pcchunk->TargetOffset = cpu_to_le64(dest_off); |
| 1868 | pcchunk->Length = |
| 1869 | cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); |
| 1870 | |
| 1871 | /* Request server copy to target from src identified by key */ |
Ronnie Sahlberg | d201d76 | 2021-05-19 08:40:11 +1000 | [diff] [blame] | 1872 | kfree(retbuf); |
| 1873 | retbuf = NULL; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1874 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1875 | trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 1876 | true /* is_fsctl */, (char *)pcchunk, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 1877 | sizeof(struct copychunk_ioctl), CIFSMaxBufSize, |
| 1878 | (char **)&retbuf, &ret_data_len); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1879 | if (rc == 0) { |
| 1880 | if (ret_data_len != |
| 1881 | sizeof(struct copychunk_ioctl_rsp)) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 1882 | cifs_tcon_dbg(VFS, "Invalid cchunk response size\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1883 | rc = -EIO; |
| 1884 | goto cchunk_out; |
| 1885 | } |
| 1886 | if (retbuf->TotalBytesWritten == 0) { |
| 1887 | cifs_dbg(FYI, "no bytes copied\n"); |
| 1888 | rc = -EIO; |
| 1889 | goto cchunk_out; |
| 1890 | } |
| 1891 | /* |
| 1892 | * Check if server claimed to write more than we asked |
| 1893 | */ |
| 1894 | if (le32_to_cpu(retbuf->TotalBytesWritten) > |
| 1895 | le32_to_cpu(pcchunk->Length)) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 1896 | cifs_tcon_dbg(VFS, "Invalid copy chunk response\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1897 | rc = -EIO; |
| 1898 | goto cchunk_out; |
| 1899 | } |
| 1900 | if (le32_to_cpu(retbuf->ChunksWritten) != 1) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 1901 | cifs_tcon_dbg(VFS, "Invalid num chunks written\n"); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1902 | rc = -EIO; |
| 1903 | goto cchunk_out; |
| 1904 | } |
| 1905 | chunks_copied++; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1906 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1907 | bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); |
| 1908 | src_off += bytes_written; |
| 1909 | dest_off += bytes_written; |
| 1910 | len -= bytes_written; |
| 1911 | total_bytes_written += bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1912 | |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1913 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n", |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1914 | le32_to_cpu(retbuf->ChunksWritten), |
| 1915 | le32_to_cpu(retbuf->ChunkBytesWritten), |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1916 | bytes_written); |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1917 | } else if (rc == -EINVAL) { |
| 1918 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 1919 | goto cchunk_out; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1920 | |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1921 | cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n", |
| 1922 | le32_to_cpu(retbuf->ChunksWritten), |
| 1923 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 1924 | le32_to_cpu(retbuf->TotalBytesWritten)); |
| 1925 | |
| 1926 | /* |
| 1927 | * Check if this is the first request using these sizes, |
| 1928 | * (ie check if copy succeed once with original sizes |
| 1929 | * and check if the server gave us different sizes after |
| 1930 | * we already updated max sizes on previous request). |
| 1931 | * if not then why is the server returning an error now |
| 1932 | */ |
| 1933 | if ((chunks_copied != 0) || chunk_sizes_updated) |
| 1934 | goto cchunk_out; |
| 1935 | |
| 1936 | /* Check that server is not asking us to grow size */ |
| 1937 | if (le32_to_cpu(retbuf->ChunkBytesWritten) < |
| 1938 | tcon->max_bytes_chunk) |
| 1939 | tcon->max_bytes_chunk = |
| 1940 | le32_to_cpu(retbuf->ChunkBytesWritten); |
| 1941 | else |
| 1942 | goto cchunk_out; /* server gave us bogus size */ |
| 1943 | |
| 1944 | /* No need to change MaxChunks since already set to 1 */ |
| 1945 | chunk_sizes_updated = true; |
Sachin Prabhu | 2477bc5 | 2015-02-04 13:10:26 +0000 | [diff] [blame] | 1946 | } else |
| 1947 | goto cchunk_out; |
Steve French | 9bf0c9c | 2013-11-16 18:05:28 -0600 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | cchunk_out: |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1951 | kfree(pcchunk); |
Steve French | 24df148 | 2016-09-29 04:20:23 -0500 | [diff] [blame] | 1952 | kfree(retbuf); |
Sachin Prabhu | 620d874 | 2017-02-10 16:03:51 +0530 | [diff] [blame] | 1953 | if (rc) |
| 1954 | return rc; |
| 1955 | else |
| 1956 | return total_bytes_written; |
Steve French | 41c1358 | 2013-11-14 00:05:36 -0600 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | static int |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 1960 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, |
| 1961 | struct cifs_fid *fid) |
| 1962 | { |
| 1963 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 1964 | } |
| 1965 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1966 | static unsigned int |
| 1967 | smb2_read_data_offset(char *buf) |
| 1968 | { |
| 1969 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 1970 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1971 | return rsp->DataOffset; |
| 1972 | } |
| 1973 | |
| 1974 | static unsigned int |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1975 | smb2_read_data_length(char *buf, bool in_remaining) |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1976 | { |
| 1977 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 1978 | |
| 1979 | if (in_remaining) |
| 1980 | return le32_to_cpu(rsp->DataRemaining); |
| 1981 | |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 1982 | return le32_to_cpu(rsp->DataLength); |
| 1983 | } |
| 1984 | |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1985 | |
| 1986 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1987 | smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1988 | struct cifs_io_parms *parms, unsigned int *bytes_read, |
| 1989 | char **buf, int *buf_type) |
| 1990 | { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1991 | parms->persistent_fid = pfid->persistent_fid; |
| 1992 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1993 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); |
| 1994 | } |
| 1995 | |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1996 | static int |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 1997 | smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 1998 | struct cifs_io_parms *parms, unsigned int *written, |
| 1999 | struct kvec *iov, unsigned long nr_segs) |
| 2000 | { |
| 2001 | |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 2002 | parms->persistent_fid = pfid->persistent_fid; |
| 2003 | parms->volatile_fid = pfid->volatile_fid; |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 2004 | return SMB2_write(xid, parms, written, iov, nr_segs); |
| 2005 | } |
| 2006 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 2007 | /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */ |
| 2008 | static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, |
| 2009 | struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse) |
| 2010 | { |
| 2011 | struct cifsInodeInfo *cifsi; |
| 2012 | int rc; |
| 2013 | |
| 2014 | cifsi = CIFS_I(inode); |
| 2015 | |
| 2016 | /* if file already sparse don't bother setting sparse again */ |
| 2017 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) |
| 2018 | return true; /* already sparse */ |
| 2019 | |
| 2020 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) |
| 2021 | return true; /* already not sparse */ |
| 2022 | |
| 2023 | /* |
| 2024 | * Can't check for sparse support on share the usual way via the |
| 2025 | * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share |
| 2026 | * since Samba server doesn't set the flag on the share, yet |
| 2027 | * supports the set sparse FSCTL and returns sparse correctly |
| 2028 | * in the file attributes. If we fail setting sparse though we |
| 2029 | * mark that server does not support sparse files for this share |
| 2030 | * to avoid repeatedly sending the unsupported fsctl to server |
| 2031 | * if the file is repeatedly extended. |
| 2032 | */ |
| 2033 | if (tcon->broken_sparse_sup) |
| 2034 | return false; |
| 2035 | |
| 2036 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 2037 | cfile->fid.volatile_fid, FSCTL_SET_SPARSE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2038 | true /* is_fctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2039 | &setsparse, 1, CIFSMaxBufSize, NULL, NULL); |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 2040 | if (rc) { |
| 2041 | tcon->broken_sparse_sup = true; |
| 2042 | cifs_dbg(FYI, "set sparse rc = %d\n", rc); |
| 2043 | return false; |
| 2044 | } |
| 2045 | |
| 2046 | if (setsparse) |
| 2047 | cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; |
| 2048 | else |
| 2049 | cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); |
| 2050 | |
| 2051 | return true; |
| 2052 | } |
| 2053 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2054 | static int |
| 2055 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 2056 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) |
| 2057 | { |
| 2058 | __le64 eof = cpu_to_le64(size); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 2059 | struct inode *inode; |
| 2060 | |
| 2061 | /* |
| 2062 | * If extending file more than one page make sparse. Many Linux fs |
| 2063 | * make files sparse by default when extending via ftruncate |
| 2064 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2065 | inode = d_inode(cfile->dentry); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 2066 | |
| 2067 | if (!set_alloc && (size > inode->i_size + 8192)) { |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 2068 | __u8 set_sparse = 1; |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 2069 | |
Steve French | d43cc79 | 2014-08-13 17:16:29 -0500 | [diff] [blame] | 2070 | /* whether set sparse succeeds or not, extend the file */ |
| 2071 | smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); |
Steve French | 3d1a374 | 2014-08-11 21:05:25 -0500 | [diff] [blame] | 2072 | } |
| 2073 | |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2074 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
Ronnie Sahlberg | 3764cbd | 2018-09-03 13:33:47 +1000 | [diff] [blame] | 2075 | cfile->fid.volatile_fid, cfile->pid, &eof); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2078 | static int |
| 2079 | smb2_duplicate_extents(const unsigned int xid, |
| 2080 | struct cifsFileInfo *srcfile, |
| 2081 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 2082 | u64 len, u64 dest_off) |
| 2083 | { |
| 2084 | int rc; |
| 2085 | unsigned int ret_data_len; |
Steve French | cfc63fc | 2021-03-26 18:41:55 -0500 | [diff] [blame] | 2086 | struct inode *inode; |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2087 | struct duplicate_extents_to_file dup_ext_buf; |
| 2088 | struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); |
| 2089 | |
| 2090 | /* server fileays advertise duplicate extent support with this flag */ |
| 2091 | if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & |
| 2092 | FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0) |
| 2093 | return -EOPNOTSUPP; |
| 2094 | |
| 2095 | dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; |
| 2096 | dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; |
| 2097 | dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off); |
| 2098 | dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off); |
| 2099 | dup_ext_buf.ByteCount = cpu_to_le64(len); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2100 | 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] | 2101 | src_off, dest_off, len); |
| 2102 | |
Steve French | cfc63fc | 2021-03-26 18:41:55 -0500 | [diff] [blame] | 2103 | inode = d_inode(trgtfile->dentry); |
| 2104 | if (inode->i_size < dest_off + len) { |
| 2105 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 2106 | if (rc) |
| 2107 | goto duplicate_extents_out; |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2108 | |
Steve French | cfc63fc | 2021-03-26 18:41:55 -0500 | [diff] [blame] | 2109 | /* |
| 2110 | * Although also could set plausible allocation size (i_blocks) |
| 2111 | * here in addition to setting the file size, in reflink |
| 2112 | * it is likely that the target file is sparse. Its allocation |
| 2113 | * size will be queried on next revalidate, but it is important |
| 2114 | * to make sure that file's cached size is updated immediately |
| 2115 | */ |
| 2116 | cifs_setsize(inode, dest_off + len); |
| 2117 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2118 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 2119 | trgtfile->fid.volatile_fid, |
| 2120 | FSCTL_DUPLICATE_EXTENTS_TO_FILE, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2121 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 2122 | (char *)&dup_ext_buf, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2123 | sizeof(struct duplicate_extents_to_file), |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2124 | CIFSMaxBufSize, NULL, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2125 | &ret_data_len); |
| 2126 | |
| 2127 | if (ret_data_len > 0) |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2128 | cifs_dbg(FYI, "Non-zero response length in duplicate extents\n"); |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2129 | |
| 2130 | duplicate_extents_out: |
| 2131 | return rc; |
| 2132 | } |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 2133 | |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2134 | static int |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 2135 | smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, |
| 2136 | struct cifsFileInfo *cfile) |
| 2137 | { |
| 2138 | return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, |
| 2139 | cfile->fid.volatile_fid); |
| 2140 | } |
| 2141 | |
| 2142 | static int |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2143 | smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, |
| 2144 | struct cifsFileInfo *cfile) |
| 2145 | { |
| 2146 | struct fsctl_set_integrity_information_req integr_info; |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2147 | unsigned int ret_data_len; |
| 2148 | |
| 2149 | integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED); |
| 2150 | integr_info.Flags = 0; |
| 2151 | integr_info.Reserved = 0; |
| 2152 | |
| 2153 | return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 2154 | cfile->fid.volatile_fid, |
| 2155 | FSCTL_SET_INTEGRITY_INFORMATION, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2156 | true /* is_fsctl */, |
Aurelien Aptel | 5114662 | 2017-02-28 15:08:41 +0100 | [diff] [blame] | 2157 | (char *)&integr_info, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2158 | sizeof(struct fsctl_set_integrity_information_req), |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2159 | CIFSMaxBufSize, NULL, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2160 | &ret_data_len); |
| 2161 | |
| 2162 | } |
| 2163 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 2164 | /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */ |
| 2165 | #define GMT_TOKEN_SIZE 50 |
| 2166 | |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2167 | #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */ |
| 2168 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 2169 | /* |
| 2170 | * Input buffer contains (empty) struct smb_snapshot array with size filled in |
| 2171 | * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2 |
| 2172 | */ |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 2173 | static int |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2174 | smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, |
| 2175 | struct cifsFileInfo *cfile, void __user *ioc_buf) |
| 2176 | { |
| 2177 | char *retbuf = NULL; |
| 2178 | unsigned int ret_data_len = 0; |
| 2179 | int rc; |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2180 | u32 max_response_size; |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2181 | struct smb_snapshot_array snapshot_in; |
| 2182 | |
Steve French | 973189a | 2019-04-04 00:41:04 -0500 | [diff] [blame] | 2183 | /* |
| 2184 | * On the first query to enumerate the list of snapshots available |
| 2185 | * for this volume the buffer begins with 0 (number of snapshots |
| 2186 | * which can be returned is zero since at that point we do not know |
| 2187 | * how big the buffer needs to be). On the second query, |
| 2188 | * it (ret_data_len) is set to number of snapshots so we can |
| 2189 | * know to set the maximum response size larger (see below). |
| 2190 | */ |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2191 | if (get_user(ret_data_len, (unsigned int __user *)ioc_buf)) |
| 2192 | return -EFAULT; |
| 2193 | |
| 2194 | /* |
| 2195 | * Note that for snapshot queries that servers like Azure expect that |
| 2196 | * the first query be minimal size (and just used to get the number/size |
| 2197 | * of previous versions) so response size must be specified as EXACTLY |
| 2198 | * sizeof(struct snapshot_array) which is 16 when rounded up to multiple |
| 2199 | * of eight bytes. |
| 2200 | */ |
| 2201 | if (ret_data_len == 0) |
| 2202 | max_response_size = MIN_SNAPSHOT_ARRAY_SIZE; |
| 2203 | else |
| 2204 | max_response_size = CIFSMaxBufSize; |
| 2205 | |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2206 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 2207 | cfile->fid.volatile_fid, |
| 2208 | FSCTL_SRV_ENUMERATE_SNAPSHOTS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2209 | true /* is_fsctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2210 | NULL, 0 /* no input data */, max_response_size, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2211 | (char **)&retbuf, |
| 2212 | &ret_data_len); |
| 2213 | cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n", |
| 2214 | rc, ret_data_len); |
| 2215 | if (rc) |
| 2216 | return rc; |
| 2217 | |
| 2218 | if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) { |
| 2219 | /* Fixup buffer */ |
| 2220 | if (copy_from_user(&snapshot_in, ioc_buf, |
| 2221 | sizeof(struct smb_snapshot_array))) { |
| 2222 | rc = -EFAULT; |
| 2223 | kfree(retbuf); |
| 2224 | return rc; |
| 2225 | } |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2226 | |
Steve French | e02789a | 2018-08-09 14:33:12 -0500 | [diff] [blame] | 2227 | /* |
| 2228 | * Check for min size, ie not large enough to fit even one GMT |
| 2229 | * token (snapshot). On the first ioctl some users may pass in |
| 2230 | * smaller size (or zero) to simply get the size of the array |
| 2231 | * so the user space caller can allocate sufficient memory |
| 2232 | * and retry the ioctl again with larger array size sufficient |
| 2233 | * to hold all of the snapshot GMT tokens on the second try. |
| 2234 | */ |
| 2235 | if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE) |
| 2236 | ret_data_len = sizeof(struct smb_snapshot_array); |
| 2237 | |
| 2238 | /* |
| 2239 | * We return struct SRV_SNAPSHOT_ARRAY, followed by |
| 2240 | * the snapshot array (of 50 byte GMT tokens) each |
| 2241 | * representing an available previous version of the data |
| 2242 | */ |
| 2243 | if (ret_data_len > (snapshot_in.snapshot_array_size + |
| 2244 | sizeof(struct smb_snapshot_array))) |
| 2245 | ret_data_len = snapshot_in.snapshot_array_size + |
| 2246 | sizeof(struct smb_snapshot_array); |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2247 | |
| 2248 | if (copy_to_user(ioc_buf, retbuf, ret_data_len)) |
| 2249 | rc = -EFAULT; |
| 2250 | } |
| 2251 | |
| 2252 | kfree(retbuf); |
| 2253 | return rc; |
| 2254 | } |
| 2255 | |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2256 | |
| 2257 | |
| 2258 | static int |
| 2259 | smb3_notify(const unsigned int xid, struct file *pfile, |
| 2260 | void __user *ioc_buf) |
| 2261 | { |
| 2262 | struct smb3_notify notify; |
| 2263 | struct dentry *dentry = pfile->f_path.dentry; |
| 2264 | struct inode *inode = file_inode(pfile); |
Al Viro | f6a9bc3 | 2021-03-05 17:36:04 -0500 | [diff] [blame] | 2265 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2266 | struct cifs_open_parms oparms; |
| 2267 | struct cifs_fid fid; |
| 2268 | struct cifs_tcon *tcon; |
Al Viro | f6a9bc3 | 2021-03-05 17:36:04 -0500 | [diff] [blame] | 2269 | const unsigned char *path; |
| 2270 | void *page = alloc_dentry_path(); |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2271 | __le16 *utf16_path = NULL; |
| 2272 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2273 | int rc = 0; |
| 2274 | |
Al Viro | f6a9bc3 | 2021-03-05 17:36:04 -0500 | [diff] [blame] | 2275 | path = build_path_from_dentry(dentry, page); |
| 2276 | if (IS_ERR(path)) { |
| 2277 | rc = PTR_ERR(path); |
| 2278 | goto notify_exit; |
| 2279 | } |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2280 | |
Eugene Korenevsky | a637f4a | 2021-04-16 10:35:30 +0300 | [diff] [blame] | 2281 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2282 | if (utf16_path == NULL) { |
| 2283 | rc = -ENOMEM; |
| 2284 | goto notify_exit; |
| 2285 | } |
| 2286 | |
| 2287 | if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) { |
| 2288 | rc = -EFAULT; |
| 2289 | goto notify_exit; |
| 2290 | } |
| 2291 | |
| 2292 | tcon = cifs_sb_master_tcon(cifs_sb); |
| 2293 | oparms.tcon = tcon; |
Steve French | 4ef9b4f | 2020-07-07 18:08:46 -0500 | [diff] [blame] | 2294 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2295 | oparms.disposition = FILE_OPEN; |
| 2296 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
| 2297 | oparms.fid = &fid; |
| 2298 | oparms.reconnect = false; |
| 2299 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 2300 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL, |
| 2301 | NULL); |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2302 | if (rc) |
| 2303 | goto notify_exit; |
| 2304 | |
| 2305 | rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid, |
| 2306 | notify.watch_tree, notify.completion_filter); |
| 2307 | |
| 2308 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 2309 | |
| 2310 | cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc); |
| 2311 | |
| 2312 | notify_exit: |
Al Viro | f6a9bc3 | 2021-03-05 17:36:04 -0500 | [diff] [blame] | 2313 | free_dentry_path(page); |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 2314 | kfree(utf16_path); |
| 2315 | return rc; |
| 2316 | } |
| 2317 | |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 2318 | static int |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2319 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, |
| 2320 | const char *path, struct cifs_sb_info *cifs_sb, |
| 2321 | struct cifs_fid *fid, __u16 search_flags, |
| 2322 | struct cifs_search_info *srch_inf) |
| 2323 | { |
| 2324 | __le16 *utf16_path; |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2325 | struct smb_rqst rqst[2]; |
| 2326 | struct kvec rsp_iov[2]; |
| 2327 | int resp_buftype[2]; |
| 2328 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 2329 | struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE]; |
| 2330 | int rc, flags = 0; |
| 2331 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2332 | struct cifs_open_parms oparms; |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2333 | struct smb2_query_directory_rsp *qd_rsp = NULL; |
| 2334 | struct smb2_create_rsp *op_rsp = NULL; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2335 | struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); |
Thiago Rafael Becker | 6efa994 | 2021-06-15 13:42:56 -0300 | [diff] [blame] | 2336 | int retry_count = 0; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2337 | |
| 2338 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 2339 | if (!utf16_path) |
| 2340 | return -ENOMEM; |
| 2341 | |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2342 | if (smb3_encryption_required(tcon)) |
| 2343 | flags |= CIFS_TRANSFORM_REQ; |
| 2344 | |
| 2345 | memset(rqst, 0, sizeof(rqst)); |
| 2346 | resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER; |
| 2347 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 2348 | |
| 2349 | /* Open */ |
| 2350 | memset(&open_iov, 0, sizeof(open_iov)); |
| 2351 | rqst[0].rq_iov = open_iov; |
| 2352 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 2353 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2354 | oparms.tcon = tcon; |
| 2355 | oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA; |
| 2356 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2357 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2358 | oparms.fid = fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 2359 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2360 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2361 | rc = SMB2_open_init(tcon, server, |
| 2362 | &rqst[0], &oplock, &oparms, utf16_path); |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2363 | if (rc) |
| 2364 | goto qdf_free; |
| 2365 | smb2_set_next_command(tcon, &rqst[0]); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2366 | |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2367 | /* Query directory */ |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2368 | srch_inf->entries_in_buffer = 0; |
Aurelien Aptel | 0595751 | 2018-05-17 16:35:07 +0200 | [diff] [blame] | 2369 | srch_inf->index_of_last_entry = 2; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2370 | |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2371 | memset(&qd_iov, 0, sizeof(qd_iov)); |
| 2372 | rqst[1].rq_iov = qd_iov; |
| 2373 | rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE; |
| 2374 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2375 | rc = SMB2_query_directory_init(xid, tcon, server, |
| 2376 | &rqst[1], |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2377 | COMPOUND_FID, COMPOUND_FID, |
| 2378 | 0, srch_inf->info_level); |
| 2379 | if (rc) |
| 2380 | goto qdf_free; |
| 2381 | |
| 2382 | smb2_set_related(&rqst[1]); |
| 2383 | |
Thiago Rafael Becker | 6efa994 | 2021-06-15 13:42:56 -0300 | [diff] [blame] | 2384 | again: |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2385 | rc = compound_send_recv(xid, tcon->ses, server, |
| 2386 | flags, 2, rqst, |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2387 | resp_buftype, rsp_iov); |
| 2388 | |
Thiago Rafael Becker | 6efa994 | 2021-06-15 13:42:56 -0300 | [diff] [blame] | 2389 | if (rc == -EAGAIN && retry_count++ < 10) |
| 2390 | goto again; |
| 2391 | |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2392 | /* If the open failed there is nothing to do */ |
| 2393 | op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2394 | if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) { |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2395 | cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc); |
| 2396 | goto qdf_free; |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2397 | } |
Ronnie Sahlberg | c462870 | 2021-09-08 12:10:15 +1000 | [diff] [blame] | 2398 | fid->persistent_fid = le64_to_cpu(op_rsp->PersistentFileId); |
| 2399 | fid->volatile_fid = le64_to_cpu(op_rsp->VolatileFileId); |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2400 | |
| 2401 | /* Anything else than ENODATA means a genuine error */ |
| 2402 | if (rc && rc != -ENODATA) { |
| 2403 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 2404 | cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc); |
| 2405 | trace_smb3_query_dir_err(xid, fid->persistent_fid, |
| 2406 | tcon->tid, tcon->ses->Suid, 0, 0, rc); |
| 2407 | goto qdf_free; |
| 2408 | } |
| 2409 | |
Shyam Prasad N | 1be1fa4 | 2020-03-09 01:35:09 -0700 | [diff] [blame] | 2410 | atomic_inc(&tcon->num_remote_opens); |
| 2411 | |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2412 | qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2413 | if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) { |
Ronnie Sahlberg | 3747860 | 2020-01-08 13:08:06 +1000 | [diff] [blame] | 2414 | trace_smb3_query_dir_done(xid, fid->persistent_fid, |
| 2415 | tcon->tid, tcon->ses->Suid, 0, 0); |
| 2416 | srch_inf->endOfSearch = true; |
| 2417 | rc = 0; |
| 2418 | goto qdf_free; |
| 2419 | } |
| 2420 | |
| 2421 | rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1], |
| 2422 | srch_inf); |
| 2423 | if (rc) { |
| 2424 | trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid, |
| 2425 | tcon->ses->Suid, 0, 0, rc); |
| 2426 | goto qdf_free; |
| 2427 | } |
| 2428 | resp_buftype[1] = CIFS_NO_BUFFER; |
| 2429 | |
| 2430 | trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid, |
| 2431 | tcon->ses->Suid, 0, srch_inf->entries_in_buffer); |
| 2432 | |
| 2433 | qdf_free: |
| 2434 | kfree(utf16_path); |
| 2435 | SMB2_open_free(&rqst[0]); |
| 2436 | SMB2_query_directory_free(&rqst[1]); |
| 2437 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 2438 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2439 | return rc; |
| 2440 | } |
| 2441 | |
| 2442 | static int |
| 2443 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, |
| 2444 | struct cifs_fid *fid, __u16 search_flags, |
| 2445 | struct cifs_search_info *srch_inf) |
| 2446 | { |
| 2447 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, |
| 2448 | fid->volatile_fid, 0, srch_inf); |
| 2449 | } |
| 2450 | |
| 2451 | static int |
| 2452 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, |
| 2453 | struct cifs_fid *fid) |
| 2454 | { |
| 2455 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); |
| 2456 | } |
| 2457 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2458 | /* |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2459 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update |
| 2460 | * the number of credits and return true. Otherwise - return false. |
| 2461 | */ |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2462 | static bool |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 2463 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2464 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2465 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 2466 | int scredits, in_flight; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2467 | |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2468 | if (shdr->Status != STATUS_PENDING) |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2469 | return false; |
| 2470 | |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 2471 | if (shdr->CreditRequest) { |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2472 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 31473fc | 2016-10-24 15:33:04 -0700 | [diff] [blame] | 2473 | server->credits += le16_to_cpu(shdr->CreditRequest); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 2474 | scredits = server->credits; |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 2475 | in_flight = server->in_flight; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2476 | spin_unlock(&server->req_lock); |
| 2477 | wake_up(&server->request_q); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 2478 | |
| 2479 | trace_smb3_add_credits(server->CurrentMid, |
Shyam Prasad N | 6d82c27 | 2021-02-03 23:20:46 -0800 | [diff] [blame] | 2480 | server->conn_id, server->hostname, scredits, |
| 2481 | le16_to_cpu(shdr->CreditRequest), in_flight); |
Shyam Prasad N | cd7b699 | 2020-11-12 08:56:49 -0800 | [diff] [blame] | 2482 | cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n", |
| 2483 | __func__, le16_to_cpu(shdr->CreditRequest), scredits); |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | return true; |
| 2487 | } |
| 2488 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2489 | static bool |
| 2490 | smb2_is_session_expired(char *buf) |
| 2491 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2492 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2493 | |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 2494 | if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && |
| 2495 | shdr->Status != STATUS_USER_SESSION_DELETED) |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2496 | return false; |
| 2497 | |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2498 | trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId), |
| 2499 | le64_to_cpu(shdr->SessionId), |
Steve French | e68a932 | 2018-07-30 14:23:58 -0500 | [diff] [blame] | 2500 | le16_to_cpu(shdr->Command), |
| 2501 | le64_to_cpu(shdr->MessageId)); |
Mark Syms | d81243c | 2018-05-24 09:47:31 +0100 | [diff] [blame] | 2502 | cifs_dbg(FYI, "Session expired or deleted\n"); |
Steve French | e68a932 | 2018-07-30 14:23:58 -0500 | [diff] [blame] | 2503 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 2504 | return true; |
| 2505 | } |
| 2506 | |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 2507 | static bool |
| 2508 | smb2_is_status_io_timeout(char *buf) |
| 2509 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2510 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 2511 | |
| 2512 | if (shdr->Status == STATUS_IO_TIMEOUT) |
| 2513 | return true; |
| 2514 | else |
| 2515 | return false; |
| 2516 | } |
| 2517 | |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 2518 | static void |
| 2519 | smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server) |
| 2520 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2521 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 2522 | struct list_head *tmp, *tmp1; |
| 2523 | struct cifs_ses *ses; |
| 2524 | struct cifs_tcon *tcon; |
| 2525 | |
Steve French | f1a0865 | 2021-02-20 18:52:15 -0600 | [diff] [blame] | 2526 | if (shdr->Status != STATUS_NETWORK_NAME_DELETED) |
| 2527 | return; |
| 2528 | |
| 2529 | spin_lock(&cifs_tcp_ses_lock); |
| 2530 | list_for_each(tmp, &server->smb_ses_list) { |
| 2531 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); |
| 2532 | list_for_each(tmp1, &ses->tcon_list) { |
| 2533 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2534 | if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) { |
Steve French | f1a0865 | 2021-02-20 18:52:15 -0600 | [diff] [blame] | 2535 | tcon->need_reconnect = true; |
| 2536 | spin_unlock(&cifs_tcp_ses_lock); |
| 2537 | pr_warn_once("Server share %s deleted.\n", |
| 2538 | tcon->treeName); |
| 2539 | return; |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 2540 | } |
| 2541 | } |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 2542 | } |
Steve French | f1a0865 | 2021-02-20 18:52:15 -0600 | [diff] [blame] | 2543 | spin_unlock(&cifs_tcp_ses_lock); |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2546 | static int |
| 2547 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, |
| 2548 | struct cifsInodeInfo *cinode) |
| 2549 | { |
Pavel Shilovsky | 0822f51 | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 2550 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) |
| 2551 | return SMB2_lease_break(0, tcon, cinode->lease_key, |
| 2552 | smb2_get_lease_state(cinode)); |
| 2553 | |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2554 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, |
| 2555 | fid->volatile_fid, |
Pavel Shilovsky | 18cceb6 | 2013-09-05 13:01:06 +0400 | [diff] [blame] | 2556 | CIFS_CACHE_READ(cinode) ? 1 : 0); |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2559 | void |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2560 | smb2_set_related(struct smb_rqst *rqst) |
| 2561 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2562 | struct smb2_hdr *shdr; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2563 | |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2564 | shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 2565 | if (shdr == NULL) { |
| 2566 | cifs_dbg(FYI, "shdr NULL in smb2_set_related\n"); |
| 2567 | return; |
| 2568 | } |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2569 | shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; |
| 2570 | } |
| 2571 | |
| 2572 | char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0}; |
| 2573 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2574 | void |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2575 | smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2576 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2577 | struct smb2_hdr *shdr; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2578 | struct cifs_ses *ses = tcon->ses; |
| 2579 | struct TCP_Server_Info *server = ses->server; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2580 | unsigned long len = smb_rqst_len(server, rqst); |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2581 | int i, num_padding; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2582 | |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 2583 | shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 2584 | if (shdr == NULL) { |
| 2585 | cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n"); |
| 2586 | return; |
| 2587 | } |
| 2588 | |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2589 | /* SMB headers in a compound are 8 byte aligned. */ |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2590 | |
| 2591 | /* No padding needed */ |
| 2592 | if (!(len & 7)) |
| 2593 | goto finished; |
| 2594 | |
| 2595 | num_padding = 8 - (len & 7); |
| 2596 | if (!smb3_encryption_required(tcon)) { |
| 2597 | /* |
| 2598 | * If we do not have encryption then we can just add an extra |
| 2599 | * iov for the padding. |
| 2600 | */ |
| 2601 | rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; |
| 2602 | rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; |
| 2603 | rqst->rq_nvec++; |
| 2604 | len += num_padding; |
| 2605 | } else { |
| 2606 | /* |
| 2607 | * We can not add a small padding iov for the encryption case |
| 2608 | * because the encryption framework can not handle the padding |
| 2609 | * iovs. |
| 2610 | * We have to flatten this into a single buffer and add |
| 2611 | * the padding to it. |
| 2612 | */ |
| 2613 | for (i = 1; i < rqst->rq_nvec; i++) { |
| 2614 | memcpy(rqst->rq_iov[0].iov_base + |
| 2615 | rqst->rq_iov[0].iov_len, |
| 2616 | rqst->rq_iov[i].iov_base, |
| 2617 | rqst->rq_iov[i].iov_len); |
| 2618 | rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; |
Ronnie Sahlberg | 271b9c0 | 2018-12-18 17:49:05 -0600 | [diff] [blame] | 2619 | } |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2620 | memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, |
| 2621 | 0, num_padding); |
| 2622 | rqst->rq_iov[0].iov_len += num_padding; |
| 2623 | len += num_padding; |
| 2624 | rqst->rq_nvec = 1; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2625 | } |
| 2626 | |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2627 | finished: |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2628 | shdr->NextCommand = cpu_to_le32(len); |
| 2629 | } |
| 2630 | |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2631 | /* |
| 2632 | * Passes the query info response back to the caller on success. |
| 2633 | * Caller need to free this with free_rsp_buf(). |
| 2634 | */ |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2635 | int |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2636 | smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, |
| 2637 | __le16 *utf16_path, u32 desired_access, |
| 2638 | u32 class, u32 type, u32 output_len, |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2639 | struct kvec *rsp, int *buftype, |
| 2640 | struct cifs_sb_info *cifs_sb) |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2641 | { |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2642 | struct cifs_ses *ses = tcon->ses; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2643 | struct TCP_Server_Info *server = cifs_pick_channel(ses); |
Paulo Alcantara | 04ad69c | 2021-03-08 12:00:50 -0300 | [diff] [blame] | 2644 | int flags = CIFS_CP_CREATE_CLOSE_OP; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2645 | struct smb_rqst rqst[3]; |
| 2646 | int resp_buftype[3]; |
| 2647 | struct kvec rsp_iov[3]; |
Ronnie Sahlberg | 4d8dfaf | 2018-08-21 11:49:21 +1000 | [diff] [blame] | 2648 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2649 | struct kvec qi_iov[1]; |
| 2650 | struct kvec close_iov[1]; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2651 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2652 | struct cifs_open_parms oparms; |
| 2653 | struct cifs_fid fid; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2654 | int rc; |
| 2655 | |
| 2656 | if (smb3_encryption_required(tcon)) |
| 2657 | flags |= CIFS_TRANSFORM_REQ; |
| 2658 | |
| 2659 | memset(rqst, 0, sizeof(rqst)); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 2660 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2661 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 2662 | |
| 2663 | memset(&open_iov, 0, sizeof(open_iov)); |
| 2664 | rqst[0].rq_iov = open_iov; |
Ronnie Sahlberg | 4d8dfaf | 2018-08-21 11:49:21 +1000 | [diff] [blame] | 2665 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2666 | |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2667 | oparms.tcon = tcon; |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2668 | oparms.desired_access = desired_access; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2669 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2670 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2671 | oparms.fid = &fid; |
Pavel Shilovsky | 9cbc0b7 | 2013-07-09 18:40:58 +0400 | [diff] [blame] | 2672 | oparms.reconnect = false; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 2673 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2674 | rc = SMB2_open_init(tcon, server, |
| 2675 | &rqst[0], &oplock, &oparms, utf16_path); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2676 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2677 | goto qic_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2678 | smb2_set_next_command(tcon, &rqst[0]); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2679 | |
| 2680 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 2681 | rqst[1].rq_iov = qi_iov; |
| 2682 | rqst[1].rq_nvec = 1; |
| 2683 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2684 | rc = SMB2_query_info_init(tcon, server, |
| 2685 | &rqst[1], COMPOUND_FID, COMPOUND_FID, |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2686 | class, type, 0, |
| 2687 | output_len, 0, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 2688 | NULL); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2689 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2690 | goto qic_exit; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 2691 | smb2_set_next_command(tcon, &rqst[1]); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2692 | smb2_set_related(&rqst[1]); |
| 2693 | |
| 2694 | memset(&close_iov, 0, sizeof(close_iov)); |
| 2695 | rqst[2].rq_iov = close_iov; |
| 2696 | rqst[2].rq_nvec = 1; |
| 2697 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2698 | rc = SMB2_close_init(tcon, server, |
| 2699 | &rqst[2], COMPOUND_FID, COMPOUND_FID, false); |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2700 | if (rc) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2701 | goto qic_exit; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2702 | smb2_set_related(&rqst[2]); |
| 2703 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 2704 | rc = compound_send_recv(xid, ses, server, |
| 2705 | flags, 3, rqst, |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2706 | resp_buftype, rsp_iov); |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2707 | if (rc) { |
| 2708 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 2709 | if (rc == -EREMCHG) { |
| 2710 | tcon->need_reconnect = true; |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 2711 | pr_warn_once("server share %s deleted\n", |
| 2712 | tcon->treeName); |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 2713 | } |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2714 | goto qic_exit; |
Ronnie Sahlberg | f9793b6 | 2018-11-27 09:52:04 +1000 | [diff] [blame] | 2715 | } |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2716 | *rsp = rsp_iov[1]; |
| 2717 | *buftype = resp_buftype[1]; |
| 2718 | |
| 2719 | qic_exit: |
| 2720 | SMB2_open_free(&rqst[0]); |
| 2721 | SMB2_query_info_free(&rqst[1]); |
| 2722 | SMB2_close_free(&rqst[2]); |
| 2723 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 2724 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
| 2725 | return rc; |
| 2726 | } |
| 2727 | |
| 2728 | static int |
| 2729 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2730 | struct cifs_sb_info *cifs_sb, struct kstatfs *buf) |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2731 | { |
| 2732 | struct smb2_query_info_rsp *rsp; |
| 2733 | struct smb2_fs_full_size_info *info = NULL; |
| 2734 | __le16 utf16_path = 0; /* Null - open root of share */ |
| 2735 | struct kvec rsp_iov = {NULL, 0}; |
| 2736 | int buftype = CIFS_NO_BUFFER; |
| 2737 | int rc; |
| 2738 | |
| 2739 | |
| 2740 | rc = smb2_query_info_compound(xid, tcon, &utf16_path, |
| 2741 | FILE_READ_ATTRIBUTES, |
| 2742 | FS_FULL_SIZE_INFORMATION, |
| 2743 | SMB2_O_INFO_FILESYSTEM, |
| 2744 | sizeof(struct smb2_fs_full_size_info), |
Steve French | 87f93d8 | 2020-02-04 13:02:59 -0600 | [diff] [blame] | 2745 | &rsp_iov, &buftype, cifs_sb); |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2746 | if (rc) |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2747 | goto qfs_exit; |
| 2748 | |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2749 | rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base; |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2750 | buf->f_type = SMB2_MAGIC_NUMBER; |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2751 | info = (struct smb2_fs_full_size_info *)( |
| 2752 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); |
| 2753 | rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), |
| 2754 | le32_to_cpu(rsp->OutputBufferLength), |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2755 | &rsp_iov, |
Ronnie Sahlberg | 730928c | 2018-08-08 15:07:49 +1000 | [diff] [blame] | 2756 | sizeof(struct smb2_fs_full_size_info)); |
| 2757 | if (!rc) |
| 2758 | smb2_copy_fs_info_to_kstatfs(info, buf); |
| 2759 | |
| 2760 | qfs_exit: |
Ronnie Sahlberg | 07d3b2e | 2018-12-20 22:03:04 -0600 | [diff] [blame] | 2761 | free_rsp_buf(buftype, rsp_iov.iov_base); |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 2762 | return rc; |
| 2763 | } |
| 2764 | |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2765 | static int |
| 2766 | smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon, |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2767 | struct cifs_sb_info *cifs_sb, struct kstatfs *buf) |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2768 | { |
| 2769 | int rc; |
| 2770 | __le16 srch_path = 0; /* Null - open root of share */ |
| 2771 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 2772 | struct cifs_open_parms oparms; |
| 2773 | struct cifs_fid fid; |
| 2774 | |
| 2775 | if (!tcon->posix_extensions) |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2776 | return smb2_queryfs(xid, tcon, cifs_sb, buf); |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2777 | |
| 2778 | oparms.tcon = tcon; |
| 2779 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 2780 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 2781 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2782 | oparms.fid = &fid; |
| 2783 | oparms.reconnect = false; |
| 2784 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 2785 | rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, |
| 2786 | NULL, NULL); |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2787 | if (rc) |
| 2788 | return rc; |
| 2789 | |
| 2790 | rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid, |
| 2791 | fid.volatile_fid, buf); |
| 2792 | buf->f_type = SMB2_MAGIC_NUMBER; |
| 2793 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 2794 | return rc; |
| 2795 | } |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 2796 | |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2797 | static bool |
| 2798 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
| 2799 | { |
| 2800 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && |
| 2801 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; |
| 2802 | } |
| 2803 | |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 2804 | static int |
| 2805 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, |
| 2806 | __u64 length, __u32 type, int lock, int unlock, bool wait) |
| 2807 | { |
| 2808 | if (unlock && !lock) |
| 2809 | type = SMB2_LOCKFLAG_UNLOCK; |
| 2810 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), |
| 2811 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, |
| 2812 | current->tgid, length, offset, type, wait); |
| 2813 | } |
| 2814 | |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2815 | static void |
| 2816 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 2817 | { |
| 2818 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); |
| 2819 | } |
| 2820 | |
| 2821 | static void |
| 2822 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) |
| 2823 | { |
| 2824 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); |
| 2825 | } |
| 2826 | |
| 2827 | static void |
| 2828 | smb2_new_lease_key(struct cifs_fid *fid) |
| 2829 | { |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 2830 | generate_random_uuid(fid->lease_key); |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2833 | static int |
| 2834 | smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses, |
| 2835 | const char *search_name, |
| 2836 | struct dfs_info3_param **target_nodes, |
| 2837 | unsigned int *num_of_nodes, |
| 2838 | const struct nls_table *nls_codepage, int remap) |
| 2839 | { |
| 2840 | int rc; |
| 2841 | __le16 *utf16_path = NULL; |
| 2842 | int utf16_path_len = 0; |
| 2843 | struct cifs_tcon *tcon; |
| 2844 | struct fsctl_get_dfs_referral_req *dfs_req = NULL; |
| 2845 | struct get_dfs_referral_rsp *dfs_rsp = NULL; |
| 2846 | u32 dfs_req_size = 0, dfs_rsp_size = 0; |
Paulo Alcantara | c88f7dc | 2021-11-03 13:53:29 -0300 | [diff] [blame] | 2847 | int retry_count = 0; |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2848 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 2849 | cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2850 | |
| 2851 | /* |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2852 | * Try to use the IPC tcon, otherwise just use any |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2853 | */ |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2854 | tcon = ses->tcon_ipc; |
| 2855 | if (tcon == NULL) { |
| 2856 | spin_lock(&cifs_tcp_ses_lock); |
| 2857 | tcon = list_first_entry_or_null(&ses->tcon_list, |
| 2858 | struct cifs_tcon, |
| 2859 | tcon_list); |
| 2860 | if (tcon) |
| 2861 | tcon->tc_count++; |
| 2862 | spin_unlock(&cifs_tcp_ses_lock); |
| 2863 | } |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2864 | |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2865 | if (tcon == NULL) { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2866 | cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", |
| 2867 | ses); |
| 2868 | rc = -ENOTCONN; |
| 2869 | goto out; |
| 2870 | } |
| 2871 | |
| 2872 | utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX, |
| 2873 | &utf16_path_len, |
| 2874 | nls_codepage, remap); |
| 2875 | if (!utf16_path) { |
| 2876 | rc = -ENOMEM; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | |
| 2880 | dfs_req_size = sizeof(*dfs_req) + utf16_path_len; |
| 2881 | dfs_req = kzalloc(dfs_req_size, GFP_KERNEL); |
| 2882 | if (!dfs_req) { |
| 2883 | rc = -ENOMEM; |
| 2884 | goto out; |
| 2885 | } |
| 2886 | |
| 2887 | /* Highest DFS referral version understood */ |
| 2888 | dfs_req->MaxReferralLevel = DFS_VERSION; |
| 2889 | |
| 2890 | /* Path to resolve in an UTF-16 null-terminated string */ |
| 2891 | memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); |
| 2892 | |
| 2893 | do { |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2894 | rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, |
| 2895 | FSCTL_DFS_GET_REFERRALS, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2896 | true /* is_fsctl */, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 2897 | (char *)dfs_req, dfs_req_size, CIFSMaxBufSize, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2898 | (char **)&dfs_rsp, &dfs_rsp_size); |
Paulo Alcantara | c88f7dc | 2021-11-03 13:53:29 -0300 | [diff] [blame] | 2899 | if (!is_retryable_error(rc)) |
| 2900 | break; |
| 2901 | usleep_range(512, 2048); |
| 2902 | } while (++retry_count < 5); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2903 | |
| 2904 | if (rc) { |
Paulo Alcantara | c88f7dc | 2021-11-03 13:53:29 -0300 | [diff] [blame] | 2905 | if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP) |
| 2906 | cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2907 | goto out; |
| 2908 | } |
| 2909 | |
| 2910 | rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size, |
| 2911 | num_of_nodes, target_nodes, |
| 2912 | nls_codepage, remap, search_name, |
| 2913 | true /* is_unicode */); |
| 2914 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 2915 | 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] | 2916 | goto out; |
| 2917 | } |
| 2918 | |
| 2919 | out: |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 2920 | if (tcon && !tcon->ipc) { |
| 2921 | /* ipc tcons are not refcounted */ |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2922 | spin_lock(&cifs_tcp_ses_lock); |
| 2923 | tcon->tc_count--; |
Shyam Prasad N | 16dd9b8 | 2021-07-14 23:00:00 -0500 | [diff] [blame] | 2924 | /* tc_count can never go negative */ |
| 2925 | WARN_ON(tcon->tc_count < 0); |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 2926 | spin_unlock(&cifs_tcp_ses_lock); |
| 2927 | } |
| 2928 | kfree(utf16_path); |
| 2929 | kfree(dfs_req); |
| 2930 | kfree(dfs_rsp); |
| 2931 | return rc; |
| 2932 | } |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2933 | |
| 2934 | static int |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2935 | parse_reparse_posix(struct reparse_posix_data *symlink_buf, |
| 2936 | u32 plen, char **target_path, |
| 2937 | struct cifs_sb_info *cifs_sb) |
| 2938 | { |
| 2939 | unsigned int len; |
| 2940 | |
| 2941 | /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ |
| 2942 | len = le16_to_cpu(symlink_buf->ReparseDataLength); |
| 2943 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2944 | if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) { |
| 2945 | cifs_dbg(VFS, "%lld not a supported symlink type\n", |
| 2946 | le64_to_cpu(symlink_buf->InodeType)); |
| 2947 | return -EOPNOTSUPP; |
| 2948 | } |
| 2949 | |
| 2950 | *target_path = cifs_strndup_from_utf16( |
| 2951 | symlink_buf->PathBuffer, |
| 2952 | len, true, cifs_sb->local_nls); |
| 2953 | if (!(*target_path)) |
| 2954 | return -ENOMEM; |
| 2955 | |
| 2956 | convert_delimiter(*target_path, '/'); |
| 2957 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 2958 | |
| 2959 | return 0; |
| 2960 | } |
| 2961 | |
| 2962 | static int |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 2963 | parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf, |
| 2964 | u32 plen, char **target_path, |
| 2965 | struct cifs_sb_info *cifs_sb) |
| 2966 | { |
| 2967 | unsigned int sub_len; |
| 2968 | unsigned int sub_offset; |
| 2969 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2970 | /* 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] | 2971 | |
| 2972 | sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset); |
| 2973 | sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength); |
| 2974 | if (sub_offset + 20 > plen || |
| 2975 | sub_offset + sub_len + 20 > plen) { |
| 2976 | cifs_dbg(VFS, "srv returned malformed symlink buffer\n"); |
| 2977 | return -EIO; |
| 2978 | } |
| 2979 | |
| 2980 | *target_path = cifs_strndup_from_utf16( |
| 2981 | symlink_buf->PathBuffer + sub_offset, |
| 2982 | sub_len, true, cifs_sb->local_nls); |
| 2983 | if (!(*target_path)) |
| 2984 | return -ENOMEM; |
| 2985 | |
| 2986 | convert_delimiter(*target_path, '/'); |
| 2987 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
| 2988 | |
| 2989 | return 0; |
| 2990 | } |
| 2991 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2992 | static int |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2993 | parse_reparse_point(struct reparse_data_buffer *buf, |
| 2994 | u32 plen, char **target_path, |
| 2995 | struct cifs_sb_info *cifs_sb) |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 2996 | { |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 2997 | if (plen < sizeof(struct reparse_data_buffer)) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 2998 | cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n", |
| 2999 | plen); |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3000 | return -EIO; |
| 3001 | } |
| 3002 | |
| 3003 | if (plen < le16_to_cpu(buf->ReparseDataLength) + |
| 3004 | sizeof(struct reparse_data_buffer)) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 3005 | cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n", |
| 3006 | plen); |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3007 | return -EIO; |
| 3008 | } |
| 3009 | |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 3010 | /* See MS-FSCC 2.1.2 */ |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3011 | switch (le32_to_cpu(buf->ReparseTag)) { |
| 3012 | case IO_REPARSE_TAG_NFS: |
| 3013 | return parse_reparse_posix( |
| 3014 | (struct reparse_posix_data *)buf, |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 3015 | plen, target_path, cifs_sb); |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3016 | case IO_REPARSE_TAG_SYMLINK: |
| 3017 | return parse_reparse_symlink( |
| 3018 | (struct reparse_symlink_data_buffer *)buf, |
| 3019 | plen, target_path, cifs_sb); |
| 3020 | default: |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 3021 | cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n", |
| 3022 | le32_to_cpu(buf->ReparseTag)); |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3023 | return -EOPNOTSUPP; |
| 3024 | } |
Steve French | d5ecebc | 2019-06-28 02:04:18 -0500 | [diff] [blame] | 3025 | } |
| 3026 | |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3027 | #define SMB2_SYMLINK_STRUCT_SIZE \ |
| 3028 | (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp)) |
| 3029 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3030 | static int |
| 3031 | smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3032 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 3033 | char **target_path, bool is_reparse_point) |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3034 | { |
| 3035 | int rc; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3036 | __le16 *utf16_path = NULL; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3037 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 3038 | struct cifs_open_parms oparms; |
| 3039 | struct cifs_fid fid; |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 3040 | struct kvec err_iov = {NULL, 0}; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3041 | struct smb2_err_rsp *err_buf = NULL; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3042 | struct smb2_symlink_err_rsp *symlink; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 3043 | struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3044 | unsigned int sub_len; |
| 3045 | unsigned int sub_offset; |
| 3046 | unsigned int print_len; |
| 3047 | unsigned int print_offset; |
Paulo Alcantara | 04ad69c | 2021-03-08 12:00:50 -0300 | [diff] [blame] | 3048 | int flags = CIFS_CP_CREATE_CLOSE_OP; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3049 | struct smb_rqst rqst[3]; |
| 3050 | int resp_buftype[3]; |
| 3051 | struct kvec rsp_iov[3]; |
| 3052 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 3053 | struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; |
| 3054 | struct kvec close_iov[1]; |
| 3055 | struct smb2_create_rsp *create_rsp; |
| 3056 | struct smb2_ioctl_rsp *ioctl_rsp; |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 3057 | struct reparse_data_buffer *reparse_buf; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 3058 | int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3059 | u32 plen; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3060 | |
| 3061 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 3062 | |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 3063 | *target_path = NULL; |
| 3064 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3065 | if (smb3_encryption_required(tcon)) |
| 3066 | flags |= CIFS_TRANSFORM_REQ; |
| 3067 | |
| 3068 | memset(rqst, 0, sizeof(rqst)); |
| 3069 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 3070 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 3071 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3072 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 3073 | if (!utf16_path) |
| 3074 | return -ENOMEM; |
| 3075 | |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3076 | /* Open */ |
| 3077 | memset(&open_iov, 0, sizeof(open_iov)); |
| 3078 | rqst[0].rq_iov = open_iov; |
| 3079 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 3080 | |
| 3081 | memset(&oparms, 0, sizeof(oparms)); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3082 | oparms.tcon = tcon; |
| 3083 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 3084 | oparms.disposition = FILE_OPEN; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 3085 | oparms.create_options = cifs_create_options(cifs_sb, create_options); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3086 | oparms.fid = &fid; |
| 3087 | oparms.reconnect = false; |
| 3088 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 3089 | rc = SMB2_open_init(tcon, server, |
| 3090 | &rqst[0], &oplock, &oparms, utf16_path); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3091 | if (rc) |
| 3092 | goto querty_exit; |
| 3093 | smb2_set_next_command(tcon, &rqst[0]); |
| 3094 | |
| 3095 | |
| 3096 | /* IOCTL */ |
| 3097 | memset(&io_iov, 0, sizeof(io_iov)); |
| 3098 | rqst[1].rq_iov = io_iov; |
| 3099 | rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; |
| 3100 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 3101 | rc = SMB2_ioctl_init(tcon, server, |
| 3102 | &rqst[1], fid.persistent_fid, |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3103 | fid.volatile_fid, FSCTL_GET_REPARSE_POINT, |
Ronnie Sahlberg | 731b82b | 2020-01-08 13:08:07 +1000 | [diff] [blame] | 3104 | true /* is_fctl */, NULL, 0, |
| 3105 | CIFSMaxBufSize - |
| 3106 | MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 3107 | MAX_SMB2_CLOSE_RESPONSE_SIZE); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3108 | if (rc) |
| 3109 | goto querty_exit; |
| 3110 | |
| 3111 | smb2_set_next_command(tcon, &rqst[1]); |
| 3112 | smb2_set_related(&rqst[1]); |
| 3113 | |
| 3114 | |
| 3115 | /* Close */ |
| 3116 | memset(&close_iov, 0, sizeof(close_iov)); |
| 3117 | rqst[2].rq_iov = close_iov; |
| 3118 | rqst[2].rq_nvec = 1; |
| 3119 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 3120 | rc = SMB2_close_init(tcon, server, |
| 3121 | &rqst[2], COMPOUND_FID, COMPOUND_FID, false); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3122 | if (rc) |
| 3123 | goto querty_exit; |
| 3124 | |
| 3125 | smb2_set_related(&rqst[2]); |
| 3126 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 3127 | rc = compound_send_recv(xid, tcon->ses, server, |
| 3128 | flags, 3, rqst, |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3129 | resp_buftype, rsp_iov); |
| 3130 | |
| 3131 | create_rsp = rsp_iov[0].iov_base; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 3132 | if (create_rsp && create_rsp->hdr.Status) |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3133 | err_iov = rsp_iov[0]; |
| 3134 | ioctl_rsp = rsp_iov[1].iov_base; |
| 3135 | |
| 3136 | /* |
| 3137 | * Open was successful and we got an ioctl response. |
| 3138 | */ |
| 3139 | if ((rc == 0) && (is_reparse_point)) { |
| 3140 | /* See MS-FSCC 2.3.23 */ |
| 3141 | |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 3142 | reparse_buf = (struct reparse_data_buffer *) |
| 3143 | ((char *)ioctl_rsp + |
| 3144 | le32_to_cpu(ioctl_rsp->OutputOffset)); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3145 | plen = le32_to_cpu(ioctl_rsp->OutputCount); |
| 3146 | |
| 3147 | if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > |
| 3148 | rsp_iov[1].iov_len) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 3149 | cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n", |
Ronnie Sahlberg | 5de254d | 2019-06-27 14:57:02 +1000 | [diff] [blame] | 3150 | plen); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3151 | rc = -EIO; |
| 3152 | goto querty_exit; |
| 3153 | } |
| 3154 | |
Ronnie Sahlberg | f5f111c | 2019-07-07 07:45:42 +1000 | [diff] [blame] | 3155 | rc = parse_reparse_point(reparse_buf, plen, target_path, |
| 3156 | cifs_sb); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3157 | goto querty_exit; |
| 3158 | } |
| 3159 | |
Gustavo A. R. Silva | 0d568cd | 2018-04-13 10:13:29 -0500 | [diff] [blame] | 3160 | if (!rc || !err_iov.iov_base) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3161 | rc = -ENOENT; |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3162 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3163 | } |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3164 | |
Ronnie Sahlberg | 91cb74f | 2018-04-13 09:03:19 +1000 | [diff] [blame] | 3165 | err_buf = err_iov.iov_base; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3166 | 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] | 3167 | err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) { |
Ronnie Sahlberg | df070af | 2019-07-09 18:41:11 +1000 | [diff] [blame] | 3168 | rc = -EINVAL; |
| 3169 | goto querty_exit; |
| 3170 | } |
| 3171 | |
| 3172 | symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; |
| 3173 | if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG || |
| 3174 | le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) { |
| 3175 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3176 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3177 | } |
| 3178 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3179 | /* open must fail on symlink - reset rc */ |
| 3180 | rc = 0; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3181 | sub_len = le16_to_cpu(symlink->SubstituteNameLength); |
| 3182 | sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3183 | print_len = le16_to_cpu(symlink->PrintNameLength); |
| 3184 | print_offset = le16_to_cpu(symlink->PrintNameOffset); |
| 3185 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 3186 | 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] | 3187 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3188 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3189 | } |
| 3190 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 3191 | if (err_iov.iov_len < |
| 3192 | SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) { |
Ronnie Sahlberg | df070af | 2019-07-09 18:41:11 +1000 | [diff] [blame] | 3193 | rc = -EINVAL; |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3194 | goto querty_exit; |
Pavel Shilovsky | 7893242 | 2016-07-24 10:37:38 +0300 | [diff] [blame] | 3195 | } |
| 3196 | |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3197 | *target_path = cifs_strndup_from_utf16( |
| 3198 | (char *)symlink->PathBuffer + sub_offset, |
| 3199 | sub_len, true, cifs_sb->local_nls); |
| 3200 | if (!(*target_path)) { |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3201 | rc = -ENOMEM; |
| 3202 | goto querty_exit; |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3203 | } |
| 3204 | convert_delimiter(*target_path, '/'); |
| 3205 | cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path); |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 3206 | |
| 3207 | querty_exit: |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3208 | cifs_dbg(FYI, "query symlink rc %d\n", rc); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3209 | kfree(utf16_path); |
Ronnie Sahlberg | ebaf546 | 2019-04-10 08:44:46 +1000 | [diff] [blame] | 3210 | SMB2_open_free(&rqst[0]); |
| 3211 | SMB2_ioctl_free(&rqst[1]); |
| 3212 | SMB2_close_free(&rqst[2]); |
| 3213 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 3214 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 3215 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 3216 | return rc; |
| 3217 | } |
| 3218 | |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3219 | int |
| 3220 | smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon, |
| 3221 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 3222 | __u32 *tag) |
| 3223 | { |
| 3224 | int rc; |
| 3225 | __le16 *utf16_path = NULL; |
| 3226 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 3227 | struct cifs_open_parms oparms; |
| 3228 | struct cifs_fid fid; |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3229 | struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); |
Paulo Alcantara | 04ad69c | 2021-03-08 12:00:50 -0300 | [diff] [blame] | 3230 | int flags = CIFS_CP_CREATE_CLOSE_OP; |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3231 | struct smb_rqst rqst[3]; |
| 3232 | int resp_buftype[3]; |
| 3233 | struct kvec rsp_iov[3]; |
| 3234 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 3235 | struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; |
| 3236 | struct kvec close_iov[1]; |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3237 | struct smb2_ioctl_rsp *ioctl_rsp; |
| 3238 | struct reparse_data_buffer *reparse_buf; |
| 3239 | u32 plen; |
| 3240 | |
| 3241 | cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path); |
| 3242 | |
| 3243 | if (smb3_encryption_required(tcon)) |
| 3244 | flags |= CIFS_TRANSFORM_REQ; |
| 3245 | |
| 3246 | memset(rqst, 0, sizeof(rqst)); |
| 3247 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 3248 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 3249 | |
| 3250 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 3251 | if (!utf16_path) |
| 3252 | return -ENOMEM; |
| 3253 | |
| 3254 | /* |
| 3255 | * setup smb2open - TODO add optimization to call cifs_get_readable_path |
| 3256 | * to see if there is a handle already open that we can use |
| 3257 | */ |
| 3258 | memset(&open_iov, 0, sizeof(open_iov)); |
| 3259 | rqst[0].rq_iov = open_iov; |
| 3260 | rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 3261 | |
| 3262 | memset(&oparms, 0, sizeof(oparms)); |
| 3263 | oparms.tcon = tcon; |
| 3264 | oparms.desired_access = FILE_READ_ATTRIBUTES; |
| 3265 | oparms.disposition = FILE_OPEN; |
| 3266 | oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT); |
| 3267 | oparms.fid = &fid; |
| 3268 | oparms.reconnect = false; |
| 3269 | |
| 3270 | rc = SMB2_open_init(tcon, server, |
| 3271 | &rqst[0], &oplock, &oparms, utf16_path); |
| 3272 | if (rc) |
| 3273 | goto query_rp_exit; |
| 3274 | smb2_set_next_command(tcon, &rqst[0]); |
| 3275 | |
| 3276 | |
| 3277 | /* IOCTL */ |
| 3278 | memset(&io_iov, 0, sizeof(io_iov)); |
| 3279 | rqst[1].rq_iov = io_iov; |
| 3280 | rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; |
| 3281 | |
| 3282 | rc = SMB2_ioctl_init(tcon, server, |
Namjae Jeon | 7963178 | 2020-12-03 12:31:36 +0900 | [diff] [blame] | 3283 | &rqst[1], COMPOUND_FID, |
| 3284 | COMPOUND_FID, FSCTL_GET_REPARSE_POINT, |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3285 | true /* is_fctl */, NULL, 0, |
| 3286 | CIFSMaxBufSize - |
| 3287 | MAX_SMB2_CREATE_RESPONSE_SIZE - |
| 3288 | MAX_SMB2_CLOSE_RESPONSE_SIZE); |
| 3289 | if (rc) |
| 3290 | goto query_rp_exit; |
| 3291 | |
| 3292 | smb2_set_next_command(tcon, &rqst[1]); |
| 3293 | smb2_set_related(&rqst[1]); |
| 3294 | |
| 3295 | |
| 3296 | /* Close */ |
| 3297 | memset(&close_iov, 0, sizeof(close_iov)); |
| 3298 | rqst[2].rq_iov = close_iov; |
| 3299 | rqst[2].rq_nvec = 1; |
| 3300 | |
| 3301 | rc = SMB2_close_init(tcon, server, |
| 3302 | &rqst[2], COMPOUND_FID, COMPOUND_FID, false); |
| 3303 | if (rc) |
| 3304 | goto query_rp_exit; |
| 3305 | |
| 3306 | smb2_set_related(&rqst[2]); |
| 3307 | |
| 3308 | rc = compound_send_recv(xid, tcon->ses, server, |
| 3309 | flags, 3, rqst, |
| 3310 | resp_buftype, rsp_iov); |
| 3311 | |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 3312 | ioctl_rsp = rsp_iov[1].iov_base; |
| 3313 | |
| 3314 | /* |
| 3315 | * Open was successful and we got an ioctl response. |
| 3316 | */ |
| 3317 | if (rc == 0) { |
| 3318 | /* See MS-FSCC 2.3.23 */ |
| 3319 | |
| 3320 | reparse_buf = (struct reparse_data_buffer *) |
| 3321 | ((char *)ioctl_rsp + |
| 3322 | le32_to_cpu(ioctl_rsp->OutputOffset)); |
| 3323 | plen = le32_to_cpu(ioctl_rsp->OutputCount); |
| 3324 | |
| 3325 | if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > |
| 3326 | rsp_iov[1].iov_len) { |
| 3327 | cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n", |
| 3328 | plen); |
| 3329 | rc = -EIO; |
| 3330 | goto query_rp_exit; |
| 3331 | } |
| 3332 | *tag = le32_to_cpu(reparse_buf->ReparseTag); |
| 3333 | } |
| 3334 | |
| 3335 | query_rp_exit: |
| 3336 | kfree(utf16_path); |
| 3337 | SMB2_open_free(&rqst[0]); |
| 3338 | SMB2_ioctl_free(&rqst[1]); |
| 3339 | SMB2_close_free(&rqst[2]); |
| 3340 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 3341 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 3342 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
| 3343 | return rc; |
| 3344 | } |
| 3345 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3346 | static struct cifs_ntsd * |
| 3347 | get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3348 | const struct cifs_fid *cifsfid, u32 *pacllen, u32 info) |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3349 | { |
| 3350 | struct cifs_ntsd *pntsd = NULL; |
| 3351 | unsigned int xid; |
| 3352 | int rc = -EOPNOTSUPP; |
| 3353 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 3354 | |
| 3355 | if (IS_ERR(tlink)) |
| 3356 | return ERR_CAST(tlink); |
| 3357 | |
| 3358 | xid = get_xid(); |
| 3359 | cifs_dbg(FYI, "trying to get acl\n"); |
| 3360 | |
| 3361 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3362 | cifsfid->volatile_fid, (void **)&pntsd, pacllen, |
| 3363 | info); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3364 | free_xid(xid); |
| 3365 | |
| 3366 | cifs_put_tlink(tlink); |
| 3367 | |
| 3368 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 3369 | if (rc) |
| 3370 | return ERR_PTR(rc); |
| 3371 | return pntsd; |
| 3372 | |
| 3373 | } |
| 3374 | |
| 3375 | static struct cifs_ntsd * |
| 3376 | get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3377 | const char *path, u32 *pacllen, u32 info) |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3378 | { |
| 3379 | struct cifs_ntsd *pntsd = NULL; |
| 3380 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 3381 | unsigned int xid; |
| 3382 | int rc; |
| 3383 | struct cifs_tcon *tcon; |
| 3384 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 3385 | struct cifs_fid fid; |
| 3386 | struct cifs_open_parms oparms; |
| 3387 | __le16 *utf16_path; |
| 3388 | |
| 3389 | cifs_dbg(FYI, "get smb3 acl for path %s\n", path); |
| 3390 | if (IS_ERR(tlink)) |
| 3391 | return ERR_CAST(tlink); |
| 3392 | |
| 3393 | tcon = tlink_tcon(tlink); |
| 3394 | xid = get_xid(); |
| 3395 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3396 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3397 | if (!utf16_path) { |
| 3398 | rc = -ENOMEM; |
| 3399 | free_xid(xid); |
| 3400 | return ERR_PTR(rc); |
| 3401 | } |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3402 | |
| 3403 | oparms.tcon = tcon; |
| 3404 | oparms.desired_access = READ_CONTROL; |
| 3405 | oparms.disposition = FILE_OPEN; |
Steve French | 3c3317d | 2020-10-21 13:12:08 -0500 | [diff] [blame] | 3406 | /* |
| 3407 | * When querying an ACL, even if the file is a symlink we want to open |
| 3408 | * the source not the target, and so the protocol requires that the |
| 3409 | * client specify this flag when opening a reparse point |
| 3410 | */ |
| 3411 | oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT; |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3412 | oparms.fid = &fid; |
| 3413 | oparms.reconnect = false; |
| 3414 | |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3415 | if (info & SACL_SECINFO) |
| 3416 | oparms.desired_access |= SYSTEM_SECURITY; |
| 3417 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 3418 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL, |
| 3419 | NULL); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3420 | kfree(utf16_path); |
| 3421 | if (!rc) { |
| 3422 | rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3423 | fid.volatile_fid, (void **)&pntsd, pacllen, |
| 3424 | info); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3425 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 3426 | } |
| 3427 | |
| 3428 | cifs_put_tlink(tlink); |
| 3429 | free_xid(xid); |
| 3430 | |
| 3431 | cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen); |
| 3432 | if (rc) |
| 3433 | return ERR_PTR(rc); |
| 3434 | return pntsd; |
| 3435 | } |
| 3436 | |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3437 | static int |
| 3438 | set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, |
| 3439 | struct inode *inode, const char *path, int aclflag) |
| 3440 | { |
| 3441 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 3442 | unsigned int xid; |
| 3443 | int rc, access_flags = 0; |
| 3444 | struct cifs_tcon *tcon; |
| 3445 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 3446 | struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); |
| 3447 | struct cifs_fid fid; |
| 3448 | struct cifs_open_parms oparms; |
| 3449 | __le16 *utf16_path; |
| 3450 | |
| 3451 | cifs_dbg(FYI, "set smb3 acl for path %s\n", path); |
| 3452 | if (IS_ERR(tlink)) |
| 3453 | return PTR_ERR(tlink); |
| 3454 | |
| 3455 | tcon = tlink_tcon(tlink); |
| 3456 | xid = get_xid(); |
| 3457 | |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3458 | if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP) |
| 3459 | access_flags |= WRITE_OWNER; |
| 3460 | if (aclflag & CIFS_ACL_SACL) |
| 3461 | access_flags |= SYSTEM_SECURITY; |
| 3462 | if (aclflag & CIFS_ACL_DACL) |
| 3463 | access_flags |= WRITE_DAC; |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3464 | |
| 3465 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3466 | if (!utf16_path) { |
| 3467 | rc = -ENOMEM; |
| 3468 | free_xid(xid); |
| 3469 | return rc; |
| 3470 | } |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3471 | |
| 3472 | oparms.tcon = tcon; |
| 3473 | oparms.desired_access = access_flags; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 3474 | oparms.create_options = cifs_create_options(cifs_sb, 0); |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3475 | oparms.disposition = FILE_OPEN; |
| 3476 | oparms.path = path; |
| 3477 | oparms.fid = &fid; |
| 3478 | oparms.reconnect = false; |
| 3479 | |
Aurelien Aptel | 69dda30 | 2020-03-02 17:53:22 +0100 | [diff] [blame] | 3480 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, |
| 3481 | NULL, NULL); |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3482 | kfree(utf16_path); |
| 3483 | if (!rc) { |
| 3484 | rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid, |
| 3485 | fid.volatile_fid, pnntsd, acllen, aclflag); |
| 3486 | SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
| 3487 | } |
| 3488 | |
| 3489 | cifs_put_tlink(tlink); |
| 3490 | free_xid(xid); |
| 3491 | return rc; |
| 3492 | } |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 3493 | |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3494 | /* Retrieve an ACL from the server */ |
| 3495 | static struct cifs_ntsd * |
| 3496 | get_smb2_acl(struct cifs_sb_info *cifs_sb, |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3497 | struct inode *inode, const char *path, |
| 3498 | u32 *pacllen, u32 info) |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3499 | { |
| 3500 | struct cifs_ntsd *pntsd = NULL; |
| 3501 | struct cifsFileInfo *open_file = NULL; |
| 3502 | |
Boris Protopopov | 9541b81 | 2020-12-17 20:58:08 +0000 | [diff] [blame] | 3503 | if (inode && !(info & SACL_SECINFO)) |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3504 | open_file = find_readable_file(CIFS_I(inode), true); |
Boris Protopopov | 9541b81 | 2020-12-17 20:58:08 +0000 | [diff] [blame] | 3505 | if (!open_file || (info & SACL_SECINFO)) |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3506 | return get_smb2_acl_by_path(cifs_sb, path, pacllen, info); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3507 | |
Boris Protopopov | 3970acf | 2020-12-18 11:30:12 -0600 | [diff] [blame] | 3508 | pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info); |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3509 | cifsFileInfo_put(open_file); |
| 3510 | return pntsd; |
| 3511 | } |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 3512 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3513 | static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, |
| 3514 | loff_t offset, loff_t len, bool keep_size) |
| 3515 | { |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3516 | struct cifs_ses *ses = tcon->ses; |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3517 | struct inode *inode; |
| 3518 | struct cifsInodeInfo *cifsi; |
| 3519 | struct cifsFileInfo *cfile = file->private_data; |
| 3520 | struct file_zero_data_information fsctl_buf; |
| 3521 | long rc; |
| 3522 | unsigned int xid; |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3523 | __le64 eof; |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3524 | |
| 3525 | xid = get_xid(); |
| 3526 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3527 | inode = d_inode(cfile->dentry); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3528 | cifsi = CIFS_I(inode); |
| 3529 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 3530 | trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3531 | ses->Suid, offset, len); |
| 3532 | |
Zhang Xiaoxu | 6b69040 | 2020-06-23 07:31:54 -0400 | [diff] [blame] | 3533 | /* |
| 3534 | * We zero the range through ioctl, so we need remove the page caches |
| 3535 | * first, otherwise the data may be inconsistent with the server. |
| 3536 | */ |
| 3537 | truncate_pagecache_range(inode, offset, offset + len - 1); |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3538 | |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3539 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 3540 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3541 | if (keep_size == false) { |
| 3542 | rc = -EOPNOTSUPP; |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3543 | trace_smb3_zero_err(xid, cfile->fid.persistent_fid, |
| 3544 | tcon->tid, ses->Suid, offset, len, rc); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3545 | free_xid(xid); |
| 3546 | return rc; |
| 3547 | } |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3548 | |
Steve French | d1c35af | 2019-05-09 00:09:37 -0500 | [diff] [blame] | 3549 | cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3550 | |
| 3551 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 3552 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 3553 | |
Ronnie Sahlberg | c425014 | 2019-05-02 15:52:57 +1000 | [diff] [blame] | 3554 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3555 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true, |
| 3556 | (char *)&fsctl_buf, |
| 3557 | sizeof(struct file_zero_data_information), |
| 3558 | 0, NULL, NULL); |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3559 | if (rc) |
| 3560 | goto zero_range_exit; |
| 3561 | |
| 3562 | /* |
| 3563 | * do we also need to change the size of the file? |
| 3564 | */ |
| 3565 | if (keep_size == false && i_size_read(inode) < offset + len) { |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3566 | eof = cpu_to_le64(offset + len); |
Ronnie Sahlberg | c425014 | 2019-05-02 15:52:57 +1000 | [diff] [blame] | 3567 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 3568 | cfile->fid.volatile_fid, cfile->pid, &eof); |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3569 | } |
| 3570 | |
Ronnie Sahlberg | 72c419d | 2019-03-13 14:37:49 +1000 | [diff] [blame] | 3571 | zero_range_exit: |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3572 | free_xid(xid); |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3573 | if (rc) |
| 3574 | trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3575 | ses->Suid, offset, len, rc); |
| 3576 | else |
| 3577 | trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3578 | ses->Suid, offset, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 3579 | return rc; |
| 3580 | } |
| 3581 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3582 | static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, |
| 3583 | loff_t offset, loff_t len) |
| 3584 | { |
| 3585 | struct inode *inode; |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3586 | struct cifsFileInfo *cfile = file->private_data; |
| 3587 | struct file_zero_data_information fsctl_buf; |
| 3588 | long rc; |
| 3589 | unsigned int xid; |
| 3590 | __u8 set_sparse = 1; |
| 3591 | |
| 3592 | xid = get_xid(); |
| 3593 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3594 | inode = d_inode(cfile->dentry); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3595 | |
| 3596 | /* Need to make file sparse, if not already, before freeing range. */ |
| 3597 | /* Consider adding equivalent for compressed since it could also work */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3598 | if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { |
| 3599 | rc = -EOPNOTSUPP; |
| 3600 | free_xid(xid); |
| 3601 | return rc; |
| 3602 | } |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3603 | |
Jan Kara | b092b3e | 2021-04-22 16:52:32 +0200 | [diff] [blame] | 3604 | filemap_invalidate_lock(inode->i_mapping); |
Zhang Xiaoxu | acc91c2 | 2020-06-23 07:31:53 -0400 | [diff] [blame] | 3605 | /* |
| 3606 | * We implement the punch hole through ioctl, so we need remove the page |
| 3607 | * caches first, otherwise the data may be inconsistent with the server. |
| 3608 | */ |
| 3609 | truncate_pagecache_range(inode, offset, offset + len - 1); |
| 3610 | |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 3611 | cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3612 | |
| 3613 | fsctl_buf.FileOffset = cpu_to_le64(offset); |
| 3614 | fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len); |
| 3615 | |
| 3616 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3617 | cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, |
Aurelien Aptel | 63a83b8 | 2018-01-24 13:46:11 +0100 | [diff] [blame] | 3618 | true /* is_fctl */, (char *)&fsctl_buf, |
Steve French | 153322f | 2019-03-28 22:32:49 -0500 | [diff] [blame] | 3619 | sizeof(struct file_zero_data_information), |
| 3620 | CIFSMaxBufSize, NULL, NULL); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3621 | free_xid(xid); |
Jan Kara | b092b3e | 2021-04-22 16:52:32 +0200 | [diff] [blame] | 3622 | filemap_invalidate_unlock(inode->i_mapping); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 3623 | return rc; |
| 3624 | } |
| 3625 | |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3626 | static int smb3_simple_fallocate_write_range(unsigned int xid, |
| 3627 | struct cifs_tcon *tcon, |
| 3628 | struct cifsFileInfo *cfile, |
| 3629 | loff_t off, loff_t len, |
| 3630 | char *buf) |
| 3631 | { |
| 3632 | struct cifs_io_parms io_parms = {0}; |
Steve French | 5ad4df5 | 2021-07-26 16:22:55 -0500 | [diff] [blame] | 3633 | int nbytes; |
| 3634 | int rc = 0; |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3635 | struct kvec iov[2]; |
| 3636 | |
| 3637 | io_parms.netfid = cfile->fid.netfid; |
| 3638 | io_parms.pid = current->tgid; |
| 3639 | io_parms.tcon = tcon; |
| 3640 | io_parms.persistent_fid = cfile->fid.persistent_fid; |
| 3641 | io_parms.volatile_fid = cfile->fid.volatile_fid; |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3642 | |
Ronnie Sahlberg | 2485bd7 | 2021-07-22 14:53:32 +1000 | [diff] [blame] | 3643 | while (len) { |
| 3644 | io_parms.offset = off; |
| 3645 | io_parms.length = len; |
| 3646 | if (io_parms.length > SMB2_MAX_BUFFER_SIZE) |
| 3647 | io_parms.length = SMB2_MAX_BUFFER_SIZE; |
| 3648 | /* iov[0] is reserved for smb header */ |
| 3649 | iov[1].iov_base = buf; |
| 3650 | iov[1].iov_len = io_parms.length; |
| 3651 | rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1); |
| 3652 | if (rc) |
| 3653 | break; |
| 3654 | if (nbytes > len) |
| 3655 | return -EINVAL; |
| 3656 | buf += nbytes; |
| 3657 | off += nbytes; |
| 3658 | len -= nbytes; |
| 3659 | } |
| 3660 | return rc; |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | static int smb3_simple_fallocate_range(unsigned int xid, |
| 3664 | struct cifs_tcon *tcon, |
| 3665 | struct cifsFileInfo *cfile, |
| 3666 | loff_t off, loff_t len) |
| 3667 | { |
| 3668 | struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data; |
| 3669 | u32 out_data_len; |
| 3670 | char *buf = NULL; |
| 3671 | loff_t l; |
| 3672 | int rc; |
| 3673 | |
| 3674 | in_data.file_offset = cpu_to_le64(off); |
| 3675 | in_data.length = cpu_to_le64(len); |
| 3676 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3677 | cfile->fid.volatile_fid, |
| 3678 | FSCTL_QUERY_ALLOCATED_RANGES, true, |
| 3679 | (char *)&in_data, sizeof(in_data), |
| 3680 | 1024 * sizeof(struct file_allocated_range_buffer), |
| 3681 | (char **)&out_data, &out_data_len); |
| 3682 | if (rc) |
| 3683 | goto out; |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3684 | |
| 3685 | buf = kzalloc(1024 * 1024, GFP_KERNEL); |
| 3686 | if (buf == NULL) { |
| 3687 | rc = -ENOMEM; |
| 3688 | goto out; |
| 3689 | } |
| 3690 | |
| 3691 | tmp_data = out_data; |
| 3692 | while (len) { |
| 3693 | /* |
| 3694 | * The rest of the region is unmapped so write it all. |
| 3695 | */ |
| 3696 | if (out_data_len == 0) { |
| 3697 | rc = smb3_simple_fallocate_write_range(xid, tcon, |
| 3698 | cfile, off, len, buf); |
| 3699 | goto out; |
| 3700 | } |
| 3701 | |
| 3702 | if (out_data_len < sizeof(struct file_allocated_range_buffer)) { |
| 3703 | rc = -EINVAL; |
| 3704 | goto out; |
| 3705 | } |
| 3706 | |
| 3707 | if (off < le64_to_cpu(tmp_data->file_offset)) { |
| 3708 | /* |
| 3709 | * We are at a hole. Write until the end of the region |
| 3710 | * or until the next allocated data, |
| 3711 | * whichever comes next. |
| 3712 | */ |
| 3713 | l = le64_to_cpu(tmp_data->file_offset) - off; |
| 3714 | if (len < l) |
| 3715 | l = len; |
| 3716 | rc = smb3_simple_fallocate_write_range(xid, tcon, |
| 3717 | cfile, off, l, buf); |
| 3718 | if (rc) |
| 3719 | goto out; |
| 3720 | off = off + l; |
| 3721 | len = len - l; |
| 3722 | if (len == 0) |
| 3723 | goto out; |
| 3724 | } |
| 3725 | /* |
| 3726 | * We are at a section of allocated data, just skip forward |
| 3727 | * until the end of the data or the end of the region |
| 3728 | * we are supposed to fallocate, whichever comes first. |
| 3729 | */ |
| 3730 | l = le64_to_cpu(tmp_data->length); |
| 3731 | if (len < l) |
| 3732 | l = len; |
| 3733 | off += l; |
| 3734 | len -= l; |
| 3735 | |
| 3736 | tmp_data = &tmp_data[1]; |
| 3737 | out_data_len -= sizeof(struct file_allocated_range_buffer); |
| 3738 | } |
| 3739 | |
| 3740 | out: |
| 3741 | kfree(out_data); |
| 3742 | kfree(buf); |
| 3743 | return rc; |
| 3744 | } |
| 3745 | |
| 3746 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3747 | static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, |
| 3748 | loff_t off, loff_t len, bool keep_size) |
| 3749 | { |
| 3750 | struct inode *inode; |
| 3751 | struct cifsInodeInfo *cifsi; |
| 3752 | struct cifsFileInfo *cfile = file->private_data; |
| 3753 | long rc = -EOPNOTSUPP; |
| 3754 | unsigned int xid; |
Ronnie Sahlberg | f169947 | 2019-03-15 00:08:48 +1000 | [diff] [blame] | 3755 | __le64 eof; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3756 | |
| 3757 | xid = get_xid(); |
| 3758 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3759 | inode = d_inode(cfile->dentry); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3760 | cifsi = CIFS_I(inode); |
| 3761 | |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3762 | trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3763 | tcon->ses->Suid, off, len); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3764 | /* if file not oplocked can't be sure whether asking to extend size */ |
| 3765 | if (!CIFS_CACHE_READ(cifsi)) |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3766 | if (keep_size == false) { |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3767 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, |
| 3768 | tcon->tid, tcon->ses->Suid, off, len, rc); |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3769 | free_xid(xid); |
| 3770 | return rc; |
| 3771 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3772 | |
| 3773 | /* |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3774 | * Extending the file |
| 3775 | */ |
| 3776 | if ((keep_size == false) && i_size_read(inode) < off + len) { |
Murphy Zhou | ef4a632 | 2020-03-18 20:43:38 +0800 | [diff] [blame] | 3777 | rc = inode_newsize_ok(inode, off + len); |
| 3778 | if (rc) |
| 3779 | goto out; |
| 3780 | |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3781 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) |
| 3782 | smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 3783 | |
| 3784 | eof = cpu_to_le64(off + len); |
| 3785 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 3786 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 3787 | if (rc == 0) { |
| 3788 | cifsi->server_eof = off + len; |
| 3789 | cifs_setsize(inode, off + len); |
| 3790 | cifs_truncate_page(inode->i_mapping, inode->i_size); |
| 3791 | truncate_setsize(inode, off + len); |
| 3792 | } |
| 3793 | goto out; |
| 3794 | } |
| 3795 | |
| 3796 | /* |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3797 | * Files are non-sparse by default so falloc may be a no-op |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3798 | * Must check if file sparse. If not sparse, and since we are not |
| 3799 | * extending then no need to do anything since file already allocated |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3800 | */ |
| 3801 | if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3802 | rc = 0; |
| 3803 | goto out; |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3804 | } |
| 3805 | |
Ronnie Sahlberg | 488968a | 2021-07-23 11:21:24 +1000 | [diff] [blame] | 3806 | if (keep_size == true) { |
| 3807 | /* |
| 3808 | * We can not preallocate pages beyond the end of the file |
| 3809 | * in SMB2 |
| 3810 | */ |
| 3811 | if (off >= i_size_read(inode)) { |
| 3812 | rc = 0; |
| 3813 | goto out; |
| 3814 | } |
| 3815 | /* |
| 3816 | * For fallocates that are partially beyond the end of file, |
| 3817 | * clamp len so we only fallocate up to the end of file. |
| 3818 | */ |
| 3819 | if (off + len > i_size_read(inode)) { |
| 3820 | len = i_size_read(inode) - off; |
| 3821 | } |
| 3822 | } |
| 3823 | |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3824 | if ((keep_size == true) || (i_size_read(inode) >= off + len)) { |
| 3825 | /* |
Ronnie Sahlberg | 966a3cb | 2021-06-03 15:31:01 +1000 | [diff] [blame] | 3826 | * At this point, we are trying to fallocate an internal |
| 3827 | * regions of a sparse file. Since smb2 does not have a |
| 3828 | * fallocate command we have two otions on how to emulate this. |
| 3829 | * We can either turn the entire file to become non-sparse |
| 3830 | * which we only do if the fallocate is for virtually |
| 3831 | * the whole file, or we can overwrite the region with zeroes |
| 3832 | * using SMB2_write, which could be prohibitevly expensive |
| 3833 | * if len is large. |
| 3834 | */ |
| 3835 | /* |
| 3836 | * We are only trying to fallocate a small region so |
| 3837 | * just write it with zero. |
| 3838 | */ |
| 3839 | if (len <= 1024 * 1024) { |
| 3840 | rc = smb3_simple_fallocate_range(xid, tcon, cfile, |
| 3841 | off, len); |
| 3842 | goto out; |
| 3843 | } |
| 3844 | |
| 3845 | /* |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3846 | * Check if falloc starts within first few pages of file |
| 3847 | * and ends within a few pages of the end of file to |
| 3848 | * ensure that most of file is being forced to be |
| 3849 | * fallocated now. If so then setting whole file sparse |
| 3850 | * ie potentially making a few extra pages at the beginning |
| 3851 | * or end of the file non-sparse via set_sparse is harmless. |
| 3852 | */ |
Steve French | cfe8909 | 2018-05-19 02:04:55 -0500 | [diff] [blame] | 3853 | if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) { |
| 3854 | rc = -EOPNOTSUPP; |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3855 | goto out; |
Ronnie Sahlberg | f169947 | 2019-03-15 00:08:48 +1000 | [diff] [blame] | 3856 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3857 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3858 | |
Ronnie Sahlberg | 8bd0d70 | 2020-01-17 11:45:02 +1000 | [diff] [blame] | 3859 | smb2_set_sparse(xid, tcon, cfile, inode, false); |
| 3860 | rc = 0; |
| 3861 | |
| 3862 | out: |
Steve French | 779ede0 | 2019-03-13 01:41:49 -0500 | [diff] [blame] | 3863 | if (rc) |
| 3864 | trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3865 | tcon->ses->Suid, off, len, rc); |
| 3866 | else |
| 3867 | trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid, |
| 3868 | tcon->ses->Suid, off, len); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 3869 | |
| 3870 | free_xid(xid); |
| 3871 | return rc; |
| 3872 | } |
| 3873 | |
Ronnie Sahlberg | 5476b5d | 2021-03-27 05:52:29 +1000 | [diff] [blame] | 3874 | static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, |
| 3875 | loff_t off, loff_t len) |
| 3876 | { |
| 3877 | int rc; |
| 3878 | unsigned int xid; |
| 3879 | struct cifsFileInfo *cfile = file->private_data; |
| 3880 | __le64 eof; |
| 3881 | |
| 3882 | xid = get_xid(); |
| 3883 | |
| 3884 | if (off >= i_size_read(file->f_inode) || |
| 3885 | off + len >= i_size_read(file->f_inode)) { |
| 3886 | rc = -EINVAL; |
| 3887 | goto out; |
| 3888 | } |
| 3889 | |
| 3890 | rc = smb2_copychunk_range(xid, cfile, cfile, off + len, |
| 3891 | i_size_read(file->f_inode) - off - len, off); |
| 3892 | if (rc < 0) |
| 3893 | goto out; |
| 3894 | |
| 3895 | eof = cpu_to_le64(i_size_read(file->f_inode) - len); |
| 3896 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 3897 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 3898 | if (rc < 0) |
| 3899 | goto out; |
| 3900 | |
| 3901 | rc = 0; |
| 3902 | out: |
| 3903 | free_xid(xid); |
| 3904 | return rc; |
| 3905 | } |
| 3906 | |
Ronnie Sahlberg | 7fe6fe9 | 2021-03-27 06:31:30 +1000 | [diff] [blame] | 3907 | static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, |
| 3908 | loff_t off, loff_t len) |
| 3909 | { |
| 3910 | int rc; |
| 3911 | unsigned int xid; |
| 3912 | struct cifsFileInfo *cfile = file->private_data; |
| 3913 | __le64 eof; |
| 3914 | __u64 count; |
| 3915 | |
| 3916 | xid = get_xid(); |
| 3917 | |
| 3918 | if (off >= i_size_read(file->f_inode)) { |
| 3919 | rc = -EINVAL; |
| 3920 | goto out; |
| 3921 | } |
| 3922 | |
| 3923 | count = i_size_read(file->f_inode) - off; |
| 3924 | eof = cpu_to_le64(i_size_read(file->f_inode) + len); |
| 3925 | |
| 3926 | rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, |
| 3927 | cfile->fid.volatile_fid, cfile->pid, &eof); |
| 3928 | if (rc < 0) |
| 3929 | goto out; |
| 3930 | |
| 3931 | rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); |
| 3932 | if (rc < 0) |
| 3933 | goto out; |
| 3934 | |
| 3935 | rc = smb3_zero_range(file, tcon, off, len, 1); |
| 3936 | if (rc < 0) |
| 3937 | goto out; |
| 3938 | |
| 3939 | rc = 0; |
| 3940 | out: |
| 3941 | free_xid(xid); |
| 3942 | return rc; |
| 3943 | } |
| 3944 | |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 3945 | static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) |
| 3946 | { |
| 3947 | struct cifsFileInfo *wrcfile, *cfile = file->private_data; |
| 3948 | struct cifsInodeInfo *cifsi; |
| 3949 | struct inode *inode; |
| 3950 | int rc = 0; |
| 3951 | struct file_allocated_range_buffer in_data, *out_data = NULL; |
| 3952 | u32 out_data_len; |
| 3953 | unsigned int xid; |
| 3954 | |
| 3955 | if (whence != SEEK_HOLE && whence != SEEK_DATA) |
| 3956 | return generic_file_llseek(file, offset, whence); |
| 3957 | |
| 3958 | inode = d_inode(cfile->dentry); |
| 3959 | cifsi = CIFS_I(inode); |
| 3960 | |
| 3961 | if (offset < 0 || offset >= i_size_read(inode)) |
| 3962 | return -ENXIO; |
| 3963 | |
| 3964 | xid = get_xid(); |
| 3965 | /* |
| 3966 | * We need to be sure that all dirty pages are written as they |
| 3967 | * might fill holes on the server. |
| 3968 | * Note that we also MUST flush any written pages since at least |
| 3969 | * some servers (Windows2016) will not reflect recent writes in |
| 3970 | * QUERY_ALLOCATED_RANGES until SMB2_flush is called. |
| 3971 | */ |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 3972 | wrcfile = find_writable_file(cifsi, FIND_WR_ANY); |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 3973 | if (wrcfile) { |
| 3974 | filemap_write_and_wait(inode->i_mapping); |
| 3975 | smb2_flush_file(xid, tcon, &wrcfile->fid); |
| 3976 | cifsFileInfo_put(wrcfile); |
| 3977 | } |
| 3978 | |
| 3979 | if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { |
| 3980 | if (whence == SEEK_HOLE) |
| 3981 | offset = i_size_read(inode); |
| 3982 | goto lseek_exit; |
| 3983 | } |
| 3984 | |
| 3985 | in_data.file_offset = cpu_to_le64(offset); |
| 3986 | in_data.length = cpu_to_le64(i_size_read(inode)); |
| 3987 | |
| 3988 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 3989 | cfile->fid.volatile_fid, |
| 3990 | FSCTL_QUERY_ALLOCATED_RANGES, true, |
| 3991 | (char *)&in_data, sizeof(in_data), |
| 3992 | sizeof(struct file_allocated_range_buffer), |
| 3993 | (char **)&out_data, &out_data_len); |
| 3994 | if (rc == -E2BIG) |
| 3995 | rc = 0; |
| 3996 | if (rc) |
| 3997 | goto lseek_exit; |
| 3998 | |
| 3999 | if (whence == SEEK_HOLE && out_data_len == 0) |
| 4000 | goto lseek_exit; |
| 4001 | |
| 4002 | if (whence == SEEK_DATA && out_data_len == 0) { |
| 4003 | rc = -ENXIO; |
| 4004 | goto lseek_exit; |
| 4005 | } |
| 4006 | |
| 4007 | if (out_data_len < sizeof(struct file_allocated_range_buffer)) { |
| 4008 | rc = -EINVAL; |
| 4009 | goto lseek_exit; |
| 4010 | } |
| 4011 | if (whence == SEEK_DATA) { |
| 4012 | offset = le64_to_cpu(out_data->file_offset); |
| 4013 | goto lseek_exit; |
| 4014 | } |
| 4015 | if (offset < le64_to_cpu(out_data->file_offset)) |
| 4016 | goto lseek_exit; |
| 4017 | |
| 4018 | offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length); |
| 4019 | |
| 4020 | lseek_exit: |
| 4021 | free_xid(xid); |
| 4022 | kfree(out_data); |
| 4023 | if (!rc) |
| 4024 | return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); |
| 4025 | else |
| 4026 | return rc; |
| 4027 | } |
| 4028 | |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4029 | static int smb3_fiemap(struct cifs_tcon *tcon, |
| 4030 | struct cifsFileInfo *cfile, |
| 4031 | struct fiemap_extent_info *fei, u64 start, u64 len) |
| 4032 | { |
| 4033 | unsigned int xid; |
| 4034 | struct file_allocated_range_buffer in_data, *out_data; |
| 4035 | u32 out_data_len; |
| 4036 | int i, num, rc, flags, last_blob; |
| 4037 | u64 next; |
| 4038 | |
Christoph Hellwig | 45dd052 | 2020-05-23 09:30:14 +0200 | [diff] [blame] | 4039 | rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0); |
Christoph Hellwig | cddf8a2 | 2020-05-23 09:30:13 +0200 | [diff] [blame] | 4040 | if (rc) |
| 4041 | return rc; |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4042 | |
| 4043 | xid = get_xid(); |
| 4044 | again: |
| 4045 | in_data.file_offset = cpu_to_le64(start); |
| 4046 | in_data.length = cpu_to_le64(len); |
| 4047 | |
| 4048 | rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, |
| 4049 | cfile->fid.volatile_fid, |
| 4050 | FSCTL_QUERY_ALLOCATED_RANGES, true, |
| 4051 | (char *)&in_data, sizeof(in_data), |
| 4052 | 1024 * sizeof(struct file_allocated_range_buffer), |
| 4053 | (char **)&out_data, &out_data_len); |
| 4054 | if (rc == -E2BIG) { |
| 4055 | last_blob = 0; |
| 4056 | rc = 0; |
| 4057 | } else |
| 4058 | last_blob = 1; |
| 4059 | if (rc) |
| 4060 | goto out; |
| 4061 | |
Murphy Zhou | 979a266 | 2020-03-14 11:38:31 +0800 | [diff] [blame] | 4062 | if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) { |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 4063 | rc = -EINVAL; |
| 4064 | goto out; |
| 4065 | } |
| 4066 | if (out_data_len % sizeof(struct file_allocated_range_buffer)) { |
| 4067 | rc = -EINVAL; |
| 4068 | goto out; |
| 4069 | } |
| 4070 | |
| 4071 | num = out_data_len / sizeof(struct file_allocated_range_buffer); |
| 4072 | for (i = 0; i < num; i++) { |
| 4073 | flags = 0; |
| 4074 | if (i == num - 1 && last_blob) |
| 4075 | flags |= FIEMAP_EXTENT_LAST; |
| 4076 | |
| 4077 | rc = fiemap_fill_next_extent(fei, |
| 4078 | le64_to_cpu(out_data[i].file_offset), |
| 4079 | le64_to_cpu(out_data[i].file_offset), |
| 4080 | le64_to_cpu(out_data[i].length), |
| 4081 | flags); |
| 4082 | if (rc < 0) |
| 4083 | goto out; |
| 4084 | if (rc == 1) { |
| 4085 | rc = 0; |
| 4086 | goto out; |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | if (!last_blob) { |
| 4091 | next = le64_to_cpu(out_data[num - 1].file_offset) + |
| 4092 | le64_to_cpu(out_data[num - 1].length); |
| 4093 | len = len - (next - start); |
| 4094 | start = next; |
| 4095 | goto again; |
| 4096 | } |
| 4097 | |
| 4098 | out: |
| 4099 | free_xid(xid); |
| 4100 | kfree(out_data); |
| 4101 | return rc; |
| 4102 | } |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 4103 | |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 4104 | static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, |
| 4105 | loff_t off, loff_t len) |
| 4106 | { |
| 4107 | /* KEEP_SIZE already checked for by do_fallocate */ |
| 4108 | if (mode & FALLOC_FL_PUNCH_HOLE) |
| 4109 | return smb3_punch_hole(file, tcon, off, len); |
Steve French | 3017562 | 2014-08-17 18:16:40 -0500 | [diff] [blame] | 4110 | else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 4111 | if (mode & FALLOC_FL_KEEP_SIZE) |
| 4112 | return smb3_zero_range(file, tcon, off, len, true); |
| 4113 | return smb3_zero_range(file, tcon, off, len, false); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 4114 | } else if (mode == FALLOC_FL_KEEP_SIZE) |
| 4115 | return smb3_simple_falloc(file, tcon, off, len, true); |
Ronnie Sahlberg | 5476b5d | 2021-03-27 05:52:29 +1000 | [diff] [blame] | 4116 | else if (mode == FALLOC_FL_COLLAPSE_RANGE) |
| 4117 | return smb3_collapse_range(file, tcon, off, len); |
Ronnie Sahlberg | 7fe6fe9 | 2021-03-27 06:31:30 +1000 | [diff] [blame] | 4118 | else if (mode == FALLOC_FL_INSERT_RANGE) |
| 4119 | return smb3_insert_range(file, tcon, off, len); |
Steve French | 9ccf321 | 2014-10-18 17:01:15 -0500 | [diff] [blame] | 4120 | else if (mode == 0) |
| 4121 | return smb3_simple_falloc(file, tcon, off, len, false); |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 4122 | |
| 4123 | return -EOPNOTSUPP; |
| 4124 | } |
| 4125 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4126 | static void |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 4127 | smb2_downgrade_oplock(struct TCP_Server_Info *server, |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 4128 | struct cifsInodeInfo *cinode, __u32 oplock, |
| 4129 | unsigned int epoch, bool *purge_cache) |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 4130 | { |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 4131 | server->ops->set_oplock_level(cinode, oplock, 0, NULL); |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | static void |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 4135 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 4136 | unsigned int epoch, bool *purge_cache); |
| 4137 | |
| 4138 | static void |
| 4139 | smb3_downgrade_oplock(struct TCP_Server_Info *server, |
| 4140 | struct cifsInodeInfo *cinode, __u32 oplock, |
| 4141 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 4142 | { |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 4143 | unsigned int old_state = cinode->oplock; |
| 4144 | unsigned int old_epoch = cinode->epoch; |
| 4145 | unsigned int new_state; |
| 4146 | |
| 4147 | if (epoch > old_epoch) { |
| 4148 | smb21_set_oplock_level(cinode, oplock, 0, NULL); |
| 4149 | cinode->epoch = epoch; |
| 4150 | } |
| 4151 | |
| 4152 | new_state = cinode->oplock; |
| 4153 | *purge_cache = false; |
| 4154 | |
| 4155 | if ((old_state & CIFS_CACHE_READ_FLG) != 0 && |
| 4156 | (new_state & CIFS_CACHE_READ_FLG) == 0) |
| 4157 | *purge_cache = true; |
| 4158 | else if (old_state == new_state && (epoch - old_epoch > 1)) |
| 4159 | *purge_cache = true; |
Pavel Shilovsky | 7b9b9ed | 2019-02-13 15:43:08 -0800 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4163 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 4164 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4165 | { |
| 4166 | oplock &= 0xFF; |
Rohith Surabattula | 0ab95c2 | 2021-05-17 11:28:34 +0000 | [diff] [blame] | 4167 | cinode->lease_granted = false; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4168 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 4169 | return; |
| 4170 | if (oplock == SMB2_OPLOCK_LEVEL_BATCH) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4171 | cinode->oplock = CIFS_CACHE_RHW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4172 | cifs_dbg(FYI, "Batch Oplock granted on inode %p\n", |
| 4173 | &cinode->vfs_inode); |
| 4174 | } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4175 | cinode->oplock = CIFS_CACHE_RW_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4176 | cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n", |
| 4177 | &cinode->vfs_inode); |
| 4178 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { |
| 4179 | cinode->oplock = CIFS_CACHE_READ_FLG; |
| 4180 | cifs_dbg(FYI, "Level II Oplock granted on inode %p\n", |
| 4181 | &cinode->vfs_inode); |
| 4182 | } else |
| 4183 | cinode->oplock = 0; |
| 4184 | } |
| 4185 | |
| 4186 | static void |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4187 | smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 4188 | unsigned int epoch, bool *purge_cache) |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4189 | { |
| 4190 | char message[5] = {0}; |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 4191 | unsigned int new_oplock = 0; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4192 | |
| 4193 | oplock &= 0xFF; |
Rohith Surabattula | 0ab95c2 | 2021-05-17 11:28:34 +0000 | [diff] [blame] | 4194 | cinode->lease_granted = true; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4195 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) |
| 4196 | return; |
| 4197 | |
Pavel Shilovsky | a016e27 | 2019-09-26 12:31:20 -0700 | [diff] [blame] | 4198 | /* Check if the server granted an oplock rather than a lease */ |
| 4199 | if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 4200 | return smb2_set_oplock_level(cinode, oplock, epoch, |
| 4201 | purge_cache); |
| 4202 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4203 | if (oplock & SMB2_LEASE_READ_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 4204 | new_oplock |= CIFS_CACHE_READ_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4205 | strcat(message, "R"); |
| 4206 | } |
| 4207 | if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 4208 | new_oplock |= CIFS_CACHE_HANDLE_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4209 | strcat(message, "H"); |
| 4210 | } |
| 4211 | if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 4212 | new_oplock |= CIFS_CACHE_WRITE_FLG; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4213 | strcat(message, "W"); |
| 4214 | } |
Christoph Probst | 6a54b2e | 2019-05-07 17:16:40 +0200 | [diff] [blame] | 4215 | if (!new_oplock) |
| 4216 | strncpy(message, "None", sizeof(message)); |
| 4217 | |
| 4218 | cinode->oplock = new_oplock; |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4219 | cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, |
| 4220 | &cinode->vfs_inode); |
| 4221 | } |
| 4222 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4223 | static void |
| 4224 | smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock, |
| 4225 | unsigned int epoch, bool *purge_cache) |
| 4226 | { |
| 4227 | unsigned int old_oplock = cinode->oplock; |
| 4228 | |
| 4229 | smb21_set_oplock_level(cinode, oplock, epoch, purge_cache); |
| 4230 | |
| 4231 | if (purge_cache) { |
| 4232 | *purge_cache = false; |
| 4233 | if (old_oplock == CIFS_CACHE_READ_FLG) { |
| 4234 | if (cinode->oplock == CIFS_CACHE_READ_FLG && |
| 4235 | (epoch - cinode->epoch > 0)) |
| 4236 | *purge_cache = true; |
| 4237 | else if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 4238 | (epoch - cinode->epoch > 1)) |
| 4239 | *purge_cache = true; |
| 4240 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 4241 | (epoch - cinode->epoch > 1)) |
| 4242 | *purge_cache = true; |
| 4243 | else if (cinode->oplock == 0 && |
| 4244 | (epoch - cinode->epoch > 0)) |
| 4245 | *purge_cache = true; |
| 4246 | } else if (old_oplock == CIFS_CACHE_RH_FLG) { |
| 4247 | if (cinode->oplock == CIFS_CACHE_RH_FLG && |
| 4248 | (epoch - cinode->epoch > 0)) |
| 4249 | *purge_cache = true; |
| 4250 | else if (cinode->oplock == CIFS_CACHE_RHW_FLG && |
| 4251 | (epoch - cinode->epoch > 1)) |
| 4252 | *purge_cache = true; |
| 4253 | } |
| 4254 | cinode->epoch = epoch; |
| 4255 | } |
| 4256 | } |
| 4257 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 4258 | static bool |
| 4259 | smb2_is_read_op(__u32 oplock) |
| 4260 | { |
| 4261 | return oplock == SMB2_OPLOCK_LEVEL_II; |
| 4262 | } |
| 4263 | |
| 4264 | static bool |
| 4265 | smb21_is_read_op(__u32 oplock) |
| 4266 | { |
| 4267 | return (oplock & SMB2_LEASE_READ_CACHING_HE) && |
| 4268 | !(oplock & SMB2_LEASE_WRITE_CACHING_HE); |
| 4269 | } |
| 4270 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4271 | static __le32 |
| 4272 | map_oplock_to_lease(u8 oplock) |
| 4273 | { |
| 4274 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) |
| 4275 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; |
| 4276 | else if (oplock == SMB2_OPLOCK_LEVEL_II) |
| 4277 | return SMB2_LEASE_READ_CACHING; |
| 4278 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) |
| 4279 | return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | |
| 4280 | SMB2_LEASE_WRITE_CACHING; |
| 4281 | return 0; |
| 4282 | } |
| 4283 | |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4284 | static char * |
| 4285 | smb2_create_lease_buf(u8 *lease_key, u8 oplock) |
| 4286 | { |
| 4287 | struct create_lease *buf; |
| 4288 | |
| 4289 | buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL); |
| 4290 | if (!buf) |
| 4291 | return NULL; |
| 4292 | |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 4293 | memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4294 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4295 | |
| 4296 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 4297 | (struct create_lease, lcontext)); |
| 4298 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); |
| 4299 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 4300 | (struct create_lease, Name)); |
| 4301 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 4302 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 4303 | buf->Name[0] = 'R'; |
| 4304 | buf->Name[1] = 'q'; |
| 4305 | buf->Name[2] = 'L'; |
| 4306 | buf->Name[3] = 's'; |
| 4307 | return (char *)buf; |
| 4308 | } |
| 4309 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4310 | static char * |
| 4311 | smb3_create_lease_buf(u8 *lease_key, u8 oplock) |
| 4312 | { |
| 4313 | struct create_lease_v2 *buf; |
| 4314 | |
| 4315 | buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL); |
| 4316 | if (!buf) |
| 4317 | return NULL; |
| 4318 | |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 4319 | memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4320 | buf->lcontext.LeaseState = map_oplock_to_lease(oplock); |
| 4321 | |
| 4322 | buf->ccontext.DataOffset = cpu_to_le16(offsetof |
| 4323 | (struct create_lease_v2, lcontext)); |
| 4324 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); |
| 4325 | buf->ccontext.NameOffset = cpu_to_le16(offsetof |
| 4326 | (struct create_lease_v2, Name)); |
| 4327 | buf->ccontext.NameLength = cpu_to_le16(4); |
Steve French | 12197a7 | 2014-05-14 05:29:40 -0700 | [diff] [blame] | 4328 | /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */ |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4329 | buf->Name[0] = 'R'; |
| 4330 | buf->Name[1] = 'q'; |
| 4331 | buf->Name[2] = 'L'; |
| 4332 | buf->Name[3] = 's'; |
| 4333 | return (char *)buf; |
| 4334 | } |
| 4335 | |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 4336 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 4337 | smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 4338 | { |
| 4339 | struct create_lease *lc = (struct create_lease *)buf; |
| 4340 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4341 | *epoch = 0; /* not used */ |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 4342 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 4343 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
| 4344 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 4345 | } |
| 4346 | |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4347 | static __u8 |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 4348 | smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key) |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4349 | { |
| 4350 | struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; |
| 4351 | |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 4352 | *epoch = le16_to_cpu(lc->lcontext.Epoch); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4353 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) |
| 4354 | return SMB2_OPLOCK_LEVEL_NOCHANGE; |
Ronnie Sahlberg | 96164ab | 2018-04-26 08:10:18 -0600 | [diff] [blame] | 4355 | if (lease_key) |
Stefano Brivio | 729c0c9 | 2018-07-05 15:10:02 +0200 | [diff] [blame] | 4356 | memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 4357 | return le32_to_cpu(lc->lcontext.LeaseState); |
| 4358 | } |
| 4359 | |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 4360 | static unsigned int |
| 4361 | smb2_wp_retry_size(struct inode *inode) |
| 4362 | { |
Ronnie Sahlberg | 522aa3b | 2020-12-14 16:40:17 +1000 | [diff] [blame] | 4363 | return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 4364 | SMB2_MAX_BUFFER_SIZE); |
| 4365 | } |
| 4366 | |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 4367 | static bool |
| 4368 | smb2_dir_needs_close(struct cifsFileInfo *cfile) |
| 4369 | { |
| 4370 | return !cfile->invalidHandle; |
| 4371 | } |
| 4372 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4373 | static void |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4374 | 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] | 4375 | struct smb_rqst *old_rq, __le16 cipher_type) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4376 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 4377 | struct smb2_hdr *shdr = |
| 4378 | (struct smb2_hdr *)old_rq->rq_iov[0].iov_base; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4379 | |
| 4380 | memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); |
| 4381 | tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; |
| 4382 | tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); |
| 4383 | tr_hdr->Flags = cpu_to_le16(0x01); |
Steve French | 63ca565 | 2020-10-15 23:41:40 -0500 | [diff] [blame] | 4384 | if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) || |
| 4385 | (cipher_type == SMB2_ENCRYPTION_AES256_GCM)) |
Steve French | fd08f2d | 2020-10-15 00:25:02 -0500 | [diff] [blame] | 4386 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE); |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 4387 | else |
Steve French | fd08f2d | 2020-10-15 00:25:02 -0500 | [diff] [blame] | 4388 | get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4389 | memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 4392 | /* We can not use the normal sg_set_buf() as we will sometimes pass a |
| 4393 | * stack object as buf. |
| 4394 | */ |
| 4395 | static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, |
| 4396 | unsigned int buflen) |
| 4397 | { |
Sebastien Tisserant | ee9d661 | 2019-08-01 12:06:08 -0500 | [diff] [blame] | 4398 | void *addr; |
| 4399 | /* |
| 4400 | * VMAP_STACK (at least) puts stack into the vmalloc address space |
| 4401 | */ |
| 4402 | if (is_vmalloc_addr(buf)) |
| 4403 | addr = vmalloc_to_page(buf); |
| 4404 | else |
| 4405 | addr = virt_to_page(buf); |
| 4406 | sg_set_page(sg, addr, buflen, offset_in_page(buf)); |
Ronnie Sahlberg | 262916b | 2018-02-20 12:45:21 +1100 | [diff] [blame] | 4407 | } |
| 4408 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4409 | /* Assumes the first rqst has a transform header as the first iov. |
| 4410 | * I.e. |
| 4411 | * rqst[0].rq_iov[0] is transform header |
| 4412 | * rqst[0].rq_iov[1+] data to be encrypted/decrypted |
| 4413 | * rqst[1+].rq_iov[0+] data to be encrypted/decrypted |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4414 | */ |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4415 | static struct scatterlist * |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4416 | init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4417 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4418 | unsigned int sg_len; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4419 | struct scatterlist *sg; |
| 4420 | unsigned int i; |
| 4421 | unsigned int j; |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4422 | unsigned int idx = 0; |
| 4423 | int skip; |
| 4424 | |
| 4425 | sg_len = 1; |
| 4426 | for (i = 0; i < num_rqst; i++) |
| 4427 | sg_len += rqst[i].rq_nvec + rqst[i].rq_npages; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4428 | |
| 4429 | sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL); |
| 4430 | if (!sg) |
| 4431 | return NULL; |
| 4432 | |
| 4433 | sg_init_table(sg, sg_len); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4434 | for (i = 0; i < num_rqst; i++) { |
| 4435 | for (j = 0; j < rqst[i].rq_nvec; j++) { |
| 4436 | /* |
| 4437 | * The first rqst has a transform header where the |
| 4438 | * first 20 bytes are not part of the encrypted blob |
| 4439 | */ |
| 4440 | skip = (i == 0) && (j == 0) ? 20 : 0; |
| 4441 | smb2_sg_set_buf(&sg[idx++], |
| 4442 | rqst[i].rq_iov[j].iov_base + skip, |
| 4443 | rqst[i].rq_iov[j].iov_len - skip); |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 4444 | } |
Steve French | d5f07fb | 2018-06-05 17:46:24 -0500 | [diff] [blame] | 4445 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4446 | for (j = 0; j < rqst[i].rq_npages; j++) { |
| 4447 | unsigned int len, offset; |
| 4448 | |
| 4449 | rqst_page_get_length(&rqst[i], j, &len, &offset); |
| 4450 | sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset); |
| 4451 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4452 | } |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4453 | smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4454 | return sg; |
| 4455 | } |
| 4456 | |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 4457 | static int |
| 4458 | smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) |
| 4459 | { |
| 4460 | struct cifs_ses *ses; |
| 4461 | u8 *ses_enc_key; |
| 4462 | |
| 4463 | spin_lock(&cifs_tcp_ses_lock); |
Aurelien Aptel | d70e9fa | 2019-09-20 06:31:10 +0200 | [diff] [blame] | 4464 | list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { |
| 4465 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 4466 | if (ses->Suid == ses_id) { |
| 4467 | ses_enc_key = enc ? ses->smb3encryptionkey : |
| 4468 | ses->smb3decryptionkey; |
Shyam Prasad N | 45a4546 | 2021-03-25 12:34:54 +0000 | [diff] [blame] | 4469 | memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE); |
Aurelien Aptel | d70e9fa | 2019-09-20 06:31:10 +0200 | [diff] [blame] | 4470 | spin_unlock(&cifs_tcp_ses_lock); |
| 4471 | return 0; |
| 4472 | } |
| 4473 | } |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 4474 | } |
| 4475 | spin_unlock(&cifs_tcp_ses_lock); |
| 4476 | |
Paul Aurich | 83728cb | 2021-04-13 14:25:27 -0700 | [diff] [blame] | 4477 | return -EAGAIN; |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 4478 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4479 | /* |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 4480 | * Encrypt or decrypt @rqst message. @rqst[0] has the following format: |
| 4481 | * iov[0] - transform header (associate data), |
| 4482 | * iov[1-N] - SMB2 header and pages - data to encrypt. |
| 4483 | * 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] | 4484 | * untouched. |
| 4485 | */ |
| 4486 | static int |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4487 | crypt_message(struct TCP_Server_Info *server, int num_rqst, |
| 4488 | struct smb_rqst *rqst, int enc) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4489 | { |
| 4490 | struct smb2_transform_hdr *tr_hdr = |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4491 | (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4492 | unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4493 | int rc = 0; |
| 4494 | struct scatterlist *sg; |
| 4495 | u8 sign[SMB2_SIGNATURE_SIZE] = {}; |
Shyam Prasad N | 45a4546 | 2021-03-25 12:34:54 +0000 | [diff] [blame] | 4496 | u8 key[SMB3_ENC_DEC_KEY_SIZE]; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4497 | struct aead_request *req; |
| 4498 | char *iv; |
| 4499 | unsigned int iv_len; |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 4500 | DECLARE_CRYPTO_WAIT(wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4501 | struct crypto_aead *tfm; |
| 4502 | unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 4503 | |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 4504 | rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key); |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 4505 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4506 | cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__, |
Pavel Shilovsky | 61cfac6f | 2017-02-28 16:05:19 -0800 | [diff] [blame] | 4507 | enc ? "en" : "de"); |
Shyam Prasad N | 0bd294b | 2020-10-15 10:41:31 -0700 | [diff] [blame] | 4508 | return rc; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | rc = smb3_crypto_aead_allocate(server); |
| 4512 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4513 | cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4514 | return rc; |
| 4515 | } |
| 4516 | |
| 4517 | tfm = enc ? server->secmech.ccmaesencrypt : |
| 4518 | server->secmech.ccmaesdecrypt; |
Steve French | 63ca565 | 2020-10-15 23:41:40 -0500 | [diff] [blame] | 4519 | |
Shyam Prasad N | 45a4546 | 2021-03-25 12:34:54 +0000 | [diff] [blame] | 4520 | if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) || |
| 4521 | (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) |
Steve French | 63ca565 | 2020-10-15 23:41:40 -0500 | [diff] [blame] | 4522 | rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE); |
| 4523 | else |
Shyam Prasad N | 45a4546 | 2021-03-25 12:34:54 +0000 | [diff] [blame] | 4524 | rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE); |
Steve French | 63ca565 | 2020-10-15 23:41:40 -0500 | [diff] [blame] | 4525 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4526 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4527 | 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] | 4528 | return rc; |
| 4529 | } |
| 4530 | |
| 4531 | rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE); |
| 4532 | if (rc) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4533 | 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] | 4534 | return rc; |
| 4535 | } |
| 4536 | |
| 4537 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 4538 | if (!req) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4539 | cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4540 | return -ENOMEM; |
| 4541 | } |
| 4542 | |
| 4543 | if (!enc) { |
| 4544 | memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); |
| 4545 | crypt_len += SMB2_SIGNATURE_SIZE; |
| 4546 | } |
| 4547 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4548 | sg = init_sg(num_rqst, rqst, sign); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4549 | if (!sg) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4550 | cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 4551 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4552 | goto free_req; |
| 4553 | } |
| 4554 | |
| 4555 | iv_len = crypto_aead_ivsize(tfm); |
| 4556 | iv = kzalloc(iv_len, GFP_KERNEL); |
| 4557 | if (!iv) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4558 | cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__); |
Christophe Jaillet | 517a6e4 | 2017-06-11 09:12:47 +0200 | [diff] [blame] | 4559 | rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4560 | goto free_sg; |
| 4561 | } |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 4562 | |
Steve French | 63ca565 | 2020-10-15 23:41:40 -0500 | [diff] [blame] | 4563 | if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) || |
| 4564 | (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) |
Steve French | fd08f2d | 2020-10-15 00:25:02 -0500 | [diff] [blame] | 4565 | memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE); |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 4566 | else { |
| 4567 | iv[0] = 3; |
Steve French | fd08f2d | 2020-10-15 00:25:02 -0500 | [diff] [blame] | 4568 | memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE); |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 4569 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4570 | |
| 4571 | aead_request_set_crypt(req, sg, sg, crypt_len, iv); |
| 4572 | aead_request_set_ad(req, assoc_data_len); |
| 4573 | |
| 4574 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 4575 | crypto_req_done, &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4576 | |
Gilad Ben-Yossef | a5186b8 | 2017-10-18 08:00:46 +0100 | [diff] [blame] | 4577 | rc = crypto_wait_req(enc ? crypto_aead_encrypt(req) |
| 4578 | : crypto_aead_decrypt(req), &wait); |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4579 | |
| 4580 | if (!rc && enc) |
| 4581 | memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); |
| 4582 | |
| 4583 | kfree(iv); |
| 4584 | free_sg: |
| 4585 | kfree(sg); |
| 4586 | free_req: |
| 4587 | kfree(req); |
| 4588 | return rc; |
| 4589 | } |
| 4590 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4591 | void |
| 4592 | smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4593 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4594 | int i, j; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4595 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4596 | for (i = 0; i < num_rqst; i++) { |
| 4597 | if (rqst[i].rq_pages) { |
| 4598 | for (j = rqst[i].rq_npages - 1; j >= 0; j--) |
| 4599 | put_page(rqst[i].rq_pages[j]); |
| 4600 | kfree(rqst[i].rq_pages); |
| 4601 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4602 | } |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4603 | } |
| 4604 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4605 | /* |
| 4606 | * This function will initialize new_rq and encrypt the content. |
| 4607 | * The first entry, new_rq[0], only contains a single iov which contains |
| 4608 | * a smb2_transform_hdr and is pre-allocated by the caller. |
| 4609 | * This function then populates new_rq[1+] with the content from olq_rq[0+]. |
| 4610 | * |
| 4611 | * The end result is an array of smb_rqst structures where the first structure |
| 4612 | * only contains a single iov for the transform header which we then can pass |
| 4613 | * to crypt_message(). |
| 4614 | * |
| 4615 | * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller |
| 4616 | * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests |
| 4617 | */ |
| 4618 | static int |
| 4619 | smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, |
| 4620 | struct smb_rqst *new_rq, struct smb_rqst *old_rq) |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4621 | { |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4622 | struct page **pages; |
| 4623 | struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base; |
| 4624 | unsigned int npages; |
| 4625 | unsigned int orig_len = 0; |
| 4626 | int i, j; |
| 4627 | int rc = -ENOMEM; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4628 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4629 | for (i = 1; i < num_rqst; i++) { |
| 4630 | npages = old_rq[i - 1].rq_npages; |
| 4631 | pages = kmalloc_array(npages, sizeof(struct page *), |
| 4632 | GFP_KERNEL); |
| 4633 | if (!pages) |
| 4634 | goto err_free; |
| 4635 | |
| 4636 | new_rq[i].rq_pages = pages; |
| 4637 | new_rq[i].rq_npages = npages; |
| 4638 | new_rq[i].rq_offset = old_rq[i - 1].rq_offset; |
| 4639 | new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz; |
| 4640 | new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz; |
| 4641 | new_rq[i].rq_iov = old_rq[i - 1].rq_iov; |
| 4642 | new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec; |
| 4643 | |
| 4644 | orig_len += smb_rqst_len(server, &old_rq[i - 1]); |
| 4645 | |
| 4646 | for (j = 0; j < npages; j++) { |
| 4647 | pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 4648 | if (!pages[j]) |
| 4649 | goto err_free; |
| 4650 | } |
| 4651 | |
| 4652 | /* copy pages form the old */ |
| 4653 | for (j = 0; j < npages; j++) { |
| 4654 | char *dst, *src; |
| 4655 | unsigned int offset, len; |
| 4656 | |
| 4657 | rqst_page_get_length(&new_rq[i], j, &len, &offset); |
| 4658 | |
| 4659 | dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset; |
| 4660 | src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset; |
| 4661 | |
| 4662 | memcpy(dst, src, len); |
| 4663 | kunmap(new_rq[i].rq_pages[j]); |
| 4664 | kunmap(old_rq[i - 1].rq_pages[j]); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | /* fill the 1st iov with a transform header */ |
Steve French | 2b2f754 | 2019-06-07 15:16:10 -0500 | [diff] [blame] | 4669 | fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4670 | |
| 4671 | rc = crypt_message(server, num_rqst, new_rq, 1); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 4672 | cifs_dbg(FYI, "Encrypt message returned %d\n", rc); |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4673 | if (rc) |
| 4674 | goto err_free; |
| 4675 | |
| 4676 | return rc; |
| 4677 | |
| 4678 | err_free: |
| 4679 | smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]); |
| 4680 | return rc; |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 4681 | } |
| 4682 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4683 | static int |
| 4684 | smb3_is_transform_hdr(void *buf) |
| 4685 | { |
| 4686 | struct smb2_transform_hdr *trhdr = buf; |
| 4687 | |
| 4688 | return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; |
| 4689 | } |
| 4690 | |
| 4691 | static int |
| 4692 | decrypt_raw_data(struct TCP_Server_Info *server, char *buf, |
| 4693 | unsigned int buf_data_size, struct page **pages, |
Rohith Surabattula | 6259301 | 2020-10-08 09:58:41 +0000 | [diff] [blame] | 4694 | unsigned int npages, unsigned int page_data_size, |
| 4695 | bool is_offloaded) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4696 | { |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 4697 | struct kvec iov[2]; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4698 | struct smb_rqst rqst = {NULL}; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4699 | int rc; |
| 4700 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 4701 | iov[0].iov_base = buf; |
| 4702 | iov[0].iov_len = sizeof(struct smb2_transform_hdr); |
| 4703 | iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); |
| 4704 | iov[1].iov_len = buf_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4705 | |
| 4706 | rqst.rq_iov = iov; |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 4707 | rqst.rq_nvec = 2; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4708 | rqst.rq_pages = pages; |
| 4709 | rqst.rq_npages = npages; |
| 4710 | rqst.rq_pagesz = PAGE_SIZE; |
| 4711 | rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE; |
| 4712 | |
Ronnie Sahlberg | b2c96de | 2018-08-01 09:26:11 +1000 | [diff] [blame] | 4713 | rc = crypt_message(server, 1, &rqst, 0); |
Christoph Probst | a205d50 | 2019-05-08 21:36:25 +0200 | [diff] [blame] | 4714 | cifs_dbg(FYI, "Decrypt message returned %d\n", rc); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4715 | |
| 4716 | if (rc) |
| 4717 | return rc; |
| 4718 | |
Ronnie Sahlberg | c713c87 | 2018-06-12 08:00:58 +1000 | [diff] [blame] | 4719 | memmove(buf, iov[1].iov_base, buf_data_size); |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 4720 | |
Rohith Surabattula | 6259301 | 2020-10-08 09:58:41 +0000 | [diff] [blame] | 4721 | if (!is_offloaded) |
| 4722 | server->total_read = buf_data_size + page_data_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4723 | |
| 4724 | return rc; |
| 4725 | } |
| 4726 | |
| 4727 | static int |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4728 | read_data_into_pages(struct TCP_Server_Info *server, struct page **pages, |
| 4729 | unsigned int npages, unsigned int len) |
| 4730 | { |
| 4731 | int i; |
| 4732 | int length; |
| 4733 | |
| 4734 | for (i = 0; i < npages; i++) { |
| 4735 | struct page *page = pages[i]; |
| 4736 | size_t n; |
| 4737 | |
| 4738 | n = len; |
| 4739 | if (len >= PAGE_SIZE) { |
| 4740 | /* enough data to fill the page */ |
| 4741 | n = PAGE_SIZE; |
| 4742 | len -= n; |
| 4743 | } else { |
| 4744 | zero_user(page, len, PAGE_SIZE - len); |
| 4745 | len = 0; |
| 4746 | } |
Long Li | 1dbe346 | 2018-05-30 12:47:55 -0700 | [diff] [blame] | 4747 | length = cifs_read_page_from_socket(server, page, 0, n); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4748 | if (length < 0) |
| 4749 | return length; |
| 4750 | server->total_read += length; |
| 4751 | } |
| 4752 | |
| 4753 | return 0; |
| 4754 | } |
| 4755 | |
| 4756 | static int |
| 4757 | init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size, |
| 4758 | unsigned int cur_off, struct bio_vec **page_vec) |
| 4759 | { |
| 4760 | struct bio_vec *bvec; |
| 4761 | int i; |
| 4762 | |
| 4763 | bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL); |
| 4764 | if (!bvec) |
| 4765 | return -ENOMEM; |
| 4766 | |
| 4767 | for (i = 0; i < npages; i++) { |
| 4768 | bvec[i].bv_page = pages[i]; |
| 4769 | bvec[i].bv_offset = (i == 0) ? cur_off : 0; |
| 4770 | bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size); |
| 4771 | data_size -= bvec[i].bv_len; |
| 4772 | } |
| 4773 | |
| 4774 | if (data_size != 0) { |
| 4775 | cifs_dbg(VFS, "%s: something went wrong\n", __func__); |
| 4776 | kfree(bvec); |
| 4777 | return -EIO; |
| 4778 | } |
| 4779 | |
| 4780 | *page_vec = bvec; |
| 4781 | return 0; |
| 4782 | } |
| 4783 | |
| 4784 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4785 | handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, |
| 4786 | char *buf, unsigned int buf_len, struct page **pages, |
Rohith Surabattula | de9ac0a | 2020-10-28 13:42:21 +0000 | [diff] [blame] | 4787 | unsigned int npages, unsigned int page_data_size, |
| 4788 | bool is_offloaded) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4789 | { |
| 4790 | unsigned int data_offset; |
| 4791 | unsigned int data_len; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4792 | unsigned int cur_off; |
| 4793 | unsigned int cur_page_idx; |
| 4794 | unsigned int pad_len; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4795 | struct cifs_readdata *rdata = mid->callback_data; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 4796 | struct smb2_hdr *shdr = (struct smb2_hdr *)buf; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4797 | struct bio_vec *bvec = NULL; |
| 4798 | struct iov_iter iter; |
| 4799 | struct kvec iov; |
| 4800 | int length; |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 4801 | bool use_rdma_mr = false; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4802 | |
| 4803 | if (shdr->Command != SMB2_READ) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 4804 | cifs_server_dbg(VFS, "only big read responses are supported\n"); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4805 | return -ENOTSUPP; |
| 4806 | } |
| 4807 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4808 | if (server->ops->is_session_expired && |
| 4809 | server->ops->is_session_expired(buf)) { |
Rohith Surabattula | de9ac0a | 2020-10-28 13:42:21 +0000 | [diff] [blame] | 4810 | if (!is_offloaded) |
| 4811 | cifs_reconnect(server); |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 4812 | return -1; |
| 4813 | } |
| 4814 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4815 | if (server->ops->is_status_pending && |
Pavel Shilovsky | 66265f1 | 2019-01-23 17:11:16 -0800 | [diff] [blame] | 4816 | server->ops->is_status_pending(buf, server)) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4817 | return -1; |
| 4818 | |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 4819 | /* set up first two iov to get credits */ |
| 4820 | rdata->iov[0].iov_base = buf; |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 4821 | rdata->iov[0].iov_len = 0; |
| 4822 | rdata->iov[1].iov_base = buf; |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 4823 | rdata->iov[1].iov_len = |
Pavel Shilovsky | bb1bccb | 2019-01-17 16:18:38 -0800 | [diff] [blame] | 4824 | min_t(unsigned int, buf_len, server->vals->read_rsp_size); |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 4825 | cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n", |
| 4826 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); |
| 4827 | cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n", |
| 4828 | rdata->iov[1].iov_base, rdata->iov[1].iov_len); |
| 4829 | |
| 4830 | rdata->result = server->ops->map_error(buf, true); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4831 | if (rdata->result != 0) { |
| 4832 | cifs_dbg(FYI, "%s: server returned error %d\n", |
| 4833 | __func__, rdata->result); |
Pavel Shilovsky | ec678ea | 2019-01-18 15:38:11 -0800 | [diff] [blame] | 4834 | /* normal error on read response */ |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4835 | if (is_offloaded) |
| 4836 | mid->mid_state = MID_RESPONSE_RECEIVED; |
| 4837 | else |
| 4838 | dequeue_mid(mid, false); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4839 | return 0; |
| 4840 | } |
| 4841 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 4842 | data_offset = server->ops->read_data_offset(buf); |
Long Li | 74dcf41 | 2017-11-22 17:38:46 -0700 | [diff] [blame] | 4843 | #ifdef CONFIG_CIFS_SMB_DIRECT |
| 4844 | use_rdma_mr = rdata->mr; |
| 4845 | #endif |
| 4846 | data_len = server->ops->read_data_length(buf, use_rdma_mr); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4847 | |
| 4848 | if (data_offset < server->vals->read_rsp_size) { |
| 4849 | /* |
| 4850 | * win2k8 sometimes sends an offset of 0 when the read |
| 4851 | * is beyond the EOF. Treat it as if the data starts just after |
| 4852 | * the header. |
| 4853 | */ |
| 4854 | cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n", |
| 4855 | __func__, data_offset); |
| 4856 | data_offset = server->vals->read_rsp_size; |
| 4857 | } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) { |
| 4858 | /* data_offset is beyond the end of smallbuf */ |
| 4859 | cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n", |
| 4860 | __func__, data_offset); |
| 4861 | rdata->result = -EIO; |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4862 | if (is_offloaded) |
| 4863 | mid->mid_state = MID_RESPONSE_MALFORMED; |
| 4864 | else |
| 4865 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4866 | return 0; |
| 4867 | } |
| 4868 | |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4869 | pad_len = data_offset - server->vals->read_rsp_size; |
| 4870 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4871 | if (buf_len <= data_offset) { |
| 4872 | /* read response payload is in pages */ |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4873 | cur_page_idx = pad_len / PAGE_SIZE; |
| 4874 | cur_off = pad_len % PAGE_SIZE; |
| 4875 | |
| 4876 | if (cur_page_idx != 0) { |
| 4877 | /* data offset is beyond the 1st page of response */ |
| 4878 | cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n", |
| 4879 | __func__, data_offset); |
| 4880 | rdata->result = -EIO; |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4881 | if (is_offloaded) |
| 4882 | mid->mid_state = MID_RESPONSE_MALFORMED; |
| 4883 | else |
| 4884 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4885 | return 0; |
| 4886 | } |
| 4887 | |
| 4888 | if (data_len > page_data_size - pad_len) { |
| 4889 | /* data_len is corrupt -- discard frame */ |
| 4890 | rdata->result = -EIO; |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4891 | if (is_offloaded) |
| 4892 | mid->mid_state = MID_RESPONSE_MALFORMED; |
| 4893 | else |
| 4894 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4895 | return 0; |
| 4896 | } |
| 4897 | |
| 4898 | rdata->result = init_read_bvec(pages, npages, page_data_size, |
| 4899 | cur_off, &bvec); |
| 4900 | if (rdata->result != 0) { |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4901 | if (is_offloaded) |
| 4902 | mid->mid_state = MID_RESPONSE_MALFORMED; |
| 4903 | else |
| 4904 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 4905 | return 0; |
| 4906 | } |
| 4907 | |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 4908 | iov_iter_bvec(&iter, WRITE, bvec, npages, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4909 | } else if (buf_len >= data_offset + data_len) { |
| 4910 | /* read response payload is in buf */ |
| 4911 | WARN_ONCE(npages > 0, "read data can be either in buf or in pages"); |
| 4912 | iov.iov_base = buf + data_offset; |
| 4913 | iov.iov_len = data_len; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 4914 | iov_iter_kvec(&iter, WRITE, &iov, 1, data_len); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4915 | } else { |
| 4916 | /* read response payload cannot be in both buf and pages */ |
| 4917 | WARN_ONCE(1, "buf can not contain only a part of read data"); |
| 4918 | rdata->result = -EIO; |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4919 | if (is_offloaded) |
| 4920 | mid->mid_state = MID_RESPONSE_MALFORMED; |
| 4921 | else |
| 4922 | dequeue_mid(mid, rdata->result); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4923 | return 0; |
| 4924 | } |
| 4925 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4926 | length = rdata->copy_into_pages(server, rdata, &iter); |
| 4927 | |
| 4928 | kfree(bvec); |
| 4929 | |
| 4930 | if (length < 0) |
| 4931 | return length; |
| 4932 | |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4933 | if (is_offloaded) |
| 4934 | mid->mid_state = MID_RESPONSE_RECEIVED; |
| 4935 | else |
| 4936 | dequeue_mid(mid, false); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 4937 | return length; |
| 4938 | } |
| 4939 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 4940 | struct smb2_decrypt_work { |
| 4941 | struct work_struct decrypt; |
| 4942 | struct TCP_Server_Info *server; |
| 4943 | struct page **ppages; |
| 4944 | char *buf; |
| 4945 | unsigned int npages; |
| 4946 | unsigned int len; |
| 4947 | }; |
| 4948 | |
| 4949 | |
| 4950 | static void smb2_decrypt_offload(struct work_struct *work) |
| 4951 | { |
| 4952 | struct smb2_decrypt_work *dw = container_of(work, |
| 4953 | struct smb2_decrypt_work, decrypt); |
| 4954 | int i, rc; |
| 4955 | struct mid_q_entry *mid; |
| 4956 | |
| 4957 | rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, |
Rohith Surabattula | 6259301 | 2020-10-08 09:58:41 +0000 | [diff] [blame] | 4958 | dw->ppages, dw->npages, dw->len, true); |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 4959 | if (rc) { |
| 4960 | cifs_dbg(VFS, "error decrypting rc=%d\n", rc); |
| 4961 | goto free_pages; |
| 4962 | } |
| 4963 | |
Steve French | 2255397 | 2019-09-13 16:47:31 -0500 | [diff] [blame] | 4964 | dw->server->lstrp = jiffies; |
Rohith Surabattula | ac873aa | 2020-10-29 05:03:10 +0000 | [diff] [blame] | 4965 | mid = smb2_find_dequeue_mid(dw->server, dw->buf); |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 4966 | if (mid == NULL) |
| 4967 | cifs_dbg(FYI, "mid not found\n"); |
| 4968 | else { |
| 4969 | mid->decrypted = true; |
| 4970 | rc = handle_read_data(dw->server, mid, dw->buf, |
| 4971 | dw->server->vals->read_rsp_size, |
Rohith Surabattula | de9ac0a | 2020-10-28 13:42:21 +0000 | [diff] [blame] | 4972 | dw->ppages, dw->npages, dw->len, |
| 4973 | true); |
Rohith Surabattula | 1254100 | 2020-10-29 06:07:56 +0000 | [diff] [blame] | 4974 | if (rc >= 0) { |
| 4975 | #ifdef CONFIG_CIFS_STATS2 |
| 4976 | mid->when_received = jiffies; |
| 4977 | #endif |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 4978 | if (dw->server->ops->is_network_name_deleted) |
| 4979 | dw->server->ops->is_network_name_deleted(dw->buf, |
| 4980 | dw->server); |
| 4981 | |
Rohith Surabattula | 1254100 | 2020-10-29 06:07:56 +0000 | [diff] [blame] | 4982 | mid->callback(mid); |
| 4983 | } else { |
| 4984 | spin_lock(&GlobalMid_Lock); |
| 4985 | if (dw->server->tcpStatus == CifsNeedReconnect) { |
| 4986 | mid->mid_state = MID_RETRY_NEEDED; |
| 4987 | spin_unlock(&GlobalMid_Lock); |
| 4988 | mid->callback(mid); |
| 4989 | } else { |
| 4990 | mid->mid_state = MID_REQUEST_SUBMITTED; |
| 4991 | mid->mid_flags &= ~(MID_DELETED); |
| 4992 | list_add_tail(&mid->qhead, |
| 4993 | &dw->server->pending_mid_q); |
| 4994 | spin_unlock(&GlobalMid_Lock); |
| 4995 | } |
| 4996 | } |
Steve French | 2255397 | 2019-09-13 16:47:31 -0500 | [diff] [blame] | 4997 | cifs_mid_q_entry_release(mid); |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 4998 | } |
| 4999 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5000 | free_pages: |
| 5001 | for (i = dw->npages-1; i >= 0; i--) |
| 5002 | put_page(dw->ppages[i]); |
| 5003 | |
| 5004 | kfree(dw->ppages); |
| 5005 | cifs_small_buf_release(dw->buf); |
Steve French | a08d897 | 2019-10-26 16:00:44 -0500 | [diff] [blame] | 5006 | kfree(dw); |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5010 | static int |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5011 | receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, |
| 5012 | int *num_mids) |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5013 | { |
| 5014 | char *buf = server->smallbuf; |
| 5015 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 5016 | unsigned int npages; |
| 5017 | struct page **pages; |
| 5018 | unsigned int len; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5019 | unsigned int buflen = server->pdu_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5020 | int rc; |
| 5021 | int i = 0; |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5022 | struct smb2_decrypt_work *dw; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5023 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5024 | *num_mids = 1; |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5025 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size + |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5026 | sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; |
| 5027 | |
| 5028 | rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); |
| 5029 | if (rc < 0) |
| 5030 | return rc; |
| 5031 | server->total_read += rc; |
| 5032 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5033 | len = le32_to_cpu(tr_hdr->OriginalMessageSize) - |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 5034 | server->vals->read_rsp_size; |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5035 | npages = DIV_ROUND_UP(len, PAGE_SIZE); |
| 5036 | |
| 5037 | pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); |
| 5038 | if (!pages) { |
| 5039 | rc = -ENOMEM; |
| 5040 | goto discard_data; |
| 5041 | } |
| 5042 | |
| 5043 | for (; i < npages; i++) { |
| 5044 | pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
| 5045 | if (!pages[i]) { |
| 5046 | rc = -ENOMEM; |
| 5047 | goto discard_data; |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | /* read read data into pages */ |
| 5052 | rc = read_data_into_pages(server, pages, npages, len); |
| 5053 | if (rc) |
| 5054 | goto free_pages; |
| 5055 | |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 5056 | rc = cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5057 | if (rc) |
| 5058 | goto free_pages; |
| 5059 | |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5060 | /* |
| 5061 | * For large reads, offload to different thread for better performance, |
| 5062 | * use more cores decrypting which can be expensive |
| 5063 | */ |
| 5064 | |
Steve French | 10328c4 | 2019-09-09 13:30:15 -0500 | [diff] [blame] | 5065 | if ((server->min_offload) && (server->in_flight > 1) && |
Steve French | 563317e | 2019-09-08 23:22:02 -0500 | [diff] [blame] | 5066 | (server->pdu_size >= server->min_offload)) { |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5067 | dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL); |
| 5068 | if (dw == NULL) |
| 5069 | goto non_offloaded_decrypt; |
| 5070 | |
| 5071 | dw->buf = server->smallbuf; |
| 5072 | server->smallbuf = (char *)cifs_small_buf_get(); |
| 5073 | |
| 5074 | INIT_WORK(&dw->decrypt, smb2_decrypt_offload); |
| 5075 | |
| 5076 | dw->npages = npages; |
| 5077 | dw->server = server; |
| 5078 | dw->ppages = pages; |
| 5079 | dw->len = len; |
Steve French | a08d897 | 2019-10-26 16:00:44 -0500 | [diff] [blame] | 5080 | queue_work(decrypt_wq, &dw->decrypt); |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5081 | *num_mids = 0; /* worker thread takes care of finding mid */ |
| 5082 | return -1; |
| 5083 | } |
| 5084 | |
| 5085 | non_offloaded_decrypt: |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5086 | rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, |
Rohith Surabattula | 6259301 | 2020-10-08 09:58:41 +0000 | [diff] [blame] | 5087 | pages, npages, len, false); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5088 | if (rc) |
| 5089 | goto free_pages; |
| 5090 | |
| 5091 | *mid = smb2_find_mid(server, buf); |
| 5092 | if (*mid == NULL) |
| 5093 | cifs_dbg(FYI, "mid not found\n"); |
| 5094 | else { |
| 5095 | cifs_dbg(FYI, "mid found\n"); |
| 5096 | (*mid)->decrypted = true; |
| 5097 | rc = handle_read_data(server, *mid, buf, |
| 5098 | server->vals->read_rsp_size, |
Rohith Surabattula | de9ac0a | 2020-10-28 13:42:21 +0000 | [diff] [blame] | 5099 | pages, npages, len, false); |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 5100 | if (rc >= 0) { |
| 5101 | if (server->ops->is_network_name_deleted) { |
| 5102 | server->ops->is_network_name_deleted(buf, |
| 5103 | server); |
| 5104 | } |
| 5105 | } |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | free_pages: |
| 5109 | for (i = i - 1; i >= 0; i--) |
| 5110 | put_page(pages[i]); |
| 5111 | kfree(pages); |
| 5112 | return rc; |
| 5113 | discard_data: |
Pavel Shilovsky | 350be25 | 2017-04-10 10:31:33 -0700 | [diff] [blame] | 5114 | cifs_discard_remaining_data(server); |
Pavel Shilovsky | c42a6ab | 2016-11-17 16:20:23 -0800 | [diff] [blame] | 5115 | goto free_pages; |
| 5116 | } |
| 5117 | |
| 5118 | static int |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5119 | receive_encrypted_standard(struct TCP_Server_Info *server, |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5120 | struct mid_q_entry **mids, char **bufs, |
| 5121 | int *num_mids) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5122 | { |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5123 | int ret, length; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5124 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5125 | struct smb2_hdr *shdr; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 5126 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5127 | unsigned int buf_size; |
| 5128 | struct mid_q_entry *mid_entry; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5129 | int next_is_large; |
| 5130 | char *next_buffer = NULL; |
| 5131 | |
| 5132 | *num_mids = 0; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5133 | |
| 5134 | /* switch to large buffer if too big for a small one */ |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5135 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) { |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5136 | server->large_buf = true; |
| 5137 | memcpy(server->bigbuf, buf, server->total_read); |
| 5138 | buf = server->bigbuf; |
| 5139 | } |
| 5140 | |
| 5141 | /* now read the rest */ |
| 5142 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5143 | pdu_length - HEADER_SIZE(server) + 1); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5144 | if (length < 0) |
| 5145 | return length; |
| 5146 | server->total_read += length; |
| 5147 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5148 | buf_size = pdu_length - sizeof(struct smb2_transform_hdr); |
Rohith Surabattula | 6259301 | 2020-10-08 09:58:41 +0000 | [diff] [blame] | 5149 | length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5150 | if (length) |
| 5151 | return length; |
| 5152 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5153 | next_is_large = server->large_buf; |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5154 | one_more: |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5155 | shdr = (struct smb2_hdr *)buf; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5156 | if (shdr->NextCommand) { |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5157 | if (next_is_large) |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5158 | next_buffer = (char *)cifs_buf_get(); |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5159 | else |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5160 | next_buffer = (char *)cifs_small_buf_get(); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5161 | memcpy(next_buffer, |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5162 | buf + le32_to_cpu(shdr->NextCommand), |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5163 | pdu_length - le32_to_cpu(shdr->NextCommand)); |
| 5164 | } |
| 5165 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5166 | mid_entry = smb2_find_mid(server, buf); |
| 5167 | if (mid_entry == NULL) |
| 5168 | cifs_dbg(FYI, "mid not found\n"); |
| 5169 | else { |
| 5170 | cifs_dbg(FYI, "mid found\n"); |
| 5171 | mid_entry->decrypted = true; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5172 | mid_entry->resp_buf_size = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5173 | } |
| 5174 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5175 | if (*num_mids >= MAX_COMPOUND) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 5176 | cifs_server_dbg(VFS, "too many PDUs in compound\n"); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5177 | return -1; |
| 5178 | } |
| 5179 | bufs[*num_mids] = buf; |
| 5180 | mids[(*num_mids)++] = mid_entry; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5181 | |
| 5182 | if (mid_entry && mid_entry->handle) |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5183 | ret = mid_entry->handle(server, mid_entry); |
| 5184 | else |
| 5185 | ret = cifs_handle_standard(server, mid_entry); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5186 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5187 | if (ret == 0 && shdr->NextCommand) { |
| 5188 | pdu_length -= le32_to_cpu(shdr->NextCommand); |
| 5189 | server->large_buf = next_is_large; |
| 5190 | if (next_is_large) |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5191 | server->bigbuf = buf = next_buffer; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5192 | else |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5193 | server->smallbuf = buf = next_buffer; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5194 | goto one_more; |
Pavel Shilovsky | 3edeb4a | 2019-07-22 11:38:22 -0700 | [diff] [blame] | 5195 | } else if (ret != 0) { |
| 5196 | /* |
| 5197 | * ret != 0 here means that we didn't get to handle_mid() thus |
| 5198 | * server->smallbuf and server->bigbuf are still valid. We need |
| 5199 | * to free next_buffer because it is not going to be used |
| 5200 | * anywhere. |
| 5201 | */ |
| 5202 | if (next_is_large) |
| 5203 | free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer); |
| 5204 | else |
| 5205 | free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer); |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | return ret; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | static int |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5212 | smb3_receive_transform(struct TCP_Server_Info *server, |
| 5213 | struct mid_q_entry **mids, char **bufs, int *num_mids) |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5214 | { |
| 5215 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 5216 | unsigned int pdu_length = server->pdu_size; |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5217 | struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf; |
| 5218 | unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); |
| 5219 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5220 | if (pdu_length < sizeof(struct smb2_transform_hdr) + |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5221 | sizeof(struct smb2_hdr)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 5222 | cifs_server_dbg(VFS, "Transform message is too small (%u)\n", |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5223 | pdu_length); |
| 5224 | cifs_reconnect(server); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5225 | return -ECONNABORTED; |
| 5226 | } |
| 5227 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5228 | if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) { |
Ronnie Sahlberg | 3175eb9 | 2019-09-04 12:32:41 +1000 | [diff] [blame] | 5229 | cifs_server_dbg(VFS, "Transform message is broken\n"); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5230 | cifs_reconnect(server); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5231 | return -ECONNABORTED; |
| 5232 | } |
| 5233 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5234 | /* TODO: add support for compounds containing READ. */ |
Paul Aurich | 6d2f84e | 2018-12-31 14:13:34 -0800 | [diff] [blame] | 5235 | if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) { |
Steve French | 35cf94a | 2019-09-07 01:09:49 -0500 | [diff] [blame] | 5236 | return receive_encrypted_read(server, &mids[0], num_mids); |
Paul Aurich | 6d2f84e | 2018-12-31 14:13:34 -0800 | [diff] [blame] | 5237 | } |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5238 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 5239 | return receive_encrypted_standard(server, mids, bufs, num_mids); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | int |
| 5243 | smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 5244 | { |
| 5245 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 5246 | |
Ronnie Sahlberg | 1fc6ad2 | 2018-06-01 10:53:07 +1000 | [diff] [blame] | 5247 | return handle_read_data(server, mid, buf, server->pdu_size, |
Rohith Surabattula | de9ac0a | 2020-10-28 13:42:21 +0000 | [diff] [blame] | 5248 | NULL, 0, 0, false); |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5249 | } |
| 5250 | |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5251 | static int |
| 5252 | smb2_next_header(char *buf) |
| 5253 | { |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5254 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5255 | struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf; |
| 5256 | |
| 5257 | if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) |
| 5258 | return sizeof(struct smb2_transform_hdr) + |
| 5259 | le32_to_cpu(t_hdr->OriginalMessageSize); |
| 5260 | |
| 5261 | return le32_to_cpu(hdr->NextCommand); |
| 5262 | } |
| 5263 | |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5264 | static int |
| 5265 | smb2_make_node(unsigned int xid, struct inode *inode, |
| 5266 | struct dentry *dentry, struct cifs_tcon *tcon, |
Al Viro | 5586913 | 2021-03-18 01:38:53 -0400 | [diff] [blame] | 5267 | const char *full_path, umode_t mode, dev_t dev) |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5268 | { |
| 5269 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 5270 | int rc = -EPERM; |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5271 | FILE_ALL_INFO *buf = NULL; |
Aurelien Aptel | 7c06514 | 2020-06-04 17:23:55 +0200 | [diff] [blame] | 5272 | struct cifs_io_parms io_parms = {0}; |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5273 | __u32 oplock = 0; |
| 5274 | struct cifs_fid fid; |
| 5275 | struct cifs_open_parms oparms; |
| 5276 | unsigned int bytes_written; |
| 5277 | struct win_dev *pdev; |
| 5278 | struct kvec iov[2]; |
| 5279 | |
| 5280 | /* |
| 5281 | * Check if mounted with mount parm 'sfu' mount parm. |
| 5282 | * SFU emulation should work with all servers, but only |
| 5283 | * supports block and char device (no socket & fifo), |
| 5284 | * and was used by default in earlier versions of Windows |
| 5285 | */ |
| 5286 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) |
| 5287 | goto out; |
| 5288 | |
| 5289 | /* |
| 5290 | * TODO: Add ability to create instead via reparse point. Windows (e.g. |
| 5291 | * their current NFS server) uses this approach to expose special files |
| 5292 | * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions |
| 5293 | */ |
| 5294 | |
| 5295 | if (!S_ISCHR(mode) && !S_ISBLK(mode)) |
| 5296 | goto out; |
| 5297 | |
| 5298 | cifs_dbg(FYI, "sfu compat create special file\n"); |
| 5299 | |
| 5300 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 5301 | if (buf == NULL) { |
| 5302 | rc = -ENOMEM; |
| 5303 | goto out; |
| 5304 | } |
| 5305 | |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5306 | oparms.tcon = tcon; |
| 5307 | oparms.cifs_sb = cifs_sb; |
| 5308 | oparms.desired_access = GENERIC_WRITE; |
Amir Goldstein | 0f06093 | 2020-02-03 21:46:43 +0200 | [diff] [blame] | 5309 | oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR | |
| 5310 | CREATE_OPTION_SPECIAL); |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5311 | oparms.disposition = FILE_CREATE; |
| 5312 | oparms.path = full_path; |
| 5313 | oparms.fid = &fid; |
| 5314 | oparms.reconnect = false; |
| 5315 | |
| 5316 | if (tcon->ses->server->oplocks) |
| 5317 | oplock = REQ_OPLOCK; |
| 5318 | else |
| 5319 | oplock = 0; |
| 5320 | rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf); |
| 5321 | if (rc) |
| 5322 | goto out; |
| 5323 | |
| 5324 | /* |
| 5325 | * BB Do not bother to decode buf since no local inode yet to put |
| 5326 | * timestamps in, but we can reuse it safely. |
| 5327 | */ |
| 5328 | |
| 5329 | pdev = (struct win_dev *)buf; |
| 5330 | io_parms.pid = current->tgid; |
| 5331 | io_parms.tcon = tcon; |
| 5332 | io_parms.offset = 0; |
| 5333 | io_parms.length = sizeof(struct win_dev); |
| 5334 | iov[1].iov_base = buf; |
| 5335 | iov[1].iov_len = sizeof(struct win_dev); |
| 5336 | if (S_ISCHR(mode)) { |
| 5337 | memcpy(pdev->type, "IntxCHR", 8); |
| 5338 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 5339 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 5340 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 5341 | &bytes_written, iov, 1); |
| 5342 | } else if (S_ISBLK(mode)) { |
| 5343 | memcpy(pdev->type, "IntxBLK", 8); |
| 5344 | pdev->major = cpu_to_le64(MAJOR(dev)); |
| 5345 | pdev->minor = cpu_to_le64(MINOR(dev)); |
| 5346 | rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, |
| 5347 | &bytes_written, iov, 1); |
| 5348 | } |
| 5349 | tcon->ses->server->ops->close(xid, tcon, &fid); |
| 5350 | d_drop(dentry); |
| 5351 | |
| 5352 | /* FIXME: add code here to set EAs */ |
| 5353 | out: |
| 5354 | kfree(buf); |
| 5355 | return rc; |
| 5356 | } |
| 5357 | |
| 5358 | |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5359 | struct smb_version_operations smb20_operations = { |
| 5360 | .compare_fids = smb2_compare_fids, |
| 5361 | .setup_request = smb2_setup_request, |
| 5362 | .setup_async_request = smb2_setup_async_request, |
| 5363 | .check_receive = smb2_check_receive, |
| 5364 | .add_credits = smb2_add_credits, |
| 5365 | .set_credits = smb2_set_credits, |
| 5366 | .get_credits_field = smb2_get_credits_field, |
| 5367 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 5368 | .wait_mtu_credits = cifs_wait_mtu_credits, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5369 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 5370 | .revert_current_mid = smb2_revert_current_mid, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5371 | .read_data_offset = smb2_read_data_offset, |
| 5372 | .read_data_length = smb2_read_data_length, |
| 5373 | .map_error = map_smb2_to_linux_error, |
| 5374 | .find_mid = smb2_find_mid, |
| 5375 | .check_message = smb2_check_message, |
| 5376 | .dump_detail = smb2_dump_detail, |
| 5377 | .clear_stats = smb2_clear_stats, |
| 5378 | .print_stats = smb2_print_stats, |
| 5379 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 5380 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Sachin Prabhu | c11f1df | 2014-03-11 16:11:47 +0000 | [diff] [blame] | 5381 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5382 | .need_neg = smb2_need_neg, |
| 5383 | .negotiate = smb2_negotiate, |
| 5384 | .negotiate_wsize = smb2_negotiate_wsize, |
| 5385 | .negotiate_rsize = smb2_negotiate_rsize, |
| 5386 | .sess_setup = SMB2_sess_setup, |
| 5387 | .logoff = SMB2_logoff, |
| 5388 | .tree_connect = SMB2_tcon, |
| 5389 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 5390 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5391 | .is_path_accessible = smb2_is_path_accessible, |
| 5392 | .can_echo = smb2_can_echo, |
| 5393 | .echo = SMB2_echo, |
| 5394 | .query_path_info = smb2_query_path_info, |
| 5395 | .get_srv_inum = smb2_get_srv_inum, |
| 5396 | .query_file_info = smb2_query_file_info, |
| 5397 | .set_path_size = smb2_set_path_size, |
| 5398 | .set_file_size = smb2_set_file_size, |
| 5399 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 5400 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5401 | .mkdir = smb2_mkdir, |
| 5402 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 5403 | .rmdir = smb2_rmdir, |
| 5404 | .unlink = smb2_unlink, |
| 5405 | .rename = smb2_rename_path, |
| 5406 | .create_hardlink = smb2_create_hardlink, |
| 5407 | .query_symlink = smb2_query_symlink, |
Sachin Prabhu | 5b23c97 | 2016-07-11 16:53:20 +0100 | [diff] [blame] | 5408 | .query_mf_symlink = smb3_query_mf_symlink, |
| 5409 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5410 | .open = smb2_open_file, |
| 5411 | .set_fid = smb2_set_fid, |
| 5412 | .close = smb2_close_file, |
| 5413 | .flush = smb2_flush_file, |
| 5414 | .async_readv = smb2_async_readv, |
| 5415 | .async_writev = smb2_async_writev, |
| 5416 | .sync_read = smb2_sync_read, |
| 5417 | .sync_write = smb2_sync_write, |
| 5418 | .query_dir_first = smb2_query_dir_first, |
| 5419 | .query_dir_next = smb2_query_dir_next, |
| 5420 | .close_dir = smb2_close_dir, |
| 5421 | .calc_smb_size = smb2_calc_size, |
| 5422 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 5423 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5424 | .oplock_response = smb2_oplock_response, |
| 5425 | .queryfs = smb2_queryfs, |
| 5426 | .mand_lock = smb2_mand_lock, |
| 5427 | .mand_unlock_range = smb2_unlock_range, |
| 5428 | .push_mand_locks = smb2_push_mandatory_locks, |
| 5429 | .get_lease_key = smb2_get_lease_key, |
| 5430 | .set_lease_key = smb2_set_lease_key, |
| 5431 | .new_lease_key = smb2_new_lease_key, |
| 5432 | .calc_signature = smb2_calc_signature, |
| 5433 | .is_read_op = smb2_is_read_op, |
| 5434 | .set_oplock_level = smb2_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 5435 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 5436 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 5437 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 5438 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 5439 | .dir_needs_close = smb2_dir_needs_close, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 5440 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 5441 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5442 | #ifdef CONFIG_CIFS_XATTR |
| 5443 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 5444 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5445 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 5446 | .get_acl = get_smb2_acl, |
| 5447 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 5448 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5449 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 5450 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5451 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 5452 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 5453 | .llseek = smb3_llseek, |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 5454 | .is_status_io_timeout = smb2_is_status_io_timeout, |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 5455 | .is_network_name_deleted = smb2_is_network_name_deleted, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5456 | }; |
| 5457 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 5458 | struct smb_version_operations smb21_operations = { |
Pavel Shilovsky | 027e8ee | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 5459 | .compare_fids = smb2_compare_fids, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 5460 | .setup_request = smb2_setup_request, |
Pavel Shilovsky | c95b8ee | 2012-07-11 14:45:28 +0400 | [diff] [blame] | 5461 | .setup_async_request = smb2_setup_async_request, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 5462 | .check_receive = smb2_check_receive, |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 5463 | .add_credits = smb2_add_credits, |
| 5464 | .set_credits = smb2_set_credits, |
| 5465 | .get_credits_field = smb2_get_credits_field, |
| 5466 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 5467 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 5468 | .adjust_credits = smb2_adjust_credits, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 5469 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 5470 | .revert_current_mid = smb2_revert_current_mid, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 5471 | .read_data_offset = smb2_read_data_offset, |
| 5472 | .read_data_length = smb2_read_data_length, |
| 5473 | .map_error = map_smb2_to_linux_error, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 5474 | .find_mid = smb2_find_mid, |
| 5475 | .check_message = smb2_check_message, |
| 5476 | .dump_detail = smb2_dump_detail, |
Pavel Shilovsky | d60622e | 2012-05-28 15:19:39 +0400 | [diff] [blame] | 5477 | .clear_stats = smb2_clear_stats, |
| 5478 | .print_stats = smb2_print_stats, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 5479 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 5480 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 5481 | .downgrade_oplock = smb2_downgrade_oplock, |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 5482 | .need_neg = smb2_need_neg, |
| 5483 | .negotiate = smb2_negotiate, |
Pavel Shilovsky | 3a3bab5 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 5484 | .negotiate_wsize = smb2_negotiate_wsize, |
| 5485 | .negotiate_rsize = smb2_negotiate_rsize, |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame] | 5486 | .sess_setup = SMB2_sess_setup, |
| 5487 | .logoff = SMB2_logoff, |
Pavel Shilovsky | faaf946 | 2011-12-27 16:04:00 +0400 | [diff] [blame] | 5488 | .tree_connect = SMB2_tcon, |
| 5489 | .tree_disconnect = SMB2_tdis, |
Steve French | 34f6264 | 2013-10-09 02:07:00 -0500 | [diff] [blame] | 5490 | .qfs_tcon = smb2_qfs_tcon, |
Pavel Shilovsky | 2503a0d | 2011-12-26 22:58:46 +0400 | [diff] [blame] | 5491 | .is_path_accessible = smb2_is_path_accessible, |
Pavel Shilovsky | 9094fad | 2012-07-12 18:30:44 +0400 | [diff] [blame] | 5492 | .can_echo = smb2_can_echo, |
| 5493 | .echo = SMB2_echo, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 5494 | .query_path_info = smb2_query_path_info, |
| 5495 | .get_srv_inum = smb2_get_srv_inum, |
Pavel Shilovsky | b7546bc | 2012-09-18 16:20:27 -0700 | [diff] [blame] | 5496 | .query_file_info = smb2_query_file_info, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 5497 | .set_path_size = smb2_set_path_size, |
| 5498 | .set_file_size = smb2_set_file_size, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 5499 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 5500 | .set_compression = smb2_set_compression, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 5501 | .mkdir = smb2_mkdir, |
| 5502 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 5503 | .rmdir = smb2_rmdir, |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 5504 | .unlink = smb2_unlink, |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5505 | .rename = smb2_rename_path, |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 5506 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 5507 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 5508 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 5509 | .create_mf_symlink = smb3_create_mf_symlink, |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 5510 | .open = smb2_open_file, |
| 5511 | .set_fid = smb2_set_fid, |
| 5512 | .close = smb2_close_file, |
Pavel Shilovsky | 7a5cfb1 | 2012-09-18 16:20:28 -0700 | [diff] [blame] | 5513 | .flush = smb2_flush_file, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 5514 | .async_readv = smb2_async_readv, |
Pavel Shilovsky | 3331914 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 5515 | .async_writev = smb2_async_writev, |
Pavel Shilovsky | d8e0503 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 5516 | .sync_read = smb2_sync_read, |
Pavel Shilovsky | 009d344 | 2012-09-18 16:20:30 -0700 | [diff] [blame] | 5517 | .sync_write = smb2_sync_write, |
Pavel Shilovsky | d324f08d | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 5518 | .query_dir_first = smb2_query_dir_first, |
| 5519 | .query_dir_next = smb2_query_dir_next, |
| 5520 | .close_dir = smb2_close_dir, |
| 5521 | .calc_smb_size = smb2_calc_size, |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 5522 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 5523 | .is_session_expired = smb2_is_session_expired, |
Pavel Shilovsky | 983c88a | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 5524 | .oplock_response = smb2_oplock_response, |
Pavel Shilovsky | 6fc05c2 | 2012-09-18 16:20:34 -0700 | [diff] [blame] | 5525 | .queryfs = smb2_queryfs, |
Pavel Shilovsky | f7ba7fe | 2012-09-19 06:22:43 -0700 | [diff] [blame] | 5526 | .mand_lock = smb2_mand_lock, |
| 5527 | .mand_unlock_range = smb2_unlock_range, |
Pavel Shilovsky | b140799 | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 5528 | .push_mand_locks = smb2_push_mandatory_locks, |
Pavel Shilovsky | b8c32db | 2012-09-19 06:22:44 -0700 | [diff] [blame] | 5529 | .get_lease_key = smb2_get_lease_key, |
| 5530 | .set_lease_key = smb2_set_lease_key, |
| 5531 | .new_lease_key = smb2_new_lease_key, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5532 | .calc_signature = smb2_calc_signature, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5533 | .is_read_op = smb21_is_read_op, |
| 5534 | .set_oplock_level = smb21_set_oplock_level, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 5535 | .create_lease_buf = smb2_create_lease_buf, |
Pavel Shilovsky | b5c7cde | 2013-09-05 20:16:45 +0400 | [diff] [blame] | 5536 | .parse_lease_buf = smb2_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 5537 | .copychunk_range = smb2_copychunk_range, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 5538 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 5539 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 5540 | .enum_snapshots = smb3_enum_snapshots, |
Steve French | 2c6251a | 2020-02-12 22:37:08 -0600 | [diff] [blame] | 5541 | .notify = smb3_notify, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 5542 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 5543 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5544 | #ifdef CONFIG_CIFS_XATTR |
| 5545 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 5546 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5547 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 5548 | .get_acl = get_smb2_acl, |
| 5549 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 5550 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5551 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 5552 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5553 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 5554 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 5555 | .llseek = smb3_llseek, |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 5556 | .is_status_io_timeout = smb2_is_status_io_timeout, |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 5557 | .is_network_name_deleted = smb2_is_network_name_deleted, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5558 | }; |
| 5559 | |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5560 | struct smb_version_operations smb30_operations = { |
| 5561 | .compare_fids = smb2_compare_fids, |
| 5562 | .setup_request = smb2_setup_request, |
| 5563 | .setup_async_request = smb2_setup_async_request, |
| 5564 | .check_receive = smb2_check_receive, |
| 5565 | .add_credits = smb2_add_credits, |
| 5566 | .set_credits = smb2_set_credits, |
| 5567 | .get_credits_field = smb2_get_credits_field, |
| 5568 | .get_credits = smb2_get_credits, |
Pavel Shilovsky | cb7e9ea | 2014-06-05 19:03:27 +0400 | [diff] [blame] | 5569 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 5570 | .adjust_credits = smb2_adjust_credits, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5571 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 5572 | .revert_current_mid = smb2_revert_current_mid, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5573 | .read_data_offset = smb2_read_data_offset, |
| 5574 | .read_data_length = smb2_read_data_length, |
| 5575 | .map_error = map_smb2_to_linux_error, |
| 5576 | .find_mid = smb2_find_mid, |
| 5577 | .check_message = smb2_check_message, |
| 5578 | .dump_detail = smb2_dump_detail, |
| 5579 | .clear_stats = smb2_clear_stats, |
| 5580 | .print_stats = smb2_print_stats, |
Steve French | 769ee6a | 2013-06-19 14:15:30 -0500 | [diff] [blame] | 5581 | .dump_share_caps = smb2_dump_share_caps, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5582 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 5583 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 5584 | .downgrade_oplock = smb3_downgrade_oplock, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5585 | .need_neg = smb2_need_neg, |
| 5586 | .negotiate = smb2_negotiate, |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 5587 | .negotiate_wsize = smb3_negotiate_wsize, |
| 5588 | .negotiate_rsize = smb3_negotiate_rsize, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5589 | .sess_setup = SMB2_sess_setup, |
| 5590 | .logoff = SMB2_logoff, |
| 5591 | .tree_connect = SMB2_tcon, |
| 5592 | .tree_disconnect = SMB2_tdis, |
Steven French | af6a12e | 2013-10-09 20:55:53 -0500 | [diff] [blame] | 5593 | .qfs_tcon = smb3_qfs_tcon, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5594 | .is_path_accessible = smb2_is_path_accessible, |
| 5595 | .can_echo = smb2_can_echo, |
| 5596 | .echo = SMB2_echo, |
| 5597 | .query_path_info = smb2_query_path_info, |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 5598 | /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */ |
| 5599 | .query_reparse_tag = smb2_query_reparse_tag, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5600 | .get_srv_inum = smb2_get_srv_inum, |
| 5601 | .query_file_info = smb2_query_file_info, |
| 5602 | .set_path_size = smb2_set_path_size, |
| 5603 | .set_file_size = smb2_set_file_size, |
| 5604 | .set_file_info = smb2_set_file_info, |
Steve French | 64a5cfa | 2013-10-14 15:31:32 -0500 | [diff] [blame] | 5605 | .set_compression = smb2_set_compression, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5606 | .mkdir = smb2_mkdir, |
| 5607 | .mkdir_setinfo = smb2_mkdir_setinfo, |
| 5608 | .rmdir = smb2_rmdir, |
| 5609 | .unlink = smb2_unlink, |
| 5610 | .rename = smb2_rename_path, |
| 5611 | .create_hardlink = smb2_create_hardlink, |
Pavel Shilovsky | b42bf88 | 2013-08-14 19:25:21 +0400 | [diff] [blame] | 5612 | .query_symlink = smb2_query_symlink, |
Steve French | c22870e | 2014-09-16 07:18:19 -0500 | [diff] [blame] | 5613 | .query_mf_symlink = smb3_query_mf_symlink, |
Steve French | 5ab9757 | 2014-09-15 04:49:28 -0500 | [diff] [blame] | 5614 | .create_mf_symlink = smb3_create_mf_symlink, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5615 | .open = smb2_open_file, |
| 5616 | .set_fid = smb2_set_fid, |
| 5617 | .close = smb2_close_file, |
Steve French | 43f8a6a | 2019-12-02 21:46:54 -0600 | [diff] [blame] | 5618 | .close_getattr = smb2_close_getattr, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5619 | .flush = smb2_flush_file, |
| 5620 | .async_readv = smb2_async_readv, |
| 5621 | .async_writev = smb2_async_writev, |
| 5622 | .sync_read = smb2_sync_read, |
| 5623 | .sync_write = smb2_sync_write, |
| 5624 | .query_dir_first = smb2_query_dir_first, |
| 5625 | .query_dir_next = smb2_query_dir_next, |
| 5626 | .close_dir = smb2_close_dir, |
| 5627 | .calc_smb_size = smb2_calc_size, |
| 5628 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 5629 | .is_session_expired = smb2_is_session_expired, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5630 | .oplock_response = smb2_oplock_response, |
| 5631 | .queryfs = smb2_queryfs, |
| 5632 | .mand_lock = smb2_mand_lock, |
| 5633 | .mand_unlock_range = smb2_unlock_range, |
| 5634 | .push_mand_locks = smb2_push_mandatory_locks, |
| 5635 | .get_lease_key = smb2_get_lease_key, |
| 5636 | .set_lease_key = smb2_set_lease_key, |
| 5637 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 5638 | .generate_signingkey = generate_smb30signingkey, |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 5639 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 5640 | .set_integrity = smb3_set_integrity, |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 5641 | .is_read_op = smb21_is_read_op, |
Pavel Shilovsky | 42873b0 | 2013-09-05 21:30:16 +0400 | [diff] [blame] | 5642 | .set_oplock_level = smb3_set_oplock_level, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 5643 | .create_lease_buf = smb3_create_lease_buf, |
| 5644 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 5645 | .copychunk_range = smb2_copychunk_range, |
Steve French | ca9e7a1 | 2015-10-01 21:40:10 -0500 | [diff] [blame] | 5646 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | ff1c038 | 2013-11-19 23:44:46 -0600 | [diff] [blame] | 5647 | .validate_negotiate = smb3_validate_negotiate, |
Pavel Shilovsky | 7f6c500 | 2014-06-22 11:03:22 +0400 | [diff] [blame] | 5648 | .wp_retry_size = smb2_wp_retry_size, |
Pavel Shilovsky | 5275580 | 2014-08-18 20:49:57 +0400 | [diff] [blame] | 5649 | .dir_needs_close = smb2_dir_needs_close, |
Steve French | 31742c5 | 2014-08-17 08:38:47 -0500 | [diff] [blame] | 5650 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 5651 | .enum_snapshots = smb3_enum_snapshots, |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 5652 | .notify = smb3_notify, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 5653 | .init_transform_rq = smb3_init_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5654 | .is_transform_hdr = smb3_is_transform_hdr, |
| 5655 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 5656 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 5657 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5658 | #ifdef CONFIG_CIFS_XATTR |
| 5659 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 5660 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5661 | #endif /* CIFS_XATTR */ |
Shirish Pargaonkar | 2f1afe2 | 2017-06-22 22:52:05 -0500 | [diff] [blame] | 5662 | .get_acl = get_smb2_acl, |
| 5663 | .get_acl_by_fid = get_smb2_acl_by_fid, |
Shirish Pargaonkar | 366ed84 | 2017-06-28 22:37:32 -0500 | [diff] [blame] | 5664 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5665 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 5666 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5667 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 5668 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 5669 | .llseek = smb3_llseek, |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 5670 | .is_status_io_timeout = smb2_is_status_io_timeout, |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 5671 | .is_network_name_deleted = smb2_is_network_name_deleted, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 5672 | }; |
| 5673 | |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5674 | struct smb_version_operations smb311_operations = { |
| 5675 | .compare_fids = smb2_compare_fids, |
| 5676 | .setup_request = smb2_setup_request, |
| 5677 | .setup_async_request = smb2_setup_async_request, |
| 5678 | .check_receive = smb2_check_receive, |
| 5679 | .add_credits = smb2_add_credits, |
| 5680 | .set_credits = smb2_set_credits, |
| 5681 | .get_credits_field = smb2_get_credits_field, |
| 5682 | .get_credits = smb2_get_credits, |
| 5683 | .wait_mtu_credits = smb2_wait_mtu_credits, |
Pavel Shilovsky | 9a1c67e | 2019-01-23 18:15:52 -0800 | [diff] [blame] | 5684 | .adjust_credits = smb2_adjust_credits, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5685 | .get_next_mid = smb2_get_next_mid, |
Pavel Shilovsky | c781af7 | 2019-03-04 14:02:50 -0800 | [diff] [blame] | 5686 | .revert_current_mid = smb2_revert_current_mid, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5687 | .read_data_offset = smb2_read_data_offset, |
| 5688 | .read_data_length = smb2_read_data_length, |
| 5689 | .map_error = map_smb2_to_linux_error, |
| 5690 | .find_mid = smb2_find_mid, |
| 5691 | .check_message = smb2_check_message, |
| 5692 | .dump_detail = smb2_dump_detail, |
| 5693 | .clear_stats = smb2_clear_stats, |
| 5694 | .print_stats = smb2_print_stats, |
| 5695 | .dump_share_caps = smb2_dump_share_caps, |
| 5696 | .is_oplock_break = smb2_is_valid_oplock_break, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 5697 | .handle_cancelled_mid = smb2_handle_cancelled_mid, |
Pavel Shilovsky | 9bd4540 | 2019-10-29 16:51:19 -0700 | [diff] [blame] | 5698 | .downgrade_oplock = smb3_downgrade_oplock, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5699 | .need_neg = smb2_need_neg, |
| 5700 | .negotiate = smb2_negotiate, |
Steve French | 3d62123 | 2018-09-25 15:33:47 -0500 | [diff] [blame] | 5701 | .negotiate_wsize = smb3_negotiate_wsize, |
| 5702 | .negotiate_rsize = smb3_negotiate_rsize, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5703 | .sess_setup = SMB2_sess_setup, |
| 5704 | .logoff = SMB2_logoff, |
| 5705 | .tree_connect = SMB2_tcon, |
| 5706 | .tree_disconnect = SMB2_tdis, |
| 5707 | .qfs_tcon = smb3_qfs_tcon, |
| 5708 | .is_path_accessible = smb2_is_path_accessible, |
| 5709 | .can_echo = smb2_can_echo, |
| 5710 | .echo = SMB2_echo, |
| 5711 | .query_path_info = smb2_query_path_info, |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 5712 | .query_reparse_tag = smb2_query_reparse_tag, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5713 | .get_srv_inum = smb2_get_srv_inum, |
| 5714 | .query_file_info = smb2_query_file_info, |
| 5715 | .set_path_size = smb2_set_path_size, |
| 5716 | .set_file_size = smb2_set_file_size, |
| 5717 | .set_file_info = smb2_set_file_info, |
| 5718 | .set_compression = smb2_set_compression, |
| 5719 | .mkdir = smb2_mkdir, |
| 5720 | .mkdir_setinfo = smb2_mkdir_setinfo, |
Steve French | bea851b | 2018-06-14 21:56:32 -0500 | [diff] [blame] | 5721 | .posix_mkdir = smb311_posix_mkdir, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5722 | .rmdir = smb2_rmdir, |
| 5723 | .unlink = smb2_unlink, |
| 5724 | .rename = smb2_rename_path, |
| 5725 | .create_hardlink = smb2_create_hardlink, |
| 5726 | .query_symlink = smb2_query_symlink, |
| 5727 | .query_mf_symlink = smb3_query_mf_symlink, |
| 5728 | .create_mf_symlink = smb3_create_mf_symlink, |
| 5729 | .open = smb2_open_file, |
| 5730 | .set_fid = smb2_set_fid, |
| 5731 | .close = smb2_close_file, |
Steve French | 43f8a6a | 2019-12-02 21:46:54 -0600 | [diff] [blame] | 5732 | .close_getattr = smb2_close_getattr, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5733 | .flush = smb2_flush_file, |
| 5734 | .async_readv = smb2_async_readv, |
| 5735 | .async_writev = smb2_async_writev, |
| 5736 | .sync_read = smb2_sync_read, |
| 5737 | .sync_write = smb2_sync_write, |
| 5738 | .query_dir_first = smb2_query_dir_first, |
| 5739 | .query_dir_next = smb2_query_dir_next, |
| 5740 | .close_dir = smb2_close_dir, |
| 5741 | .calc_smb_size = smb2_calc_size, |
| 5742 | .is_status_pending = smb2_is_status_pending, |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 5743 | .is_session_expired = smb2_is_session_expired, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5744 | .oplock_response = smb2_oplock_response, |
Steve French | 2d30421 | 2018-06-24 23:28:12 -0500 | [diff] [blame] | 5745 | .queryfs = smb311_queryfs, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5746 | .mand_lock = smb2_mand_lock, |
| 5747 | .mand_unlock_range = smb2_unlock_range, |
| 5748 | .push_mand_locks = smb2_push_mandatory_locks, |
| 5749 | .get_lease_key = smb2_get_lease_key, |
| 5750 | .set_lease_key = smb2_set_lease_key, |
| 5751 | .new_lease_key = smb2_new_lease_key, |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 5752 | .generate_signingkey = generate_smb311signingkey, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5753 | .calc_signature = smb3_calc_signature, |
Steve French | b3152e2 | 2015-06-24 03:17:02 -0500 | [diff] [blame] | 5754 | .set_integrity = smb3_set_integrity, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5755 | .is_read_op = smb21_is_read_op, |
| 5756 | .set_oplock_level = smb3_set_oplock_level, |
| 5757 | .create_lease_buf = smb3_create_lease_buf, |
| 5758 | .parse_lease_buf = smb3_parse_lease_buf, |
Sachin Prabhu | 312bbc5 | 2017-04-04 02:12:04 -0500 | [diff] [blame] | 5759 | .copychunk_range = smb2_copychunk_range, |
Steve French | 02b1666 | 2015-06-27 21:18:36 -0700 | [diff] [blame] | 5760 | .duplicate_extents = smb2_duplicate_extents, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5761 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 5762 | .wp_retry_size = smb2_wp_retry_size, |
| 5763 | .dir_needs_close = smb2_dir_needs_close, |
| 5764 | .fallocate = smb3_fallocate, |
Steve French | 834170c | 2016-09-30 21:14:26 -0500 | [diff] [blame] | 5765 | .enum_snapshots = smb3_enum_snapshots, |
Steve French | d26c2dd | 2020-02-06 06:00:14 -0600 | [diff] [blame] | 5766 | .notify = smb3_notify, |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 5767 | .init_transform_rq = smb3_init_transform_rq, |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 5768 | .is_transform_hdr = smb3_is_transform_hdr, |
| 5769 | .receive_transform = smb3_receive_transform, |
Aurelien Aptel | 9d49640 | 2017-02-13 16:16:49 +0100 | [diff] [blame] | 5770 | .get_dfs_refer = smb2_get_dfs_refer, |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 5771 | .select_sectype = smb2_select_sectype, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5772 | #ifdef CONFIG_CIFS_XATTR |
| 5773 | .query_all_EAs = smb2_query_eas, |
Ronnie Sahlberg | 5517554 | 2017-08-24 11:24:56 +1000 | [diff] [blame] | 5774 | .set_EA = smb2_set_ea, |
Ronnie Sahlberg | 95907fe | 2017-08-24 11:24:55 +1000 | [diff] [blame] | 5775 | #endif /* CIFS_XATTR */ |
Ronnie Sahlberg | c1777df | 2018-08-10 11:03:55 +1000 | [diff] [blame] | 5776 | .get_acl = get_smb2_acl, |
| 5777 | .get_acl_by_fid = get_smb2_acl_by_fid, |
| 5778 | .set_acl = set_smb2_acl, |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 5779 | .next_header = smb2_next_header, |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 5780 | .ioctl_query_info = smb2_ioctl_query_info, |
Aurelien Aptel | c847dcc | 2019-03-14 00:29:17 -0500 | [diff] [blame] | 5781 | .make_node = smb2_make_node, |
Ronnie Sahlberg | 2f3ebab | 2019-04-25 16:45:29 +1000 | [diff] [blame] | 5782 | .fiemap = smb3_fiemap, |
Ronnie Sahlberg | dece44e | 2019-05-15 07:17:02 +1000 | [diff] [blame] | 5783 | .llseek = smb3_llseek, |
Rohith Surabattula | 8e670f7 | 2020-09-18 05:37:28 +0000 | [diff] [blame] | 5784 | .is_status_io_timeout = smb2_is_status_io_timeout, |
Rohith Surabattula | 9e550b0 | 2021-02-16 10:40:45 +0000 | [diff] [blame] | 5785 | .is_network_name_deleted = smb2_is_network_name_deleted, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5786 | }; |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 5787 | |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 5788 | struct smb_version_values smb20_values = { |
| 5789 | .version_string = SMB20_VERSION_STRING, |
| 5790 | .protocol_id = SMB20_PROT_ID, |
| 5791 | .req_capabilities = 0, /* MBZ */ |
| 5792 | .large_lock_type = 0, |
| 5793 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5794 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5795 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5796 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5797 | .header_preamble_size = 0, |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 5798 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5799 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5800 | .lock_cmd = SMB2_LOCK, |
| 5801 | .cap_unix = 0, |
| 5802 | .cap_nt_find = SMB2_NT_FIND, |
| 5803 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 5804 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5805 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 5806 | .create_lease_size = sizeof(struct create_lease), |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 5807 | }; |
| 5808 | |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 5809 | struct smb_version_values smb21_values = { |
| 5810 | .version_string = SMB21_VERSION_STRING, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 5811 | .protocol_id = SMB21_PROT_ID, |
| 5812 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ |
| 5813 | .large_lock_type = 0, |
| 5814 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5815 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5816 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5817 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5818 | .header_preamble_size = 0, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 5819 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5820 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5821 | .lock_cmd = SMB2_LOCK, |
| 5822 | .cap_unix = 0, |
| 5823 | .cap_nt_find = SMB2_NT_FIND, |
| 5824 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 5825 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5826 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | a41a28b | 2013-09-04 13:07:41 +0400 | [diff] [blame] | 5827 | .create_lease_size = sizeof(struct create_lease), |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 5828 | }; |
| 5829 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 5830 | struct smb_version_values smb3any_values = { |
| 5831 | .version_string = SMB3ANY_VERSION_STRING, |
| 5832 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 5833 | .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] | 5834 | .large_lock_type = 0, |
| 5835 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5836 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5837 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5838 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5839 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 5840 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5841 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5842 | .lock_cmd = SMB2_LOCK, |
| 5843 | .cap_unix = 0, |
| 5844 | .cap_nt_find = SMB2_NT_FIND, |
| 5845 | .cap_large_files = SMB2_LARGE_FILES, |
| 5846 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5847 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5848 | .create_lease_size = sizeof(struct create_lease_v2), |
| 5849 | }; |
| 5850 | |
| 5851 | struct smb_version_values smbdefault_values = { |
| 5852 | .version_string = SMBDEFAULT_VERSION_STRING, |
| 5853 | .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */ |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 5854 | .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] | 5855 | .large_lock_type = 0, |
| 5856 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5857 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5858 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5859 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5860 | .header_preamble_size = 0, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 5861 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5862 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5863 | .lock_cmd = SMB2_LOCK, |
| 5864 | .cap_unix = 0, |
| 5865 | .cap_nt_find = SMB2_NT_FIND, |
| 5866 | .cap_large_files = SMB2_LARGE_FILES, |
| 5867 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5868 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5869 | .create_lease_size = sizeof(struct create_lease_v2), |
| 5870 | }; |
| 5871 | |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 5872 | struct smb_version_values smb30_values = { |
| 5873 | .version_string = SMB30_VERSION_STRING, |
| 5874 | .protocol_id = SMB30_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 5875 | .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] | 5876 | .large_lock_type = 0, |
| 5877 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5878 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5879 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5880 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5881 | .header_preamble_size = 0, |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 5882 | .max_header_size = MAX_SMB2_HDR_SIZE, |
Pavel Shilovsky | 09a4707 | 2012-09-18 16:20:29 -0700 | [diff] [blame] | 5883 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 5884 | .lock_cmd = SMB2_LOCK, |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 5885 | .cap_unix = 0, |
| 5886 | .cap_nt_find = SMB2_NT_FIND, |
| 5887 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 5888 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5889 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 5890 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 5891 | }; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 5892 | |
| 5893 | struct smb_version_values smb302_values = { |
| 5894 | .version_string = SMB302_VERSION_STRING, |
| 5895 | .protocol_id = SMB302_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 5896 | .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] | 5897 | .large_lock_type = 0, |
| 5898 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5899 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5900 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5901 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5902 | .header_preamble_size = 0, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 5903 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5904 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5905 | .lock_cmd = SMB2_LOCK, |
| 5906 | .cap_unix = 0, |
| 5907 | .cap_nt_find = SMB2_NT_FIND, |
| 5908 | .cap_large_files = SMB2_LARGE_FILES, |
Jeff Layton | 50285882 | 2013-06-27 12:45:00 -0400 | [diff] [blame] | 5909 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5910 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
Pavel Shilovsky | f047390 | 2013-09-04 13:44:05 +0400 | [diff] [blame] | 5911 | .create_lease_size = sizeof(struct create_lease_v2), |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 5912 | }; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 5913 | |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 5914 | struct smb_version_values smb311_values = { |
| 5915 | .version_string = SMB311_VERSION_STRING, |
| 5916 | .protocol_id = SMB311_PROT_ID, |
Steve French | f801568 | 2018-08-31 15:12:10 -0500 | [diff] [blame] | 5917 | .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] | 5918 | .large_lock_type = 0, |
| 5919 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, |
| 5920 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, |
| 5921 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 5922 | .header_size = sizeof(struct smb2_hdr), |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 5923 | .header_preamble_size = 0, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 5924 | .max_header_size = MAX_SMB2_HDR_SIZE, |
| 5925 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, |
| 5926 | .lock_cmd = SMB2_LOCK, |
| 5927 | .cap_unix = 0, |
| 5928 | .cap_nt_find = SMB2_NT_FIND, |
| 5929 | .cap_large_files = SMB2_LARGE_FILES, |
| 5930 | .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5931 | .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED, |
| 5932 | .create_lease_size = sizeof(struct create_lease_v2), |
| 5933 | }; |