Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/connect.c |
| 3 | * |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2011 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Lesser General Public License as published |
| 9 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 15 | * the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this library; if not, write to the Free Software |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/net.h> |
| 23 | #include <linux/string.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 24 | #include <linux/sched/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/list.h> |
| 26 | #include <linux/wait.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/pagemap.h> |
| 29 | #include <linux/ctype.h> |
| 30 | #include <linux/utsname.h> |
| 31 | #include <linux/mempool.h> |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 32 | #include <linux/delay.h> |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 33 | #include <linux/completion.h> |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 34 | #include <linux/kthread.h> |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 35 | #include <linux/pagevec.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 36 | #include <linux/freezer.h> |
Igor Mammedov | 5c2503a | 2009-04-21 19:31:05 +0400 | [diff] [blame] | 37 | #include <linux/namei.h> |
Andrew Lunn | c6e970a | 2017-03-28 23:45:06 +0200 | [diff] [blame] | 38 | #include <linux/uuid.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 39 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/processor.h> |
Jeff Layton | 50b64e3 | 2009-06-02 06:55:20 -0400 | [diff] [blame] | 41 | #include <linux/inet.h> |
Paul Gortmaker | 143cb49 | 2011-07-01 14:23:34 -0400 | [diff] [blame] | 42 | #include <linux/module.h> |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 43 | #include <keys/user-type.h> |
Steve French | 0e2beda | 2009-01-30 21:24:41 +0000 | [diff] [blame] | 44 | #include <net/ipv6.h> |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 45 | #include <linux/parser.h> |
Christoph Hellwig | 2f8b544 | 2016-11-01 07:40:13 -0600 | [diff] [blame] | 46 | #include <linux/bvec.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include "cifspdu.h" |
| 48 | #include "cifsglob.h" |
| 49 | #include "cifsproto.h" |
| 50 | #include "cifs_unicode.h" |
| 51 | #include "cifs_debug.h" |
| 52 | #include "cifs_fs_sb.h" |
| 53 | #include "ntlmssp.h" |
| 54 | #include "nterr.h" |
| 55 | #include "rfc1002pdu.h" |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 56 | #include "fscache.h" |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 57 | #include "smb2proto.h" |
Long Li | 2f89464 | 2017-11-22 17:38:34 -0700 | [diff] [blame] | 58 | #include "smbdirect.h" |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 59 | #include "dns_resolve.h" |
| 60 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 61 | #include "dfs_cache.h" |
| 62 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | extern mempool_t *cifs_req_poolp; |
Steve French | f92a720 | 2018-05-24 04:11:07 -0500 | [diff] [blame] | 65 | extern bool disable_legacy_dialects; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 67 | /* FIXME: should these be tunable? */ |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 68 | #define TLINK_ERROR_EXPIRE (1 * HZ) |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 69 | #define TLINK_IDLE_EXPIRE (600 * HZ) |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 70 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 71 | enum { |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 72 | /* Mount options that take no arguments */ |
| 73 | Opt_user_xattr, Opt_nouser_xattr, |
| 74 | Opt_forceuid, Opt_noforceuid, |
Jeff Layton | 72bd481 | 2012-10-03 16:02:36 -0400 | [diff] [blame] | 75 | Opt_forcegid, Opt_noforcegid, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 76 | Opt_noblocksend, Opt_noautotune, |
| 77 | Opt_hard, Opt_soft, Opt_perm, Opt_noperm, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 78 | Opt_mapposix, Opt_nomapposix, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 79 | Opt_mapchars, Opt_nomapchars, Opt_sfu, |
| 80 | Opt_nosfu, Opt_nodfs, Opt_posixpaths, |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 81 | Opt_noposixpaths, Opt_nounix, Opt_unix, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 82 | Opt_nocase, |
| 83 | Opt_brl, Opt_nobrl, |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 84 | Opt_handlecache, Opt_nohandlecache, |
Steve French | 9593265 | 2016-09-23 01:36:34 -0500 | [diff] [blame] | 85 | Opt_forcemandatorylock, Opt_setuidfromacl, Opt_setuids, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 86 | Opt_nosetuids, Opt_dynperm, Opt_nodynperm, |
| 87 | Opt_nohard, Opt_nosoft, |
| 88 | Opt_nointr, Opt_intr, |
| 89 | Opt_nostrictsync, Opt_strictsync, |
| 90 | Opt_serverino, Opt_noserverino, |
| 91 | Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl, |
| 92 | Opt_acl, Opt_noacl, Opt_locallease, |
Jeff Layton | 1b35920 | 2012-09-19 15:20:27 -0700 | [diff] [blame] | 93 | Opt_sign, Opt_seal, Opt_noac, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 94 | Opt_fsc, Opt_mfsymlinks, |
Jeff Layton | a0b3df5 | 2013-05-24 07:40:59 -0400 | [diff] [blame] | 95 | Opt_multiuser, Opt_sloppy, Opt_nosharesock, |
Steve French | b2a3077 | 2015-09-29 21:49:28 -0500 | [diff] [blame] | 96 | Opt_persistent, Opt_nopersistent, |
Steve French | 592fafe | 2015-11-03 10:08:53 -0600 | [diff] [blame] | 97 | Opt_resilient, Opt_noresilient, |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 98 | Opt_domainauto, Opt_rdma, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 99 | |
| 100 | /* Mount options which take numeric value */ |
| 101 | Opt_backupuid, Opt_backupgid, Opt_uid, |
| 102 | Opt_cruid, Opt_gid, Opt_file_mode, |
| 103 | Opt_dirmode, Opt_port, |
| 104 | Opt_rsize, Opt_wsize, Opt_actimeo, |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 105 | Opt_echo_interval, Opt_max_credits, |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 106 | Opt_snapshot, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 107 | |
| 108 | /* Mount options which take string value */ |
| 109 | Opt_user, Opt_pass, Opt_ip, |
Jeff Layton | 73a999f | 2013-03-22 08:42:57 -0400 | [diff] [blame] | 110 | Opt_domain, Opt_srcaddr, Opt_iocharset, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 111 | Opt_netbiosname, Opt_servern, |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 112 | Opt_ver, Opt_vers, Opt_sec, Opt_cache, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 113 | |
| 114 | /* Mount options to be ignored */ |
| 115 | Opt_ignore, |
| 116 | |
| 117 | /* Options which could be blank */ |
| 118 | Opt_blank_pass, |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 119 | Opt_blank_user, |
| 120 | Opt_blank_ip, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 121 | |
| 122 | Opt_err |
| 123 | }; |
| 124 | |
| 125 | static const match_table_t cifs_mount_option_tokens = { |
| 126 | |
| 127 | { Opt_user_xattr, "user_xattr" }, |
| 128 | { Opt_nouser_xattr, "nouser_xattr" }, |
| 129 | { Opt_forceuid, "forceuid" }, |
| 130 | { Opt_noforceuid, "noforceuid" }, |
Jeff Layton | 72bd481 | 2012-10-03 16:02:36 -0400 | [diff] [blame] | 131 | { Opt_forcegid, "forcegid" }, |
| 132 | { Opt_noforcegid, "noforcegid" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 133 | { Opt_noblocksend, "noblocksend" }, |
| 134 | { Opt_noautotune, "noautotune" }, |
| 135 | { Opt_hard, "hard" }, |
| 136 | { Opt_soft, "soft" }, |
| 137 | { Opt_perm, "perm" }, |
| 138 | { Opt_noperm, "noperm" }, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 139 | { Opt_mapchars, "mapchars" }, /* SFU style */ |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 140 | { Opt_nomapchars, "nomapchars" }, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 141 | { Opt_mapposix, "mapposix" }, /* SFM style */ |
| 142 | { Opt_nomapposix, "nomapposix" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 143 | { Opt_sfu, "sfu" }, |
| 144 | { Opt_nosfu, "nosfu" }, |
| 145 | { Opt_nodfs, "nodfs" }, |
| 146 | { Opt_posixpaths, "posixpaths" }, |
| 147 | { Opt_noposixpaths, "noposixpaths" }, |
| 148 | { Opt_nounix, "nounix" }, |
| 149 | { Opt_nounix, "nolinux" }, |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 150 | { Opt_nounix, "noposix" }, |
| 151 | { Opt_unix, "unix" }, |
| 152 | { Opt_unix, "linux" }, |
| 153 | { Opt_unix, "posix" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 154 | { Opt_nocase, "nocase" }, |
| 155 | { Opt_nocase, "ignorecase" }, |
| 156 | { Opt_brl, "brl" }, |
| 157 | { Opt_nobrl, "nobrl" }, |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 158 | { Opt_handlecache, "handlecache" }, |
| 159 | { Opt_nohandlecache, "nohandlecache" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 160 | { Opt_nobrl, "nolock" }, |
| 161 | { Opt_forcemandatorylock, "forcemandatorylock" }, |
Pavel Shilovsky | 5cfdddc | 2012-03-27 20:51:15 +0400 | [diff] [blame] | 162 | { Opt_forcemandatorylock, "forcemand" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 163 | { Opt_setuids, "setuids" }, |
| 164 | { Opt_nosetuids, "nosetuids" }, |
Steve French | 9593265 | 2016-09-23 01:36:34 -0500 | [diff] [blame] | 165 | { Opt_setuidfromacl, "idsfromsid" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 166 | { Opt_dynperm, "dynperm" }, |
| 167 | { Opt_nodynperm, "nodynperm" }, |
| 168 | { Opt_nohard, "nohard" }, |
| 169 | { Opt_nosoft, "nosoft" }, |
| 170 | { Opt_nointr, "nointr" }, |
| 171 | { Opt_intr, "intr" }, |
| 172 | { Opt_nostrictsync, "nostrictsync" }, |
| 173 | { Opt_strictsync, "strictsync" }, |
| 174 | { Opt_serverino, "serverino" }, |
| 175 | { Opt_noserverino, "noserverino" }, |
| 176 | { Opt_rwpidforward, "rwpidforward" }, |
| 177 | { Opt_cifsacl, "cifsacl" }, |
| 178 | { Opt_nocifsacl, "nocifsacl" }, |
| 179 | { Opt_acl, "acl" }, |
| 180 | { Opt_noacl, "noacl" }, |
| 181 | { Opt_locallease, "locallease" }, |
| 182 | { Opt_sign, "sign" }, |
| 183 | { Opt_seal, "seal" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 184 | { Opt_noac, "noac" }, |
| 185 | { Opt_fsc, "fsc" }, |
| 186 | { Opt_mfsymlinks, "mfsymlinks" }, |
| 187 | { Opt_multiuser, "multiuser" }, |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 188 | { Opt_sloppy, "sloppy" }, |
Jeff Layton | a0b3df5 | 2013-05-24 07:40:59 -0400 | [diff] [blame] | 189 | { Opt_nosharesock, "nosharesock" }, |
Steve French | b2a3077 | 2015-09-29 21:49:28 -0500 | [diff] [blame] | 190 | { Opt_persistent, "persistenthandles"}, |
| 191 | { Opt_nopersistent, "nopersistenthandles"}, |
Steve French | 592fafe | 2015-11-03 10:08:53 -0600 | [diff] [blame] | 192 | { Opt_resilient, "resilienthandles"}, |
| 193 | { Opt_noresilient, "noresilienthandles"}, |
Germano Percossi | 3956644 | 2016-12-15 12:31:18 +0530 | [diff] [blame] | 194 | { Opt_domainauto, "domainauto"}, |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 195 | { Opt_rdma, "rdma"}, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 196 | |
| 197 | { Opt_backupuid, "backupuid=%s" }, |
| 198 | { Opt_backupgid, "backupgid=%s" }, |
| 199 | { Opt_uid, "uid=%s" }, |
| 200 | { Opt_cruid, "cruid=%s" }, |
| 201 | { Opt_gid, "gid=%s" }, |
| 202 | { Opt_file_mode, "file_mode=%s" }, |
| 203 | { Opt_dirmode, "dirmode=%s" }, |
| 204 | { Opt_dirmode, "dir_mode=%s" }, |
| 205 | { Opt_port, "port=%s" }, |
| 206 | { Opt_rsize, "rsize=%s" }, |
| 207 | { Opt_wsize, "wsize=%s" }, |
| 208 | { Opt_actimeo, "actimeo=%s" }, |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 209 | { Opt_echo_interval, "echo_interval=%s" }, |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 210 | { Opt_max_credits, "max_credits=%s" }, |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 211 | { Opt_snapshot, "snapshot=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 212 | |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 213 | { Opt_blank_user, "user=" }, |
| 214 | { Opt_blank_user, "username=" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 215 | { Opt_user, "user=%s" }, |
| 216 | { Opt_user, "username=%s" }, |
| 217 | { Opt_blank_pass, "pass=" }, |
Jesper Nilsson | 3c15b4c | 2012-11-29 17:31:16 +0100 | [diff] [blame] | 218 | { Opt_blank_pass, "password=" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 219 | { Opt_pass, "pass=%s" }, |
| 220 | { Opt_pass, "password=%s" }, |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 221 | { Opt_blank_ip, "ip=" }, |
| 222 | { Opt_blank_ip, "addr=" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 223 | { Opt_ip, "ip=%s" }, |
| 224 | { Opt_ip, "addr=%s" }, |
Jeff Layton | 73a999f | 2013-03-22 08:42:57 -0400 | [diff] [blame] | 225 | { Opt_ignore, "unc=%s" }, |
| 226 | { Opt_ignore, "target=%s" }, |
| 227 | { Opt_ignore, "path=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 228 | { Opt_domain, "dom=%s" }, |
| 229 | { Opt_domain, "domain=%s" }, |
| 230 | { Opt_domain, "workgroup=%s" }, |
| 231 | { Opt_srcaddr, "srcaddr=%s" }, |
Jeff Layton | 73a999f | 2013-03-22 08:42:57 -0400 | [diff] [blame] | 232 | { Opt_ignore, "prefixpath=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 233 | { Opt_iocharset, "iocharset=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 234 | { Opt_netbiosname, "netbiosname=%s" }, |
| 235 | { Opt_servern, "servern=%s" }, |
| 236 | { Opt_ver, "ver=%s" }, |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 237 | { Opt_vers, "vers=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 238 | { Opt_sec, "sec=%s" }, |
Jeff Layton | 15b6a47 | 2012-05-16 07:50:15 -0400 | [diff] [blame] | 239 | { Opt_cache, "cache=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 240 | |
| 241 | { Opt_ignore, "cred" }, |
| 242 | { Opt_ignore, "credentials" }, |
Jeff Layton | a557b97 | 2012-05-02 14:02:40 -0400 | [diff] [blame] | 243 | { Opt_ignore, "cred=%s" }, |
| 244 | { Opt_ignore, "credentials=%s" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 245 | { Opt_ignore, "guest" }, |
| 246 | { Opt_ignore, "rw" }, |
| 247 | { Opt_ignore, "ro" }, |
| 248 | { Opt_ignore, "suid" }, |
| 249 | { Opt_ignore, "nosuid" }, |
| 250 | { Opt_ignore, "exec" }, |
| 251 | { Opt_ignore, "noexec" }, |
| 252 | { Opt_ignore, "nodev" }, |
| 253 | { Opt_ignore, "noauto" }, |
| 254 | { Opt_ignore, "dev" }, |
| 255 | { Opt_ignore, "mand" }, |
| 256 | { Opt_ignore, "nomand" }, |
Steve French | 9b9c5be | 2018-09-22 12:07:06 -0500 | [diff] [blame] | 257 | { Opt_ignore, "relatime" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 258 | { Opt_ignore, "_netdev" }, |
| 259 | |
| 260 | { Opt_err, NULL } |
| 261 | }; |
| 262 | |
| 263 | enum { |
| 264 | Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, |
| 265 | Opt_sec_ntlmsspi, Opt_sec_ntlmssp, |
Jeff Layton | 7659624 | 2012-07-23 20:34:17 -0400 | [diff] [blame] | 266 | Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2, |
| 267 | Opt_sec_ntlmv2i, Opt_sec_lanman, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 268 | Opt_sec_none, |
| 269 | |
| 270 | Opt_sec_err |
| 271 | }; |
| 272 | |
| 273 | static const match_table_t cifs_secflavor_tokens = { |
| 274 | { Opt_sec_krb5, "krb5" }, |
| 275 | { Opt_sec_krb5i, "krb5i" }, |
| 276 | { Opt_sec_krb5p, "krb5p" }, |
| 277 | { Opt_sec_ntlmsspi, "ntlmsspi" }, |
| 278 | { Opt_sec_ntlmssp, "ntlmssp" }, |
| 279 | { Opt_ntlm, "ntlm" }, |
| 280 | { Opt_sec_ntlmi, "ntlmi" }, |
Jeff Layton | 7659624 | 2012-07-23 20:34:17 -0400 | [diff] [blame] | 281 | { Opt_sec_ntlmv2, "nontlm" }, |
| 282 | { Opt_sec_ntlmv2, "ntlmv2" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 283 | { Opt_sec_ntlmv2i, "ntlmv2i" }, |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 284 | { Opt_sec_lanman, "lanman" }, |
| 285 | { Opt_sec_none, "none" }, |
| 286 | |
| 287 | { Opt_sec_err, NULL } |
| 288 | }; |
| 289 | |
Jeff Layton | 15b6a47 | 2012-05-16 07:50:15 -0400 | [diff] [blame] | 290 | /* cache flavors */ |
| 291 | enum { |
| 292 | Opt_cache_loose, |
| 293 | Opt_cache_strict, |
| 294 | Opt_cache_none, |
| 295 | Opt_cache_err |
| 296 | }; |
| 297 | |
| 298 | static const match_table_t cifs_cacheflavor_tokens = { |
| 299 | { Opt_cache_loose, "loose" }, |
| 300 | { Opt_cache_strict, "strict" }, |
| 301 | { Opt_cache_none, "none" }, |
| 302 | { Opt_cache_err, NULL } |
| 303 | }; |
| 304 | |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 305 | static const match_table_t cifs_smb_version_tokens = { |
| 306 | { Smb_1, SMB1_VERSION_STRING }, |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 307 | { Smb_20, SMB20_VERSION_STRING}, |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 308 | { Smb_21, SMB21_VERSION_STRING }, |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 309 | { Smb_30, SMB30_VERSION_STRING }, |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 310 | { Smb_302, SMB302_VERSION_STRING }, |
Kenneth D'souza | 4a3b38a | 2018-11-17 10:33:30 +0530 | [diff] [blame] | 311 | { Smb_302, ALT_SMB302_VERSION_STRING }, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 312 | { Smb_311, SMB311_VERSION_STRING }, |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 313 | { Smb_311, ALT_SMB311_VERSION_STRING }, |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 314 | { Smb_3any, SMB3ANY_VERSION_STRING }, |
| 315 | { Smb_default, SMBDEFAULT_VERSION_STRING }, |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 316 | { Smb_version_err, NULL } |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 317 | }; |
| 318 | |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 319 | static int ip_connect(struct TCP_Server_Info *server); |
| 320 | static int generic_ip_connect(struct TCP_Server_Info *server); |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 321 | static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink); |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 322 | static void cifs_prune_tlinks(struct work_struct *work); |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 323 | static int cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data, |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 324 | const char *devname, bool is_smb3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Jeff Layton | d5c5605 | 2008-12-01 18:42:33 -0500 | [diff] [blame] | 326 | /* |
| 327 | * cifs tcp session reconnection |
| 328 | * |
| 329 | * mark tcp session as reconnecting so temporarily locked |
| 330 | * mark all smb sessions as reconnecting for tcp session |
| 331 | * reconnect tcp session |
| 332 | * wake up waiters on reconnection? - (not needed currently) |
| 333 | */ |
Pavel Shilovsky | 28ea529 | 2012-05-23 16:18:00 +0400 | [diff] [blame] | 334 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | cifs_reconnect(struct TCP_Server_Info *server) |
| 336 | { |
| 337 | int rc = 0; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 338 | struct list_head *tmp, *tmp2; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 339 | struct cifs_ses *ses; |
| 340 | struct cifs_tcon *tcon; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 341 | struct mid_q_entry *mid_entry; |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 342 | struct list_head retry_list; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | spin_lock(&GlobalMid_Lock); |
Jeff Layton | 469ee61 | 2008-10-16 18:46:39 +0000 | [diff] [blame] | 345 | if (server->tcpStatus == CifsExiting) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 346 | /* the demux thread will exit normally |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | next time through the loop */ |
| 348 | spin_unlock(&GlobalMid_Lock); |
| 349 | return rc; |
| 350 | } else |
| 351 | server->tcpStatus = CifsNeedReconnect; |
| 352 | spin_unlock(&GlobalMid_Lock); |
| 353 | server->maxBuf = 0; |
Pavel Shilovsky | aa24d1e | 2011-12-27 16:23:34 +0400 | [diff] [blame] | 354 | server->max_read = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Steve French | 6e4d3bb | 2018-09-22 11:25:04 -0500 | [diff] [blame] | 356 | cifs_dbg(FYI, "Mark tcp session as need reconnect\n"); |
Steve French | bf1fdeb | 2018-07-30 19:23:09 -0500 | [diff] [blame] | 357 | trace_smb3_reconnect(server->CurrentMid, server->hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | /* before reconnecting the tcp session, mark the smb session (uid) |
| 360 | and the tid bad so they are not used until reconnected */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 361 | cifs_dbg(FYI, "%s: marking sessions and tcons for reconnect\n", |
| 362 | __func__); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 363 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 364 | list_for_each(tmp, &server->smb_ses_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 365 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 366 | ses->need_reconnect = true; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 367 | list_for_each(tmp2, &ses->tcon_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 368 | tcon = list_entry(tmp2, struct cifs_tcon, tcon_list); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 369 | tcon->need_reconnect = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 371 | if (ses->tcon_ipc) |
| 372 | ses->tcon_ipc->need_reconnect = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 374 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* do not want to be sending data on a socket we are freeing */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 377 | cifs_dbg(FYI, "%s: tearing down socket\n", __func__); |
Jeff Layton | 72ca545 | 2008-12-01 07:09:36 -0500 | [diff] [blame] | 378 | mutex_lock(&server->srv_mutex); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 379 | if (server->ssocket) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 380 | cifs_dbg(FYI, "State: 0x%x Flags: 0x%lx\n", |
| 381 | server->ssocket->state, server->ssocket->flags); |
Trond Myklebust | 91cf45f | 2007-11-12 18:10:39 -0800 | [diff] [blame] | 382 | kernel_sock_shutdown(server->ssocket, SHUT_WR); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 383 | cifs_dbg(FYI, "Post shutdown state: 0x%x Flags: 0x%lx\n", |
| 384 | server->ssocket->state, server->ssocket->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | sock_release(server->ssocket); |
| 386 | server->ssocket = NULL; |
| 387 | } |
Shirish Pargaonkar | 5d0d288 | 2010-10-13 18:15:00 -0500 | [diff] [blame] | 388 | server->sequence_number = 0; |
| 389 | server->session_estab = false; |
Shirish Pargaonkar | 21e7339 | 2010-10-21 06:42:55 -0500 | [diff] [blame] | 390 | kfree(server->session_key.response); |
| 391 | server->session_key.response = NULL; |
| 392 | server->session_key.len = 0; |
Steve French | fda3594 | 2011-01-20 18:06:34 +0000 | [diff] [blame] | 393 | server->lstrp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 395 | /* mark submitted MIDs for retry and issue callback */ |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 396 | INIT_LIST_HEAD(&retry_list); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 397 | cifs_dbg(FYI, "%s: moving mids to private list\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | spin_lock(&GlobalMid_Lock); |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 399 | list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { |
| 400 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 401 | if (mid_entry->mid_state == MID_REQUEST_SUBMITTED) |
| 402 | mid_entry->mid_state = MID_RETRY_NEEDED; |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 403 | list_move(&mid_entry->qhead, &retry_list); |
| 404 | } |
| 405 | spin_unlock(&GlobalMid_Lock); |
Rabin Vincent | 820962d | 2015-12-23 07:32:41 +0100 | [diff] [blame] | 406 | mutex_unlock(&server->srv_mutex); |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 407 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 408 | cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__); |
Jeff Layton | 3c1105d | 2011-05-22 07:09:13 -0400 | [diff] [blame] | 409 | list_for_each_safe(tmp, tmp2, &retry_list) { |
| 410 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 411 | list_del_init(&mid_entry->qhead); |
| 412 | mid_entry->callback(mid_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Jeff Layton | 7fdbaa1 | 2011-06-10 16:14:57 -0400 | [diff] [blame] | 415 | do { |
Steve French | 6c3d890 | 2006-07-31 22:46:20 +0000 | [diff] [blame] | 416 | try_to_freeze(); |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 417 | |
| 418 | /* we should try only the port we connected to before */ |
Jeff Layton | 73e216a | 2013-09-05 08:38:10 -0400 | [diff] [blame] | 419 | mutex_lock(&server->srv_mutex); |
Long Li | 781a805 | 2017-11-22 17:38:36 -0700 | [diff] [blame] | 420 | if (cifs_rdma_enabled(server)) |
| 421 | rc = smbd_reconnect(server); |
| 422 | else |
| 423 | rc = generic_ip_connect(server); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 424 | if (rc) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 425 | cifs_dbg(FYI, "reconnect error %d\n", rc); |
Federico Sauter | 4afe260 | 2015-03-17 17:45:28 +0100 | [diff] [blame] | 426 | mutex_unlock(&server->srv_mutex); |
Steve French | 0cb766a | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 427 | msleep(3000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } else { |
| 429 | atomic_inc(&tcpSesReconnectCount); |
| 430 | spin_lock(&GlobalMid_Lock); |
Jeff Layton | 469ee61 | 2008-10-16 18:46:39 +0000 | [diff] [blame] | 431 | if (server->tcpStatus != CifsExiting) |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 432 | server->tcpStatus = CifsNeedNegotiate; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 433 | spin_unlock(&GlobalMid_Lock); |
Federico Sauter | 4afe260 | 2015-03-17 17:45:28 +0100 | [diff] [blame] | 434 | mutex_unlock(&server->srv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
Jeff Layton | 7fdbaa1 | 2011-06-10 16:14:57 -0400 | [diff] [blame] | 436 | } while (server->tcpStatus == CifsNeedReconnect); |
Jeff Layton | 2b84a36c | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 437 | |
Sachin Prabhu | b8c6001 | 2016-10-20 19:52:24 -0400 | [diff] [blame] | 438 | if (server->tcpStatus == CifsNeedNegotiate) |
| 439 | mod_delayed_work(cifsiod_wq, &server->echo, 0); |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return rc; |
| 442 | } |
| 443 | |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 444 | static void |
| 445 | cifs_echo_request(struct work_struct *work) |
| 446 | { |
| 447 | int rc; |
| 448 | struct TCP_Server_Info *server = container_of(work, |
| 449 | struct TCP_Server_Info, echo.work); |
Sachin Prabhu | b8c6001 | 2016-10-20 19:52:24 -0400 | [diff] [blame] | 450 | unsigned long echo_interval; |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 451 | |
Jeff Layton | 247ec9b | 2011-02-04 17:09:50 -0500 | [diff] [blame] | 452 | /* |
Sachin Prabhu | b8c6001 | 2016-10-20 19:52:24 -0400 | [diff] [blame] | 453 | * If we need to renegotiate, set echo interval to zero to |
| 454 | * immediately call echo service where we can renegotiate. |
| 455 | */ |
| 456 | if (server->tcpStatus == CifsNeedNegotiate) |
| 457 | echo_interval = 0; |
| 458 | else |
| 459 | echo_interval = server->echo_interval; |
| 460 | |
| 461 | /* |
| 462 | * We cannot send an echo if it is disabled. |
| 463 | * Also, no need to ping if we got a response recently. |
Jeff Layton | 247ec9b | 2011-02-04 17:09:50 -0500 | [diff] [blame] | 464 | */ |
Steve French | 4fcd181 | 2016-06-22 20:12:05 -0500 | [diff] [blame] | 465 | |
| 466 | if (server->tcpStatus == CifsNeedReconnect || |
Sachin Prabhu | b8c6001 | 2016-10-20 19:52:24 -0400 | [diff] [blame] | 467 | server->tcpStatus == CifsExiting || |
| 468 | server->tcpStatus == CifsNew || |
Pavel Shilovsky | f6d7617 | 2012-05-25 14:47:16 +0400 | [diff] [blame] | 469 | (server->ops->can_echo && !server->ops->can_echo(server)) || |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 470 | time_before(jiffies, server->lstrp + echo_interval - HZ)) |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 471 | goto requeue_echo; |
| 472 | |
Pavel Shilovsky | f6d7617 | 2012-05-25 14:47:16 +0400 | [diff] [blame] | 473 | rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS; |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 474 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 475 | cifs_dbg(FYI, "Unable to send echo request to server: %s\n", |
| 476 | server->hostname); |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 477 | |
| 478 | requeue_echo: |
Sachin Prabhu | b8c6001 | 2016-10-20 19:52:24 -0400 | [diff] [blame] | 479 | queue_delayed_work(cifsiod_wq, &server->echo, server->echo_interval); |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 480 | } |
| 481 | |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 482 | static bool |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 483 | allocate_buffers(struct TCP_Server_Info *server) |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 484 | { |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 485 | if (!server->bigbuf) { |
| 486 | server->bigbuf = (char *)cifs_buf_get(); |
| 487 | if (!server->bigbuf) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 488 | cifs_dbg(VFS, "No memory for large SMB response\n"); |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 489 | msleep(3000); |
| 490 | /* retry will check if exiting */ |
| 491 | return false; |
| 492 | } |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 493 | } else if (server->large_buf) { |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 494 | /* we are reusing a dirty large buf, clear its start */ |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 495 | memset(server->bigbuf, 0, HEADER_SIZE(server)); |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 496 | } |
| 497 | |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 498 | if (!server->smallbuf) { |
| 499 | server->smallbuf = (char *)cifs_small_buf_get(); |
| 500 | if (!server->smallbuf) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 501 | cifs_dbg(VFS, "No memory for SMB response\n"); |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 502 | msleep(1000); |
| 503 | /* retry will check if exiting */ |
| 504 | return false; |
| 505 | } |
| 506 | /* beginning of smb buffer is cleared in our buf_get */ |
| 507 | } else { |
| 508 | /* if existing small buf clear beginning */ |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 509 | memset(server->smallbuf, 0, HEADER_SIZE(server)); |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 510 | } |
| 511 | |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 512 | return true; |
| 513 | } |
| 514 | |
Jeff Layton | ba749e6 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 515 | static bool |
| 516 | server_unresponsive(struct TCP_Server_Info *server) |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 517 | { |
Pavel Shilovsky | 6dae51a | 2012-02-21 16:50:23 +0300 | [diff] [blame] | 518 | /* |
| 519 | * We need to wait 2 echo intervals to make sure we handle such |
| 520 | * situations right: |
| 521 | * 1s client sends a normal SMB request |
| 522 | * 2s client gets a response |
| 523 | * 30s echo workqueue job pops, and decides we got a response recently |
| 524 | * and don't need to send another |
| 525 | * ... |
| 526 | * 65s kernel_recvmsg times out, and we see that we haven't gotten |
| 527 | * a response in >60s. |
| 528 | */ |
Samuel Cabrero | 76e7527 | 2017-07-11 12:44:39 +0200 | [diff] [blame] | 529 | if ((server->tcpStatus == CifsGood || |
| 530 | server->tcpStatus == CifsNeedNegotiate) && |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 531 | time_after(jiffies, server->lstrp + 2 * server->echo_interval)) { |
| 532 | cifs_dbg(VFS, "Server %s has not responded in %lu seconds. Reconnecting...\n", |
| 533 | server->hostname, (2 * server->echo_interval) / HZ); |
Jeff Layton | ba749e6 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 534 | cifs_reconnect(server); |
| 535 | wake_up(&server->response_q); |
| 536 | return true; |
| 537 | } |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 538 | |
Jeff Layton | ba749e6 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 539 | return false; |
| 540 | } |
| 541 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 542 | static int |
| 543 | cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg) |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 544 | { |
Jeff Layton | a52c1eb | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 545 | int length = 0; |
| 546 | int total_read; |
Jeff Layton | 42c4dfc | 2011-10-19 15:28:17 -0400 | [diff] [blame] | 547 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 548 | smb_msg->msg_control = NULL; |
| 549 | smb_msg->msg_controllen = 0; |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 550 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 551 | for (total_read = 0; msg_data_left(smb_msg); total_read += length) { |
Jeff Layton | 95edcff | 2011-12-01 20:22:41 -0500 | [diff] [blame] | 552 | try_to_freeze(); |
| 553 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 554 | if (server_unresponsive(server)) |
| 555 | return -ECONNABORTED; |
Long Li | 2fef137 | 2017-11-22 17:38:41 -0700 | [diff] [blame] | 556 | if (cifs_rdma_enabled(server) && server->smbd_conn) |
| 557 | length = smbd_recv(server->smbd_conn, smb_msg); |
| 558 | else |
| 559 | length = sock_recvmsg(server->ssocket, smb_msg, 0); |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 560 | |
| 561 | if (server->tcpStatus == CifsExiting) |
| 562 | return -ESHUTDOWN; |
| 563 | |
| 564 | if (server->tcpStatus == CifsNeedReconnect) { |
| 565 | cifs_reconnect(server); |
| 566 | return -ECONNABORTED; |
Jeff Layton | ba749e6 | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 569 | if (length == -ERESTARTSYS || |
| 570 | length == -EAGAIN || |
| 571 | length == -EINTR) { |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 572 | /* |
| 573 | * Minimum sleep to prevent looping, allowing socket |
| 574 | * to clear and app threads to set tcpStatus |
| 575 | * CifsNeedReconnect if server hung. |
| 576 | */ |
| 577 | usleep_range(1000, 2000); |
| 578 | length = 0; |
Jeff Layton | a52c1eb | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 579 | continue; |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | if (length <= 0) { |
Al Viro | 09aab88 | 2015-11-13 03:00:17 -0500 | [diff] [blame] | 583 | cifs_dbg(FYI, "Received no data or error: %d\n", length); |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 584 | cifs_reconnect(server); |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 585 | return -ECONNABORTED; |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 586 | } |
| 587 | } |
Jeff Layton | a52c1eb | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 588 | return total_read; |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 589 | } |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 590 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 591 | int |
| 592 | cifs_read_from_socket(struct TCP_Server_Info *server, char *buf, |
| 593 | unsigned int to_read) |
Jeff Layton | 42c4dfc | 2011-10-19 15:28:17 -0400 | [diff] [blame] | 594 | { |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 595 | struct msghdr smb_msg; |
| 596 | struct kvec iov = {.iov_base = buf, .iov_len = to_read}; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 597 | iov_iter_kvec(&smb_msg.msg_iter, READ, &iov, 1, to_read); |
Jeff Layton | 42c4dfc | 2011-10-19 15:28:17 -0400 | [diff] [blame] | 598 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 599 | return cifs_readv_from_socket(server, &smb_msg); |
| 600 | } |
Jeff Layton | 42c4dfc | 2011-10-19 15:28:17 -0400 | [diff] [blame] | 601 | |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 602 | int |
| 603 | cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page, |
Long Li | 1dbe346 | 2018-05-30 12:47:55 -0700 | [diff] [blame] | 604 | unsigned int page_offset, unsigned int to_read) |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 605 | { |
| 606 | struct msghdr smb_msg; |
Long Li | 1dbe346 | 2018-05-30 12:47:55 -0700 | [diff] [blame] | 607 | struct bio_vec bv = { |
| 608 | .bv_page = page, .bv_len = to_read, .bv_offset = page_offset}; |
David Howells | aa563d7 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 609 | iov_iter_bvec(&smb_msg.msg_iter, READ, &bv, 1, to_read); |
Al Viro | 7133566 | 2016-01-09 19:54:50 -0500 | [diff] [blame] | 610 | return cifs_readv_from_socket(server, &smb_msg); |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 611 | } |
| 612 | |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 613 | static bool |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 614 | is_smb_response(struct TCP_Server_Info *server, unsigned char type) |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 615 | { |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 616 | /* |
| 617 | * The first byte big endian of the length field, |
| 618 | * is actually not part of the length but the type |
| 619 | * with the most common, zero, as regular data. |
| 620 | */ |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 621 | switch (type) { |
| 622 | case RFC1002_SESSION_MESSAGE: |
| 623 | /* Regular SMB response */ |
| 624 | return true; |
| 625 | case RFC1002_SESSION_KEEP_ALIVE: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 626 | cifs_dbg(FYI, "RFC 1002 session keep alive\n"); |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 627 | break; |
| 628 | case RFC1002_POSITIVE_SESSION_RESPONSE: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 629 | cifs_dbg(FYI, "RFC 1002 positive session response\n"); |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 630 | break; |
| 631 | case RFC1002_NEGATIVE_SESSION_RESPONSE: |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 632 | /* |
| 633 | * We get this from Windows 98 instead of an error on |
| 634 | * SMB negprot response. |
| 635 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 636 | cifs_dbg(FYI, "RFC 1002 negative session response\n"); |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 637 | /* give server a second to clean up */ |
| 638 | msleep(1000); |
| 639 | /* |
| 640 | * Always try 445 first on reconnect since we get NACK |
| 641 | * on some if we ever connected to port 139 (the NACK |
| 642 | * is since we do not begin with RFC1001 session |
| 643 | * initialize frame). |
| 644 | */ |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 645 | cifs_set_port((struct sockaddr *)&server->dstaddr, CIFS_PORT); |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 646 | cifs_reconnect(server); |
| 647 | wake_up(&server->response_q); |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 648 | break; |
| 649 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 650 | cifs_dbg(VFS, "RFC 1002 unknown response type 0x%x\n", type); |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 651 | cifs_reconnect(server); |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 652 | } |
| 653 | |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 654 | return false; |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 655 | } |
| 656 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 657 | void |
| 658 | dequeue_mid(struct mid_q_entry *mid, bool malformed) |
Jeff Layton | ea1f450 | 2011-10-19 15:29:05 -0400 | [diff] [blame] | 659 | { |
| 660 | #ifdef CONFIG_CIFS_STATS2 |
| 661 | mid->when_received = jiffies; |
| 662 | #endif |
| 663 | spin_lock(&GlobalMid_Lock); |
| 664 | if (!malformed) |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 665 | mid->mid_state = MID_RESPONSE_RECEIVED; |
Jeff Layton | ea1f450 | 2011-10-19 15:29:05 -0400 | [diff] [blame] | 666 | else |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 667 | mid->mid_state = MID_RESPONSE_MALFORMED; |
Ronnie Sahlberg | ddf83af | 2018-08-30 10:12:59 +1000 | [diff] [blame] | 668 | /* |
| 669 | * Trying to handle/dequeue a mid after the send_recv() |
| 670 | * function has finished processing it is a bug. |
| 671 | */ |
| 672 | if (mid->mid_flags & MID_DELETED) |
| 673 | printk_once(KERN_WARNING |
| 674 | "trying to dequeue a deleted mid\n"); |
| 675 | else |
| 676 | list_del_init(&mid->qhead); |
Jeff Layton | ea1f450 | 2011-10-19 15:29:05 -0400 | [diff] [blame] | 677 | spin_unlock(&GlobalMid_Lock); |
| 678 | } |
| 679 | |
Jeff Layton | c8054eb | 2011-10-19 15:29:31 -0400 | [diff] [blame] | 680 | static void |
| 681 | handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 682 | char *buf, int malformed) |
Jeff Layton | ea1f450 | 2011-10-19 15:29:05 -0400 | [diff] [blame] | 683 | { |
Pavel Shilovsky | 316cf94 | 2012-05-23 14:31:03 +0400 | [diff] [blame] | 684 | if (server->ops->check_trans2 && |
| 685 | server->ops->check_trans2(mid, server, buf, malformed)) |
Jeff Layton | c8054eb | 2011-10-19 15:29:31 -0400 | [diff] [blame] | 686 | return; |
Jeff Layton | ea1f450 | 2011-10-19 15:29:05 -0400 | [diff] [blame] | 687 | mid->resp_buf = buf; |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 688 | mid->large_buf = server->large_buf; |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 689 | /* Was previous buf put in mpx struct for multi-rsp? */ |
| 690 | if (!mid->multiRsp) { |
| 691 | /* smb buffer will be freed by user thread */ |
| 692 | if (server->large_buf) |
| 693 | server->bigbuf = NULL; |
| 694 | else |
| 695 | server->smallbuf = NULL; |
| 696 | } |
Jeff Layton | ffc00e2 | 2011-10-19 15:29:13 -0400 | [diff] [blame] | 697 | dequeue_mid(mid, malformed); |
Pavel Shilovsky | ad69bae | 2011-08-01 13:19:43 +0400 | [diff] [blame] | 698 | } |
| 699 | |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 700 | static void clean_demultiplex_info(struct TCP_Server_Info *server) |
| 701 | { |
| 702 | int length; |
| 703 | |
| 704 | /* take it off the list, if it's not already */ |
| 705 | spin_lock(&cifs_tcp_ses_lock); |
| 706 | list_del_init(&server->tcp_ses_list); |
| 707 | spin_unlock(&cifs_tcp_ses_lock); |
| 708 | |
| 709 | spin_lock(&GlobalMid_Lock); |
| 710 | server->tcpStatus = CifsExiting; |
| 711 | spin_unlock(&GlobalMid_Lock); |
| 712 | wake_up_all(&server->response_q); |
| 713 | |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 714 | /* check if we have blocked requests that need to free */ |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 715 | spin_lock(&server->req_lock); |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 716 | if (server->credits <= 0) |
| 717 | server->credits = 1; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 718 | spin_unlock(&server->req_lock); |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 719 | /* |
| 720 | * Although there should not be any requests blocked on this queue it |
| 721 | * can not hurt to be paranoid and try to wake up requests that may |
| 722 | * haven been blocked when more than 50 at time were on the wire to the |
| 723 | * same server - they now will see the session is in exit state and get |
| 724 | * out of SendReceive. |
| 725 | */ |
| 726 | wake_up_all(&server->request_q); |
| 727 | /* give those requests time to exit */ |
| 728 | msleep(125); |
Long Li | bce9ce7 | 2017-11-22 17:38:38 -0700 | [diff] [blame] | 729 | if (cifs_rdma_enabled(server) && server->smbd_conn) { |
| 730 | smbd_destroy(server->smbd_conn); |
| 731 | server->smbd_conn = NULL; |
| 732 | } |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 733 | if (server->ssocket) { |
| 734 | sock_release(server->ssocket); |
| 735 | server->ssocket = NULL; |
| 736 | } |
| 737 | |
| 738 | if (!list_empty(&server->pending_mid_q)) { |
| 739 | struct list_head dispose_list; |
| 740 | struct mid_q_entry *mid_entry; |
| 741 | struct list_head *tmp, *tmp2; |
| 742 | |
| 743 | INIT_LIST_HEAD(&dispose_list); |
| 744 | spin_lock(&GlobalMid_Lock); |
| 745 | list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { |
| 746 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 747 | cifs_dbg(FYI, "Clearing mid 0x%llx\n", mid_entry->mid); |
Pavel Shilovsky | 7c9421e | 2012-03-23 14:28:03 -0400 | [diff] [blame] | 748 | mid_entry->mid_state = MID_SHUTDOWN; |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 749 | list_move(&mid_entry->qhead, &dispose_list); |
| 750 | } |
| 751 | spin_unlock(&GlobalMid_Lock); |
| 752 | |
| 753 | /* now walk dispose list and issue callbacks */ |
| 754 | list_for_each_safe(tmp, tmp2, &dispose_list) { |
| 755 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 756 | cifs_dbg(FYI, "Callback mid 0x%llx\n", mid_entry->mid); |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 757 | list_del_init(&mid_entry->qhead); |
| 758 | mid_entry->callback(mid_entry); |
| 759 | } |
| 760 | /* 1/8th of sec is more than enough time for them to exit */ |
| 761 | msleep(125); |
| 762 | } |
| 763 | |
| 764 | if (!list_empty(&server->pending_mid_q)) { |
| 765 | /* |
| 766 | * mpx threads have not exited yet give them at least the smb |
| 767 | * send timeout time for long ops. |
| 768 | * |
| 769 | * Due to delays on oplock break requests, we need to wait at |
| 770 | * least 45 seconds before giving up on a request getting a |
| 771 | * response and going ahead and killing cifsd. |
| 772 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 773 | cifs_dbg(FYI, "Wait for exit from demultiplex thread\n"); |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 774 | msleep(46000); |
| 775 | /* |
| 776 | * If threads still have not exited they are probably never |
| 777 | * coming home not much else we can do but free the memory. |
| 778 | */ |
| 779 | } |
| 780 | |
| 781 | kfree(server->hostname); |
| 782 | kfree(server); |
| 783 | |
| 784 | length = atomic_dec_return(&tcpSesAllocCount); |
| 785 | if (length > 0) |
David Rientjes | 11d8336 | 2015-04-14 15:48:21 -0700 | [diff] [blame] | 786 | mempool_resize(cifs_req_poolp, length + cifs_min_rcv); |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 787 | } |
| 788 | |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 789 | static int |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 790 | standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 791 | { |
| 792 | int length; |
| 793 | char *buf = server->smallbuf; |
Ronnie Sahlberg | 2e96467 | 2018-04-09 18:06:26 +1000 | [diff] [blame] | 794 | unsigned int pdu_length = server->pdu_size; |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 795 | |
| 796 | /* make sure this will fit in a large buffer */ |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 797 | if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) - |
| 798 | server->vals->header_preamble_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 799 | cifs_dbg(VFS, "SMB response too long (%u bytes)\n", pdu_length); |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 800 | cifs_reconnect(server); |
| 801 | wake_up(&server->response_q); |
Pavel Shilovsky | 3fabaa2 | 2014-07-10 09:55:52 +0400 | [diff] [blame] | 802 | return -ECONNABORTED; |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /* switch to large buffer if too big for a small one */ |
| 806 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { |
| 807 | server->large_buf = true; |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 808 | memcpy(server->bigbuf, buf, server->total_read); |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 809 | buf = server->bigbuf; |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* now read the rest */ |
Pavel Shilovsky | 1887f60 | 2012-05-17 12:45:31 +0400 | [diff] [blame] | 813 | length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 814 | pdu_length - HEADER_SIZE(server) + 1 |
| 815 | + server->vals->header_preamble_size); |
| 816 | |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 817 | if (length < 0) |
| 818 | return length; |
| 819 | server->total_read += length; |
| 820 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 821 | dump_smb(buf, server->total_read); |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 822 | |
Pavel Shilovsky | 4326ed2 | 2016-11-17 15:24:46 -0800 | [diff] [blame] | 823 | return cifs_handle_standard(server, mid); |
| 824 | } |
| 825 | |
| 826 | int |
| 827 | cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
| 828 | { |
| 829 | char *buf = server->large_buf ? server->bigbuf : server->smallbuf; |
| 830 | int length; |
| 831 | |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 832 | /* |
| 833 | * We know that we received enough to get to the MID as we |
| 834 | * checked the pdu_length earlier. Now check to see |
| 835 | * if the rest of the header is OK. We borrow the length |
| 836 | * var for the rest of the loop to avoid a new stack var. |
| 837 | * |
| 838 | * 48 bytes is enough to display the header and a little bit |
| 839 | * into the payload for debugging purposes. |
| 840 | */ |
Steve French | 373512e | 2015-12-18 13:05:30 -0600 | [diff] [blame] | 841 | length = server->ops->check_message(buf, server->total_read, server); |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 842 | if (length != 0) |
| 843 | cifs_dump_mem("Bad SMB: ", buf, |
| 844 | min_t(unsigned int, server->total_read, 48)); |
| 845 | |
Pavel Shilovsky | 511c54a | 2017-07-08 14:32:00 -0700 | [diff] [blame] | 846 | if (server->ops->is_session_expired && |
| 847 | server->ops->is_session_expired(buf)) { |
| 848 | cifs_reconnect(server); |
| 849 | wake_up(&server->response_q); |
| 850 | return -1; |
| 851 | } |
| 852 | |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 853 | if (server->ops->is_status_pending && |
| 854 | server->ops->is_status_pending(buf, server, length)) |
| 855 | return -1; |
| 856 | |
Jeff Layton | ff4fa4a | 2012-02-07 06:31:05 -0500 | [diff] [blame] | 857 | if (!mid) |
| 858 | return length; |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 859 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 860 | handle_mid(mid, server, buf, length); |
Jeff Layton | ff4fa4a | 2012-02-07 06:31:05 -0500 | [diff] [blame] | 861 | return 0; |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static int |
Al Viro | 7c97c20 | 2011-06-21 08:51:28 -0400 | [diff] [blame] | 865 | cifs_demultiplex_thread(void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 867 | int i, num_mids, length; |
Al Viro | 7c97c20 | 2011-06-21 08:51:28 -0400 | [diff] [blame] | 868 | struct TCP_Server_Info *server = p; |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 869 | unsigned int pdu_length; |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 870 | unsigned int next_offset; |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 871 | char *buf = NULL; |
Steve French | a5c3e1c | 2014-09-16 04:16:19 -0500 | [diff] [blame] | 872 | struct task_struct *task_to_wake = NULL; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 873 | struct mid_q_entry *mids[MAX_COMPOUND]; |
| 874 | char *bufs[MAX_COMPOUND]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | current->flags |= PF_MEMALLOC; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 877 | cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); |
Jeff Layton | 93d0ec8 | 2008-08-02 08:00:48 -0400 | [diff] [blame] | 878 | |
| 879 | length = atomic_inc_return(&tcpSesAllocCount); |
| 880 | if (length > 1) |
David Rientjes | 11d8336 | 2015-04-14 15:48:21 -0700 | [diff] [blame] | 881 | mempool_resize(cifs_req_poolp, length + cifs_min_rcv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 883 | set_freezable(); |
Jeff Layton | 469ee61 | 2008-10-16 18:46:39 +0000 | [diff] [blame] | 884 | while (server->tcpStatus != CifsExiting) { |
Steve French | ede1327 | 2005-08-30 20:10:14 -0700 | [diff] [blame] | 885 | if (try_to_freeze()) |
| 886 | continue; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 887 | |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 888 | if (!allocate_buffers(server)) |
Pavel Shilovsky | 3d9c247 | 2011-08-01 13:19:40 +0400 | [diff] [blame] | 889 | continue; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 890 | |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 891 | server->large_buf = false; |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 892 | buf = server->smallbuf; |
Steve French | f01d5e1 | 2007-08-30 21:13:31 +0000 | [diff] [blame] | 893 | pdu_length = 4; /* enough to get RFC1001 header */ |
Steve French | fda3594 | 2011-01-20 18:06:34 +0000 | [diff] [blame] | 894 | |
Jeff Layton | e28bc5b | 2011-10-19 15:30:07 -0400 | [diff] [blame] | 895 | length = cifs_read_from_socket(server, buf, pdu_length); |
Jeff Layton | a52c1eb | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 896 | if (length < 0) |
Steve French | fda3594 | 2011-01-20 18:06:34 +0000 | [diff] [blame] | 897 | continue; |
Ronnie Sahlberg | 977b617 | 2018-06-01 10:53:02 +1000 | [diff] [blame] | 898 | |
| 899 | if (server->vals->header_preamble_size == 0) |
| 900 | server->total_read = 0; |
| 901 | else |
| 902 | server->total_read = length; |
Steve French | 67010fb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 903 | |
Pavel Shilovsky | 98bac62 | 2011-08-01 13:19:42 +0400 | [diff] [blame] | 904 | /* |
| 905 | * The right amount was read from socket - 4 bytes, |
| 906 | * so we can now interpret the length field. |
| 907 | */ |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 908 | pdu_length = get_rfc1002_length(buf); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 909 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 910 | cifs_dbg(FYI, "RFC1002 header 0x%x\n", pdu_length); |
Jeff Layton | fe11e4c | 2011-10-11 06:41:32 -0400 | [diff] [blame] | 911 | if (!is_smb_response(server, buf[0])) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 912 | continue; |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 913 | next_pdu: |
| 914 | server->pdu_size = pdu_length; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 915 | |
Jeff Layton | 89482a5 | 2011-10-19 15:28:57 -0400 | [diff] [blame] | 916 | /* make sure we have enough to get to the MID */ |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 917 | if (server->pdu_size < HEADER_SIZE(server) - 1 - |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 918 | server->vals->header_preamble_size) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 919 | cifs_dbg(VFS, "SMB response too short (%u bytes)\n", |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 920 | server->pdu_size); |
Jeff Layton | 89482a5 | 2011-10-19 15:28:57 -0400 | [diff] [blame] | 921 | cifs_reconnect(server); |
| 922 | wake_up(&server->response_q); |
| 923 | continue; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 924 | } |
Pavel Shilovsky | e7015fb | 2011-08-01 13:19:41 +0400 | [diff] [blame] | 925 | |
Jeff Layton | 89482a5 | 2011-10-19 15:28:57 -0400 | [diff] [blame] | 926 | /* read down to the MID */ |
Ronnie Sahlberg | 93012bf | 2018-03-31 11:45:31 +1100 | [diff] [blame] | 927 | length = cifs_read_from_socket(server, |
| 928 | buf + server->vals->header_preamble_size, |
| 929 | HEADER_SIZE(server) - 1 |
| 930 | - server->vals->header_preamble_size); |
Jeff Layton | 89482a5 | 2011-10-19 15:28:57 -0400 | [diff] [blame] | 931 | if (length < 0) |
| 932 | continue; |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 933 | server->total_read += length; |
Jeff Layton | 89482a5 | 2011-10-19 15:28:57 -0400 | [diff] [blame] | 934 | |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 935 | if (server->ops->next_header) { |
| 936 | next_offset = server->ops->next_header(buf); |
| 937 | if (next_offset) |
| 938 | server->pdu_size = next_offset; |
| 939 | } |
| 940 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 941 | memset(mids, 0, sizeof(mids)); |
| 942 | memset(bufs, 0, sizeof(bufs)); |
| 943 | num_mids = 0; |
| 944 | |
Pavel Shilovsky | 9bb17e0 | 2016-11-17 15:24:34 -0800 | [diff] [blame] | 945 | if (server->ops->is_transform_hdr && |
| 946 | server->ops->receive_transform && |
| 947 | server->ops->is_transform_hdr(buf)) { |
| 948 | length = server->ops->receive_transform(server, |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 949 | mids, |
| 950 | bufs, |
| 951 | &num_mids); |
Pavel Shilovsky | 9bb17e0 | 2016-11-17 15:24:34 -0800 | [diff] [blame] | 952 | } else { |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 953 | mids[0] = server->ops->find_mid(server, buf); |
| 954 | bufs[0] = buf; |
Steve French | 7af929d | 2018-10-02 18:54:09 -0500 | [diff] [blame] | 955 | num_mids = 1; |
Jeff Layton | c8054eb | 2011-10-19 15:29:31 -0400 | [diff] [blame] | 956 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 957 | if (!mids[0] || !mids[0]->receive) |
| 958 | length = standard_receive3(server, mids[0]); |
Pavel Shilovsky | 9bb17e0 | 2016-11-17 15:24:34 -0800 | [diff] [blame] | 959 | else |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 960 | length = mids[0]->receive(server, mids[0]); |
Pavel Shilovsky | 9bb17e0 | 2016-11-17 15:24:34 -0800 | [diff] [blame] | 961 | } |
Jeff Layton | 44d22d8 | 2011-10-19 15:29:49 -0400 | [diff] [blame] | 962 | |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 963 | if (length < 0) { |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 964 | for (i = 0; i < num_mids; i++) |
| 965 | if (mids[i]) |
| 966 | cifs_mid_q_entry_release(mids[i]); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 967 | continue; |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 968 | } |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 969 | |
Pavel Shilovsky | d4e4854 | 2012-03-23 14:28:02 -0400 | [diff] [blame] | 970 | if (server->large_buf) |
Jeff Layton | e9097ab | 2011-10-19 15:29:40 -0400 | [diff] [blame] | 971 | buf = server->bigbuf; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 972 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 973 | |
Steve French | fda3594 | 2011-01-20 18:06:34 +0000 | [diff] [blame] | 974 | server->lstrp = jiffies; |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 975 | |
| 976 | for (i = 0; i < num_mids; i++) { |
| 977 | if (mids[i] != NULL) { |
| 978 | mids[i]->resp_buf_size = server->pdu_size; |
| 979 | if ((mids[i]->mid_flags & MID_WAIT_CANCELLED) && |
| 980 | mids[i]->mid_state == MID_RESPONSE_RECEIVED && |
| 981 | server->ops->handle_cancelled_mid) |
| 982 | server->ops->handle_cancelled_mid( |
| 983 | mids[i]->resp_buf, |
Sachin Prabhu | 38bd490 | 2017-03-03 15:41:38 -0800 | [diff] [blame] | 984 | server); |
| 985 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 986 | if (!mids[i]->multiRsp || mids[i]->multiEnd) |
| 987 | mids[i]->callback(mids[i]); |
Lars Persson | 696e420 | 2018-06-25 14:05:25 +0200 | [diff] [blame] | 988 | |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 989 | cifs_mid_q_entry_release(mids[i]); |
| 990 | } else if (server->ops->is_oplock_break && |
| 991 | server->ops->is_oplock_break(bufs[i], |
| 992 | server)) { |
| 993 | cifs_dbg(FYI, "Received oplock break\n"); |
| 994 | } else { |
| 995 | cifs_dbg(VFS, "No task to wake, unknown frame " |
| 996 | "received! NumMids %d\n", |
| 997 | atomic_read(&midCount)); |
| 998 | cifs_dump_mem("Received Data is: ", bufs[i], |
| 999 | HEADER_SIZE(server)); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1000 | #ifdef CONFIG_CIFS_DEBUG2 |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 1001 | if (server->ops->dump_detail) |
| 1002 | server->ops->dump_detail(bufs[i], |
| 1003 | server); |
| 1004 | cifs_dump_mids(server); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1005 | #endif /* CIFS_DEBUG2 */ |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 1006 | } |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 1007 | } |
Ronnie Sahlberg | b24df3e | 2018-08-08 15:07:45 +1000 | [diff] [blame] | 1008 | |
Ronnie Sahlberg | 8ce79ec | 2018-06-01 10:53:08 +1000 | [diff] [blame] | 1009 | if (pdu_length > server->pdu_size) { |
| 1010 | if (!allocate_buffers(server)) |
| 1011 | continue; |
| 1012 | pdu_length -= server->pdu_size; |
| 1013 | server->total_read = 0; |
| 1014 | server->large_buf = false; |
| 1015 | buf = server->smallbuf; |
| 1016 | goto next_pdu; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } /* end while !EXITING */ |
| 1019 | |
Justin P. Mattock | fd62cb7 | 2011-02-24 22:15:02 -0800 | [diff] [blame] | 1020 | /* buffer usually freed in free_mid - need to free it here on exit */ |
Jeff Layton | 2a37ef9 | 2011-10-19 15:29:23 -0400 | [diff] [blame] | 1021 | cifs_buf_release(server->bigbuf); |
| 1022 | if (server->smallbuf) /* no sense logging a debug message if NULL */ |
| 1023 | cifs_small_buf_release(server->smallbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
Steve French | a5c3e1c | 2014-09-16 04:16:19 -0500 | [diff] [blame] | 1025 | task_to_wake = xchg(&server->tsk, NULL); |
Pavel Shilovsky | 762dfd1 | 2011-08-01 13:19:44 +0400 | [diff] [blame] | 1026 | clean_demultiplex_info(server); |
Steve French | a5c3e1c | 2014-09-16 04:16:19 -0500 | [diff] [blame] | 1027 | |
| 1028 | /* if server->tsk was NULL then wait for a signal before exiting */ |
| 1029 | if (!task_to_wake) { |
| 1030 | set_current_state(TASK_INTERRUPTIBLE); |
| 1031 | while (!signal_pending(current)) { |
| 1032 | schedule(); |
| 1033 | set_current_state(TASK_INTERRUPTIBLE); |
| 1034 | } |
| 1035 | set_current_state(TASK_RUNNING); |
| 1036 | } |
| 1037 | |
Jeff Layton | 0468a2c | 2008-12-01 07:09:35 -0500 | [diff] [blame] | 1038 | module_put_and_exit(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Jeff Layton | c359cf3 | 2007-11-16 22:22:06 +0000 | [diff] [blame] | 1041 | /* extract the host portion of the UNC string */ |
| 1042 | static char * |
| 1043 | extract_hostname(const char *unc) |
| 1044 | { |
| 1045 | const char *src; |
| 1046 | char *dst, *delim; |
| 1047 | unsigned int len; |
| 1048 | |
| 1049 | /* skip double chars at beginning of string */ |
| 1050 | /* BB: check validity of these bytes? */ |
Paulo Alcantara | c34fea5 | 2018-11-14 14:03:40 -0200 | [diff] [blame] | 1051 | if (strlen(unc) < 3) |
| 1052 | return ERR_PTR(-EINVAL); |
| 1053 | for (src = unc; *src && *src == '\\'; src++) |
| 1054 | ; |
| 1055 | if (!*src) |
| 1056 | return ERR_PTR(-EINVAL); |
Jeff Layton | c359cf3 | 2007-11-16 22:22:06 +0000 | [diff] [blame] | 1057 | |
| 1058 | /* delimiter between hostname and sharename is always '\\' now */ |
| 1059 | delim = strchr(src, '\\'); |
| 1060 | if (!delim) |
| 1061 | return ERR_PTR(-EINVAL); |
| 1062 | |
| 1063 | len = delim - src; |
| 1064 | dst = kmalloc((len + 1), GFP_KERNEL); |
| 1065 | if (dst == NULL) |
| 1066 | return ERR_PTR(-ENOMEM); |
| 1067 | |
| 1068 | memcpy(dst, src, len); |
| 1069 | dst[len] = '\0'; |
| 1070 | |
| 1071 | return dst; |
| 1072 | } |
| 1073 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1074 | static int get_option_ul(substring_t args[], unsigned long *option) |
| 1075 | { |
| 1076 | int rc; |
| 1077 | char *string; |
| 1078 | |
| 1079 | string = match_strdup(args); |
| 1080 | if (string == NULL) |
| 1081 | return -ENOMEM; |
Sachin Prabhu | bfa890a | 2012-04-13 14:04:32 +0100 | [diff] [blame] | 1082 | rc = kstrtoul(string, 0, option); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1083 | kfree(string); |
| 1084 | |
| 1085 | return rc; |
| 1086 | } |
| 1087 | |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1088 | static int get_option_uid(substring_t args[], kuid_t *result) |
| 1089 | { |
| 1090 | unsigned long value; |
| 1091 | kuid_t uid; |
| 1092 | int rc; |
| 1093 | |
| 1094 | rc = get_option_ul(args, &value); |
| 1095 | if (rc) |
| 1096 | return rc; |
| 1097 | |
| 1098 | uid = make_kuid(current_user_ns(), value); |
| 1099 | if (!uid_valid(uid)) |
| 1100 | return -EINVAL; |
| 1101 | |
| 1102 | *result = uid; |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | static int get_option_gid(substring_t args[], kgid_t *result) |
| 1107 | { |
| 1108 | unsigned long value; |
| 1109 | kgid_t gid; |
| 1110 | int rc; |
| 1111 | |
| 1112 | rc = get_option_ul(args, &value); |
| 1113 | if (rc) |
| 1114 | return rc; |
| 1115 | |
| 1116 | gid = make_kgid(current_user_ns(), value); |
| 1117 | if (!gid_valid(gid)) |
| 1118 | return -EINVAL; |
| 1119 | |
| 1120 | *result = gid; |
| 1121 | return 0; |
| 1122 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1123 | |
| 1124 | static int cifs_parse_security_flavors(char *value, |
| 1125 | struct smb_vol *vol) |
| 1126 | { |
| 1127 | |
| 1128 | substring_t args[MAX_OPT_ARGS]; |
| 1129 | |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1130 | /* |
| 1131 | * With mount options, the last one should win. Reset any existing |
| 1132 | * settings back to default. |
| 1133 | */ |
| 1134 | vol->sectype = Unspecified; |
| 1135 | vol->sign = false; |
| 1136 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1137 | switch (match_token(value, cifs_secflavor_tokens, args)) { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 1138 | case Opt_sec_krb5p: |
| 1139 | cifs_dbg(VFS, "sec=krb5p is not supported!\n"); |
| 1140 | return 1; |
| 1141 | case Opt_sec_krb5i: |
| 1142 | vol->sign = true; |
| 1143 | /* Fallthrough */ |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1144 | case Opt_sec_krb5: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1145 | vol->sectype = Kerberos; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1146 | break; |
| 1147 | case Opt_sec_ntlmsspi: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1148 | vol->sign = true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 1149 | /* Fallthrough */ |
| 1150 | case Opt_sec_ntlmssp: |
| 1151 | vol->sectype = RawNTLMSSP; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1152 | break; |
| 1153 | case Opt_sec_ntlmi: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1154 | vol->sign = true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 1155 | /* Fallthrough */ |
| 1156 | case Opt_ntlm: |
| 1157 | vol->sectype = NTLM; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1158 | break; |
| 1159 | case Opt_sec_ntlmv2i: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1160 | vol->sign = true; |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 1161 | /* Fallthrough */ |
| 1162 | case Opt_sec_ntlmv2: |
| 1163 | vol->sectype = NTLMv2; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1164 | break; |
| 1165 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 1166 | case Opt_sec_lanman: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1167 | vol->sectype = LANMAN; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1168 | break; |
| 1169 | #endif |
| 1170 | case Opt_sec_none: |
| 1171 | vol->nullauth = 1; |
| 1172 | break; |
| 1173 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1174 | cifs_dbg(VFS, "bad security option: %s\n", value); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1175 | return 1; |
| 1176 | } |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | static int |
Jeff Layton | 15b6a47 | 2012-05-16 07:50:15 -0400 | [diff] [blame] | 1182 | cifs_parse_cache_flavor(char *value, struct smb_vol *vol) |
| 1183 | { |
| 1184 | substring_t args[MAX_OPT_ARGS]; |
| 1185 | |
| 1186 | switch (match_token(value, cifs_cacheflavor_tokens, args)) { |
| 1187 | case Opt_cache_loose: |
| 1188 | vol->direct_io = false; |
| 1189 | vol->strict_io = false; |
| 1190 | break; |
| 1191 | case Opt_cache_strict: |
| 1192 | vol->direct_io = false; |
| 1193 | vol->strict_io = true; |
| 1194 | break; |
| 1195 | case Opt_cache_none: |
| 1196 | vol->direct_io = true; |
| 1197 | vol->strict_io = false; |
| 1198 | break; |
| 1199 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1200 | cifs_dbg(VFS, "bad cache= option: %s\n", value); |
Jeff Layton | 15b6a47 | 2012-05-16 07:50:15 -0400 | [diff] [blame] | 1201 | return 1; |
| 1202 | } |
| 1203 | return 0; |
| 1204 | } |
| 1205 | |
| 1206 | static int |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 1207 | cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3) |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1208 | { |
| 1209 | substring_t args[MAX_OPT_ARGS]; |
| 1210 | |
| 1211 | switch (match_token(value, cifs_smb_version_tokens, args)) { |
Steve French | 7420451 | 2018-06-19 14:34:08 -0500 | [diff] [blame] | 1212 | #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1213 | case Smb_1: |
Steve French | f92a720 | 2018-05-24 04:11:07 -0500 | [diff] [blame] | 1214 | if (disable_legacy_dialects) { |
| 1215 | cifs_dbg(VFS, "mount with legacy dialect disabled\n"); |
| 1216 | return 1; |
| 1217 | } |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 1218 | if (is_smb3) { |
| 1219 | cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n"); |
| 1220 | return 1; |
| 1221 | } |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1222 | vol->ops = &smb1_operations; |
| 1223 | vol->vals = &smb1_values; |
| 1224 | break; |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1225 | case Smb_20: |
Steve French | f92a720 | 2018-05-24 04:11:07 -0500 | [diff] [blame] | 1226 | if (disable_legacy_dialects) { |
| 1227 | cifs_dbg(VFS, "mount with legacy dialect disabled\n"); |
| 1228 | return 1; |
| 1229 | } |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 1230 | if (is_smb3) { |
| 1231 | cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n"); |
| 1232 | return 1; |
| 1233 | } |
Pavel Shilovsky | 53ef101 | 2013-09-05 16:11:28 +0400 | [diff] [blame] | 1234 | vol->ops = &smb20_operations; |
Steve French | dd446b1 | 2012-11-28 23:21:06 -0600 | [diff] [blame] | 1235 | vol->vals = &smb20_values; |
| 1236 | break; |
Steve French | 7420451 | 2018-06-19 14:34:08 -0500 | [diff] [blame] | 1237 | #else |
| 1238 | case Smb_1: |
| 1239 | cifs_dbg(VFS, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n"); |
| 1240 | return 1; |
| 1241 | case Smb_20: |
| 1242 | cifs_dbg(VFS, "vers=2.0 mount not permitted when legacy dialects disabled\n"); |
| 1243 | return 1; |
| 1244 | #endif /* CIFS_ALLOW_INSECURE_LEGACY */ |
Steve French | 1080ef7 | 2011-02-24 18:07:19 +0000 | [diff] [blame] | 1245 | case Smb_21: |
| 1246 | vol->ops = &smb21_operations; |
| 1247 | vol->vals = &smb21_values; |
| 1248 | break; |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1249 | case Smb_30: |
Steve French | 38107d4 | 2012-12-08 22:08:06 -0600 | [diff] [blame] | 1250 | vol->ops = &smb30_operations; |
Steve French | e4aa25e | 2012-10-01 12:26:22 -0500 | [diff] [blame] | 1251 | vol->vals = &smb30_values; |
| 1252 | break; |
Steve French | 20b6d8b | 2013-06-12 22:48:41 -0500 | [diff] [blame] | 1253 | case Smb_302: |
| 1254 | vol->ops = &smb30_operations; /* currently identical with 3.0 */ |
| 1255 | vol->vals = &smb302_values; |
| 1256 | break; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 1257 | case Smb_311: |
Steve French | aab1893 | 2015-06-23 23:37:11 -0500 | [diff] [blame] | 1258 | vol->ops = &smb311_operations; |
Steve French | 5f7fbf7 | 2014-12-17 22:52:58 -0600 | [diff] [blame] | 1259 | vol->vals = &smb311_values; |
| 1260 | break; |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 1261 | case Smb_3any: |
| 1262 | vol->ops = &smb30_operations; /* currently identical with 3.0 */ |
| 1263 | vol->vals = &smb3any_values; |
| 1264 | break; |
| 1265 | case Smb_default: |
| 1266 | vol->ops = &smb30_operations; /* currently identical with 3.0 */ |
| 1267 | vol->vals = &smbdefault_values; |
| 1268 | break; |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1269 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1270 | cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value); |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1271 | return 1; |
| 1272 | } |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
Jeff Layton | d387a5c | 2012-12-10 06:10:46 -0500 | [diff] [blame] | 1276 | /* |
| 1277 | * Parse a devname into substrings and populate the vol->UNC and vol->prepath |
| 1278 | * fields with the result. Returns 0 on success and an error otherwise. |
| 1279 | */ |
| 1280 | static int |
| 1281 | cifs_parse_devname(const char *devname, struct smb_vol *vol) |
| 1282 | { |
| 1283 | char *pos; |
| 1284 | const char *delims = "/\\"; |
| 1285 | size_t len; |
| 1286 | |
| 1287 | /* make sure we have a valid UNC double delimiter prefix */ |
| 1288 | len = strspn(devname, delims); |
| 1289 | if (len != 2) |
| 1290 | return -EINVAL; |
| 1291 | |
| 1292 | /* find delimiter between host and sharename */ |
| 1293 | pos = strpbrk(devname + 2, delims); |
| 1294 | if (!pos) |
| 1295 | return -EINVAL; |
| 1296 | |
| 1297 | /* skip past delimiter */ |
| 1298 | ++pos; |
| 1299 | |
| 1300 | /* now go until next delimiter or end of string */ |
| 1301 | len = strcspn(pos, delims); |
| 1302 | |
| 1303 | /* move "pos" up to delimiter or NULL */ |
| 1304 | pos += len; |
| 1305 | vol->UNC = kstrndup(devname, pos - devname, GFP_KERNEL); |
| 1306 | if (!vol->UNC) |
| 1307 | return -ENOMEM; |
| 1308 | |
| 1309 | convert_delimiter(vol->UNC, '\\'); |
| 1310 | |
Sachin Prabhu | 11e3164 | 2016-02-08 13:44:01 +0530 | [diff] [blame] | 1311 | /* skip any delimiter */ |
| 1312 | if (*pos == '/' || *pos == '\\') |
| 1313 | pos++; |
| 1314 | |
| 1315 | /* If pos is NULL then no prepath */ |
| 1316 | if (!*pos) |
Jeff Layton | d387a5c | 2012-12-10 06:10:46 -0500 | [diff] [blame] | 1317 | return 0; |
| 1318 | |
| 1319 | vol->prepath = kstrdup(pos, GFP_KERNEL); |
| 1320 | if (!vol->prepath) |
| 1321 | return -ENOMEM; |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1326 | static int |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 1327 | cifs_parse_mount_options(const char *mountdata, const char *devname, |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 1328 | struct smb_vol *vol, bool is_smb3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | { |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1330 | char *data, *end; |
Vasily Averin | 957df45 | 2011-06-06 11:33:12 +0400 | [diff] [blame] | 1331 | char *mountdata_copy = NULL, *options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | unsigned int temp_len, i, j; |
| 1333 | char separator[2]; |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 1334 | short int override_uid = -1; |
| 1335 | short int override_gid = -1; |
| 1336 | bool uid_specified = false; |
| 1337 | bool gid_specified = false; |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1338 | bool sloppy = false; |
| 1339 | char *invalid = NULL; |
Jeff Layton | 8846399 | 2010-11-22 15:31:03 -0500 | [diff] [blame] | 1340 | char *nodename = utsname()->nodename; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1341 | char *string = NULL; |
| 1342 | char *tmp_end, *value; |
| 1343 | char delim; |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1344 | bool got_ip = false; |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 1345 | bool got_version = false; |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1346 | unsigned short port = 0; |
| 1347 | struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
| 1349 | separator[0] = ','; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1350 | separator[1] = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1351 | delim = separator[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
Jeff Layton | 6ee9542 | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 1353 | /* ensure we always start with zeroed-out smb_vol */ |
| 1354 | memset(vol, 0, sizeof(*vol)); |
| 1355 | |
Jeff Layton | 8846399 | 2010-11-22 15:31:03 -0500 | [diff] [blame] | 1356 | /* |
| 1357 | * does not have to be perfect mapping since field is |
| 1358 | * informational, only used for servers that do not support |
| 1359 | * port 445 and it can be overridden at mount time |
| 1360 | */ |
Jeff Layton | 1397f2e | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 1361 | memset(vol->source_rfc1001_name, 0x20, RFC1001_NAME_LEN); |
| 1362 | for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++) |
Jeff Layton | 8846399 | 2010-11-22 15:31:03 -0500 | [diff] [blame] | 1363 | vol->source_rfc1001_name[i] = toupper(nodename[i]); |
| 1364 | |
Jeff Layton | 1397f2e | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 1365 | vol->source_rfc1001_name[RFC1001_NAME_LEN] = 0; |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1366 | /* null target name indicates to use *SMBSERVR default called name |
| 1367 | if we end up sending RFC1001 session initialize */ |
| 1368 | vol->target_rfc1001_name[0] = 0; |
Jeff Layton | 3e4b3e1 | 2010-07-19 18:00:17 -0400 | [diff] [blame] | 1369 | vol->cred_uid = current_uid(); |
| 1370 | vol->linux_uid = current_uid(); |
David Howells | a001e5b | 2008-11-14 10:38:47 +1100 | [diff] [blame] | 1371 | vol->linux_gid = current_gid(); |
Jeff Layton | f55ed1a | 2009-05-26 16:28:11 -0400 | [diff] [blame] | 1372 | |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1373 | /* |
| 1374 | * default to SFM style remapping of seven reserved characters |
| 1375 | * unless user overrides it or we negotiate CIFS POSIX where |
| 1376 | * it is unnecessary. Can not simultaneously use more than one mapping |
| 1377 | * since then readdir could list files that open could not open |
| 1378 | */ |
| 1379 | vol->remap = true; |
| 1380 | |
Jeff Layton | f55ed1a | 2009-05-26 16:28:11 -0400 | [diff] [blame] | 1381 | /* default to only allowing write access to owner of the mount */ |
| 1382 | vol->dir_mode = vol->file_mode = S_IRUGO | S_IXUGO | S_IWUSR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 1385 | /* default is always to request posix paths. */ |
| 1386 | vol->posix_paths = 1; |
Jeff Layton | a0c9217 | 2009-05-27 15:40:47 -0400 | [diff] [blame] | 1387 | /* default to using server inode numbers where available */ |
| 1388 | vol->server_ino = 1; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 1389 | |
Jeff Layton | 1b35920 | 2012-09-19 15:20:27 -0700 | [diff] [blame] | 1390 | /* default is to use strict cifs caching semantics */ |
| 1391 | vol->strict_io = true; |
| 1392 | |
Suresh Jayaraman | 6d20e84 | 2010-12-01 14:42:28 +0530 | [diff] [blame] | 1393 | vol->actimeo = CIFS_DEF_ACTIMEO; |
| 1394 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 1395 | /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */ |
| 1396 | vol->ops = &smb30_operations; |
| 1397 | vol->vals = &smbdefault_values; |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 1398 | |
Rabin Vincent | b782fcc | 2016-07-19 09:25:45 +0200 | [diff] [blame] | 1399 | vol->echo_interval = SMB_ECHO_INTERVAL_DEFAULT; |
| 1400 | |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 1401 | if (!mountdata) |
| 1402 | goto cifs_parse_mount_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 1404 | mountdata_copy = kstrndup(mountdata, PAGE_SIZE, GFP_KERNEL); |
| 1405 | if (!mountdata_copy) |
| 1406 | goto cifs_parse_mount_err; |
| 1407 | |
| 1408 | options = mountdata_copy; |
Pavel Shilovsky | 4906e50 | 2011-04-14 22:00:56 +0400 | [diff] [blame] | 1409 | end = options + strlen(options); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1410 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1411 | if (strncmp(options, "sep=", 4) == 0) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1412 | if (options[4] != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | separator[0] = options[4]; |
| 1414 | options += 5; |
| 1415 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1416 | cifs_dbg(FYI, "Null separator not allowed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | } |
| 1418 | } |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 1419 | vol->backupuid_specified = false; /* no backup intent for a user */ |
| 1420 | vol->backupgid_specified = false; /* no backup intent for a group */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1421 | |
Jeff Layton | 37d4f99 | 2013-05-24 07:40:05 -0400 | [diff] [blame] | 1422 | switch (cifs_parse_devname(devname, vol)) { |
| 1423 | case 0: |
| 1424 | break; |
| 1425 | case -ENOMEM: |
| 1426 | cifs_dbg(VFS, "Unable to allocate memory for devname.\n"); |
| 1427 | goto cifs_parse_mount_err; |
| 1428 | case -EINVAL: |
| 1429 | cifs_dbg(VFS, "Malformed UNC in devname.\n"); |
| 1430 | goto cifs_parse_mount_err; |
| 1431 | default: |
| 1432 | cifs_dbg(VFS, "Unknown error parsing devname.\n"); |
| 1433 | goto cifs_parse_mount_err; |
Jeff Layton | d387a5c | 2012-12-10 06:10:46 -0500 | [diff] [blame] | 1434 | } |
| 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | while ((data = strsep(&options, separator)) != NULL) { |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1437 | substring_t args[MAX_OPT_ARGS]; |
| 1438 | unsigned long option; |
| 1439 | int token; |
| 1440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | if (!*data) |
| 1442 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1444 | token = match_token(data, cifs_mount_option_tokens, args); |
| 1445 | |
| 1446 | switch (token) { |
| 1447 | |
| 1448 | /* Ingnore the following */ |
| 1449 | case Opt_ignore: |
| 1450 | break; |
| 1451 | |
| 1452 | /* Boolean values */ |
| 1453 | case Opt_user_xattr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | vol->no_xattr = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1455 | break; |
| 1456 | case Opt_nouser_xattr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | vol->no_xattr = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1458 | break; |
| 1459 | case Opt_forceuid: |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 1460 | override_uid = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1461 | break; |
| 1462 | case Opt_noforceuid: |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 1463 | override_uid = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1464 | break; |
Jeff Layton | 72bd481 | 2012-10-03 16:02:36 -0400 | [diff] [blame] | 1465 | case Opt_forcegid: |
| 1466 | override_gid = 1; |
| 1467 | break; |
| 1468 | case Opt_noforcegid: |
| 1469 | override_gid = 0; |
| 1470 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1471 | case Opt_noblocksend: |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 1472 | vol->noblocksnd = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1473 | break; |
| 1474 | case Opt_noautotune: |
Steve French | edf1ae4 | 2008-10-29 00:47:57 +0000 | [diff] [blame] | 1475 | vol->noautotune = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1476 | break; |
| 1477 | case Opt_hard: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | vol->retry = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1479 | break; |
| 1480 | case Opt_soft: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | vol->retry = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1482 | break; |
| 1483 | case Opt_perm: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | vol->noperm = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1485 | break; |
| 1486 | case Opt_noperm: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | vol->noperm = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1488 | break; |
| 1489 | case Opt_mapchars: |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1490 | vol->sfu_remap = true; |
| 1491 | vol->remap = false; /* disable SFM mapping */ |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1492 | break; |
| 1493 | case Opt_nomapchars: |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 1494 | vol->sfu_remap = false; |
| 1495 | break; |
| 1496 | case Opt_mapposix: |
| 1497 | vol->remap = true; |
| 1498 | vol->sfu_remap = false; /* disable SFU mapping */ |
| 1499 | break; |
| 1500 | case Opt_nomapposix: |
| 1501 | vol->remap = false; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1502 | break; |
| 1503 | case Opt_sfu: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1504 | vol->sfu_emul = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1505 | break; |
| 1506 | case Opt_nosfu: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1507 | vol->sfu_emul = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1508 | break; |
| 1509 | case Opt_nodfs: |
Steve French | 2c1b861 | 2008-10-16 18:35:21 +0000 | [diff] [blame] | 1510 | vol->nodfs = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1511 | break; |
| 1512 | case Opt_posixpaths: |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 1513 | vol->posix_paths = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1514 | break; |
| 1515 | case Opt_noposixpaths: |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 1516 | vol->posix_paths = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1517 | break; |
| 1518 | case Opt_nounix: |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 1519 | if (vol->linux_ext) |
| 1520 | cifs_dbg(VFS, |
| 1521 | "conflicting unix mount options\n"); |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 1522 | vol->no_linux_ext = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1523 | break; |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 1524 | case Opt_unix: |
| 1525 | if (vol->no_linux_ext) |
| 1526 | cifs_dbg(VFS, |
| 1527 | "conflicting unix mount options\n"); |
| 1528 | vol->linux_ext = 1; |
| 1529 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1530 | case Opt_nocase: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1531 | vol->nocase = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1532 | break; |
| 1533 | case Opt_brl: |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 1534 | vol->nobrl = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1535 | break; |
| 1536 | case Opt_nobrl: |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 1537 | vol->nobrl = 1; |
Pavel Shilovsky | 5cfdddc | 2012-03-27 20:51:15 +0400 | [diff] [blame] | 1538 | /* |
| 1539 | * turn off mandatory locking in mode |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1540 | * if remote locking is turned off since the |
Pavel Shilovsky | 5cfdddc | 2012-03-27 20:51:15 +0400 | [diff] [blame] | 1541 | * local vfs will do advisory |
| 1542 | */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1543 | if (vol->file_mode == |
| 1544 | (S_IALLUGO & ~(S_ISUID | S_IXGRP))) |
Steve French | d3485d3 | 2005-08-19 11:04:29 -0700 | [diff] [blame] | 1545 | vol->file_mode = S_IALLUGO; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1546 | break; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 1547 | case Opt_nohandlecache: |
| 1548 | vol->nohandlecache = 1; |
| 1549 | break; |
| 1550 | case Opt_handlecache: |
| 1551 | vol->nohandlecache = 0; |
| 1552 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1553 | case Opt_forcemandatorylock: |
Steve French | 13a6e42 | 2008-12-02 17:24:33 +0000 | [diff] [blame] | 1554 | vol->mand_lock = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1555 | break; |
| 1556 | case Opt_setuids: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | vol->setuids = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1558 | break; |
| 1559 | case Opt_nosetuids: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | vol->setuids = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1561 | break; |
Steve French | 9593265 | 2016-09-23 01:36:34 -0500 | [diff] [blame] | 1562 | case Opt_setuidfromacl: |
| 1563 | vol->setuidfromacl = 1; |
| 1564 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1565 | case Opt_dynperm: |
Jeff Layton | d0a9c07 | 2008-05-12 22:23:49 +0000 | [diff] [blame] | 1566 | vol->dynperm = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1567 | break; |
| 1568 | case Opt_nodynperm: |
Jeff Layton | d0a9c07 | 2008-05-12 22:23:49 +0000 | [diff] [blame] | 1569 | vol->dynperm = false; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1570 | break; |
| 1571 | case Opt_nohard: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | vol->retry = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1573 | break; |
| 1574 | case Opt_nosoft: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | vol->retry = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1576 | break; |
| 1577 | case Opt_nointr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | vol->intr = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1579 | break; |
| 1580 | case Opt_intr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | vol->intr = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1582 | break; |
| 1583 | case Opt_nostrictsync: |
Steve French | be65244 | 2009-02-23 15:21:59 +0000 | [diff] [blame] | 1584 | vol->nostrictsync = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1585 | break; |
| 1586 | case Opt_strictsync: |
Steve French | be65244 | 2009-02-23 15:21:59 +0000 | [diff] [blame] | 1587 | vol->nostrictsync = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1588 | break; |
| 1589 | case Opt_serverino: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | vol->server_ino = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1591 | break; |
| 1592 | case Opt_noserverino: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | vol->server_ino = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1594 | break; |
| 1595 | case Opt_rwpidforward: |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 1596 | vol->rwpidforward = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1597 | break; |
| 1598 | case Opt_cifsacl: |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 1599 | vol->cifs_acl = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1600 | break; |
| 1601 | case Opt_nocifsacl: |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 1602 | vol->cifs_acl = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1603 | break; |
| 1604 | case Opt_acl: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | vol->no_psx_acl = 0; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1606 | break; |
| 1607 | case Opt_noacl: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | vol->no_psx_acl = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1609 | break; |
| 1610 | case Opt_locallease: |
Steve French | 84210e9 | 2008-10-23 04:42:37 +0000 | [diff] [blame] | 1611 | vol->local_lease = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1612 | break; |
| 1613 | case Opt_sign: |
Jeff Layton | 1e3cc57 | 2013-06-10 17:12:23 -0500 | [diff] [blame] | 1614 | vol->sign = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1615 | break; |
| 1616 | case Opt_seal: |
Steve French | 95b1cb9 | 2008-05-15 16:44:38 +0000 | [diff] [blame] | 1617 | /* we do not do the following in secFlags because seal |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1618 | * is a per tree connection (mount) not a per socket |
| 1619 | * or per-smb connection option in the protocol |
| 1620 | * vol->secFlg |= CIFSSEC_MUST_SEAL; |
| 1621 | */ |
Steve French | 95b1cb9 | 2008-05-15 16:44:38 +0000 | [diff] [blame] | 1622 | vol->seal = 1; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1623 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1624 | case Opt_noac: |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1625 | pr_warn("CIFS: Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1626 | break; |
| 1627 | case Opt_fsc: |
Suresh Jayaraman | 607a569 | 2010-11-24 17:49:05 +0530 | [diff] [blame] | 1628 | #ifndef CONFIG_CIFS_FSCACHE |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1629 | cifs_dbg(VFS, "FS-Cache support needs CONFIG_CIFS_FSCACHE kernel config option set\n"); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 1630 | goto cifs_parse_mount_err; |
Suresh Jayaraman | 607a569 | 2010-11-24 17:49:05 +0530 | [diff] [blame] | 1631 | #endif |
Suresh Jayaraman | fa1df75 | 2010-07-05 18:13:36 +0530 | [diff] [blame] | 1632 | vol->fsc = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1633 | break; |
| 1634 | case Opt_mfsymlinks: |
Stefan Metzmacher | 736a3320 | 2010-07-30 14:56:00 +0200 | [diff] [blame] | 1635 | vol->mfsymlinks = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1636 | break; |
| 1637 | case Opt_multiuser: |
Jeff Layton | 0eb8a13 | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 1638 | vol->multiuser = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1639 | break; |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1640 | case Opt_sloppy: |
| 1641 | sloppy = true; |
| 1642 | break; |
Jeff Layton | a0b3df5 | 2013-05-24 07:40:59 -0400 | [diff] [blame] | 1643 | case Opt_nosharesock: |
| 1644 | vol->nosharesock = true; |
| 1645 | break; |
Steve French | b2a3077 | 2015-09-29 21:49:28 -0500 | [diff] [blame] | 1646 | case Opt_nopersistent: |
| 1647 | vol->nopersistent = true; |
| 1648 | if (vol->persistent) { |
| 1649 | cifs_dbg(VFS, |
| 1650 | "persistenthandles mount options conflict\n"); |
| 1651 | goto cifs_parse_mount_err; |
| 1652 | } |
| 1653 | break; |
| 1654 | case Opt_persistent: |
| 1655 | vol->persistent = true; |
Steve French | 592fafe | 2015-11-03 10:08:53 -0600 | [diff] [blame] | 1656 | if ((vol->nopersistent) || (vol->resilient)) { |
Steve French | b2a3077 | 2015-09-29 21:49:28 -0500 | [diff] [blame] | 1657 | cifs_dbg(VFS, |
| 1658 | "persistenthandles mount options conflict\n"); |
| 1659 | goto cifs_parse_mount_err; |
| 1660 | } |
| 1661 | break; |
Steve French | 592fafe | 2015-11-03 10:08:53 -0600 | [diff] [blame] | 1662 | case Opt_resilient: |
| 1663 | vol->resilient = true; |
| 1664 | if (vol->persistent) { |
| 1665 | cifs_dbg(VFS, |
| 1666 | "persistenthandles mount options conflict\n"); |
| 1667 | goto cifs_parse_mount_err; |
| 1668 | } |
| 1669 | break; |
| 1670 | case Opt_noresilient: |
| 1671 | vol->resilient = false; /* already the default */ |
| 1672 | break; |
Germano Percossi | 3956644 | 2016-12-15 12:31:18 +0530 | [diff] [blame] | 1673 | case Opt_domainauto: |
| 1674 | vol->domainauto = true; |
| 1675 | break; |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 1676 | case Opt_rdma: |
| 1677 | vol->rdma = true; |
| 1678 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1679 | |
| 1680 | /* Numeric Values */ |
| 1681 | case Opt_backupuid: |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1682 | if (get_option_uid(args, &vol->backupuid)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1683 | cifs_dbg(VFS, "%s: Invalid backupuid value\n", |
| 1684 | __func__); |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 1685 | goto cifs_parse_mount_err; |
| 1686 | } |
| 1687 | vol->backupuid_specified = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1688 | break; |
| 1689 | case Opt_backupgid: |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1690 | if (get_option_gid(args, &vol->backupgid)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1691 | cifs_dbg(VFS, "%s: Invalid backupgid value\n", |
| 1692 | __func__); |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 1693 | goto cifs_parse_mount_err; |
| 1694 | } |
| 1695 | vol->backupgid_specified = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1696 | break; |
| 1697 | case Opt_uid: |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1698 | if (get_option_uid(args, &vol->linux_uid)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1699 | cifs_dbg(VFS, "%s: Invalid uid value\n", |
| 1700 | __func__); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 1701 | goto cifs_parse_mount_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1703 | uid_specified = true; |
| 1704 | break; |
| 1705 | case Opt_cruid: |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1706 | if (get_option_uid(args, &vol->cred_uid)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1707 | cifs_dbg(VFS, "%s: Invalid cruid value\n", |
| 1708 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1709 | goto cifs_parse_mount_err; |
| 1710 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1711 | break; |
| 1712 | case Opt_gid: |
Eric W. Biederman | 3da4656 | 2013-02-06 01:37:39 -0800 | [diff] [blame] | 1713 | if (get_option_gid(args, &vol->linux_gid)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1714 | cifs_dbg(VFS, "%s: Invalid gid value\n", |
| 1715 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1716 | goto cifs_parse_mount_err; |
| 1717 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1718 | gid_specified = true; |
| 1719 | break; |
| 1720 | case Opt_file_mode: |
| 1721 | if (get_option_ul(args, &option)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1722 | cifs_dbg(VFS, "%s: Invalid file_mode value\n", |
| 1723 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1724 | goto cifs_parse_mount_err; |
| 1725 | } |
| 1726 | vol->file_mode = option; |
| 1727 | break; |
| 1728 | case Opt_dirmode: |
| 1729 | if (get_option_ul(args, &option)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1730 | cifs_dbg(VFS, "%s: Invalid dir_mode value\n", |
| 1731 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1732 | goto cifs_parse_mount_err; |
| 1733 | } |
| 1734 | vol->dir_mode = option; |
| 1735 | break; |
| 1736 | case Opt_port: |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1737 | if (get_option_ul(args, &option) || |
| 1738 | option > USHRT_MAX) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1739 | cifs_dbg(VFS, "%s: Invalid port value\n", |
| 1740 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1741 | goto cifs_parse_mount_err; |
| 1742 | } |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1743 | port = (unsigned short)option; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1744 | break; |
| 1745 | case Opt_rsize: |
| 1746 | if (get_option_ul(args, &option)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1747 | cifs_dbg(VFS, "%s: Invalid rsize value\n", |
| 1748 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1749 | goto cifs_parse_mount_err; |
| 1750 | } |
| 1751 | vol->rsize = option; |
| 1752 | break; |
| 1753 | case Opt_wsize: |
| 1754 | if (get_option_ul(args, &option)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1755 | cifs_dbg(VFS, "%s: Invalid wsize value\n", |
| 1756 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1757 | goto cifs_parse_mount_err; |
| 1758 | } |
| 1759 | vol->wsize = option; |
| 1760 | break; |
| 1761 | case Opt_actimeo: |
| 1762 | if (get_option_ul(args, &option)) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1763 | cifs_dbg(VFS, "%s: Invalid actimeo value\n", |
| 1764 | __func__); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1765 | goto cifs_parse_mount_err; |
| 1766 | } |
| 1767 | vol->actimeo = HZ * option; |
| 1768 | if (vol->actimeo > CIFS_MAX_ACTIMEO) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1769 | cifs_dbg(VFS, "attribute cache timeout too large\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1770 | goto cifs_parse_mount_err; |
| 1771 | } |
| 1772 | break; |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 1773 | case Opt_echo_interval: |
| 1774 | if (get_option_ul(args, &option)) { |
| 1775 | cifs_dbg(VFS, "%s: Invalid echo interval value\n", |
| 1776 | __func__); |
| 1777 | goto cifs_parse_mount_err; |
| 1778 | } |
| 1779 | vol->echo_interval = option; |
| 1780 | break; |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 1781 | case Opt_snapshot: |
| 1782 | if (get_option_ul(args, &option)) { |
| 1783 | cifs_dbg(VFS, "%s: Invalid snapshot time\n", |
| 1784 | __func__); |
| 1785 | goto cifs_parse_mount_err; |
| 1786 | } |
| 1787 | vol->snapshot_time = option; |
| 1788 | break; |
Steve French | 141891f | 2016-09-23 00:44:16 -0500 | [diff] [blame] | 1789 | case Opt_max_credits: |
| 1790 | if (get_option_ul(args, &option) || (option < 20) || |
| 1791 | (option > 60000)) { |
| 1792 | cifs_dbg(VFS, "%s: Invalid max_credits value\n", |
| 1793 | __func__); |
| 1794 | goto cifs_parse_mount_err; |
| 1795 | } |
| 1796 | vol->max_credits = option; |
| 1797 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1798 | |
| 1799 | /* String Arguments */ |
| 1800 | |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 1801 | case Opt_blank_user: |
| 1802 | /* null user, ie. anonymous authentication */ |
| 1803 | vol->nullauth = 1; |
| 1804 | vol->username = NULL; |
| 1805 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1806 | case Opt_user: |
| 1807 | string = match_strdup(args); |
| 1808 | if (string == NULL) |
| 1809 | goto out_nomem; |
| 1810 | |
Scott Lovenberg | 8c3a2b4 | 2013-08-09 08:47:17 -0400 | [diff] [blame] | 1811 | if (strnlen(string, CIFS_MAX_USERNAME_LEN) > |
| 1812 | CIFS_MAX_USERNAME_LEN) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1813 | pr_warn("CIFS: username too long\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1814 | goto cifs_parse_mount_err; |
| 1815 | } |
Taesoo Kim | 2bd50fb | 2015-03-21 19:08:30 -0400 | [diff] [blame] | 1816 | |
| 1817 | kfree(vol->username); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1818 | vol->username = kstrdup(string, GFP_KERNEL); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1819 | if (!vol->username) |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1820 | goto cifs_parse_mount_err; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1821 | break; |
| 1822 | case Opt_blank_pass: |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1823 | /* passwords have to be handled differently |
| 1824 | * to allow the character used for deliminator |
| 1825 | * to be passed within them |
| 1826 | */ |
| 1827 | |
Sachin Prabhu | c369c9a | 2013-04-09 18:17:41 +0100 | [diff] [blame] | 1828 | /* |
| 1829 | * Check if this is a case where the password |
| 1830 | * starts with a delimiter |
| 1831 | */ |
| 1832 | tmp_end = strchr(data, '='); |
| 1833 | tmp_end++; |
| 1834 | if (!(tmp_end < end && tmp_end[1] == delim)) { |
| 1835 | /* No it is not. Set the password to NULL */ |
Aurelien Aptel | 97f4b72 | 2018-01-25 15:59:39 +0100 | [diff] [blame] | 1836 | kzfree(vol->password); |
Sachin Prabhu | c369c9a | 2013-04-09 18:17:41 +0100 | [diff] [blame] | 1837 | vol->password = NULL; |
| 1838 | break; |
| 1839 | } |
Gustavo A. R. Silva | 07fa601 | 2018-11-27 10:01:51 +1100 | [diff] [blame] | 1840 | /* Fallthrough - to Opt_pass below.*/ |
Sachin Prabhu | c369c9a | 2013-04-09 18:17:41 +0100 | [diff] [blame] | 1841 | case Opt_pass: |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1842 | /* Obtain the value string */ |
| 1843 | value = strchr(data, '='); |
Sachin Prabhu | 1023807 | 2012-03-28 18:07:08 +0100 | [diff] [blame] | 1844 | value++; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1845 | |
| 1846 | /* Set tmp_end to end of the string */ |
| 1847 | tmp_end = (char *) value + strlen(value); |
| 1848 | |
| 1849 | /* Check if following character is the deliminator |
| 1850 | * If yes, we have encountered a double deliminator |
| 1851 | * reset the NULL character to the deliminator |
| 1852 | */ |
Suresh Jayaraman | e73f843 | 2012-06-12 07:15:50 +0530 | [diff] [blame] | 1853 | if (tmp_end < end && tmp_end[1] == delim) { |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1854 | tmp_end[0] = delim; |
| 1855 | |
Suresh Jayaraman | e73f843 | 2012-06-12 07:15:50 +0530 | [diff] [blame] | 1856 | /* Keep iterating until we get to a single |
| 1857 | * deliminator OR the end |
| 1858 | */ |
| 1859 | while ((tmp_end = strchr(tmp_end, delim)) |
| 1860 | != NULL && (tmp_end[1] == delim)) { |
| 1861 | tmp_end = (char *) &tmp_end[2]; |
| 1862 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1863 | |
Suresh Jayaraman | e73f843 | 2012-06-12 07:15:50 +0530 | [diff] [blame] | 1864 | /* Reset var options to point to next element */ |
| 1865 | if (tmp_end) { |
| 1866 | tmp_end[0] = '\0'; |
| 1867 | options = (char *) &tmp_end[1]; |
| 1868 | } else |
| 1869 | /* Reached the end of the mount option |
| 1870 | * string */ |
| 1871 | options = end; |
| 1872 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1873 | |
Aurelien Aptel | 97f4b72 | 2018-01-25 15:59:39 +0100 | [diff] [blame] | 1874 | kzfree(vol->password); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1875 | /* Now build new password string */ |
| 1876 | temp_len = strlen(value); |
| 1877 | vol->password = kzalloc(temp_len+1, GFP_KERNEL); |
| 1878 | if (vol->password == NULL) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1879 | pr_warn("CIFS: no memory for password\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1880 | goto cifs_parse_mount_err; |
| 1881 | } |
| 1882 | |
| 1883 | for (i = 0, j = 0; i < temp_len; i++, j++) { |
| 1884 | vol->password[j] = value[i]; |
| 1885 | if ((value[i] == delim) && |
| 1886 | value[i+1] == delim) |
| 1887 | /* skip the second deliminator */ |
| 1888 | i++; |
| 1889 | } |
| 1890 | vol->password[j] = '\0'; |
| 1891 | break; |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 1892 | case Opt_blank_ip: |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1893 | /* FIXME: should this be an error instead? */ |
| 1894 | got_ip = false; |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 1895 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1896 | case Opt_ip: |
| 1897 | string = match_strdup(args); |
| 1898 | if (string == NULL) |
| 1899 | goto out_nomem; |
| 1900 | |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1901 | if (!cifs_convert_address(dstaddr, string, |
| 1902 | strlen(string))) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1903 | pr_err("CIFS: bad ip= option (%s).\n", string); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1904 | goto cifs_parse_mount_err; |
| 1905 | } |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 1906 | got_ip = true; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1907 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1908 | case Opt_domain: |
| 1909 | string = match_strdup(args); |
| 1910 | if (string == NULL) |
| 1911 | goto out_nomem; |
| 1912 | |
Chen Gang | 057d633 | 2013-07-19 09:01:36 +0800 | [diff] [blame] | 1913 | if (strnlen(string, CIFS_MAX_DOMAINNAME_LEN) |
| 1914 | == CIFS_MAX_DOMAINNAME_LEN) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1915 | pr_warn("CIFS: domain name too long\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1916 | goto cifs_parse_mount_err; |
| 1917 | } |
| 1918 | |
Taesoo Kim | 2bd50fb | 2015-03-21 19:08:30 -0400 | [diff] [blame] | 1919 | kfree(vol->domainname); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1920 | vol->domainname = kstrdup(string, GFP_KERNEL); |
| 1921 | if (!vol->domainname) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1922 | pr_warn("CIFS: no memory for domainname\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1923 | goto cifs_parse_mount_err; |
| 1924 | } |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1925 | cifs_dbg(FYI, "Domain name set\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1926 | break; |
| 1927 | case Opt_srcaddr: |
| 1928 | string = match_strdup(args); |
| 1929 | if (string == NULL) |
| 1930 | goto out_nomem; |
| 1931 | |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 1932 | if (!cifs_convert_address( |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1933 | (struct sockaddr *)&vol->srcaddr, |
| 1934 | string, strlen(string))) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1935 | pr_warn("CIFS: Could not parse srcaddr: %s\n", |
| 1936 | string); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1937 | goto cifs_parse_mount_err; |
| 1938 | } |
| 1939 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1940 | case Opt_iocharset: |
| 1941 | string = match_strdup(args); |
| 1942 | if (string == NULL) |
| 1943 | goto out_nomem; |
| 1944 | |
Sachin Prabhu | 4fe9e96 | 2012-04-10 18:12:27 +0100 | [diff] [blame] | 1945 | if (strnlen(string, 1024) >= 65) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1946 | pr_warn("CIFS: iocharset name too long.\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1947 | goto cifs_parse_mount_err; |
| 1948 | } |
| 1949 | |
Rasmus Villemoes | 87e747c | 2014-10-13 15:54:35 -0700 | [diff] [blame] | 1950 | if (strncasecmp(string, "default", 7) != 0) { |
Taesoo Kim | 2bd50fb | 2015-03-21 19:08:30 -0400 | [diff] [blame] | 1951 | kfree(vol->iocharset); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1952 | vol->iocharset = kstrdup(string, |
| 1953 | GFP_KERNEL); |
| 1954 | if (!vol->iocharset) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1955 | pr_warn("CIFS: no memory for charset\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1956 | goto cifs_parse_mount_err; |
| 1957 | } |
| 1958 | } |
| 1959 | /* if iocharset not set then load_nls_default |
| 1960 | * is used by caller |
| 1961 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 1962 | cifs_dbg(FYI, "iocharset set to %s\n", string); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1963 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1964 | case Opt_netbiosname: |
| 1965 | string = match_strdup(args); |
| 1966 | if (string == NULL) |
| 1967 | goto out_nomem; |
| 1968 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1969 | memset(vol->source_rfc1001_name, 0x20, |
| 1970 | RFC1001_NAME_LEN); |
| 1971 | /* |
| 1972 | * FIXME: are there cases in which a comma can |
| 1973 | * be valid in workstation netbios name (and |
| 1974 | * need special handling)? |
| 1975 | */ |
| 1976 | for (i = 0; i < RFC1001_NAME_LEN; i++) { |
| 1977 | /* don't ucase netbiosname for user */ |
| 1978 | if (string[i] == 0) |
| 1979 | break; |
| 1980 | vol->source_rfc1001_name[i] = string[i]; |
| 1981 | } |
| 1982 | /* The string has 16th byte zero still from |
| 1983 | * set at top of the function |
| 1984 | */ |
| 1985 | if (i == RFC1001_NAME_LEN && string[i] != 0) |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 1986 | pr_warn("CIFS: netbiosname longer than 15 truncated.\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1987 | break; |
| 1988 | case Opt_servern: |
| 1989 | /* servernetbiosname specified override *SMBSERVER */ |
| 1990 | string = match_strdup(args); |
| 1991 | if (string == NULL) |
| 1992 | goto out_nomem; |
| 1993 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 1994 | /* last byte, type, is 0x20 for servr type */ |
| 1995 | memset(vol->target_rfc1001_name, 0x20, |
| 1996 | RFC1001_NAME_LEN_WITH_NULL); |
| 1997 | |
| 1998 | /* BB are there cases in which a comma can be |
| 1999 | valid in this workstation netbios name |
| 2000 | (and need special handling)? */ |
| 2001 | |
| 2002 | /* user or mount helper must uppercase the |
| 2003 | netbios name */ |
| 2004 | for (i = 0; i < 15; i++) { |
| 2005 | if (string[i] == 0) |
| 2006 | break; |
| 2007 | vol->target_rfc1001_name[i] = string[i]; |
| 2008 | } |
| 2009 | /* The string has 16th byte zero still from |
| 2010 | set at top of the function */ |
| 2011 | if (i == RFC1001_NAME_LEN && string[i] != 0) |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2012 | pr_warn("CIFS: server netbiosname longer than 15 truncated.\n"); |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2013 | break; |
| 2014 | case Opt_ver: |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2015 | /* version of mount userspace tools, not dialect */ |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2016 | string = match_strdup(args); |
| 2017 | if (string == NULL) |
| 2018 | goto out_nomem; |
| 2019 | |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2020 | /* If interface changes in mount.cifs bump to new ver */ |
Rasmus Villemoes | 87e747c | 2014-10-13 15:54:35 -0700 | [diff] [blame] | 2021 | if (strncasecmp(string, "1", 1) == 0) { |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2022 | if (strlen(string) > 1) { |
| 2023 | pr_warn("Bad mount helper ver=%s. Did " |
| 2024 | "you want SMB1 (CIFS) dialect " |
| 2025 | "and mean to type vers=1.0 " |
| 2026 | "instead?\n", string); |
| 2027 | goto cifs_parse_mount_err; |
| 2028 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2029 | /* This is the default */ |
| 2030 | break; |
| 2031 | } |
| 2032 | /* For all other value, error */ |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2033 | pr_warn("CIFS: Invalid mount helper version specified\n"); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2034 | goto cifs_parse_mount_err; |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2035 | case Opt_vers: |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2036 | /* protocol version (dialect) */ |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2037 | string = match_strdup(args); |
| 2038 | if (string == NULL) |
| 2039 | goto out_nomem; |
| 2040 | |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 2041 | if (cifs_parse_smb_version(string, vol, is_smb3) != 0) |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2042 | goto cifs_parse_mount_err; |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2043 | got_version = true; |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2044 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2045 | case Opt_sec: |
| 2046 | string = match_strdup(args); |
| 2047 | if (string == NULL) |
| 2048 | goto out_nomem; |
| 2049 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2050 | if (cifs_parse_security_flavors(string, vol) != 0) |
| 2051 | goto cifs_parse_mount_err; |
| 2052 | break; |
Jeff Layton | 15b6a47 | 2012-05-16 07:50:15 -0400 | [diff] [blame] | 2053 | case Opt_cache: |
| 2054 | string = match_strdup(args); |
| 2055 | if (string == NULL) |
| 2056 | goto out_nomem; |
| 2057 | |
| 2058 | if (cifs_parse_cache_flavor(string, vol) != 0) |
| 2059 | goto cifs_parse_mount_err; |
| 2060 | break; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2061 | default: |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2062 | /* |
| 2063 | * An option we don't recognize. Save it off for later |
| 2064 | * if we haven't already found one |
| 2065 | */ |
| 2066 | if (!invalid) |
| 2067 | invalid = data; |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2068 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | } |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2070 | /* Free up any allocated string */ |
| 2071 | kfree(string); |
| 2072 | string = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
Jeff Layton | 0eb8a13 | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 2074 | |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2075 | if (!sloppy && invalid) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2076 | pr_err("CIFS: Unknown mount option \"%s\"\n", invalid); |
Jeff Layton | d816255 | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2077 | goto cifs_parse_mount_err; |
| 2078 | } |
| 2079 | |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 2080 | if (vol->rdma && vol->vals->protocol_id < SMB30_PROT_ID) { |
| 2081 | cifs_dbg(VFS, "SMB Direct requires Version >=3.0\n"); |
| 2082 | goto cifs_parse_mount_err; |
| 2083 | } |
| 2084 | |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2085 | #ifndef CONFIG_KEYS |
| 2086 | /* Muliuser mounts require CONFIG_KEYS support */ |
| 2087 | if (vol->multiuser) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2088 | cifs_dbg(VFS, "Multiuser mounts require kernels with CONFIG_KEYS enabled\n"); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2089 | goto cifs_parse_mount_err; |
Jeff Layton | 0eb8a13 | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 2090 | } |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2091 | #endif |
Jeff Layton | e5e69ab | 2012-11-25 08:00:42 -0500 | [diff] [blame] | 2092 | if (!vol->UNC) { |
Jeff Layton | 37d4f99 | 2013-05-24 07:40:05 -0400 | [diff] [blame] | 2093 | cifs_dbg(VFS, "CIFS mount error: No usable UNC path provided in device string!\n"); |
Jeff Layton | e5e69ab | 2012-11-25 08:00:42 -0500 | [diff] [blame] | 2094 | goto cifs_parse_mount_err; |
| 2095 | } |
Jeff Layton | 0eb8a13 | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 2096 | |
Jeff Layton | 62a1a43 | 2012-12-10 06:10:45 -0500 | [diff] [blame] | 2097 | /* make sure UNC has a share name */ |
| 2098 | if (!strchr(vol->UNC + 3, '\\')) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2099 | cifs_dbg(VFS, "Malformed UNC. Unable to find share name.\n"); |
Jeff Layton | 62a1a43 | 2012-12-10 06:10:45 -0500 | [diff] [blame] | 2100 | goto cifs_parse_mount_err; |
| 2101 | } |
| 2102 | |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 2103 | if (!got_ip) { |
Daniel N Pettersson | 29bb315 | 2017-04-27 11:32:36 +0200 | [diff] [blame] | 2104 | int len; |
| 2105 | const char *slash; |
| 2106 | |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 2107 | /* No ip= option specified? Try to get it from UNC */ |
Daniel N Pettersson | 29bb315 | 2017-04-27 11:32:36 +0200 | [diff] [blame] | 2108 | /* Use the address part of the UNC. */ |
| 2109 | slash = strchr(&vol->UNC[2], '\\'); |
| 2110 | len = slash - &vol->UNC[2]; |
| 2111 | if (!cifs_convert_address(dstaddr, &vol->UNC[2], len)) { |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2112 | pr_err("Unable to determine destination address.\n"); |
Jeff Layton | b979aaa | 2012-11-26 11:09:55 -0500 | [diff] [blame] | 2113 | goto cifs_parse_mount_err; |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | /* set the port that we got earlier */ |
| 2118 | cifs_set_port(dstaddr, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 2120 | if (uid_specified) |
| 2121 | vol->override_uid = override_uid; |
| 2122 | else if (override_uid == 1) |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2123 | pr_notice("CIFS: ignoring forceuid mount option specified with no uid= option.\n"); |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 2124 | |
| 2125 | if (gid_specified) |
| 2126 | vol->override_gid = override_gid; |
| 2127 | else if (override_gid == 1) |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2128 | pr_notice("CIFS: ignoring forcegid mount option specified with no gid= option.\n"); |
Jeff Layton | 9b9d6b24 | 2009-07-31 06:56:09 -0400 | [diff] [blame] | 2129 | |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2130 | if (got_version == false) |
| 2131 | pr_warn("No dialect specified on mount. Default has changed to " |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 2132 | "a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS " |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2133 | "(SMB1). To use the less secure SMB1 dialect to access " |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 2134 | "old servers which do not support SMB3 (or SMB2.1) specify vers=1.0" |
| 2135 | " on mount.\n"); |
Steve French | 7e682f7 | 2017-08-31 21:34:24 -0500 | [diff] [blame] | 2136 | |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2137 | kfree(mountdata_copy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | return 0; |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2139 | |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2140 | out_nomem: |
Andy Shevchenko | 0b456f0 | 2014-08-27 16:49:44 +0300 | [diff] [blame] | 2141 | pr_warn("Could not allocate temporary buffer\n"); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2142 | cifs_parse_mount_err: |
Sachin Prabhu | 8830d7e | 2012-03-23 14:40:56 -0400 | [diff] [blame] | 2143 | kfree(string); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 2144 | kfree(mountdata_copy); |
| 2145 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 2148 | /** Returns true if srcaddr isn't specified and rhs isn't |
| 2149 | * specified, or if srcaddr is specified and |
| 2150 | * matches the IP address of the rhs argument. |
| 2151 | */ |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2152 | static bool |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 2153 | srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs) |
| 2154 | { |
| 2155 | switch (srcaddr->sa_family) { |
| 2156 | case AF_UNSPEC: |
| 2157 | return (rhs->sa_family == AF_UNSPEC); |
| 2158 | case AF_INET: { |
| 2159 | struct sockaddr_in *saddr4 = (struct sockaddr_in *)srcaddr; |
| 2160 | struct sockaddr_in *vaddr4 = (struct sockaddr_in *)rhs; |
| 2161 | return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr); |
| 2162 | } |
| 2163 | case AF_INET6: { |
| 2164 | struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)srcaddr; |
Nickolai Zeldovich | e3e2775 | 2013-01-16 21:36:17 -0500 | [diff] [blame] | 2165 | struct sockaddr_in6 *vaddr6 = (struct sockaddr_in6 *)rhs; |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 2166 | return ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr); |
| 2167 | } |
| 2168 | default: |
| 2169 | WARN_ON(1); |
| 2170 | return false; /* don't expect to be here */ |
| 2171 | } |
| 2172 | } |
| 2173 | |
Pavel Shilovsky | 4b88613 | 2010-12-13 22:18:07 +0300 | [diff] [blame] | 2174 | /* |
| 2175 | * If no port is specified in addr structure, we try to match with 445 port |
| 2176 | * and if it fails - with 139 ports. It should be called only if address |
| 2177 | * families of server and addr are equal. |
| 2178 | */ |
| 2179 | static bool |
| 2180 | match_port(struct TCP_Server_Info *server, struct sockaddr *addr) |
| 2181 | { |
Steve French | 6da9791 | 2011-03-13 18:55:55 +0000 | [diff] [blame] | 2182 | __be16 port, *sport; |
Pavel Shilovsky | 4b88613 | 2010-12-13 22:18:07 +0300 | [diff] [blame] | 2183 | |
| 2184 | switch (addr->sa_family) { |
| 2185 | case AF_INET: |
| 2186 | sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port; |
| 2187 | port = ((struct sockaddr_in *) addr)->sin_port; |
| 2188 | break; |
| 2189 | case AF_INET6: |
| 2190 | sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port; |
| 2191 | port = ((struct sockaddr_in6 *) addr)->sin6_port; |
| 2192 | break; |
| 2193 | default: |
| 2194 | WARN_ON(1); |
| 2195 | return false; |
| 2196 | } |
| 2197 | |
| 2198 | if (!port) { |
| 2199 | port = htons(CIFS_PORT); |
| 2200 | if (port == *sport) |
| 2201 | return true; |
| 2202 | |
| 2203 | port = htons(RFC1001_PORT); |
| 2204 | } |
| 2205 | |
| 2206 | return port == *sport; |
| 2207 | } |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 2208 | |
| 2209 | static bool |
| 2210 | match_address(struct TCP_Server_Info *server, struct sockaddr *addr, |
| 2211 | struct sockaddr *srcaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | { |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2213 | switch (addr->sa_family) { |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2214 | case AF_INET: { |
| 2215 | struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; |
| 2216 | struct sockaddr_in *srv_addr4 = |
| 2217 | (struct sockaddr_in *)&server->dstaddr; |
| 2218 | |
| 2219 | if (addr4->sin_addr.s_addr != srv_addr4->sin_addr.s_addr) |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2220 | return false; |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2221 | break; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2222 | } |
| 2223 | case AF_INET6: { |
| 2224 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; |
| 2225 | struct sockaddr_in6 *srv_addr6 = |
| 2226 | (struct sockaddr_in6 *)&server->dstaddr; |
| 2227 | |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2228 | if (!ipv6_addr_equal(&addr6->sin6_addr, |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2229 | &srv_addr6->sin6_addr)) |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2230 | return false; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2231 | if (addr6->sin6_scope_id != srv_addr6->sin6_scope_id) |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2232 | return false; |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2233 | break; |
| 2234 | } |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2235 | default: |
| 2236 | WARN_ON(1); |
| 2237 | return false; /* don't expect to be here */ |
| 2238 | } |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2239 | |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 2240 | if (!srcip_matches(srcaddr, (struct sockaddr *)&server->srcaddr)) |
| 2241 | return false; |
| 2242 | |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2243 | return true; |
| 2244 | } |
| 2245 | |
Jeff Layton | daf5b0b | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2246 | static bool |
| 2247 | match_security(struct TCP_Server_Info *server, struct smb_vol *vol) |
| 2248 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 2249 | /* |
| 2250 | * The select_sectype function should either return the vol->sectype |
| 2251 | * that was specified, or "Unspecified" if that sectype was not |
| 2252 | * compatible with the given NEGOTIATE request. |
| 2253 | */ |
Sachin Prabhu | ef65aae | 2017-01-18 15:35:57 +0530 | [diff] [blame] | 2254 | if (server->ops->select_sectype(server, vol->sectype) |
| 2255 | == Unspecified) |
Jeff Layton | daf5b0b | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2256 | return false; |
Jeff Layton | daf5b0b | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2257 | |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 2258 | /* |
| 2259 | * Now check if signing mode is acceptable. No need to check |
| 2260 | * global_secflags at this point since if MUST_SIGN is set then |
| 2261 | * the server->sign had better be too. |
| 2262 | */ |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 2263 | if (vol->sign && !server->sign) |
| 2264 | return false; |
Jeff Layton | daf5b0b | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2265 | |
| 2266 | return true; |
| 2267 | } |
| 2268 | |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2269 | static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2270 | { |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2271 | struct sockaddr *addr = (struct sockaddr *)&vol->dstaddr; |
| 2272 | |
Jeff Layton | a0b3df5 | 2013-05-24 07:40:59 -0400 | [diff] [blame] | 2273 | if (vol->nosharesock) |
| 2274 | return 0; |
| 2275 | |
Steve French | 9764c02 | 2017-09-17 10:41:35 -0500 | [diff] [blame] | 2276 | /* BB update this for smb3any and default case */ |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2277 | if ((server->vals != vol->vals) || (server->ops != vol->ops)) |
| 2278 | return 0; |
| 2279 | |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2280 | if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) |
| 2281 | return 0; |
| 2282 | |
| 2283 | if (!match_address(server, addr, |
| 2284 | (struct sockaddr *)&vol->srcaddr)) |
| 2285 | return 0; |
| 2286 | |
| 2287 | if (!match_port(server, addr)) |
| 2288 | return 0; |
| 2289 | |
| 2290 | if (!match_security(server, vol)) |
| 2291 | return 0; |
| 2292 | |
Rabin Vincent | b782fcc | 2016-07-19 09:25:45 +0200 | [diff] [blame] | 2293 | if (server->echo_interval != vol->echo_interval * HZ) |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 2294 | return 0; |
| 2295 | |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 2296 | if (server->rdma != vol->rdma) |
| 2297 | return 0; |
| 2298 | |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2299 | return 1; |
| 2300 | } |
| 2301 | |
Paulo Alcantara | 54be1f6 | 2018-11-14 16:01:21 -0200 | [diff] [blame] | 2302 | struct TCP_Server_Info * |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2303 | cifs_find_tcp_session(struct smb_vol *vol) |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2304 | { |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2305 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2307 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 4515148 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2308 | list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2309 | if (!match_server(server, vol)) |
Jeff Layton | daf5b0b | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2310 | continue; |
| 2311 | |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2312 | ++server->srv_count; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2313 | spin_unlock(&cifs_tcp_ses_lock); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2314 | cifs_dbg(FYI, "Existing tcp session with server found\n"); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2315 | return server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2317 | spin_unlock(&cifs_tcp_ses_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | return NULL; |
| 2319 | } |
| 2320 | |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2321 | void |
| 2322 | cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | { |
Steve French | a5c3e1c | 2014-09-16 04:16:19 -0500 | [diff] [blame] | 2324 | struct task_struct *task; |
| 2325 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2326 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2327 | if (--server->srv_count > 0) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2328 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2329 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | } |
Steve French | dea570e0 | 2008-05-06 22:05:51 +0000 | [diff] [blame] | 2331 | |
Rob Landley | f1d0c99 | 2011-01-22 15:44:05 -0600 | [diff] [blame] | 2332 | put_net(cifs_net_ns(server)); |
| 2333 | |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2334 | list_del_init(&server->tcp_ses_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2335 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2336 | |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 2337 | cancel_delayed_work_sync(&server->echo); |
| 2338 | |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2339 | if (from_reconnect) |
| 2340 | /* |
| 2341 | * Avoid deadlock here: reconnect work calls |
| 2342 | * cifs_put_tcp_session() at its end. Need to be sure |
| 2343 | * that reconnect work does nothing with server pointer after |
| 2344 | * that step. |
| 2345 | */ |
| 2346 | cancel_delayed_work(&server->reconnect); |
| 2347 | else |
| 2348 | cancel_delayed_work_sync(&server->reconnect); |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2349 | |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 2350 | spin_lock(&GlobalMid_Lock); |
| 2351 | server->tcpStatus = CifsExiting; |
| 2352 | spin_unlock(&GlobalMid_Lock); |
| 2353 | |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2354 | cifs_crypto_secmech_release(server); |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 2355 | cifs_fscache_release_client_cookie(server); |
| 2356 | |
Shirish Pargaonkar | 21e7339 | 2010-10-21 06:42:55 -0500 | [diff] [blame] | 2357 | kfree(server->session_key.response); |
| 2358 | server->session_key.response = NULL; |
| 2359 | server->session_key.len = 0; |
Steve French | a5c3e1c | 2014-09-16 04:16:19 -0500 | [diff] [blame] | 2360 | |
| 2361 | task = xchg(&server->tsk, NULL); |
| 2362 | if (task) |
| 2363 | force_sig(SIGKILL, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2366 | static struct TCP_Server_Info * |
| 2367 | cifs_get_tcp_session(struct smb_vol *volume_info) |
| 2368 | { |
| 2369 | struct TCP_Server_Info *tcp_ses = NULL; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2370 | int rc; |
| 2371 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2372 | cifs_dbg(FYI, "UNC: %s\n", volume_info->UNC); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2373 | |
| 2374 | /* see if we already have a matching tcp_ses */ |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2375 | tcp_ses = cifs_find_tcp_session(volume_info); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2376 | if (tcp_ses) |
| 2377 | return tcp_ses; |
| 2378 | |
| 2379 | tcp_ses = kzalloc(sizeof(struct TCP_Server_Info), GFP_KERNEL); |
| 2380 | if (!tcp_ses) { |
| 2381 | rc = -ENOMEM; |
| 2382 | goto out_err; |
| 2383 | } |
| 2384 | |
Jeff Layton | 23db65f | 2012-05-15 12:20:51 -0400 | [diff] [blame] | 2385 | tcp_ses->ops = volume_info->ops; |
| 2386 | tcp_ses->vals = volume_info->vals; |
Rob Landley | f1d0c99 | 2011-01-22 15:44:05 -0600 | [diff] [blame] | 2387 | cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2388 | tcp_ses->hostname = extract_hostname(volume_info->UNC); |
| 2389 | if (IS_ERR(tcp_ses->hostname)) { |
| 2390 | rc = PTR_ERR(tcp_ses->hostname); |
Shirish Pargaonkar | f7c5445a | 2010-10-26 18:10:24 -0500 | [diff] [blame] | 2391 | goto out_err_crypto_release; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | tcp_ses->noblocksnd = volume_info->noblocksnd; |
| 2395 | tcp_ses->noautotune = volume_info->noautotune; |
Steve French | 6a5fa236 | 2010-01-01 01:28:43 +0000 | [diff] [blame] | 2396 | tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay; |
Long Li | 8339dd3 | 2017-11-07 01:54:55 -0700 | [diff] [blame] | 2397 | tcp_ses->rdma = volume_info->rdma; |
Pavel Shilovsky | fc40f9c | 2012-02-17 17:09:12 +0300 | [diff] [blame] | 2398 | tcp_ses->in_flight = 0; |
Pavel Shilovsky | 2d86dbc | 2012-02-06 15:59:18 +0400 | [diff] [blame] | 2399 | tcp_ses->credits = 1; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2400 | init_waitqueue_head(&tcp_ses->response_q); |
| 2401 | init_waitqueue_head(&tcp_ses->request_q); |
| 2402 | INIT_LIST_HEAD(&tcp_ses->pending_mid_q); |
| 2403 | mutex_init(&tcp_ses->srv_mutex); |
| 2404 | memcpy(tcp_ses->workstation_RFC1001_name, |
| 2405 | volume_info->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); |
| 2406 | memcpy(tcp_ses->server_RFC1001_name, |
| 2407 | volume_info->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); |
Shirish Pargaonkar | 5d0d288 | 2010-10-13 18:15:00 -0500 | [diff] [blame] | 2408 | tcp_ses->session_estab = false; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2409 | tcp_ses->sequence_number = 0; |
Steve French | 9e1a37d | 2018-09-19 02:38:17 -0500 | [diff] [blame] | 2410 | tcp_ses->reconnect_instance = 0; |
Steve French | fda3594 | 2011-01-20 18:06:34 +0000 | [diff] [blame] | 2411 | tcp_ses->lstrp = jiffies; |
Jeff Layton | 58fa015 | 2012-05-01 17:41:16 -0400 | [diff] [blame] | 2412 | spin_lock_init(&tcp_ses->req_lock); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2413 | INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); |
| 2414 | INIT_LIST_HEAD(&tcp_ses->smb_ses_list); |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 2415 | INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2416 | INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); |
| 2417 | mutex_init(&tcp_ses->reconnect_mutex); |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 2418 | memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr, |
| 2419 | sizeof(tcp_ses->srcaddr)); |
| 2420 | memcpy(&tcp_ses->dstaddr, &volume_info->dstaddr, |
| 2421 | sizeof(tcp_ses->dstaddr)); |
Steve French | fa70b87 | 2016-09-22 00:39:34 -0500 | [diff] [blame] | 2422 | generate_random_uuid(tcp_ses->client_guid); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2423 | /* |
| 2424 | * at this point we are the only ones with the pointer |
| 2425 | * to the struct since the kernel thread not created yet |
| 2426 | * no need to spinlock this init of tcpStatus or srv_count |
| 2427 | */ |
| 2428 | tcp_ses->tcpStatus = CifsNew; |
| 2429 | ++tcp_ses->srv_count; |
| 2430 | |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 2431 | if (volume_info->echo_interval >= SMB_ECHO_INTERVAL_MIN && |
| 2432 | volume_info->echo_interval <= SMB_ECHO_INTERVAL_MAX) |
| 2433 | tcp_ses->echo_interval = volume_info->echo_interval * HZ; |
| 2434 | else |
| 2435 | tcp_ses->echo_interval = SMB_ECHO_INTERVAL_DEFAULT * HZ; |
Long Li | 2f89464 | 2017-11-22 17:38:34 -0700 | [diff] [blame] | 2436 | if (tcp_ses->rdma) { |
| 2437 | #ifndef CONFIG_CIFS_SMB_DIRECT |
| 2438 | cifs_dbg(VFS, "CONFIG_CIFS_SMB_DIRECT is not enabled\n"); |
| 2439 | rc = -ENOENT; |
| 2440 | goto out_err_crypto_release; |
| 2441 | #endif |
| 2442 | tcp_ses->smbd_conn = smbd_get_connection( |
| 2443 | tcp_ses, (struct sockaddr *)&volume_info->dstaddr); |
| 2444 | if (tcp_ses->smbd_conn) { |
| 2445 | cifs_dbg(VFS, "RDMA transport established\n"); |
| 2446 | rc = 0; |
| 2447 | goto smbd_connected; |
| 2448 | } else { |
| 2449 | rc = -ENOENT; |
| 2450 | goto out_err_crypto_release; |
| 2451 | } |
| 2452 | } |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2453 | rc = ip_connect(tcp_ses); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2454 | if (rc < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2455 | cifs_dbg(VFS, "Error connecting to socket. Aborting operation.\n"); |
Shirish Pargaonkar | f7c5445a | 2010-10-26 18:10:24 -0500 | [diff] [blame] | 2456 | goto out_err_crypto_release; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2457 | } |
Long Li | 2f89464 | 2017-11-22 17:38:34 -0700 | [diff] [blame] | 2458 | smbd_connected: |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2459 | /* |
| 2460 | * since we're in a cifs function already, we know that |
| 2461 | * this will succeed. No need for try_module_get(). |
| 2462 | */ |
| 2463 | __module_get(THIS_MODULE); |
Al Viro | 7c97c20 | 2011-06-21 08:51:28 -0400 | [diff] [blame] | 2464 | tcp_ses->tsk = kthread_run(cifs_demultiplex_thread, |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2465 | tcp_ses, "cifsd"); |
| 2466 | if (IS_ERR(tcp_ses->tsk)) { |
| 2467 | rc = PTR_ERR(tcp_ses->tsk); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2468 | cifs_dbg(VFS, "error %d create cifsd thread\n", rc); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2469 | module_put(THIS_MODULE); |
Shirish Pargaonkar | f7c5445a | 2010-10-26 18:10:24 -0500 | [diff] [blame] | 2470 | goto out_err_crypto_release; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2471 | } |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 2472 | tcp_ses->tcpStatus = CifsNeedNegotiate; |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2473 | |
| 2474 | /* thread spawned, put it on the list */ |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2475 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2476 | list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2477 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2478 | |
Suresh Jayaraman | 488f1d2d | 2010-07-05 18:12:15 +0530 | [diff] [blame] | 2479 | cifs_fscache_get_client_cookie(tcp_ses); |
| 2480 | |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 2481 | /* queue echo request delayed work */ |
Steve French | adfeb3e | 2015-12-18 12:31:36 -0600 | [diff] [blame] | 2482 | queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval); |
Jeff Layton | c74093b | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 2483 | |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2484 | return tcp_ses; |
| 2485 | |
Shirish Pargaonkar | f7c5445a | 2010-10-26 18:10:24 -0500 | [diff] [blame] | 2486 | out_err_crypto_release: |
Pavel Shilovsky | 026e93d | 2016-11-03 16:47:37 -0700 | [diff] [blame] | 2487 | cifs_crypto_secmech_release(tcp_ses); |
Shirish Pargaonkar | d2b9152 | 2010-10-21 14:25:08 -0500 | [diff] [blame] | 2488 | |
Rob Landley | f1d0c99 | 2011-01-22 15:44:05 -0600 | [diff] [blame] | 2489 | put_net(cifs_net_ns(tcp_ses)); |
| 2490 | |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2491 | out_err: |
| 2492 | if (tcp_ses) { |
Steve French | 8347a5c | 2009-10-06 18:31:29 +0000 | [diff] [blame] | 2493 | if (!IS_ERR(tcp_ses->hostname)) |
| 2494 | kfree(tcp_ses->hostname); |
Jeff Layton | 63c038c | 2008-12-01 18:41:46 -0500 | [diff] [blame] | 2495 | if (tcp_ses->ssocket) |
| 2496 | sock_release(tcp_ses->ssocket); |
| 2497 | kfree(tcp_ses); |
| 2498 | } |
| 2499 | return ERR_PTR(rc); |
| 2500 | } |
| 2501 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2502 | static int match_session(struct cifs_ses *ses, struct smb_vol *vol) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2503 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 2504 | if (vol->sectype != Unspecified && |
| 2505 | vol->sectype != ses->sectype) |
| 2506 | return 0; |
| 2507 | |
| 2508 | switch (ses->sectype) { |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2509 | case Kerberos: |
Eric W. Biederman | 64ed39d | 2013-02-06 02:30:39 -0800 | [diff] [blame] | 2510 | if (!uid_eq(vol->cred_uid, ses->cred_uid)) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2511 | return 0; |
| 2512 | break; |
| 2513 | default: |
Jeff Layton | 04febab | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2514 | /* NULL username means anonymous session */ |
| 2515 | if (ses->user_name == NULL) { |
| 2516 | if (!vol->nullauth) |
| 2517 | return 0; |
| 2518 | break; |
| 2519 | } |
| 2520 | |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2521 | /* anything else takes username/password */ |
Jeff Layton | 04febab | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2522 | if (strncmp(ses->user_name, |
| 2523 | vol->username ? vol->username : "", |
Scott Lovenberg | 8c3a2b4 | 2013-08-09 08:47:17 -0400 | [diff] [blame] | 2524 | CIFS_MAX_USERNAME_LEN)) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2525 | return 0; |
Jeff Layton | 08b37d5 | 2014-05-23 06:53:10 -0400 | [diff] [blame] | 2526 | if ((vol->username && strlen(vol->username) != 0) && |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2527 | ses->password != NULL && |
| 2528 | strncmp(ses->password, |
| 2529 | vol->password ? vol->password : "", |
Scott Lovenberg | 8c3a2b4 | 2013-08-09 08:47:17 -0400 | [diff] [blame] | 2530 | CIFS_MAX_PASSWORD_LEN)) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2531 | return 0; |
| 2532 | } |
| 2533 | return 1; |
| 2534 | } |
| 2535 | |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2536 | /** |
| 2537 | * cifs_setup_ipc - helper to setup the IPC tcon for the session |
| 2538 | * |
| 2539 | * A new IPC connection is made and stored in the session |
| 2540 | * tcon_ipc. The IPC tcon has the same lifetime as the session. |
| 2541 | */ |
| 2542 | static int |
| 2543 | cifs_setup_ipc(struct cifs_ses *ses, struct smb_vol *volume_info) |
| 2544 | { |
| 2545 | int rc = 0, xid; |
| 2546 | struct cifs_tcon *tcon; |
| 2547 | struct nls_table *nls_codepage; |
| 2548 | char unc[SERVER_NAME_LENGTH + sizeof("//x/IPC$")] = {0}; |
| 2549 | bool seal = false; |
| 2550 | |
| 2551 | /* |
| 2552 | * If the mount request that resulted in the creation of the |
| 2553 | * session requires encryption, force IPC to be encrypted too. |
| 2554 | */ |
| 2555 | if (volume_info->seal) { |
| 2556 | if (ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) |
| 2557 | seal = true; |
| 2558 | else { |
| 2559 | cifs_dbg(VFS, |
| 2560 | "IPC: server doesn't support encryption\n"); |
| 2561 | return -EOPNOTSUPP; |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | tcon = tconInfoAlloc(); |
| 2566 | if (tcon == NULL) |
| 2567 | return -ENOMEM; |
| 2568 | |
Thomas Werschlein | 395a207 | 2018-08-30 18:29:20 +0200 | [diff] [blame] | 2569 | snprintf(unc, sizeof(unc), "\\\\%s\\IPC$", ses->server->hostname); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2570 | |
| 2571 | /* cannot fail */ |
| 2572 | nls_codepage = load_nls_default(); |
| 2573 | |
| 2574 | xid = get_xid(); |
| 2575 | tcon->ses = ses; |
| 2576 | tcon->ipc = true; |
| 2577 | tcon->seal = seal; |
| 2578 | rc = ses->server->ops->tree_connect(xid, ses, unc, tcon, nls_codepage); |
| 2579 | free_xid(xid); |
| 2580 | |
| 2581 | if (rc) { |
| 2582 | cifs_dbg(VFS, "failed to connect to IPC (rc=%d)\n", rc); |
| 2583 | tconInfoFree(tcon); |
| 2584 | goto out; |
| 2585 | } |
| 2586 | |
| 2587 | cifs_dbg(FYI, "IPC tcon rc = %d ipc tid = %d\n", rc, tcon->tid); |
| 2588 | |
| 2589 | ses->tcon_ipc = tcon; |
| 2590 | out: |
| 2591 | unload_nls(nls_codepage); |
| 2592 | return rc; |
| 2593 | } |
| 2594 | |
| 2595 | /** |
| 2596 | * cifs_free_ipc - helper to release the session IPC tcon |
| 2597 | * |
| 2598 | * Needs to be called everytime a session is destroyed |
| 2599 | */ |
| 2600 | static int |
| 2601 | cifs_free_ipc(struct cifs_ses *ses) |
| 2602 | { |
| 2603 | int rc = 0, xid; |
| 2604 | struct cifs_tcon *tcon = ses->tcon_ipc; |
| 2605 | |
| 2606 | if (tcon == NULL) |
| 2607 | return 0; |
| 2608 | |
| 2609 | if (ses->server->ops->tree_disconnect) { |
| 2610 | xid = get_xid(); |
| 2611 | rc = ses->server->ops->tree_disconnect(xid, tcon); |
| 2612 | free_xid(xid); |
| 2613 | } |
| 2614 | |
| 2615 | if (rc) |
| 2616 | cifs_dbg(FYI, "failed to disconnect IPC tcon (rc=%d)\n", rc); |
| 2617 | |
| 2618 | tconInfoFree(tcon); |
| 2619 | ses->tcon_ipc = NULL; |
| 2620 | return rc; |
| 2621 | } |
| 2622 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2623 | static struct cifs_ses * |
Jeff Layton | 4ff67b7 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2624 | cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2626 | struct cifs_ses *ses; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2628 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 4ff67b7 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2629 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2630 | if (ses->status == CifsExiting) |
| 2631 | continue; |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2632 | if (!match_session(ses, vol)) |
| 2633 | continue; |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2634 | ++ses->ses_count; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2635 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2636 | return ses; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2638 | spin_unlock(&cifs_tcp_ses_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | return NULL; |
| 2640 | } |
| 2641 | |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2642 | static void |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2643 | cifs_put_smb_ses(struct cifs_ses *ses) |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2644 | { |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2645 | unsigned int rc, xid; |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2646 | struct TCP_Server_Info *server = ses->server; |
| 2647 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2648 | cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count); |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2649 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2650 | spin_lock(&cifs_tcp_ses_lock); |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2651 | if (ses->status == CifsExiting) { |
| 2652 | spin_unlock(&cifs_tcp_ses_lock); |
| 2653 | return; |
| 2654 | } |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2655 | if (--ses->ses_count > 0) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2656 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2657 | return; |
| 2658 | } |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2659 | if (ses->status == CifsGood) |
| 2660 | ses->status = CifsExiting; |
| 2661 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2662 | |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2663 | cifs_free_ipc(ses); |
| 2664 | |
Shirish Pargaonkar | 7f48558 | 2013-10-12 10:06:03 -0500 | [diff] [blame] | 2665 | if (ses->status == CifsExiting && server->ops->logoff) { |
| 2666 | xid = get_xid(); |
| 2667 | rc = server->ops->logoff(xid, ses); |
| 2668 | if (rc) |
| 2669 | cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n", |
| 2670 | __func__, rc); |
| 2671 | _free_xid(xid); |
| 2672 | } |
| 2673 | |
| 2674 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2675 | list_del_init(&ses->smb_ses_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2676 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2677 | |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2678 | sesInfoFree(ses); |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2679 | cifs_put_tcp_session(server, 0); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 2680 | } |
| 2681 | |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2682 | #ifdef CONFIG_KEYS |
| 2683 | |
Chen Gang | 057d633 | 2013-07-19 09:01:36 +0800 | [diff] [blame] | 2684 | /* strlen("cifs:a:") + CIFS_MAX_DOMAINNAME_LEN + 1 */ |
| 2685 | #define CIFSCREDS_DESC_SIZE (7 + CIFS_MAX_DOMAINNAME_LEN + 1) |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2686 | |
| 2687 | /* Populate username and pw fields from keyring if possible */ |
| 2688 | static int |
| 2689 | cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses) |
| 2690 | { |
| 2691 | int rc = 0; |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 2692 | const char *delim, *payload; |
| 2693 | char *desc; |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2694 | ssize_t len; |
| 2695 | struct key *key; |
| 2696 | struct TCP_Server_Info *server = ses->server; |
| 2697 | struct sockaddr_in *sa; |
| 2698 | struct sockaddr_in6 *sa6; |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 2699 | const struct user_key_payload *upayload; |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2700 | |
| 2701 | desc = kmalloc(CIFSCREDS_DESC_SIZE, GFP_KERNEL); |
| 2702 | if (!desc) |
| 2703 | return -ENOMEM; |
| 2704 | |
| 2705 | /* try to find an address key first */ |
| 2706 | switch (server->dstaddr.ss_family) { |
| 2707 | case AF_INET: |
| 2708 | sa = (struct sockaddr_in *)&server->dstaddr; |
| 2709 | sprintf(desc, "cifs:a:%pI4", &sa->sin_addr.s_addr); |
| 2710 | break; |
| 2711 | case AF_INET6: |
| 2712 | sa6 = (struct sockaddr_in6 *)&server->dstaddr; |
| 2713 | sprintf(desc, "cifs:a:%pI6c", &sa6->sin6_addr.s6_addr); |
| 2714 | break; |
| 2715 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2716 | cifs_dbg(FYI, "Bad ss_family (%hu)\n", |
| 2717 | server->dstaddr.ss_family); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2718 | rc = -EINVAL; |
| 2719 | goto out_err; |
| 2720 | } |
| 2721 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2722 | cifs_dbg(FYI, "%s: desc=%s\n", __func__, desc); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2723 | key = request_key(&key_type_logon, desc, ""); |
| 2724 | if (IS_ERR(key)) { |
| 2725 | if (!ses->domainName) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2726 | cifs_dbg(FYI, "domainName is NULL\n"); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2727 | rc = PTR_ERR(key); |
| 2728 | goto out_err; |
| 2729 | } |
| 2730 | |
| 2731 | /* didn't work, try to find a domain key */ |
| 2732 | sprintf(desc, "cifs:d:%s", ses->domainName); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2733 | cifs_dbg(FYI, "%s: desc=%s\n", __func__, desc); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2734 | key = request_key(&key_type_logon, desc, ""); |
| 2735 | if (IS_ERR(key)) { |
| 2736 | rc = PTR_ERR(key); |
| 2737 | goto out_err; |
| 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | down_read(&key->sem); |
David Howells | 0837e49 | 2017-03-01 15:11:23 +0000 | [diff] [blame] | 2742 | upayload = user_key_payload_locked(key); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2743 | if (IS_ERR_OR_NULL(upayload)) { |
Jeff Layton | 4edc53c | 2012-02-07 06:30:51 -0500 | [diff] [blame] | 2744 | rc = upayload ? PTR_ERR(upayload) : -EINVAL; |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2745 | goto out_key_put; |
| 2746 | } |
| 2747 | |
| 2748 | /* find first : in payload */ |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 2749 | payload = upayload->data; |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2750 | delim = strnchr(payload, upayload->datalen, ':'); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2751 | cifs_dbg(FYI, "payload=%s\n", payload); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2752 | if (!delim) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2753 | cifs_dbg(FYI, "Unable to find ':' in payload (datalen=%d)\n", |
| 2754 | upayload->datalen); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2755 | rc = -EINVAL; |
| 2756 | goto out_key_put; |
| 2757 | } |
| 2758 | |
| 2759 | len = delim - payload; |
Scott Lovenberg | 8c3a2b4 | 2013-08-09 08:47:17 -0400 | [diff] [blame] | 2760 | if (len > CIFS_MAX_USERNAME_LEN || len <= 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2761 | cifs_dbg(FYI, "Bad value from username search (len=%zd)\n", |
| 2762 | len); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2763 | rc = -EINVAL; |
| 2764 | goto out_key_put; |
| 2765 | } |
| 2766 | |
| 2767 | vol->username = kstrndup(payload, len, GFP_KERNEL); |
| 2768 | if (!vol->username) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2769 | cifs_dbg(FYI, "Unable to allocate %zd bytes for username\n", |
| 2770 | len); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2771 | rc = -ENOMEM; |
| 2772 | goto out_key_put; |
| 2773 | } |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2774 | cifs_dbg(FYI, "%s: username=%s\n", __func__, vol->username); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2775 | |
| 2776 | len = key->datalen - (len + 1); |
Scott Lovenberg | 8c3a2b4 | 2013-08-09 08:47:17 -0400 | [diff] [blame] | 2777 | if (len > CIFS_MAX_PASSWORD_LEN || len <= 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2778 | cifs_dbg(FYI, "Bad len for password search (len=%zd)\n", len); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2779 | rc = -EINVAL; |
| 2780 | kfree(vol->username); |
| 2781 | vol->username = NULL; |
| 2782 | goto out_key_put; |
| 2783 | } |
| 2784 | |
| 2785 | ++delim; |
| 2786 | vol->password = kstrndup(delim, len, GFP_KERNEL); |
| 2787 | if (!vol->password) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2788 | cifs_dbg(FYI, "Unable to allocate %zd bytes for password\n", |
| 2789 | len); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2790 | rc = -ENOMEM; |
| 2791 | kfree(vol->username); |
| 2792 | vol->username = NULL; |
| 2793 | goto out_key_put; |
| 2794 | } |
| 2795 | |
| 2796 | out_key_put: |
| 2797 | up_read(&key->sem); |
| 2798 | key_put(key); |
| 2799 | out_err: |
| 2800 | kfree(desc); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2801 | cifs_dbg(FYI, "%s: returning %d\n", __func__, rc); |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 2802 | return rc; |
| 2803 | } |
| 2804 | #else /* ! CONFIG_KEYS */ |
| 2805 | static inline int |
| 2806 | cifs_set_cifscreds(struct smb_vol *vol __attribute__((unused)), |
| 2807 | struct cifs_ses *ses __attribute__((unused))) |
| 2808 | { |
| 2809 | return -ENOSYS; |
| 2810 | } |
| 2811 | #endif /* CONFIG_KEYS */ |
| 2812 | |
Aurelien Aptel | 4a1360d | 2018-01-25 18:47:52 +0100 | [diff] [blame] | 2813 | /** |
| 2814 | * cifs_get_smb_ses - get a session matching @volume_info data from @server |
| 2815 | * |
| 2816 | * This function assumes it is being called from cifs_mount() where we |
| 2817 | * already got a server reference (server refcount +1). See |
| 2818 | * cifs_get_tcon() for refcount explanations. |
| 2819 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2820 | static struct cifs_ses * |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2821 | cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) |
| 2822 | { |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 2823 | int rc = -ENOMEM; |
| 2824 | unsigned int xid; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2825 | struct cifs_ses *ses; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2826 | struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; |
| 2827 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2828 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2829 | xid = get_xid(); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2830 | |
Jeff Layton | 4ff67b7 | 2010-07-06 20:43:02 -0400 | [diff] [blame] | 2831 | ses = cifs_find_smb_ses(server, volume_info); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2832 | if (ses) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2833 | cifs_dbg(FYI, "Existing smb sess found (status=%d)\n", |
| 2834 | ses->status); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2835 | |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2836 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 2837 | rc = cifs_negotiate_protocol(xid, ses); |
| 2838 | if (rc) { |
| 2839 | mutex_unlock(&ses->session_mutex); |
| 2840 | /* problem -- put our ses reference */ |
| 2841 | cifs_put_smb_ses(ses); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2842 | free_xid(xid); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 2843 | return ERR_PTR(rc); |
| 2844 | } |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2845 | if (ses->need_reconnect) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2846 | cifs_dbg(FYI, "Session needs reconnect\n"); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2847 | rc = cifs_setup_session(xid, ses, |
| 2848 | volume_info->local_nls); |
| 2849 | if (rc) { |
| 2850 | mutex_unlock(&ses->session_mutex); |
| 2851 | /* problem -- put our reference */ |
| 2852 | cifs_put_smb_ses(ses); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2853 | free_xid(xid); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2854 | return ERR_PTR(rc); |
| 2855 | } |
| 2856 | } |
| 2857 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 460cf34 | 2010-09-14 11:38:24 -0400 | [diff] [blame] | 2858 | |
| 2859 | /* existing SMB ses has a server reference already */ |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2860 | cifs_put_tcp_session(server, 0); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2861 | free_xid(xid); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2862 | return ses; |
| 2863 | } |
| 2864 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2865 | cifs_dbg(FYI, "Existing smb sess not found\n"); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2866 | ses = sesInfoAlloc(); |
| 2867 | if (ses == NULL) |
| 2868 | goto get_ses_fail; |
| 2869 | |
| 2870 | /* new SMB session uses our server ref */ |
| 2871 | ses->server = server; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2872 | if (server->dstaddr.ss_family == AF_INET6) |
| 2873 | sprintf(ses->serverName, "%pI6", &addr6->sin6_addr); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2874 | else |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 2875 | sprintf(ses->serverName, "%pI4", &addr->sin_addr); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2876 | |
Steve French | 8727c8a | 2011-02-25 01:11:56 -0600 | [diff] [blame] | 2877 | if (volume_info->username) { |
| 2878 | ses->user_name = kstrdup(volume_info->username, GFP_KERNEL); |
| 2879 | if (!ses->user_name) |
| 2880 | goto get_ses_fail; |
| 2881 | } |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2882 | |
| 2883 | /* volume_info->password freed at unmount */ |
| 2884 | if (volume_info->password) { |
| 2885 | ses->password = kstrdup(volume_info->password, GFP_KERNEL); |
| 2886 | if (!ses->password) |
| 2887 | goto get_ses_fail; |
| 2888 | } |
| 2889 | if (volume_info->domainname) { |
Shirish Pargaonkar | d3686d5 | 2010-10-28 09:53:07 -0500 | [diff] [blame] | 2890 | ses->domainName = kstrdup(volume_info->domainname, GFP_KERNEL); |
| 2891 | if (!ses->domainName) |
| 2892 | goto get_ses_fail; |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2893 | } |
Germano Percossi | 3956644 | 2016-12-15 12:31:18 +0530 | [diff] [blame] | 2894 | if (volume_info->domainauto) |
| 2895 | ses->domainAuto = volume_info->domainauto; |
Jeff Layton | 3e4b3e1 | 2010-07-19 18:00:17 -0400 | [diff] [blame] | 2896 | ses->cred_uid = volume_info->cred_uid; |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2897 | ses->linux_uid = volume_info->linux_uid; |
Steve French | d9b9420 | 2011-04-12 01:24:57 +0000 | [diff] [blame] | 2898 | |
Jeff Layton | 28e11bd | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 2899 | ses->sectype = volume_info->sectype; |
| 2900 | ses->sign = volume_info->sign; |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2901 | |
| 2902 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 2903 | rc = cifs_negotiate_protocol(xid, ses); |
| 2904 | if (!rc) |
| 2905 | rc = cifs_setup_session(xid, ses, volume_info->local_nls); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2906 | mutex_unlock(&ses->session_mutex); |
Steve French | c8e56f1 | 2010-09-08 21:10:58 +0000 | [diff] [blame] | 2907 | if (rc) |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2908 | goto get_ses_fail; |
| 2909 | |
| 2910 | /* success, put it on the list */ |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2911 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2912 | list_add(&ses->smb_ses_list, &server->smb_ses_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2913 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2914 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2915 | free_xid(xid); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2916 | |
| 2917 | cifs_setup_ipc(ses, volume_info); |
| 2918 | |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2919 | return ses; |
| 2920 | |
| 2921 | get_ses_fail: |
| 2922 | sesInfoFree(ses); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2923 | free_xid(xid); |
Jeff Layton | 36988c7 | 2010-04-24 07:57:43 -0400 | [diff] [blame] | 2924 | return ERR_PTR(rc); |
| 2925 | } |
| 2926 | |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 2927 | static int match_tcon(struct cifs_tcon *tcon, struct smb_vol *volume_info) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2928 | { |
| 2929 | if (tcon->tidStatus == CifsExiting) |
| 2930 | return 0; |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 2931 | if (strncmp(tcon->treeName, volume_info->UNC, MAX_TREE_SIZE)) |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2932 | return 0; |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 2933 | if (tcon->seal != volume_info->seal) |
| 2934 | return 0; |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 2935 | if (tcon->snapshot_time != volume_info->snapshot_time) |
| 2936 | return 0; |
Pavel Shilovsky | 37bb04e | 2011-05-05 09:55:11 +0000 | [diff] [blame] | 2937 | return 1; |
| 2938 | } |
| 2939 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2940 | static struct cifs_tcon * |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 2941 | cifs_find_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | { |
| 2943 | struct list_head *tmp; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2944 | struct cifs_tcon *tcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2946 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2947 | list_for_each(tmp, &ses->tcon_list) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2948 | tcon = list_entry(tmp, struct cifs_tcon, tcon_list); |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 2949 | if (!match_tcon(tcon, volume_info)) |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2950 | continue; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2951 | ++tcon->tc_count; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2952 | spin_unlock(&cifs_tcp_ses_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | return tcon; |
| 2954 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2955 | spin_unlock(&cifs_tcp_ses_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | return NULL; |
| 2957 | } |
| 2958 | |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 2959 | void |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 2960 | cifs_put_tcon(struct cifs_tcon *tcon) |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2961 | { |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 2962 | unsigned int xid; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2963 | struct cifs_ses *ses; |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2964 | |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 2965 | /* |
| 2966 | * IPC tcon share the lifetime of their session and are |
| 2967 | * destroyed in the session put function |
| 2968 | */ |
| 2969 | if (tcon == NULL || tcon->ipc) |
| 2970 | return; |
| 2971 | |
| 2972 | ses = tcon->ses; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 2973 | cifs_dbg(FYI, "%s: tc_count=%d\n", __func__, tcon->tc_count); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2974 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2975 | if (--tcon->tc_count > 0) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2976 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2977 | return; |
| 2978 | } |
| 2979 | |
| 2980 | list_del_init(&tcon->tcon_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 2981 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2982 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2983 | xid = get_xid(); |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 2984 | if (ses->server->ops->tree_disconnect) |
| 2985 | ses->server->ops->tree_disconnect(xid, tcon); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 2986 | _free_xid(xid); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2987 | |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 2988 | cifs_fscache_release_super_cookie(tcon); |
Steve French | 9f84159 | 2010-07-23 20:37:53 +0000 | [diff] [blame] | 2989 | tconInfoFree(tcon); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 2990 | cifs_put_smb_ses(ses); |
| 2991 | } |
| 2992 | |
Aurelien Aptel | 4a1360d | 2018-01-25 18:47:52 +0100 | [diff] [blame] | 2993 | /** |
| 2994 | * cifs_get_tcon - get a tcon matching @volume_info data from @ses |
| 2995 | * |
| 2996 | * - tcon refcount is the number of mount points using the tcon. |
| 2997 | * - ses refcount is the number of tcon using the session. |
| 2998 | * |
| 2999 | * 1. This function assumes it is being called from cifs_mount() where |
| 3000 | * we already got a session reference (ses refcount +1). |
| 3001 | * |
| 3002 | * 2. Since we're in the context of adding a mount point, the end |
| 3003 | * result should be either: |
| 3004 | * |
| 3005 | * a) a new tcon already allocated with refcount=1 (1 mount point) and |
| 3006 | * its session refcount incremented (1 new tcon). This +1 was |
| 3007 | * already done in (1). |
| 3008 | * |
| 3009 | * b) an existing tcon with refcount+1 (add a mount point to it) and |
| 3010 | * identical ses refcount (no new tcon). Because of (1) we need to |
| 3011 | * decrement the ses refcount. |
| 3012 | */ |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3013 | static struct cifs_tcon * |
| 3014 | cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3015 | { |
| 3016 | int rc, xid; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3017 | struct cifs_tcon *tcon; |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3018 | |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 3019 | tcon = cifs_find_tcon(ses, volume_info); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3020 | if (tcon) { |
Aurelien Aptel | 4a1360d | 2018-01-25 18:47:52 +0100 | [diff] [blame] | 3021 | /* |
| 3022 | * tcon has refcount already incremented but we need to |
| 3023 | * decrement extra ses reference gotten by caller (case b) |
| 3024 | */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3025 | cifs_dbg(FYI, "Found match on UNC path\n"); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3026 | cifs_put_smb_ses(ses); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3027 | return tcon; |
| 3028 | } |
| 3029 | |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 3030 | if (!ses->server->ops->tree_connect) { |
| 3031 | rc = -ENOSYS; |
| 3032 | goto out_fail; |
| 3033 | } |
| 3034 | |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3035 | tcon = tconInfoAlloc(); |
| 3036 | if (tcon == NULL) { |
| 3037 | rc = -ENOMEM; |
| 3038 | goto out_fail; |
| 3039 | } |
| 3040 | |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 3041 | if (volume_info->snapshot_time) { |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 3042 | if (ses->server->vals->protocol_id == 0) { |
| 3043 | cifs_dbg(VFS, |
| 3044 | "Use SMB2 or later for snapshot mount option\n"); |
| 3045 | rc = -EOPNOTSUPP; |
| 3046 | goto out_fail; |
| 3047 | } else |
| 3048 | tcon->snapshot_time = volume_info->snapshot_time; |
Steve French | 8b217fe | 2016-11-11 22:36:20 -0600 | [diff] [blame] | 3049 | } |
| 3050 | |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3051 | tcon->ses = ses; |
| 3052 | if (volume_info->password) { |
| 3053 | tcon->password = kstrdup(volume_info->password, GFP_KERNEL); |
| 3054 | if (!tcon->password) { |
| 3055 | rc = -ENOMEM; |
| 3056 | goto out_fail; |
| 3057 | } |
| 3058 | } |
| 3059 | |
Steve French | 23657ad | 2018-04-22 15:14:58 -0500 | [diff] [blame] | 3060 | if (volume_info->seal) { |
| 3061 | if (ses->server->vals->protocol_id == 0) { |
| 3062 | cifs_dbg(VFS, |
| 3063 | "SMB3 or later required for encryption\n"); |
| 3064 | rc = -EOPNOTSUPP; |
| 3065 | goto out_fail; |
| 3066 | } else if (tcon->ses->server->capabilities & |
| 3067 | SMB2_GLOBAL_CAP_ENCRYPTION) |
| 3068 | tcon->seal = true; |
| 3069 | else { |
| 3070 | cifs_dbg(VFS, "Encryption is not supported on share\n"); |
| 3071 | rc = -EOPNOTSUPP; |
| 3072 | goto out_fail; |
| 3073 | } |
| 3074 | } |
| 3075 | |
Steve French | 8505c8b | 2018-06-18 14:01:59 -0500 | [diff] [blame] | 3076 | if (volume_info->linux_ext) { |
| 3077 | if (ses->server->posix_ext_supported) { |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 3078 | tcon->posix_extensions = true; |
Steve French | 2fbb564 | 2018-06-12 12:11:31 -0500 | [diff] [blame] | 3079 | printk_once(KERN_WARNING |
| 3080 | "SMB3.11 POSIX Extensions are experimental\n"); |
Steve French | 8505c8b | 2018-06-18 14:01:59 -0500 | [diff] [blame] | 3081 | } else { |
| 3082 | cifs_dbg(VFS, "Server does not support mounting with posix SMB3.11 extensions.\n"); |
| 3083 | rc = -EOPNOTSUPP; |
| 3084 | goto out_fail; |
Steve French | 2fbb564 | 2018-06-12 12:11:31 -0500 | [diff] [blame] | 3085 | } |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 3086 | } |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 3087 | |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 3088 | /* |
| 3089 | * BB Do we need to wrap session_mutex around this TCon call and Unix |
| 3090 | * SetFS as we do on SessSetup and reconnect? |
| 3091 | */ |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3092 | xid = get_xid(); |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 3093 | rc = ses->server->ops->tree_connect(xid, ses, volume_info->UNC, tcon, |
| 3094 | volume_info->local_nls); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3095 | free_xid(xid); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3096 | cifs_dbg(FYI, "Tcon rc = %d\n", rc); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3097 | if (rc) |
| 3098 | goto out_fail; |
| 3099 | |
Steve French | b618f00 | 2015-11-03 09:15:03 -0600 | [diff] [blame] | 3100 | tcon->use_persistent = false; |
| 3101 | /* check if SMB2 or later, CIFS does not support persistent handles */ |
| 3102 | if (volume_info->persistent) { |
| 3103 | if (ses->server->vals->protocol_id == 0) { |
| 3104 | cifs_dbg(VFS, |
| 3105 | "SMB3 or later required for persistent handles\n"); |
| 3106 | rc = -EOPNOTSUPP; |
| 3107 | goto out_fail; |
| 3108 | } else if (ses->server->capabilities & |
| 3109 | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) |
| 3110 | tcon->use_persistent = true; |
| 3111 | else /* persistent handles requested but not supported */ { |
| 3112 | cifs_dbg(VFS, |
| 3113 | "Persistent handles not supported on share\n"); |
| 3114 | rc = -EOPNOTSUPP; |
| 3115 | goto out_fail; |
| 3116 | } |
| 3117 | } else if ((tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) |
| 3118 | && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) |
| 3119 | && (volume_info->nopersistent == false)) { |
| 3120 | cifs_dbg(FYI, "enabling persistent handles\n"); |
| 3121 | tcon->use_persistent = true; |
Steve French | 592fafe | 2015-11-03 10:08:53 -0600 | [diff] [blame] | 3122 | } else if (volume_info->resilient) { |
| 3123 | if (ses->server->vals->protocol_id == 0) { |
| 3124 | cifs_dbg(VFS, |
| 3125 | "SMB2.1 or later required for resilient handles\n"); |
| 3126 | rc = -EOPNOTSUPP; |
| 3127 | goto out_fail; |
| 3128 | } |
| 3129 | tcon->use_resilient = true; |
Steve French | b618f00 | 2015-11-03 09:15:03 -0600 | [diff] [blame] | 3130 | } |
| 3131 | |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 3132 | /* |
| 3133 | * We can have only one retry value for a connection to a share so for |
| 3134 | * resources mounted more than once to the same server share the last |
| 3135 | * value passed in for the retry flag is used. |
| 3136 | */ |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3137 | tcon->retry = volume_info->retry; |
| 3138 | tcon->nocase = volume_info->nocase; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 3139 | tcon->nohandlecache = volume_info->nohandlecache; |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3140 | tcon->local_lease = volume_info->local_lease; |
Pavel Shilovsky | 233839b | 2012-09-19 06:22:45 -0700 | [diff] [blame] | 3141 | INIT_LIST_HEAD(&tcon->pending_opens); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3142 | |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 3143 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3144 | list_add(&tcon->tcon_list, &ses->tcon_list); |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 3145 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3146 | |
Suresh Jayaraman | d03382c | 2010-07-05 18:12:27 +0530 | [diff] [blame] | 3147 | cifs_fscache_get_super_cookie(tcon); |
| 3148 | |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3149 | return tcon; |
| 3150 | |
| 3151 | out_fail: |
| 3152 | tconInfoFree(tcon); |
| 3153 | return ERR_PTR(rc); |
| 3154 | } |
| 3155 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 3156 | void |
| 3157 | cifs_put_tlink(struct tcon_link *tlink) |
| 3158 | { |
| 3159 | if (!tlink || IS_ERR(tlink)) |
| 3160 | return; |
| 3161 | |
| 3162 | if (!atomic_dec_and_test(&tlink->tl_count) || |
| 3163 | test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags)) { |
| 3164 | tlink->tl_time = jiffies; |
| 3165 | return; |
| 3166 | } |
| 3167 | |
| 3168 | if (!IS_ERR(tlink_tcon(tlink))) |
| 3169 | cifs_put_tcon(tlink_tcon(tlink)); |
| 3170 | kfree(tlink); |
| 3171 | return; |
| 3172 | } |
Jeff Layton | d00c28d | 2010-04-24 07:57:44 -0400 | [diff] [blame] | 3173 | |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3174 | static int |
| 3175 | compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data) |
| 3176 | { |
| 3177 | struct cifs_sb_info *old = CIFS_SB(sb); |
| 3178 | struct cifs_sb_info *new = mnt_data->cifs_sb; |
| 3179 | |
| 3180 | if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK)) |
| 3181 | return 0; |
| 3182 | |
| 3183 | if ((old->mnt_cifs_flags & CIFS_MOUNT_MASK) != |
| 3184 | (new->mnt_cifs_flags & CIFS_MOUNT_MASK)) |
| 3185 | return 0; |
| 3186 | |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3187 | /* |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 3188 | * We want to share sb only if we don't specify an r/wsize or |
| 3189 | * specified r/wsize is greater than or equal to existing one. |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3190 | */ |
| 3191 | if (new->wsize && new->wsize < old->wsize) |
| 3192 | return 0; |
| 3193 | |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 3194 | if (new->rsize && new->rsize < old->rsize) |
| 3195 | return 0; |
| 3196 | |
Eric W. Biederman | 1f68233 | 2013-02-06 01:20:20 -0800 | [diff] [blame] | 3197 | if (!uid_eq(old->mnt_uid, new->mnt_uid) || !gid_eq(old->mnt_gid, new->mnt_gid)) |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3198 | return 0; |
| 3199 | |
| 3200 | if (old->mnt_file_mode != new->mnt_file_mode || |
| 3201 | old->mnt_dir_mode != new->mnt_dir_mode) |
| 3202 | return 0; |
| 3203 | |
| 3204 | if (strcmp(old->local_nls->charset, new->local_nls->charset)) |
| 3205 | return 0; |
| 3206 | |
| 3207 | if (old->actimeo != new->actimeo) |
| 3208 | return 0; |
| 3209 | |
| 3210 | return 1; |
| 3211 | } |
| 3212 | |
Sachin Prabhu | c1d8b24 | 2016-07-29 22:38:20 +0100 | [diff] [blame] | 3213 | static int |
| 3214 | match_prepath(struct super_block *sb, struct cifs_mnt_data *mnt_data) |
| 3215 | { |
| 3216 | struct cifs_sb_info *old = CIFS_SB(sb); |
| 3217 | struct cifs_sb_info *new = mnt_data->cifs_sb; |
Sachin Prabhu | cd8c429 | 2017-04-26 14:05:46 +0100 | [diff] [blame] | 3218 | bool old_set = old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH; |
| 3219 | bool new_set = new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH; |
Sachin Prabhu | c1d8b24 | 2016-07-29 22:38:20 +0100 | [diff] [blame] | 3220 | |
Sachin Prabhu | cd8c429 | 2017-04-26 14:05:46 +0100 | [diff] [blame] | 3221 | if (old_set && new_set && !strcmp(new->prepath, old->prepath)) |
Sachin Prabhu | c1d8b24 | 2016-07-29 22:38:20 +0100 | [diff] [blame] | 3222 | return 1; |
Sachin Prabhu | cd8c429 | 2017-04-26 14:05:46 +0100 | [diff] [blame] | 3223 | else if (!old_set && !new_set) |
| 3224 | return 1; |
| 3225 | |
Sachin Prabhu | c1d8b24 | 2016-07-29 22:38:20 +0100 | [diff] [blame] | 3226 | return 0; |
| 3227 | } |
| 3228 | |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3229 | int |
| 3230 | cifs_match_super(struct super_block *sb, void *data) |
| 3231 | { |
| 3232 | struct cifs_mnt_data *mnt_data = (struct cifs_mnt_data *)data; |
| 3233 | struct smb_vol *volume_info; |
| 3234 | struct cifs_sb_info *cifs_sb; |
| 3235 | struct TCP_Server_Info *tcp_srv; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 3236 | struct cifs_ses *ses; |
| 3237 | struct cifs_tcon *tcon; |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3238 | struct tcon_link *tlink; |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3239 | int rc = 0; |
| 3240 | |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3241 | spin_lock(&cifs_tcp_ses_lock); |
| 3242 | cifs_sb = CIFS_SB(sb); |
| 3243 | tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb)); |
| 3244 | if (IS_ERR(tlink)) { |
| 3245 | spin_unlock(&cifs_tcp_ses_lock); |
| 3246 | return rc; |
| 3247 | } |
| 3248 | tcon = tlink_tcon(tlink); |
| 3249 | ses = tcon->ses; |
| 3250 | tcp_srv = ses->server; |
| 3251 | |
| 3252 | volume_info = mnt_data->vol; |
| 3253 | |
Jeff Layton | 9fa114f | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 3254 | if (!match_server(tcp_srv, volume_info) || |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3255 | !match_session(ses, volume_info) || |
Pavel Shilovsky | ae6f8dd | 2016-11-17 13:59:23 -0800 | [diff] [blame] | 3256 | !match_tcon(tcon, volume_info) || |
Sachin Prabhu | c1d8b24 | 2016-07-29 22:38:20 +0100 | [diff] [blame] | 3257 | !match_prepath(sb, mnt_data)) { |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3258 | rc = 0; |
| 3259 | goto out; |
| 3260 | } |
| 3261 | |
| 3262 | rc = compare_mount_options(sb, mnt_data); |
| 3263 | out: |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3264 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | f484b5d0 | 2011-07-11 10:16:34 -0400 | [diff] [blame] | 3265 | cifs_put_tlink(tlink); |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3266 | return rc; |
| 3267 | } |
| 3268 | |
Jeff Layton | 09e50d5 | 2008-07-23 10:11:19 -0400 | [diff] [blame] | 3269 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 3270 | static struct lock_class_key cifs_key[2]; |
| 3271 | static struct lock_class_key cifs_slock_key[2]; |
| 3272 | |
| 3273 | static inline void |
| 3274 | cifs_reclassify_socket4(struct socket *sock) |
| 3275 | { |
| 3276 | struct sock *sk = sock->sk; |
Hannes Frederic Sowa | fafc4e1 | 2016-04-08 15:11:27 +0200 | [diff] [blame] | 3277 | BUG_ON(!sock_allow_reclassification(sk)); |
Jeff Layton | 09e50d5 | 2008-07-23 10:11:19 -0400 | [diff] [blame] | 3278 | sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS", |
| 3279 | &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]); |
| 3280 | } |
| 3281 | |
| 3282 | static inline void |
| 3283 | cifs_reclassify_socket6(struct socket *sock) |
| 3284 | { |
| 3285 | struct sock *sk = sock->sk; |
Hannes Frederic Sowa | fafc4e1 | 2016-04-08 15:11:27 +0200 | [diff] [blame] | 3286 | BUG_ON(!sock_allow_reclassification(sk)); |
Jeff Layton | 09e50d5 | 2008-07-23 10:11:19 -0400 | [diff] [blame] | 3287 | sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS", |
| 3288 | &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]); |
| 3289 | } |
| 3290 | #else |
| 3291 | static inline void |
| 3292 | cifs_reclassify_socket4(struct socket *sock) |
| 3293 | { |
| 3294 | } |
| 3295 | |
| 3296 | static inline void |
| 3297 | cifs_reclassify_socket6(struct socket *sock) |
| 3298 | { |
| 3299 | } |
| 3300 | #endif |
| 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | /* See RFC1001 section 14 on representation of Netbios names */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3303 | static void rfc1002mangle(char *target, char *source, unsigned int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3305 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3307 | for (i = 0, j = 0; i < (length); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | /* mask a nibble at a time and encode */ |
| 3309 | target[j] = 'A' + (0x0F & (source[i] >> 4)); |
| 3310 | target[j+1] = 'A' + (0x0F & source[i]); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3311 | j += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | } |
| 3315 | |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 3316 | static int |
| 3317 | bind_socket(struct TCP_Server_Info *server) |
| 3318 | { |
| 3319 | int rc = 0; |
| 3320 | if (server->srcaddr.ss_family != AF_UNSPEC) { |
| 3321 | /* Bind to the specified local IP address */ |
| 3322 | struct socket *socket = server->ssocket; |
| 3323 | rc = socket->ops->bind(socket, |
| 3324 | (struct sockaddr *) &server->srcaddr, |
| 3325 | sizeof(server->srcaddr)); |
| 3326 | if (rc < 0) { |
| 3327 | struct sockaddr_in *saddr4; |
| 3328 | struct sockaddr_in6 *saddr6; |
| 3329 | saddr4 = (struct sockaddr_in *)&server->srcaddr; |
| 3330 | saddr6 = (struct sockaddr_in6 *)&server->srcaddr; |
| 3331 | if (saddr6->sin6_family == AF_INET6) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3332 | cifs_dbg(VFS, "Failed to bind to: %pI6c, error: %d\n", |
| 3333 | &saddr6->sin6_addr, rc); |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 3334 | else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3335 | cifs_dbg(VFS, "Failed to bind to: %pI4, error: %d\n", |
| 3336 | &saddr4->sin_addr.s_addr, rc); |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | return rc; |
| 3340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | |
| 3342 | static int |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3343 | ip_rfc1001_connect(struct TCP_Server_Info *server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | { |
| 3345 | int rc = 0; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3346 | /* |
| 3347 | * some servers require RFC1001 sessinit before sending |
| 3348 | * negprot - BB check reconnection in case where second |
| 3349 | * sessinit is sent but no second negprot |
| 3350 | */ |
| 3351 | struct rfc1002_session_packet *ses_init_buf; |
| 3352 | struct smb_hdr *smb_buf; |
| 3353 | ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet), |
| 3354 | GFP_KERNEL); |
| 3355 | if (ses_init_buf) { |
| 3356 | ses_init_buf->trailer.session_req.called_len = 32; |
| 3357 | |
Colin Ian King | 997152f | 2016-01-25 16:25:54 +0000 | [diff] [blame] | 3358 | if (server->server_RFC1001_name[0] != 0) |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3359 | rfc1002mangle(ses_init_buf->trailer. |
| 3360 | session_req.called_name, |
| 3361 | server->server_RFC1001_name, |
| 3362 | RFC1001_NAME_LEN_WITH_NULL); |
| 3363 | else |
| 3364 | rfc1002mangle(ses_init_buf->trailer. |
| 3365 | session_req.called_name, |
| 3366 | DEFAULT_CIFS_CALLED_NAME, |
| 3367 | RFC1001_NAME_LEN_WITH_NULL); |
| 3368 | |
| 3369 | ses_init_buf->trailer.session_req.calling_len = 32; |
| 3370 | |
| 3371 | /* |
| 3372 | * calling name ends in null (byte 16) from old smb |
| 3373 | * convention. |
| 3374 | */ |
Steve French | c85c35f | 2015-03-27 01:15:02 -0500 | [diff] [blame] | 3375 | if (server->workstation_RFC1001_name[0] != 0) |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3376 | rfc1002mangle(ses_init_buf->trailer. |
| 3377 | session_req.calling_name, |
| 3378 | server->workstation_RFC1001_name, |
| 3379 | RFC1001_NAME_LEN_WITH_NULL); |
| 3380 | else |
| 3381 | rfc1002mangle(ses_init_buf->trailer. |
| 3382 | session_req.calling_name, |
| 3383 | "LINUX_CIFS_CLNT", |
| 3384 | RFC1001_NAME_LEN_WITH_NULL); |
| 3385 | |
| 3386 | ses_init_buf->trailer.session_req.scope1 = 0; |
| 3387 | ses_init_buf->trailer.session_req.scope2 = 0; |
| 3388 | smb_buf = (struct smb_hdr *)ses_init_buf; |
| 3389 | |
| 3390 | /* sizeof RFC1002_SESSION_REQUEST with no scope */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3391 | smb_buf->smb_buf_length = cpu_to_be32(0x81000044); |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3392 | rc = smb_send(server, smb_buf, 0x44); |
| 3393 | kfree(ses_init_buf); |
| 3394 | /* |
| 3395 | * RFC1001 layer in at least one server |
| 3396 | * requires very short break before negprot |
| 3397 | * presumably because not expecting negprot |
| 3398 | * to follow so fast. This is a simple |
| 3399 | * solution that works without |
| 3400 | * complicating the code and causes no |
| 3401 | * significant slowing down on mount |
| 3402 | * for everyone else |
| 3403 | */ |
| 3404 | usleep_range(1000, 2000); |
| 3405 | } |
| 3406 | /* |
| 3407 | * else the negprot may still work without this |
| 3408 | * even though malloc failed |
| 3409 | */ |
| 3410 | |
| 3411 | return rc; |
| 3412 | } |
| 3413 | |
| 3414 | static int |
| 3415 | generic_ip_connect(struct TCP_Server_Info *server) |
| 3416 | { |
| 3417 | int rc = 0; |
Steve French | 6da9791 | 2011-03-13 18:55:55 +0000 | [diff] [blame] | 3418 | __be16 sport; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3419 | int slen, sfamily; |
Jeff Layton | bcf4b10 | 2008-12-01 18:42:15 -0500 | [diff] [blame] | 3420 | struct socket *socket = server->ssocket; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3421 | struct sockaddr *saddr; |
| 3422 | |
| 3423 | saddr = (struct sockaddr *) &server->dstaddr; |
| 3424 | |
| 3425 | if (server->dstaddr.ss_family == AF_INET6) { |
| 3426 | sport = ((struct sockaddr_in6 *) saddr)->sin6_port; |
| 3427 | slen = sizeof(struct sockaddr_in6); |
| 3428 | sfamily = AF_INET6; |
| 3429 | } else { |
| 3430 | sport = ((struct sockaddr_in *) saddr)->sin_port; |
| 3431 | slen = sizeof(struct sockaddr_in); |
| 3432 | sfamily = AF_INET; |
| 3433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | |
Jeff Layton | bcf4b10 | 2008-12-01 18:42:15 -0500 | [diff] [blame] | 3435 | if (socket == NULL) { |
Rob Landley | f1d0c99 | 2011-01-22 15:44:05 -0600 | [diff] [blame] | 3436 | rc = __sock_create(cifs_net_ns(server), sfamily, SOCK_STREAM, |
| 3437 | IPPROTO_TCP, &socket, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | if (rc < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3439 | cifs_dbg(VFS, "Error %d creating socket\n", rc); |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3440 | server->ssocket = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | } |
Jeff Layton | bcf4b10 | 2008-12-01 18:42:15 -0500 | [diff] [blame] | 3443 | |
| 3444 | /* BB other socket options to set KEEPALIVE, NODELAY? */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3445 | cifs_dbg(FYI, "Socket created\n"); |
Jeff Layton | bcf4b10 | 2008-12-01 18:42:15 -0500 | [diff] [blame] | 3446 | server->ssocket = socket; |
| 3447 | socket->sk->sk_allocation = GFP_NOFS; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3448 | if (sfamily == AF_INET6) |
| 3449 | cifs_reclassify_socket6(socket); |
| 3450 | else |
| 3451 | cifs_reclassify_socket4(socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Ben Greear | 3eb9a88 | 2010-09-01 17:06:02 -0700 | [diff] [blame] | 3454 | rc = bind_socket(server); |
| 3455 | if (rc < 0) |
| 3456 | return rc; |
| 3457 | |
Jeff Layton | d5c5605 | 2008-12-01 18:42:33 -0500 | [diff] [blame] | 3458 | /* |
| 3459 | * Eventually check for other socket options to change from |
| 3460 | * the default. sock_setsockopt not used because it expects |
| 3461 | * user space buffer |
| 3462 | */ |
| 3463 | socket->sk->sk_rcvtimeo = 7 * HZ; |
Steve French | da505c3 | 2009-01-19 03:49:35 +0000 | [diff] [blame] | 3464 | socket->sk->sk_sndtimeo = 5 * HZ; |
Steve French | 6a5fa236 | 2010-01-01 01:28:43 +0000 | [diff] [blame] | 3465 | |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3466 | /* make the bufsizes depend on wsize/rsize and max requests */ |
| 3467 | if (server->noautotune) { |
| 3468 | if (socket->sk->sk_sndbuf < (200 * 1024)) |
| 3469 | socket->sk->sk_sndbuf = 200 * 1024; |
| 3470 | if (socket->sk->sk_rcvbuf < (140 * 1024)) |
| 3471 | socket->sk->sk_rcvbuf = 140 * 1024; |
| 3472 | } |
| 3473 | |
Steve French | 6a5fa236 | 2010-01-01 01:28:43 +0000 | [diff] [blame] | 3474 | if (server->tcp_nodelay) { |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3475 | int val = 1; |
Steve French | 6a5fa236 | 2010-01-01 01:28:43 +0000 | [diff] [blame] | 3476 | rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, |
| 3477 | (char *)&val, sizeof(val)); |
| 3478 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3479 | cifs_dbg(FYI, "set TCP_NODELAY socket option error %d\n", |
| 3480 | rc); |
Steve French | 6a5fa236 | 2010-01-01 01:28:43 +0000 | [diff] [blame] | 3481 | } |
| 3482 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3483 | cifs_dbg(FYI, "sndbuf %d rcvbuf %d rcvtimeo 0x%lx\n", |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3484 | socket->sk->sk_sndbuf, |
| 3485 | socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); |
| 3486 | |
Jeff Layton | ee1b3ea | 2011-06-21 07:18:26 -0400 | [diff] [blame] | 3487 | rc = socket->ops->connect(socket, saddr, slen, 0); |
| 3488 | if (rc < 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3489 | cifs_dbg(FYI, "Error %d connecting to server\n", rc); |
Jeff Layton | ee1b3ea | 2011-06-21 07:18:26 -0400 | [diff] [blame] | 3490 | sock_release(socket); |
| 3491 | server->ssocket = NULL; |
| 3492 | return rc; |
| 3493 | } |
| 3494 | |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3495 | if (sport == htons(RFC1001_PORT)) |
| 3496 | rc = ip_rfc1001_connect(server); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | return rc; |
| 3499 | } |
| 3500 | |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3501 | static int |
| 3502 | ip_connect(struct TCP_Server_Info *server) |
| 3503 | { |
Steve French | 6da9791 | 2011-03-13 18:55:55 +0000 | [diff] [blame] | 3504 | __be16 *sport; |
Pavel Shilovsky | a9f1b85 | 2010-12-13 19:08:35 +0300 | [diff] [blame] | 3505 | struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; |
| 3506 | struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; |
| 3507 | |
| 3508 | if (server->dstaddr.ss_family == AF_INET6) |
| 3509 | sport = &addr6->sin6_port; |
| 3510 | else |
| 3511 | sport = &addr->sin_port; |
| 3512 | |
| 3513 | if (*sport == 0) { |
| 3514 | int rc; |
| 3515 | |
| 3516 | /* try with 445 port at first */ |
| 3517 | *sport = htons(CIFS_PORT); |
| 3518 | |
| 3519 | rc = generic_ip_connect(server); |
| 3520 | if (rc >= 0) |
| 3521 | return rc; |
| 3522 | |
| 3523 | /* if it failed, try with 139 port */ |
| 3524 | *sport = htons(RFC1001_PORT); |
| 3525 | } |
| 3526 | |
| 3527 | return generic_ip_connect(server); |
| 3528 | } |
| 3529 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 3530 | void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, |
Al Viro | 2c6292a | 2011-06-17 09:05:48 -0400 | [diff] [blame] | 3531 | struct cifs_sb_info *cifs_sb, struct smb_vol *vol_info) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3532 | { |
| 3533 | /* if we are reconnecting then should we check to see if |
| 3534 | * any requested capabilities changed locally e.g. via |
| 3535 | * remount but we can not do much about it here |
| 3536 | * if they have (even if we could detect it by the following) |
| 3537 | * Perhaps we could add a backpointer to array of sb from tcon |
| 3538 | * or if we change to make all sb to same share the same |
| 3539 | * sb as NFS - then we only have one backpointer to sb. |
| 3540 | * What if we wanted to mount the server share twice once with |
| 3541 | * and once without posixacls or posix paths? */ |
| 3542 | __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3543 | |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 3544 | if (vol_info && vol_info->no_linux_ext) { |
| 3545 | tcon->fsUnixInfo.Capability = 0; |
| 3546 | tcon->unix_ext = 0; /* Unix Extensions disabled */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3547 | cifs_dbg(FYI, "Linux protocol extensions disabled\n"); |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 3548 | return; |
| 3549 | } else if (vol_info) |
| 3550 | tcon->unix_ext = 1; /* Unix Extensions supported */ |
| 3551 | |
| 3552 | if (tcon->unix_ext == 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3553 | cifs_dbg(FYI, "Unix extensions disabled so not set on reconnect\n"); |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 3554 | return; |
| 3555 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3556 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3557 | if (!CIFSSMBQFSUnixInfo(xid, tcon)) { |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3558 | __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3559 | cifs_dbg(FYI, "unix caps which server supports %lld\n", cap); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3560 | /* check for reconnect case in which we do not |
| 3561 | want to change the mount behavior if we can avoid it */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3562 | if (vol_info == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3563 | /* turn off POSIX ACL and PATHNAMES if not set |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3564 | originally at mount time */ |
| 3565 | if ((saved_cap & CIFS_UNIX_POSIX_ACL_CAP) == 0) |
| 3566 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
Igor Mammedov | 11b6d64 | 2008-02-15 19:06:04 +0000 | [diff] [blame] | 3567 | if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { |
| 3568 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3569 | cifs_dbg(VFS, "POSIXPATH support change\n"); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3570 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
Igor Mammedov | 11b6d64 | 2008-02-15 19:06:04 +0000 | [diff] [blame] | 3571 | } else if ((cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3572 | cifs_dbg(VFS, "possible reconnect error\n"); |
| 3573 | cifs_dbg(VFS, "server disabled POSIX path support\n"); |
Igor Mammedov | 11b6d64 | 2008-02-15 19:06:04 +0000 | [diff] [blame] | 3574 | } |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3575 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3576 | |
Steve French | 6848b73 | 2011-05-26 18:38:54 +0000 | [diff] [blame] | 3577 | if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3578 | cifs_dbg(VFS, "per-share encryption not supported yet\n"); |
Steve French | 6848b73 | 2011-05-26 18:38:54 +0000 | [diff] [blame] | 3579 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3580 | cap &= CIFS_UNIX_CAP_MASK; |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3581 | if (vol_info && vol_info->no_psx_acl) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3582 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3583 | else if (CIFS_UNIX_POSIX_ACL_CAP & cap) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3584 | cifs_dbg(FYI, "negotiated posix acl support\n"); |
Al Viro | 2c6292a | 2011-06-17 09:05:48 -0400 | [diff] [blame] | 3585 | if (cifs_sb) |
| 3586 | cifs_sb->mnt_cifs_flags |= |
| 3587 | CIFS_MOUNT_POSIXACL; |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3590 | if (vol_info && vol_info->posix_paths == 0) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3591 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3592 | else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3593 | cifs_dbg(FYI, "negotiate posix pathnames\n"); |
Al Viro | 2c6292a | 2011-06-17 09:05:48 -0400 | [diff] [blame] | 3594 | if (cifs_sb) |
| 3595 | cifs_sb->mnt_cifs_flags |= |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3596 | CIFS_MOUNT_POSIX_PATHS; |
| 3597 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3598 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3599 | cifs_dbg(FYI, "Negotiate caps 0x%x\n", (int)cap); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3600 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3601 | if (cap & CIFS_UNIX_FCNTL_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3602 | cifs_dbg(FYI, "FCNTL cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3603 | if (cap & CIFS_UNIX_EXTATTR_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3604 | cifs_dbg(FYI, "EXTATTR cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3605 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3606 | cifs_dbg(FYI, "POSIX path cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3607 | if (cap & CIFS_UNIX_XATTR_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3608 | cifs_dbg(FYI, "XATTR cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3609 | if (cap & CIFS_UNIX_POSIX_ACL_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3610 | cifs_dbg(FYI, "POSIX ACL cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3611 | if (cap & CIFS_UNIX_LARGE_READ_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3612 | cifs_dbg(FYI, "very large read cap\n"); |
Steve French | 75865f8c | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 3613 | if (cap & CIFS_UNIX_LARGE_WRITE_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3614 | cifs_dbg(FYI, "very large write cap\n"); |
Steve French | 6848b73 | 2011-05-26 18:38:54 +0000 | [diff] [blame] | 3615 | if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3616 | cifs_dbg(FYI, "transport encryption cap\n"); |
Steve French | 6848b73 | 2011-05-26 18:38:54 +0000 | [diff] [blame] | 3617 | if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3618 | cifs_dbg(FYI, "mandatory transport encryption cap\n"); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3619 | #endif /* CIFS_DEBUG2 */ |
| 3620 | if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { |
Steve French | 442aa31 | 2007-09-24 20:25:46 +0000 | [diff] [blame] | 3621 | if (vol_info == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3622 | cifs_dbg(FYI, "resetting capabilities failed\n"); |
Steve French | 442aa31 | 2007-09-24 20:25:46 +0000 | [diff] [blame] | 3623 | } else |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3624 | cifs_dbg(VFS, "Negotiating Unix capabilities with the server failed. Consider mounting with the Unix Extensions disabled if problems are found by specifying the nounix mount option.\n"); |
Steve French | 5a44b31 | 2007-09-20 15:16:24 +0000 | [diff] [blame] | 3625 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | } |
| 3629 | |
Sachin Prabhu | 4214ebf | 2016-07-29 22:38:19 +0100 | [diff] [blame] | 3630 | int cifs_setup_cifs_sb(struct smb_vol *pvolume_info, |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 3631 | struct cifs_sb_info *cifs_sb) |
Jeff Layton | b1c8d2b | 2008-10-22 13:57:07 -0400 | [diff] [blame] | 3632 | { |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 3633 | INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks); |
| 3634 | |
Al Viro | 2ced6f6 | 2011-06-17 09:20:04 -0400 | [diff] [blame] | 3635 | spin_lock_init(&cifs_sb->tlink_tree_lock); |
| 3636 | cifs_sb->tlink_tree = RB_ROOT; |
| 3637 | |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3638 | /* |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 3639 | * Temporarily set r/wsize for matching superblock. If we end up using |
| 3640 | * new sb then client will later negotiate it downward if needed. |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3641 | */ |
Jeff Layton | 5eba8ab | 2011-10-19 15:30:26 -0400 | [diff] [blame] | 3642 | cifs_sb->rsize = pvolume_info->rsize; |
Pavel Shilovsky | 25c7f41 | 2011-05-26 23:35:47 +0400 | [diff] [blame] | 3643 | cifs_sb->wsize = pvolume_info->wsize; |
| 3644 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3645 | cifs_sb->mnt_uid = pvolume_info->linux_uid; |
| 3646 | cifs_sb->mnt_gid = pvolume_info->linux_gid; |
| 3647 | cifs_sb->mnt_file_mode = pvolume_info->file_mode; |
| 3648 | cifs_sb->mnt_dir_mode = pvolume_info->dir_mode; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3649 | cifs_dbg(FYI, "file mode: 0x%hx dir mode: 0x%hx\n", |
| 3650 | cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3651 | |
Suresh Jayaraman | 6d20e84 | 2010-12-01 14:42:28 +0530 | [diff] [blame] | 3652 | cifs_sb->actimeo = pvolume_info->actimeo; |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 3653 | cifs_sb->local_nls = pvolume_info->local_nls; |
Suresh Jayaraman | 6d20e84 | 2010-12-01 14:42:28 +0530 | [diff] [blame] | 3654 | |
Aurelien Aptel | 8393072 | 2018-09-20 18:10:25 -0700 | [diff] [blame] | 3655 | if (pvolume_info->nodfs) |
| 3656 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_DFS; |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3657 | if (pvolume_info->noperm) |
| 3658 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM; |
| 3659 | if (pvolume_info->setuids) |
| 3660 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID; |
Steve French | 9593265 | 2016-09-23 01:36:34 -0500 | [diff] [blame] | 3661 | if (pvolume_info->setuidfromacl) |
| 3662 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UID_FROM_ACL; |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3663 | if (pvolume_info->server_ino) |
| 3664 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM; |
| 3665 | if (pvolume_info->remap) |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 3666 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SFM_CHR; |
| 3667 | if (pvolume_info->sfu_remap) |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3668 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR; |
| 3669 | if (pvolume_info->no_xattr) |
| 3670 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR; |
| 3671 | if (pvolume_info->sfu_emul) |
| 3672 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL; |
| 3673 | if (pvolume_info->nobrl) |
| 3674 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 3675 | if (pvolume_info->nohandlecache) |
| 3676 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_HANDLE_CACHE; |
Steve French | be65244 | 2009-02-23 15:21:59 +0000 | [diff] [blame] | 3677 | if (pvolume_info->nostrictsync) |
Steve French | 4717bed | 2009-02-24 14:44:19 +0000 | [diff] [blame] | 3678 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC; |
Steve French | 13a6e42 | 2008-12-02 17:24:33 +0000 | [diff] [blame] | 3679 | if (pvolume_info->mand_lock) |
| 3680 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL; |
Pavel Shilovsky | d4ffff1 | 2011-05-26 06:02:00 +0000 | [diff] [blame] | 3681 | if (pvolume_info->rwpidforward) |
| 3682 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD; |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3683 | if (pvolume_info->cifs_acl) |
| 3684 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL; |
Sachin Prabhu | 3c7c87f | 2012-04-24 15:28:14 +0100 | [diff] [blame] | 3685 | if (pvolume_info->backupuid_specified) { |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 3686 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID; |
Sachin Prabhu | 3c7c87f | 2012-04-24 15:28:14 +0100 | [diff] [blame] | 3687 | cifs_sb->mnt_backupuid = pvolume_info->backupuid; |
| 3688 | } |
| 3689 | if (pvolume_info->backupgid_specified) { |
Shirish Pargaonkar | 3d3ea8e | 2011-09-26 09:56:44 -0500 | [diff] [blame] | 3690 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID; |
Sachin Prabhu | 3c7c87f | 2012-04-24 15:28:14 +0100 | [diff] [blame] | 3691 | cifs_sb->mnt_backupgid = pvolume_info->backupgid; |
| 3692 | } |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3693 | if (pvolume_info->override_uid) |
| 3694 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID; |
| 3695 | if (pvolume_info->override_gid) |
| 3696 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID; |
| 3697 | if (pvolume_info->dynperm) |
| 3698 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM; |
Suresh Jayaraman | fa1df75 | 2010-07-05 18:13:36 +0530 | [diff] [blame] | 3699 | if (pvolume_info->fsc) |
| 3700 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE; |
Jeff Layton | 0eb8a13 | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 3701 | if (pvolume_info->multiuser) |
| 3702 | cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER | |
| 3703 | CIFS_MOUNT_NO_PERM); |
Pavel Shilovsky | d39454f | 2011-01-24 14:16:35 -0500 | [diff] [blame] | 3704 | if (pvolume_info->strict_io) |
| 3705 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO; |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3706 | if (pvolume_info->direct_io) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3707 | cifs_dbg(FYI, "mounting share using direct i/o\n"); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3708 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; |
| 3709 | } |
Stefan Metzmacher | 736a3320 | 2010-07-30 14:56:00 +0200 | [diff] [blame] | 3710 | if (pvolume_info->mfsymlinks) { |
| 3711 | if (pvolume_info->sfu_emul) { |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 3712 | /* |
| 3713 | * Our SFU ("Services for Unix" emulation does not allow |
| 3714 | * creating symlinks but does allow reading existing SFU |
| 3715 | * symlinks (it does allow both creating and reading SFU |
| 3716 | * style mknod and FIFOs though). When "mfsymlinks" and |
| 3717 | * "sfu" are both enabled at the same time, it allows |
| 3718 | * reading both types of symlinks, but will only create |
| 3719 | * them with mfsymlinks format. This allows better |
| 3720 | * Apple compatibility (probably better for Samba too) |
| 3721 | * while still recognizing old Windows style symlinks. |
| 3722 | */ |
| 3723 | cifs_dbg(VFS, "mount options mfsymlinks and sfu both enabled\n"); |
Stefan Metzmacher | 736a3320 | 2010-07-30 14:56:00 +0200 | [diff] [blame] | 3724 | } |
Steve French | db8b631 | 2014-09-22 05:13:55 -0500 | [diff] [blame] | 3725 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MF_SYMLINKS; |
Stefan Metzmacher | 736a3320 | 2010-07-30 14:56:00 +0200 | [diff] [blame] | 3726 | } |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 3727 | |
| 3728 | if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm)) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3729 | cifs_dbg(VFS, "mount option dynperm ignored if cifsacl mount option supported\n"); |
Sachin Prabhu | 4214ebf | 2016-07-29 22:38:19 +0100 | [diff] [blame] | 3730 | |
| 3731 | if (pvolume_info->prepath) { |
| 3732 | cifs_sb->prepath = kstrdup(pvolume_info->prepath, GFP_KERNEL); |
| 3733 | if (cifs_sb->prepath == NULL) |
| 3734 | return -ENOMEM; |
| 3735 | } |
| 3736 | |
| 3737 | return 0; |
Jeff Layton | b1c8d2b | 2008-10-22 13:57:07 -0400 | [diff] [blame] | 3738 | } |
| 3739 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 3740 | void |
| 3741 | cifs_cleanup_volume_info_contents(struct smb_vol *volume_info) |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3742 | { |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 3743 | kfree(volume_info->username); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3744 | kzfree(volume_info->password); |
Jesper Juhl | 95c7545 | 2011-08-27 18:58:34 +0200 | [diff] [blame] | 3745 | kfree(volume_info->UNC); |
Sean Finney | b946845 | 2011-04-11 13:19:32 +0000 | [diff] [blame] | 3746 | kfree(volume_info->domainname); |
| 3747 | kfree(volume_info->iocharset); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3748 | kfree(volume_info->prepath); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3749 | } |
| 3750 | |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3751 | void |
| 3752 | cifs_cleanup_volume_info(struct smb_vol *volume_info) |
| 3753 | { |
| 3754 | if (!volume_info) |
| 3755 | return; |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 3756 | cifs_cleanup_volume_info_contents(volume_info); |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3757 | kfree(volume_info); |
| 3758 | } |
| 3759 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 3760 | /* Release all succeed connections */ |
| 3761 | static inline void mount_put_conns(struct cifs_sb_info *cifs_sb, |
| 3762 | unsigned int xid, |
| 3763 | struct TCP_Server_Info *server, |
| 3764 | struct cifs_ses *ses, struct cifs_tcon *tcon) |
| 3765 | { |
| 3766 | int rc = 0; |
| 3767 | |
| 3768 | if (tcon) |
| 3769 | cifs_put_tcon(tcon); |
| 3770 | else if (ses) |
| 3771 | cifs_put_smb_ses(ses); |
| 3772 | else if (server) |
| 3773 | cifs_put_tcp_session(server, 0); |
| 3774 | cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_POSIX_PATHS; |
| 3775 | free_xid(xid); |
| 3776 | } |
| 3777 | |
| 3778 | /* Get connections for tcp, ses and tcon */ |
| 3779 | static int mount_get_conns(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, |
| 3780 | unsigned int *xid, |
| 3781 | struct TCP_Server_Info **nserver, |
| 3782 | struct cifs_ses **nses, struct cifs_tcon **ntcon) |
| 3783 | { |
| 3784 | int rc = 0; |
| 3785 | struct TCP_Server_Info *server; |
| 3786 | struct cifs_ses *ses; |
| 3787 | struct cifs_tcon *tcon; |
| 3788 | |
| 3789 | *nserver = NULL; |
| 3790 | *nses = NULL; |
| 3791 | *ntcon = NULL; |
| 3792 | |
| 3793 | *xid = get_xid(); |
| 3794 | |
| 3795 | /* get a reference to a tcp session */ |
| 3796 | server = cifs_get_tcp_session(vol); |
| 3797 | if (IS_ERR(server)) { |
| 3798 | rc = PTR_ERR(server); |
| 3799 | return rc; |
| 3800 | } |
| 3801 | |
| 3802 | *nserver = server; |
| 3803 | |
| 3804 | if ((vol->max_credits < 20) || (vol->max_credits > 60000)) |
| 3805 | server->max_credits = SMB2_MAX_CREDITS_AVAILABLE; |
| 3806 | else |
| 3807 | server->max_credits = vol->max_credits; |
| 3808 | |
| 3809 | /* get a reference to a SMB session */ |
| 3810 | ses = cifs_get_smb_ses(server, vol); |
| 3811 | if (IS_ERR(ses)) { |
| 3812 | rc = PTR_ERR(ses); |
| 3813 | return rc; |
| 3814 | } |
| 3815 | |
| 3816 | *nses = ses; |
| 3817 | |
| 3818 | if ((vol->persistent == true) && (!(ses->server->capabilities & |
| 3819 | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES))) { |
| 3820 | cifs_dbg(VFS, "persistent handles not supported by server\n"); |
| 3821 | return -EOPNOTSUPP; |
| 3822 | } |
| 3823 | |
| 3824 | /* search for existing tcon to this server share */ |
| 3825 | tcon = cifs_get_tcon(ses, vol); |
| 3826 | if (IS_ERR(tcon)) { |
| 3827 | rc = PTR_ERR(tcon); |
| 3828 | return rc; |
| 3829 | } |
| 3830 | |
| 3831 | *ntcon = tcon; |
| 3832 | |
| 3833 | /* if new SMB3.11 POSIX extensions are supported do not remap / and \ */ |
| 3834 | if (tcon->posix_extensions) |
| 3835 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; |
| 3836 | |
| 3837 | /* tell server which Unix caps we support */ |
| 3838 | if (cap_unix(tcon->ses)) { |
| 3839 | /* |
| 3840 | * reset of caps checks mount to see if unix extensions disabled |
| 3841 | * for just this mount. |
| 3842 | */ |
| 3843 | reset_cifs_unix_caps(*xid, tcon, cifs_sb, vol); |
| 3844 | if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) && |
| 3845 | (le64_to_cpu(tcon->fsUnixInfo.Capability) & |
| 3846 | CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)) |
| 3847 | return -EACCES; |
| 3848 | } else |
| 3849 | tcon->unix_ext = 0; /* server does not support them */ |
| 3850 | |
| 3851 | /* do not care if a following call succeed - informational */ |
| 3852 | if (!tcon->pipe && server->ops->qfs_tcon) |
| 3853 | server->ops->qfs_tcon(*xid, tcon); |
| 3854 | |
| 3855 | cifs_sb->wsize = server->ops->negotiate_wsize(tcon, vol); |
| 3856 | cifs_sb->rsize = server->ops->negotiate_rsize(tcon, vol); |
| 3857 | |
| 3858 | return 0; |
| 3859 | } |
| 3860 | |
| 3861 | static int mount_setup_tlink(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses, |
| 3862 | struct cifs_tcon *tcon) |
| 3863 | { |
| 3864 | struct tcon_link *tlink; |
| 3865 | |
| 3866 | /* hang the tcon off of the superblock */ |
| 3867 | tlink = kzalloc(sizeof(*tlink), GFP_KERNEL); |
| 3868 | if (tlink == NULL) |
| 3869 | return -ENOMEM; |
| 3870 | |
| 3871 | tlink->tl_uid = ses->linux_uid; |
| 3872 | tlink->tl_tcon = tcon; |
| 3873 | tlink->tl_time = jiffies; |
| 3874 | set_bit(TCON_LINK_MASTER, &tlink->tl_flags); |
| 3875 | set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); |
| 3876 | |
| 3877 | cifs_sb->master_tlink = tlink; |
| 3878 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 3879 | tlink_rb_insert(&cifs_sb->tlink_tree, tlink); |
| 3880 | spin_unlock(&cifs_sb->tlink_tree_lock); |
| 3881 | |
| 3882 | queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, |
| 3883 | TLINK_IDLE_EXPIRE); |
| 3884 | return 0; |
| 3885 | } |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3886 | |
Steve French | 2d6d589 | 2009-04-09 00:36:44 +0000 | [diff] [blame] | 3887 | #ifdef CONFIG_CIFS_DFS_UPCALL |
Steve French | 6d3ea7e | 2012-11-28 22:34:41 -0600 | [diff] [blame] | 3888 | /* |
| 3889 | * cifs_build_path_to_root returns full path to root when we do not have an |
| 3890 | * exiting connection (tcon) |
| 3891 | */ |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3892 | static char * |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3893 | build_unc_path_to_root(const struct smb_vol *vol, |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3894 | const struct cifs_sb_info *cifs_sb) |
| 3895 | { |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3896 | char *full_path, *pos; |
Jeff Layton | 839db3d | 2012-12-10 06:10:45 -0500 | [diff] [blame] | 3897 | unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0; |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3898 | unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3899 | |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3900 | full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3901 | if (full_path == NULL) |
| 3902 | return ERR_PTR(-ENOMEM); |
| 3903 | |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3904 | strncpy(full_path, vol->UNC, unc_len); |
| 3905 | pos = full_path + unc_len; |
| 3906 | |
| 3907 | if (pplen) { |
Jeff Layton | 1fc29ba | 2013-05-31 10:00:18 -0400 | [diff] [blame] | 3908 | *pos = CIFS_DIR_SEP(cifs_sb); |
| 3909 | strncpy(pos + 1, vol->prepath, pplen); |
Jeff Layton | b2a0fa1 | 2011-07-06 08:10:36 -0400 | [diff] [blame] | 3910 | pos += pplen; |
| 3911 | } |
| 3912 | |
| 3913 | *pos = '\0'; /* add trailing null */ |
Steve French | f87d39d | 2011-05-27 03:50:55 +0000 | [diff] [blame] | 3914 | convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb)); |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3915 | cifs_dbg(FYI, "%s: full_path=%s\n", __func__, full_path); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3916 | return full_path; |
| 3917 | } |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3918 | |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3919 | /** |
| 3920 | * expand_dfs_referral - Perform a dfs referral query and update the cifs_sb |
| 3921 | * |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3922 | * |
Sean Finney | 046462a | 2011-04-11 13:19:33 +0000 | [diff] [blame] | 3923 | * If a referral is found, cifs_sb->mountdata will be (re-)allocated |
| 3924 | * to a string containing updated options for the submount. Otherwise it |
| 3925 | * will be left untouched. |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3926 | * |
| 3927 | * Returns the rc from get_dfs_path to the caller, which can be used to |
| 3928 | * determine whether there were referrals. |
| 3929 | */ |
| 3930 | static int |
Pavel Shilovsky | b669f33 | 2012-05-27 20:21:53 +0400 | [diff] [blame] | 3931 | expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses, |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3932 | struct smb_vol *volume_info, struct cifs_sb_info *cifs_sb, |
Sean Finney | 046462a | 2011-04-11 13:19:33 +0000 | [diff] [blame] | 3933 | int check_prefix) |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3934 | { |
| 3935 | int rc; |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3936 | struct dfs_info3_param referral = {0}; |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3937 | char *full_path = NULL, *ref_path = NULL, *mdata = NULL; |
| 3938 | |
Aurelien Aptel | 8393072 | 2018-09-20 18:10:25 -0700 | [diff] [blame] | 3939 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS) |
| 3940 | return -EREMOTE; |
| 3941 | |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3942 | full_path = build_unc_path_to_root(volume_info, cifs_sb); |
| 3943 | if (IS_ERR(full_path)) |
| 3944 | return PTR_ERR(full_path); |
| 3945 | |
| 3946 | /* For DFS paths, skip the first '\' of the UNC */ |
| 3947 | ref_path = check_prefix ? full_path + 1 : volume_info->UNC + 1; |
| 3948 | |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3949 | rc = dfs_cache_find(xid, ses, cifs_sb->local_nls, cifs_remap(cifs_sb), |
| 3950 | ref_path, &referral, NULL); |
| 3951 | if (!rc) { |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3952 | char *fake_devname = NULL; |
| 3953 | |
| 3954 | mdata = cifs_compose_mount_options(cifs_sb->mountdata, |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3955 | full_path + 1, &referral, |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3956 | &fake_devname); |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3957 | free_dfs_info_param(&referral); |
Sean Finney | 046462a | 2011-04-11 13:19:33 +0000 | [diff] [blame] | 3958 | |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3959 | if (IS_ERR(mdata)) { |
| 3960 | rc = PTR_ERR(mdata); |
| 3961 | mdata = NULL; |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3962 | } else { |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 3963 | cifs_cleanup_volume_info_contents(volume_info); |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3964 | rc = cifs_setup_volume_info(volume_info, mdata, |
Paulo Alcantara | 1c78022 | 2018-11-14 16:24:03 -0200 | [diff] [blame^] | 3965 | fake_devname, false); |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3966 | } |
Jeff Layton | b9bce2e | 2011-07-06 08:10:39 -0400 | [diff] [blame] | 3967 | kfree(fake_devname); |
| 3968 | kfree(cifs_sb->mountdata); |
Sean Finney | 046462a | 2011-04-11 13:19:33 +0000 | [diff] [blame] | 3969 | cifs_sb->mountdata = mdata; |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3970 | } |
| 3971 | kfree(full_path); |
| 3972 | return rc; |
| 3973 | } |
Steve French | 2d6d589 | 2009-04-09 00:36:44 +0000 | [diff] [blame] | 3974 | #endif |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 3975 | |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 3976 | static int |
| 3977 | cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data, |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 3978 | const char *devname, bool is_smb3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | { |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 3980 | int rc = 0; |
Sean Finney | dd61394 | 2011-04-11 13:19:30 +0000 | [diff] [blame] | 3981 | |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 3982 | if (cifs_parse_mount_options(mount_data, devname, volume_info, is_smb3)) |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 3983 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | |
Jeff Layton | 7586b76 | 2008-12-01 18:41:49 -0500 | [diff] [blame] | 3985 | if (volume_info->nullauth) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3986 | cifs_dbg(FYI, "Anonymous login\n"); |
Jeff Layton | 04febab | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 3987 | kfree(volume_info->username); |
| 3988 | volume_info->username = NULL; |
Jeff Layton | 7586b76 | 2008-12-01 18:41:49 -0500 | [diff] [blame] | 3989 | } else if (volume_info->username) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | /* BB fixme parse for domain name here */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3991 | cifs_dbg(FYI, "Username: %s\n", volume_info->username); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | } else { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 3993 | cifs_dbg(VFS, "No username specified\n"); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3994 | /* In userspace mount helper we can get user name from alternate |
| 3995 | locations such as env variables and files on disk */ |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 3996 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | /* this is needed for ASCII cp to Unicode converts */ |
Jeff Layton | 7586b76 | 2008-12-01 18:41:49 -0500 | [diff] [blame] | 4000 | if (volume_info->iocharset == NULL) { |
Jeff Layton | a5fc4ce | 2010-04-24 07:57:42 -0400 | [diff] [blame] | 4001 | /* load_nls_default cannot return null */ |
| 4002 | volume_info->local_nls = load_nls_default(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | } else { |
Jeff Layton | a5fc4ce | 2010-04-24 07:57:42 -0400 | [diff] [blame] | 4004 | volume_info->local_nls = load_nls(volume_info->iocharset); |
| 4005 | if (volume_info->local_nls == NULL) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4006 | cifs_dbg(VFS, "CIFS mount error: iocharset %s not found\n", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4007 | volume_info->iocharset); |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 4008 | return -ELIBACC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | } |
| 4010 | } |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4011 | |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4012 | return rc; |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | struct smb_vol * |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 4016 | cifs_get_volume_info(char *mount_data, const char *devname, bool is_smb3) |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 4017 | { |
| 4018 | int rc; |
| 4019 | struct smb_vol *volume_info; |
| 4020 | |
Jeff Layton | 6ee9542 | 2012-11-26 11:09:57 -0500 | [diff] [blame] | 4021 | volume_info = kmalloc(sizeof(struct smb_vol), GFP_KERNEL); |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 4022 | if (!volume_info) |
| 4023 | return ERR_PTR(-ENOMEM); |
| 4024 | |
Steve French | c7c137b | 2018-06-06 17:59:29 -0500 | [diff] [blame] | 4025 | rc = cifs_setup_volume_info(volume_info, mount_data, devname, is_smb3); |
Jeff Layton | 04db79b | 2011-07-06 08:10:38 -0400 | [diff] [blame] | 4026 | if (rc) { |
| 4027 | cifs_cleanup_volume_info(volume_info); |
| 4028 | volume_info = ERR_PTR(rc); |
| 4029 | } |
| 4030 | |
| 4031 | return volume_info; |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
Aurelien Aptel | a6b5058 | 2016-05-25 19:59:09 +0200 | [diff] [blame] | 4034 | static int |
| 4035 | cifs_are_all_path_components_accessible(struct TCP_Server_Info *server, |
| 4036 | unsigned int xid, |
| 4037 | struct cifs_tcon *tcon, |
| 4038 | struct cifs_sb_info *cifs_sb, |
| 4039 | char *full_path) |
| 4040 | { |
| 4041 | int rc; |
| 4042 | char *s; |
| 4043 | char sep, tmp; |
| 4044 | |
| 4045 | sep = CIFS_DIR_SEP(cifs_sb); |
| 4046 | s = full_path; |
| 4047 | |
| 4048 | rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, ""); |
| 4049 | while (rc == 0) { |
| 4050 | /* skip separators */ |
| 4051 | while (*s == sep) |
| 4052 | s++; |
| 4053 | if (!*s) |
| 4054 | break; |
| 4055 | /* next separator */ |
| 4056 | while (*s && *s != sep) |
| 4057 | s++; |
| 4058 | |
| 4059 | /* |
| 4060 | * temporarily null-terminate the path at the end of |
| 4061 | * the current component |
| 4062 | */ |
| 4063 | tmp = *s; |
| 4064 | *s = 0; |
| 4065 | rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, |
| 4066 | full_path); |
| 4067 | *s = tmp; |
| 4068 | } |
| 4069 | return rc; |
| 4070 | } |
| 4071 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4072 | /* |
| 4073 | * Check if path is remote (e.g. a DFS share). Return -EREMOTE if it is, |
| 4074 | * otherwise 0. |
| 4075 | */ |
| 4076 | static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol, |
| 4077 | const unsigned int xid, |
| 4078 | struct TCP_Server_Info *server, |
| 4079 | struct cifs_tcon *tcon) |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4080 | { |
Jeff Layton | 1daaae8 | 2012-03-21 06:30:40 -0400 | [diff] [blame] | 4081 | int rc; |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4082 | char *full_path; |
| 4083 | |
| 4084 | if (!server->ops->is_path_accessible) |
| 4085 | return -EOPNOTSUPP; |
| 4086 | |
| 4087 | /* |
| 4088 | * cifs_build_path_to_root works only when we have a valid tcon |
| 4089 | */ |
| 4090 | full_path = cifs_build_path_to_root(vol, cifs_sb, tcon, |
| 4091 | tcon->Flags & SMB_SHARE_IS_IN_DFS); |
| 4092 | if (full_path == NULL) |
| 4093 | return -ENOMEM; |
| 4094 | |
| 4095 | cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path); |
| 4096 | |
| 4097 | rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, |
| 4098 | full_path); |
| 4099 | if (rc != 0 && rc != -EREMOTE) { |
| 4100 | kfree(full_path); |
| 4101 | return rc; |
| 4102 | } |
| 4103 | |
| 4104 | if (rc != -EREMOTE) { |
| 4105 | rc = cifs_are_all_path_components_accessible(server, xid, tcon, |
| 4106 | cifs_sb, |
| 4107 | full_path); |
| 4108 | if (rc != 0) { |
| 4109 | cifs_dbg(VFS, "cannot query dirs between root and final path, " |
| 4110 | "enabling CIFS_MOUNT_USE_PREFIX_PATH\n"); |
| 4111 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; |
| 4112 | rc = 0; |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | kfree(full_path); |
| 4117 | return rc; |
| 4118 | } |
| 4119 | |
| 4120 | #ifdef CONFIG_CIFS_DFS_UPCALL |
| 4121 | int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) |
| 4122 | { |
| 4123 | int rc = 0; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4124 | unsigned int xid; |
Pavel Shilovsky | af4281d | 2012-05-27 20:48:35 +0400 | [diff] [blame] | 4125 | struct cifs_ses *ses; |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4126 | struct cifs_tcon *tcon = NULL; |
Pavel Shilovsky | af4281d | 2012-05-27 20:48:35 +0400 | [diff] [blame] | 4127 | struct TCP_Server_Info *server; |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4128 | char *old_mountdata; |
| 4129 | int count; |
Al Viro | dd85446 | 2011-06-17 08:24:42 -0400 | [diff] [blame] | 4130 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4131 | rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, &tcon); |
| 4132 | if (!rc && tcon) { |
| 4133 | rc = is_path_remote(cifs_sb, vol, xid, server, tcon); |
| 4134 | if (!rc) |
| 4135 | goto out; |
| 4136 | if (rc != -EREMOTE) |
| 4137 | goto error; |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4138 | } |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4139 | if ((rc == -EACCES) || (rc == -EOPNOTSUPP) || (ses == NULL) || (server == NULL)) |
| 4140 | goto error; |
Pavel Shilovsky | 724d9f1 | 2011-05-05 09:55:12 +0000 | [diff] [blame] | 4141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | |
Sean Finney | c1508ca | 2011-04-11 13:19:31 +0000 | [diff] [blame] | 4143 | /* |
| 4144 | * Perform an unconditional check for whether there are DFS |
| 4145 | * referrals for this path without prefix, to provide support |
| 4146 | * for DFS referrals from w2k8 servers which don't seem to respond |
| 4147 | * with PATH_NOT_COVERED to requests that include the prefix. |
| 4148 | * Chase the referral if found, otherwise continue normally. |
| 4149 | */ |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4150 | old_mountdata = cifs_sb->mountdata; |
| 4151 | (void)expand_dfs_referral(xid, ses, vol, cifs_sb, false); |
Sean Finney | c1508ca | 2011-04-11 13:19:31 +0000 | [diff] [blame] | 4152 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4153 | if (cifs_sb->mountdata == NULL) { |
| 4154 | rc = -ENOENT; |
| 4155 | goto error; |
| 4156 | } |
| 4157 | |
| 4158 | if (cifs_sb->mountdata != old_mountdata) { |
| 4159 | /* If we were redirected, reconnect to new target server */ |
| 4160 | mount_put_conns(cifs_sb, xid, server, ses, tcon); |
| 4161 | rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, &tcon); |
| 4162 | } |
| 4163 | if (rc) { |
| 4164 | if (rc == -EACCES || rc == -EOPNOTSUPP) |
| 4165 | goto error; |
| 4166 | } |
| 4167 | |
| 4168 | for (count = 1; ;) { |
| 4169 | if (!rc && tcon) { |
| 4170 | rc = is_path_remote(cifs_sb, vol, xid, server, tcon); |
| 4171 | if (!rc || rc != -EREMOTE) |
| 4172 | break; |
Pavel Shilovsky | 68889f2 | 2012-05-25 14:40:22 +0400 | [diff] [blame] | 4173 | } |
Steve French | 6d3ea7e | 2012-11-28 22:34:41 -0600 | [diff] [blame] | 4174 | /* |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4175 | * BB: when we implement proper loop detection, |
| 4176 | * we will remove this check. But now we need it |
| 4177 | * to prevent an indefinite loop if 'DFS tree' is |
| 4178 | * misconfigured (i.e. has loops). |
Steve French | 6d3ea7e | 2012-11-28 22:34:41 -0600 | [diff] [blame] | 4179 | */ |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4180 | if (count++ > MAX_NESTED_LINKS) { |
Igor Mammedov | 5c2503a | 2009-04-21 19:31:05 +0400 | [diff] [blame] | 4181 | rc = -ELOOP; |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4182 | break; |
Igor Mammedov | 5c2503a | 2009-04-21 19:31:05 +0400 | [diff] [blame] | 4183 | } |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 4184 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4185 | old_mountdata = cifs_sb->mountdata; |
| 4186 | rc = expand_dfs_referral(xid, tcon->ses, vol, cifs_sb, |
| 4187 | true); |
| 4188 | if (rc) |
| 4189 | break; |
Jeff Layton | 7b91e26 | 2009-07-23 15:22:30 -0400 | [diff] [blame] | 4190 | |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4191 | if (cifs_sb->mountdata != old_mountdata) { |
| 4192 | mount_put_conns(cifs_sb, xid, server, ses, tcon); |
| 4193 | rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, |
| 4194 | &tcon); |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 4195 | } |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4196 | if (rc) { |
| 4197 | if (rc == -EACCES || rc == -EOPNOTSUPP || !server || |
| 4198 | !ses) |
| 4199 | goto error; |
| 4200 | } |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 4201 | } |
| 4202 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4203 | if (rc) |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4204 | goto error; |
Igor Mammedov | 1bfe73c | 2009-04-01 17:54:42 +0400 | [diff] [blame] | 4205 | |
Aurelien Aptel | 5fc7fcd | 2018-11-16 16:13:25 +0100 | [diff] [blame] | 4206 | /* |
| 4207 | * After reconnecting to a different server, unique ids won't |
| 4208 | * match anymore, so we disable serverino. This prevents |
| 4209 | * dentry revalidation to think the dentry are stale (ESTALE). |
| 4210 | */ |
| 4211 | cifs_autodisable_serverino(cifs_sb); |
Jeff Layton | 70fe7dc | 2007-11-16 22:21:07 +0000 | [diff] [blame] | 4212 | out: |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 4213 | free_xid(xid); |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4214 | return mount_setup_tlink(cifs_sb, ses, tcon); |
| 4215 | |
| 4216 | error: |
| 4217 | mount_put_conns(cifs_sb, xid, server, ses, tcon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | return rc; |
| 4219 | } |
Paulo Alcantara | 56c762e | 2018-11-14 13:03:14 -0200 | [diff] [blame] | 4220 | #else |
| 4221 | int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) |
| 4222 | { |
| 4223 | int rc = 0; |
| 4224 | unsigned int xid; |
| 4225 | struct cifs_ses *ses; |
| 4226 | struct cifs_tcon *tcon; |
| 4227 | struct TCP_Server_Info *server; |
| 4228 | |
| 4229 | rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, &tcon); |
| 4230 | if (rc) |
| 4231 | goto error; |
| 4232 | |
| 4233 | if (tcon) { |
| 4234 | rc = is_path_remote(cifs_sb, vol, xid, server, tcon); |
| 4235 | if (rc == -EREMOTE) |
| 4236 | rc = -EOPNOTSUPP; |
| 4237 | if (rc) |
| 4238 | goto error; |
| 4239 | } |
| 4240 | |
| 4241 | free_xid(xid); |
| 4242 | |
| 4243 | return mount_setup_tlink(cifs_sb, ses, tcon); |
| 4244 | |
| 4245 | error: |
| 4246 | mount_put_conns(cifs_sb, xid, server, ses, tcon); |
| 4247 | return rc; |
| 4248 | } |
| 4249 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | |
Jeff Layton | 8d1bca3 | 2011-06-11 21:17:10 -0400 | [diff] [blame] | 4251 | /* |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4252 | * Issue a TREE_CONNECT request. |
Jeff Layton | 8d1bca3 | 2011-06-11 21:17:10 -0400 | [diff] [blame] | 4253 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | int |
Pavel Shilovsky | 2e6e02a | 2012-05-25 11:11:39 +0400 | [diff] [blame] | 4255 | CIFSTCon(const unsigned int xid, struct cifs_ses *ses, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4256 | const char *tree, struct cifs_tcon *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | const struct nls_table *nls_codepage) |
| 4258 | { |
| 4259 | struct smb_hdr *smb_buffer; |
| 4260 | struct smb_hdr *smb_buffer_response; |
| 4261 | TCONX_REQ *pSMB; |
| 4262 | TCONX_RSP *pSMBr; |
| 4263 | unsigned char *bcc_ptr; |
| 4264 | int rc = 0; |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 4265 | int length; |
| 4266 | __u16 bytes_left, count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
| 4268 | if (ses == NULL) |
| 4269 | return -EIO; |
| 4270 | |
| 4271 | smb_buffer = cifs_buf_get(); |
Steve French | ca43e3b | 2009-09-01 17:20:50 +0000 | [diff] [blame] | 4272 | if (smb_buffer == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | return -ENOMEM; |
Steve French | ca43e3b | 2009-09-01 17:20:50 +0000 | [diff] [blame] | 4274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | smb_buffer_response = smb_buffer; |
| 4276 | |
| 4277 | header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX, |
| 4278 | NULL /*no tid */ , 4 /*wct */ ); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4279 | |
Pavel Shilovsky | 8825736 | 2012-05-23 14:01:59 +0400 | [diff] [blame] | 4280 | smb_buffer->Mid = get_next_mid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | smb_buffer->Uid = ses->Suid; |
| 4282 | pSMB = (TCONX_REQ *) smb_buffer; |
| 4283 | pSMBr = (TCONX_RSP *) smb_buffer_response; |
| 4284 | |
| 4285 | pSMB->AndXCommand = 0xFF; |
| 4286 | pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | bcc_ptr = &pSMB->Password[0]; |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4288 | if (tcon->pipe || (ses->server->sec_mode & SECMODE_USER)) { |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4289 | pSMB->PasswordLength = cpu_to_le16(1); /* minimum */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4290 | *bcc_ptr = 0; /* password is null byte */ |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4291 | bcc_ptr++; /* skip password */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4292 | /* already aligned so no need to do it below */ |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4293 | } else { |
Shirish Pargaonkar | 540b2e3 | 2011-01-18 22:33:54 -0600 | [diff] [blame] | 4294 | pSMB->PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE); |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4295 | /* BB FIXME add code to fail this if NTLMv2 or Kerberos |
| 4296 | specified as required (when that support is added to |
| 4297 | the vfs in the future) as only NTLM or the much |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4298 | weaker LANMAN (which we do not send by default) is accepted |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4299 | by Samba (not sure whether other servers allow |
| 4300 | NTLMv2 password here) */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4301 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 4302 | if ((global_secflags & CIFSSEC_MAY_LANMAN) && |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 4303 | (ses->sectype == LANMAN)) |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 4304 | calc_lanman_hash(tcon->password, ses->server->cryptkey, |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4305 | ses->server->sec_mode & |
Jeff Layton | 4e53a3f | 2008-12-05 20:41:21 -0500 | [diff] [blame] | 4306 | SECMODE_PW_ENCRYPT ? true : false, |
| 4307 | bcc_ptr); |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4308 | else |
| 4309 | #endif /* CIFS_WEAK_PW_HASH */ |
Shirish Pargaonkar | ee2c925 | 2011-01-27 09:58:04 -0600 | [diff] [blame] | 4310 | rc = SMBNTencrypt(tcon->password, ses->server->cryptkey, |
Shirish Pargaonkar | 9ef5992 | 2011-10-20 13:21:59 -0500 | [diff] [blame] | 4311 | bcc_ptr, nls_codepage); |
Steve French | f3a31a2 | 2015-03-26 19:23:20 -0500 | [diff] [blame] | 4312 | if (rc) { |
| 4313 | cifs_dbg(FYI, "%s Can't generate NTLM rsp. Error: %d\n", |
| 4314 | __func__, rc); |
| 4315 | cifs_buf_release(smb_buffer); |
| 4316 | return rc; |
| 4317 | } |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4318 | |
Shirish Pargaonkar | 540b2e3 | 2011-01-18 22:33:54 -0600 | [diff] [blame] | 4319 | bcc_ptr += CIFS_AUTH_RESP_SIZE; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 4320 | if (ses->capabilities & CAP_UNICODE) { |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 4321 | /* must align unicode strings */ |
| 4322 | *bcc_ptr = 0; /* null byte password */ |
| 4323 | bcc_ptr++; |
| 4324 | } |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 4325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | |
Jeff Layton | 38d77c5 | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4327 | if (ses->server->sign) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4329 | |
| 4330 | if (ses->capabilities & CAP_STATUS32) { |
| 4331 | smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 4332 | } |
| 4333 | if (ses->capabilities & CAP_DFS) { |
| 4334 | smb_buffer->Flags2 |= SMBFLG2_DFS; |
| 4335 | } |
| 4336 | if (ses->capabilities & CAP_UNICODE) { |
| 4337 | smb_buffer->Flags2 |= SMBFLG2_UNICODE; |
| 4338 | length = |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4339 | cifs_strtoUTF16((__le16 *) bcc_ptr, tree, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4340 | 6 /* max utf8 char length in bytes */ * |
Steve French | a878fb2 | 2006-05-30 18:04:19 +0000 | [diff] [blame] | 4341 | (/* server len*/ + 256 /* share len */), nls_codepage); |
| 4342 | bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | bcc_ptr += 2; /* skip trailing null */ |
| 4344 | } else { /* ASCII */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | strcpy(bcc_ptr, tree); |
| 4346 | bcc_ptr += strlen(tree) + 1; |
| 4347 | } |
| 4348 | strcpy(bcc_ptr, "?????"); |
| 4349 | bcc_ptr += strlen("?????"); |
| 4350 | bcc_ptr += 1; |
| 4351 | count = bcc_ptr - &pSMB->Password[0]; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4352 | pSMB->hdr.smb_buf_length = cpu_to_be32(be32_to_cpu( |
| 4353 | pSMB->hdr.smb_buf_length) + count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | pSMB->ByteCount = cpu_to_le16(count); |
| 4355 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4356 | rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 4357 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | /* above now done in SendReceive */ |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4360 | if (rc == 0) { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4361 | bool is_unicode; |
| 4362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | tcon->tidStatus = CifsGood; |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 4364 | tcon->need_reconnect = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | tcon->tid = smb_buffer_response->Tid; |
| 4366 | bcc_ptr = pByteArea(smb_buffer_response); |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 4367 | bytes_left = get_bcc(smb_buffer_response); |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4368 | length = strnlen(bcc_ptr, bytes_left - 2); |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4369 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) |
| 4370 | is_unicode = true; |
| 4371 | else |
| 4372 | is_unicode = false; |
| 4373 | |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4374 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4375 | /* skip service field (NB: this field is always ASCII) */ |
Steve French | 7f8ed42 | 2007-09-28 22:28:55 +0000 | [diff] [blame] | 4376 | if (length == 3) { |
| 4377 | if ((bcc_ptr[0] == 'I') && (bcc_ptr[1] == 'P') && |
| 4378 | (bcc_ptr[2] == 'C')) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4379 | cifs_dbg(FYI, "IPC connection\n"); |
Aurelien Aptel | b327a71 | 2018-01-24 13:46:10 +0100 | [diff] [blame] | 4380 | tcon->ipc = true; |
| 4381 | tcon->pipe = true; |
Steve French | 7f8ed42 | 2007-09-28 22:28:55 +0000 | [diff] [blame] | 4382 | } |
| 4383 | } else if (length == 2) { |
| 4384 | if ((bcc_ptr[0] == 'A') && (bcc_ptr[1] == ':')) { |
| 4385 | /* the most common case */ |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4386 | cifs_dbg(FYI, "disk share connection\n"); |
Steve French | 7f8ed42 | 2007-09-28 22:28:55 +0000 | [diff] [blame] | 4387 | } |
| 4388 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4389 | bcc_ptr += length + 1; |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4390 | bytes_left -= (length + 1); |
Zhao Hongjiang | 46b51d0 | 2013-06-24 01:57:47 -0500 | [diff] [blame] | 4391 | strlcpy(tcon->treeName, tree, sizeof(tcon->treeName)); |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4392 | |
| 4393 | /* mostly informational -- no need to fail on error here */ |
Jeff Layton | 90a98b2 | 2009-07-20 13:40:52 -0400 | [diff] [blame] | 4394 | kfree(tcon->nativeFileSystem); |
Steve French | acbbb76 | 2012-01-18 22:32:33 -0600 | [diff] [blame] | 4395 | tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr, |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4396 | bytes_left, is_unicode, |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4397 | nls_codepage); |
| 4398 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4399 | cifs_dbg(FYI, "nativeFileSystem=%s\n", tcon->nativeFileSystem); |
Jeff Layton | cc20c03 | 2009-04-30 07:16:21 -0400 | [diff] [blame] | 4400 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 4401 | if ((smb_buffer_response->WordCount == 3) || |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4402 | (smb_buffer_response->WordCount == 7)) |
| 4403 | /* field is in same location */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 4404 | tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); |
| 4405 | else |
| 4406 | tcon->Flags = 0; |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4407 | cifs_dbg(FYI, "Tcon flags: 0x%x\n", tcon->Flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
Mariusz Kozlowski | a8a11d3 | 2007-10-03 16:41:24 +0000 | [diff] [blame] | 4410 | cifs_buf_release(smb_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | return rc; |
| 4412 | } |
| 4413 | |
Al Viro | 2e32cf5 | 2013-10-03 12:53:37 -0400 | [diff] [blame] | 4414 | static void delayed_free(struct rcu_head *p) |
| 4415 | { |
| 4416 | struct cifs_sb_info *sbi = container_of(p, struct cifs_sb_info, rcu); |
| 4417 | unload_nls(sbi->local_nls); |
| 4418 | kfree(sbi); |
| 4419 | } |
| 4420 | |
Al Viro | 2a9b995 | 2011-06-17 09:27:16 -0400 | [diff] [blame] | 4421 | void |
| 4422 | cifs_umount(struct cifs_sb_info *cifs_sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | { |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4424 | struct rb_root *root = &cifs_sb->tlink_tree; |
| 4425 | struct rb_node *node; |
| 4426 | struct tcon_link *tlink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4428 | cancel_delayed_work_sync(&cifs_sb->prune_tlinks); |
| 4429 | |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4430 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 4431 | while ((node = rb_first(root))) { |
| 4432 | tlink = rb_entry(node, struct tcon_link, tl_rbnode); |
| 4433 | cifs_get_tlink(tlink); |
| 4434 | clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); |
| 4435 | rb_erase(node, root); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4436 | |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4437 | spin_unlock(&cifs_sb->tlink_tree_lock); |
| 4438 | cifs_put_tlink(tlink); |
| 4439 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 4440 | } |
| 4441 | spin_unlock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4442 | |
Al Viro | d757d71 | 2011-06-17 09:42:43 -0400 | [diff] [blame] | 4443 | kfree(cifs_sb->mountdata); |
Aurelien Aptel | a6b5058 | 2016-05-25 19:59:09 +0200 | [diff] [blame] | 4444 | kfree(cifs_sb->prepath); |
Al Viro | 2e32cf5 | 2013-10-03 12:53:37 -0400 | [diff] [blame] | 4445 | call_rcu(&cifs_sb->rcu, delayed_free); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 4448 | int |
| 4449 | cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | { |
| 4451 | int rc = 0; |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4452 | struct TCP_Server_Info *server = ses->server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 4454 | if (!server->ops->need_neg || !server->ops->negotiate) |
| 4455 | return -ENOSYS; |
| 4456 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4457 | /* only send once per connect */ |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 4458 | if (!server->ops->need_neg(server)) |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4459 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | |
Pavel Shilovsky | 4527578 | 2012-05-17 17:53:29 +0400 | [diff] [blame] | 4461 | set_credits(server, 1); |
Pavel Shilovsky | 286170a | 2012-05-25 10:43:58 +0400 | [diff] [blame] | 4462 | |
| 4463 | rc = server->ops->negotiate(xid, ses); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4464 | if (rc == 0) { |
| 4465 | spin_lock(&GlobalMid_Lock); |
Jeff Layton | 7fdbaa1 | 2011-06-10 16:14:57 -0400 | [diff] [blame] | 4466 | if (server->tcpStatus == CifsNeedNegotiate) |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4467 | server->tcpStatus = CifsGood; |
| 4468 | else |
| 4469 | rc = -EHOSTDOWN; |
| 4470 | spin_unlock(&GlobalMid_Lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | } |
Steve French | 26b994f | 2008-08-06 05:11:33 +0000 | [diff] [blame] | 4472 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4473 | return rc; |
| 4474 | } |
Steve French | 26b994f | 2008-08-06 05:11:33 +0000 | [diff] [blame] | 4475 | |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 4476 | int |
| 4477 | cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, |
| 4478 | struct nls_table *nls_info) |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4479 | { |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 4480 | int rc = -ENOSYS; |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4481 | struct TCP_Server_Info *server = ses->server; |
| 4482 | |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 4483 | ses->capabilities = server->capabilities; |
Steve French | 26b994f | 2008-08-06 05:11:33 +0000 | [diff] [blame] | 4484 | if (linuxExtEnabled == 0) |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 4485 | ses->capabilities &= (~server->vals->cap_unix); |
Steve French | 20418ac | 2009-04-30 16:13:32 +0000 | [diff] [blame] | 4486 | |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4487 | cifs_dbg(FYI, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d\n", |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4488 | server->sec_mode, server->capabilities, server->timeAdj); |
Jeff Layton | cb7691b | 2008-08-18 15:41:05 -0400 | [diff] [blame] | 4489 | |
Shu Wang | f5c4ba8 | 2017-09-08 18:48:33 +0800 | [diff] [blame] | 4490 | if (ses->auth_key.response) { |
Steve French | 2a18287 | 2018-03-29 12:16:34 -0500 | [diff] [blame] | 4491 | cifs_dbg(FYI, "Free previous auth_key.response = %p\n", |
Shu Wang | f5c4ba8 | 2017-09-08 18:48:33 +0800 | [diff] [blame] | 4492 | ses->auth_key.response); |
| 4493 | kfree(ses->auth_key.response); |
| 4494 | ses->auth_key.response = NULL; |
| 4495 | ses->auth_key.len = 0; |
| 4496 | } |
| 4497 | |
Pavel Shilovsky | 58c45c5 | 2012-05-25 10:54:49 +0400 | [diff] [blame] | 4498 | if (server->ops->sess_setup) |
| 4499 | rc = server->ops->sess_setup(xid, ses, nls_info); |
| 4500 | |
Shirish Pargaonkar | d4e63bd | 2013-08-29 08:35:09 -0500 | [diff] [blame] | 4501 | if (rc) |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 4502 | cifs_dbg(VFS, "Send error in SessSetup = %d\n", rc); |
Shirish Pargaonkar | 21e7339 | 2010-10-21 06:42:55 -0500 | [diff] [blame] | 4503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | return rc; |
| 4505 | } |
| 4506 | |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4507 | static int |
| 4508 | cifs_set_vol_auth(struct smb_vol *vol, struct cifs_ses *ses) |
| 4509 | { |
Jeff Layton | 3f61822 | 2013-06-12 19:52:14 -0500 | [diff] [blame] | 4510 | vol->sectype = ses->sectype; |
| 4511 | |
| 4512 | /* krb5 is special, since we don't need username or pw */ |
| 4513 | if (vol->sectype == Kerberos) |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4514 | return 0; |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4515 | |
| 4516 | return cifs_set_cifscreds(vol, ses); |
| 4517 | } |
| 4518 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4519 | static struct cifs_tcon * |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4520 | cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4521 | { |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4522 | int rc; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4523 | struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb); |
| 4524 | struct cifs_ses *ses; |
| 4525 | struct cifs_tcon *tcon = NULL; |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4526 | struct smb_vol *vol_info; |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4527 | |
| 4528 | vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL); |
Dan Carpenter | 803ab97 | 2012-01-24 11:39:22 +0300 | [diff] [blame] | 4529 | if (vol_info == NULL) |
| 4530 | return ERR_PTR(-ENOMEM); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4531 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4532 | vol_info->local_nls = cifs_sb->local_nls; |
| 4533 | vol_info->linux_uid = fsuid; |
| 4534 | vol_info->cred_uid = fsuid; |
| 4535 | vol_info->UNC = master_tcon->treeName; |
| 4536 | vol_info->retry = master_tcon->retry; |
| 4537 | vol_info->nocase = master_tcon->nocase; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 4538 | vol_info->nohandlecache = master_tcon->nohandlecache; |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4539 | vol_info->local_lease = master_tcon->local_lease; |
| 4540 | vol_info->no_linux_ext = !master_tcon->unix_ext; |
Jeff Layton | 28e11bd | 2013-05-26 07:01:00 -0400 | [diff] [blame] | 4541 | vol_info->sectype = master_tcon->ses->sectype; |
| 4542 | vol_info->sign = master_tcon->ses->sign; |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4543 | |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4544 | rc = cifs_set_vol_auth(vol_info, master_tcon->ses); |
| 4545 | if (rc) { |
| 4546 | tcon = ERR_PTR(rc); |
| 4547 | goto out; |
| 4548 | } |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4549 | |
| 4550 | /* get a reference for the same TCP session */ |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 4551 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4552 | ++master_tcon->ses->server->srv_count; |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 4553 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4554 | |
| 4555 | ses = cifs_get_smb_ses(master_tcon->ses->server, vol_info); |
| 4556 | if (IS_ERR(ses)) { |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4557 | tcon = (struct cifs_tcon *)ses; |
Pavel Shilovsky | 53e0e11 | 2016-11-04 11:50:31 -0700 | [diff] [blame] | 4558 | cifs_put_tcp_session(master_tcon->ses->server, 0); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4559 | goto out; |
| 4560 | } |
| 4561 | |
| 4562 | tcon = cifs_get_tcon(ses, vol_info); |
| 4563 | if (IS_ERR(tcon)) { |
| 4564 | cifs_put_smb_ses(ses); |
| 4565 | goto out; |
| 4566 | } |
| 4567 | |
Steve French | ce558b0 | 2018-05-31 19:16:54 -0500 | [diff] [blame] | 4568 | /* if new SMB3.11 POSIX extensions are supported do not remap / and \ */ |
| 4569 | if (tcon->posix_extensions) |
| 4570 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; |
Steve French | 0fdfef9 | 2018-06-28 19:30:23 -0500 | [diff] [blame] | 4571 | |
Pavel Shilovsky | 29e20f9 | 2012-07-13 13:58:14 +0400 | [diff] [blame] | 4572 | if (cap_unix(ses)) |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4573 | reset_cifs_unix_caps(0, tcon, NULL, vol_info); |
Steve French | b326614 | 2018-05-20 23:41:10 -0500 | [diff] [blame] | 4574 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4575 | out: |
Jeff Layton | 8a8798a | 2012-01-17 16:09:15 -0500 | [diff] [blame] | 4576 | kfree(vol_info->username); |
Aurelien Aptel | 97f4b72 | 2018-01-25 15:59:39 +0100 | [diff] [blame] | 4577 | kzfree(vol_info->password); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4578 | kfree(vol_info); |
| 4579 | |
| 4580 | return tcon; |
| 4581 | } |
| 4582 | |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 4583 | struct cifs_tcon * |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4584 | cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb) |
| 4585 | { |
| 4586 | return tlink_tcon(cifs_sb_master_tlink(cifs_sb)); |
| 4587 | } |
| 4588 | |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4589 | /* find and return a tlink with given uid */ |
| 4590 | static struct tcon_link * |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4591 | tlink_rb_search(struct rb_root *root, kuid_t uid) |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4592 | { |
| 4593 | struct rb_node *node = root->rb_node; |
| 4594 | struct tcon_link *tlink; |
| 4595 | |
| 4596 | while (node) { |
| 4597 | tlink = rb_entry(node, struct tcon_link, tl_rbnode); |
| 4598 | |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4599 | if (uid_gt(tlink->tl_uid, uid)) |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4600 | node = node->rb_left; |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4601 | else if (uid_lt(tlink->tl_uid, uid)) |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4602 | node = node->rb_right; |
| 4603 | else |
| 4604 | return tlink; |
| 4605 | } |
| 4606 | return NULL; |
| 4607 | } |
| 4608 | |
| 4609 | /* insert a tcon_link into the tree */ |
| 4610 | static void |
| 4611 | tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink) |
| 4612 | { |
| 4613 | struct rb_node **new = &(root->rb_node), *parent = NULL; |
| 4614 | struct tcon_link *tlink; |
| 4615 | |
| 4616 | while (*new) { |
| 4617 | tlink = rb_entry(*new, struct tcon_link, tl_rbnode); |
| 4618 | parent = *new; |
| 4619 | |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4620 | if (uid_gt(tlink->tl_uid, new_tlink->tl_uid)) |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4621 | new = &((*new)->rb_left); |
| 4622 | else |
| 4623 | new = &((*new)->rb_right); |
| 4624 | } |
| 4625 | |
| 4626 | rb_link_node(&new_tlink->tl_rbnode, parent, new); |
| 4627 | rb_insert_color(&new_tlink->tl_rbnode, root); |
| 4628 | } |
| 4629 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4630 | /* |
| 4631 | * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the |
| 4632 | * current task. |
| 4633 | * |
| 4634 | * If the superblock doesn't refer to a multiuser mount, then just return |
| 4635 | * the master tcon for the mount. |
| 4636 | * |
Suresh Jayaraman | 6ef933a | 2010-11-03 10:53:49 +0530 | [diff] [blame] | 4637 | * First, search the rbtree for an existing tcon for this fsuid. If one |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4638 | * exists, then check to see if it's pending construction. If it is then wait |
| 4639 | * for construction to complete. Once it's no longer pending, check to see if |
| 4640 | * it failed and either return an error or retry construction, depending on |
| 4641 | * the timeout. |
| 4642 | * |
| 4643 | * If one doesn't exist then insert a new tcon_link struct into the tree and |
| 4644 | * try to construct a new one. |
| 4645 | */ |
| 4646 | struct tcon_link * |
| 4647 | cifs_sb_tlink(struct cifs_sb_info *cifs_sb) |
| 4648 | { |
| 4649 | int ret; |
Eric W. Biederman | 6d4a083 | 2013-02-06 01:48:56 -0800 | [diff] [blame] | 4650 | kuid_t fsuid = current_fsuid(); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4651 | struct tcon_link *tlink, *newtlink; |
| 4652 | |
| 4653 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) |
| 4654 | return cifs_get_tlink(cifs_sb_master_tlink(cifs_sb)); |
| 4655 | |
| 4656 | spin_lock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4657 | tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4658 | if (tlink) |
| 4659 | cifs_get_tlink(tlink); |
| 4660 | spin_unlock(&cifs_sb->tlink_tree_lock); |
| 4661 | |
| 4662 | if (tlink == NULL) { |
| 4663 | newtlink = kzalloc(sizeof(*tlink), GFP_KERNEL); |
| 4664 | if (newtlink == NULL) |
| 4665 | return ERR_PTR(-ENOMEM); |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4666 | newtlink->tl_uid = fsuid; |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4667 | newtlink->tl_tcon = ERR_PTR(-EACCES); |
| 4668 | set_bit(TCON_LINK_PENDING, &newtlink->tl_flags); |
| 4669 | set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags); |
| 4670 | cifs_get_tlink(newtlink); |
| 4671 | |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4672 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 4673 | /* was one inserted after previous search? */ |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4674 | tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4675 | if (tlink) { |
| 4676 | cifs_get_tlink(tlink); |
| 4677 | spin_unlock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4678 | kfree(newtlink); |
| 4679 | goto wait_for_construction; |
| 4680 | } |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4681 | tlink = newtlink; |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4682 | tlink_rb_insert(&cifs_sb->tlink_tree, tlink); |
| 4683 | spin_unlock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4684 | } else { |
| 4685 | wait_for_construction: |
| 4686 | ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING, |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4687 | TASK_INTERRUPTIBLE); |
| 4688 | if (ret) { |
| 4689 | cifs_put_tlink(tlink); |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 4690 | return ERR_PTR(-ERESTARTSYS); |
Jeff Layton | 9d002df | 2010-10-06 19:51:11 -0400 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | /* if it's good, return it */ |
| 4694 | if (!IS_ERR(tlink->tl_tcon)) |
| 4695 | return tlink; |
| 4696 | |
| 4697 | /* return error if we tried this already recently */ |
| 4698 | if (time_before(jiffies, tlink->tl_time + TLINK_ERROR_EXPIRE)) { |
| 4699 | cifs_put_tlink(tlink); |
| 4700 | return ERR_PTR(-EACCES); |
| 4701 | } |
| 4702 | |
| 4703 | if (test_and_set_bit(TCON_LINK_PENDING, &tlink->tl_flags)) |
| 4704 | goto wait_for_construction; |
| 4705 | } |
| 4706 | |
| 4707 | tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid); |
| 4708 | clear_bit(TCON_LINK_PENDING, &tlink->tl_flags); |
| 4709 | wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING); |
| 4710 | |
| 4711 | if (IS_ERR(tlink->tl_tcon)) { |
| 4712 | cifs_put_tlink(tlink); |
| 4713 | return ERR_PTR(-EACCES); |
| 4714 | } |
| 4715 | |
| 4716 | return tlink; |
| 4717 | } |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4718 | |
| 4719 | /* |
| 4720 | * periodic workqueue job that scans tcon_tree for a superblock and closes |
| 4721 | * out tcons. |
| 4722 | */ |
| 4723 | static void |
| 4724 | cifs_prune_tlinks(struct work_struct *work) |
| 4725 | { |
| 4726 | struct cifs_sb_info *cifs_sb = container_of(work, struct cifs_sb_info, |
| 4727 | prune_tlinks.work); |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4728 | struct rb_root *root = &cifs_sb->tlink_tree; |
Colin Ian King | 37e12f5 | 2018-01-17 09:52:39 +0000 | [diff] [blame] | 4729 | struct rb_node *node; |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4730 | struct rb_node *tmp; |
| 4731 | struct tcon_link *tlink; |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4732 | |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4733 | /* |
| 4734 | * Because we drop the spinlock in the loop in order to put the tlink |
| 4735 | * it's not guarded against removal of links from the tree. The only |
| 4736 | * places that remove entries from the tree are this function and |
| 4737 | * umounts. Because this function is non-reentrant and is canceled |
| 4738 | * before umount can proceed, this is safe. |
| 4739 | */ |
| 4740 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 4741 | node = rb_first(root); |
| 4742 | while (node != NULL) { |
| 4743 | tmp = node; |
| 4744 | node = rb_next(tmp); |
| 4745 | tlink = rb_entry(tmp, struct tcon_link, tl_rbnode); |
| 4746 | |
| 4747 | if (test_bit(TCON_LINK_MASTER, &tlink->tl_flags) || |
| 4748 | atomic_read(&tlink->tl_count) != 0 || |
| 4749 | time_after(tlink->tl_time + TLINK_IDLE_EXPIRE, jiffies)) |
| 4750 | continue; |
| 4751 | |
| 4752 | cifs_get_tlink(tlink); |
| 4753 | clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); |
| 4754 | rb_erase(tmp, root); |
| 4755 | |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4756 | spin_unlock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | b647c35 | 2010-10-28 11:16:44 -0400 | [diff] [blame] | 4757 | cifs_put_tlink(tlink); |
| 4758 | spin_lock(&cifs_sb->tlink_tree_lock); |
| 4759 | } |
| 4760 | spin_unlock(&cifs_sb->tlink_tree_lock); |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4761 | |
Jeff Layton | da472fc | 2012-03-23 14:40:53 -0400 | [diff] [blame] | 4762 | queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, |
Jeff Layton | 2de970f | 2010-10-06 19:51:12 -0400 | [diff] [blame] | 4763 | TLINK_IDLE_EXPIRE); |
| 4764 | } |