aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-19 11:35:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-19 11:35:42 -0400
commit24420862bfb0db7c6b950b51dfecf3066766cb61 (patch)
tree265881c84f36e5c427aa8856277f52e105866c3d
parentebb2c2437d8008d46796902ff390653822af6cc4 (diff)
parent94a9daeaece415ce37ccb413b49a580e68e3477b (diff)
Merge tag '4.14-smb3-multidialect-support-and-fixes-for-stable' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs fixes from Steve French: "Convert default dialect to smb2.1 or later to allow connecting to Windows 7 for example, also includes some fixes for stable" * tag '4.14-smb3-multidialect-support-and-fixes-for-stable' of git://git.samba.org/sfrench/cifs-2.6: Update version of cifs module cifs: hide unused functions SMB3: Add support for multidialect negotiate (SMB2.1 and later) CIFS/SMB3: Update documentation to reflect SMB3 and various changes cifs: check rsp for NULL before dereferencing in SMB2_open
-rw-r--r--Documentation/filesystems/cifs/AUTHORS5
-rw-r--r--Documentation/filesystems/cifs/README81
-rw-r--r--Documentation/filesystems/cifs/TODO72
-rw-r--r--Documentation/filesystems/cifs/cifs.txt24
-rw-r--r--fs/cifs/cifsfs.h2
-rw-r--r--fs/cifs/cifsglob.h6
-rw-r--r--fs/cifs/connect.c24
-rw-r--r--fs/cifs/smb2ops.c42
-rw-r--r--fs/cifs/smb2pdu.c89
-rw-r--r--fs/cifs/smb2pdu.h2
10 files changed, 235 insertions, 112 deletions
diff --git a/Documentation/filesystems/cifs/AUTHORS b/Documentation/filesystems/cifs/AUTHORS
index c98800df677f..9f4f87e16240 100644
--- a/Documentation/filesystems/cifs/AUTHORS
+++ b/Documentation/filesystems/cifs/AUTHORS
@@ -41,6 +41,11 @@ Igor Mammedov (DFS support)
41Jeff Layton (many, many fixes, as well as great work on the cifs Kerberos code) 41Jeff Layton (many, many fixes, as well as great work on the cifs Kerberos code)
42Scott Lovenberg 42Scott Lovenberg
43Pavel Shilovsky (for great work adding SMB2 support, and various SMB3 features) 43Pavel Shilovsky (for great work adding SMB2 support, and various SMB3 features)
44Aurelien Aptel (for DFS SMB3 work and some key bug fixes)
45Ronnie Sahlberg (for SMB3 xattr work and bug fixes)
46Shirish Pargaonkar (for many ACL patches over the years)
47Sachin Prabhu (many bug fixes, including for reconnect, copy offload and security)
48
44 49
45Test case and Bug Report contributors 50Test case and Bug Report contributors
46------------------------------------- 51-------------------------------------
diff --git a/Documentation/filesystems/cifs/README b/Documentation/filesystems/cifs/README
index a54788405429..a9da51553ba3 100644
--- a/Documentation/filesystems/cifs/README
+++ b/Documentation/filesystems/cifs/README
@@ -1,10 +1,14 @@
1The CIFS VFS support for Linux supports many advanced network filesystem 1This module supports the SMB3 family of advanced network protocols (as well
2features such as hierarchical dfs like namespace, hardlinks, locking and more. 2as older dialects, originally called "CIFS" or SMB1).
3
4The CIFS VFS module for Linux supports many advanced network filesystem
5features such as hierarchical DFS like namespace, hardlinks, locking and more.
3It was designed to comply with the SNIA CIFS Technical Reference (which 6It was designed to comply with the SNIA CIFS Technical Reference (which
4supersedes the 1992 X/Open SMB Standard) as well as to perform best practice 7supersedes the 1992 X/Open SMB Standard) as well as to perform best practice
5practical interoperability with Windows 2000, Windows XP, Samba and equivalent 8practical interoperability with Windows 2000, Windows XP, Samba and equivalent
6servers. This code was developed in participation with the Protocol Freedom 9servers. This code was developed in participation with the Protocol Freedom
7Information Foundation. 10Information Foundation. CIFS and now SMB3 has now become a defacto
11standard for interoperating between Macs and Windows and major NAS appliances.
8 12
9Please see 13Please see
10 http://protocolfreedom.org/ and 14 http://protocolfreedom.org/ and
@@ -15,30 +19,11 @@ for more details.
15For questions or bug reports please contact: 19For questions or bug reports please contact:
16 sfrench@samba.org (sfrench@us.ibm.com) 20 sfrench@samba.org (sfrench@us.ibm.com)
17 21
22See the project page at: https://wiki.samba.org/index.php/LinuxCIFS_utils
23
18Build instructions: 24Build instructions:
19================== 25==================
20For Linux 2.4: 26For Linux:
211) Get the kernel source (e.g.from http://www.kernel.org)
22and download the cifs vfs source (see the project page
23at http://us1.samba.org/samba/Linux_CIFS_client.html)
24and change directory into the top of the kernel directory
25then patch the kernel (e.g. "patch -p1 < cifs_24.patch")
26to add the cifs vfs to your kernel configure options if
27it has not already been added (e.g. current SuSE and UL
28users do not need to apply the cifs_24.patch since the cifs vfs is
29already in the kernel configure menu) and then
30mkdir linux/fs/cifs and then copy the current cifs vfs files from
31the cifs download to your kernel build directory e.g.
32
33 cp <cifs_download_dir>/fs/cifs/* to <kernel_download_dir>/fs/cifs
34
352) make menuconfig (or make xconfig)
363) select cifs from within the network filesystem choices
374) save and exit
385) make dep
396) make modules (or "make" if CIFS VFS not to be built as a module)
40
41For Linux 2.6:
421) Download the kernel (e.g. from http://www.kernel.org) 271) Download the kernel (e.g. from http://www.kernel.org)
43and change directory into the top of the kernel directory tree 28and change directory into the top of the kernel directory tree
44(e.g. /usr/src/linux-2.5.73) 29(e.g. /usr/src/linux-2.5.73)
@@ -61,16 +46,13 @@ would simply type "make install").
61If you do not have the utility mount.cifs (in the Samba 3.0 source tree and on 46If you do not have the utility mount.cifs (in the Samba 3.0 source tree and on
62the CIFS VFS web site) copy it to the same directory in which mount.smbfs and 47the CIFS VFS web site) copy it to the same directory in which mount.smbfs and
63similar files reside (usually /sbin). Although the helper software is not 48similar files reside (usually /sbin). Although the helper software is not
64required, mount.cifs is recommended. Eventually the Samba 3.0 utility program 49required, mount.cifs is recommended. Most distros include a "cifs-utils"
65"net" may also be helpful since it may someday provide easier mount syntax for 50package that includes this utility so it is recommended to install this.
66users who are used to Windows e.g. 51
67 net use <mount point> <UNC name or cifs URL>
68Note that running the Winbind pam/nss module (logon service) on all of your 52Note that running the Winbind pam/nss module (logon service) on all of your
69Linux clients is useful in mapping Uids and Gids consistently across the 53Linux clients is useful in mapping Uids and Gids consistently across the
70domain to the proper network user. The mount.cifs mount helper can be 54domain to the proper network user. The mount.cifs mount helper can be
71trivially built from Samba 3.0 or later source e.g. by executing: 55found at cifs-utils.git on git.samba.org
72
73 gcc samba/source/client/mount.cifs.c -o mount.cifs
74 56
75If cifs is built as a module, then the size and number of network buffers 57If cifs is built as a module, then the size and number of network buffers
76and maximum number of simultaneous requests to one server can be configured. 58and maximum number of simultaneous requests to one server can be configured.
@@ -79,6 +61,18 @@ Changing these from their defaults is not recommended. By executing modinfo
79on kernel/fs/cifs/cifs.ko the list of configuration changes that can be made 61on kernel/fs/cifs/cifs.ko the list of configuration changes that can be made
80at module initialization time (by running insmod cifs.ko) can be seen. 62at module initialization time (by running insmod cifs.ko) can be seen.
81 63
64Recommendations
65===============
66To improve security the SMB2.1 dialect or later (usually will get SMB3) is now
67the new default. To use old dialects (e.g. to mount Windows XP) use "vers=1.0"
68on mount (or vers=2.0 for Windows Vista). Note that the CIFS (vers=1.0) is
69much older and less secure than the default dialect SMB3 which includes
70many advanced security features such as downgrade attack detection
71and encrypted shares and stronger signing and authentication algorithms.
72There are additional mount options that may be helpful for SMB3 to get
73improved POSIX behavior (NB: can use vers=3.0 to force only SMB3, never 2.1):
74 "mfsymlinks" and "cifsacl" and "idsfromsid"
75
82Allowing User Mounts 76Allowing User Mounts
83==================== 77====================
84To permit users to mount and unmount over directories they own is possible 78To permit users to mount and unmount over directories they own is possible
@@ -98,9 +92,7 @@ and execution of suid programs on the remote target would be enabled
98by default. This can be changed, as with nfs and other filesystems, 92by default. This can be changed, as with nfs and other filesystems,
99by simply specifying "nosuid" among the mount options. For user mounts 93by simply specifying "nosuid" among the mount options. For user mounts
100though to be able to pass the suid flag to mount requires rebuilding 94though to be able to pass the suid flag to mount requires rebuilding
101mount.cifs with the following flag: 95mount.cifs with the following flag: CIFS_ALLOW_USR_SUID
102
103 gcc samba/source/client/mount.cifs.c -DCIFS_ALLOW_USR_SUID -o mount.cifs
104 96
105There is a corresponding manual page for cifs mounting in the Samba 3.0 and 97There is a corresponding manual page for cifs mounting in the Samba 3.0 and
106later source tree in docs/manpages/mount.cifs.8 98later source tree in docs/manpages/mount.cifs.8
@@ -189,18 +181,18 @@ applications running on the same server as Samba.
189Use instructions: 181Use instructions:
190================ 182================
191Once the CIFS VFS support is built into the kernel or installed as a module 183Once the CIFS VFS support is built into the kernel or installed as a module
192(cifs.o), you can use mount syntax like the following to access Samba or Windows 184(cifs.ko), you can use mount syntax like the following to access Samba or
193servers: 185Mac or Windows servers:
194 186
195 mount -t cifs //9.53.216.11/e$ /mnt -o user=myname,pass=mypassword 187 mount -t cifs //9.53.216.11/e$ /mnt -o username=myname,password=mypassword
196 188
197Before -o the option -v may be specified to make the mount.cifs 189Before -o the option -v may be specified to make the mount.cifs
198mount helper display the mount steps more verbosely. 190mount helper display the mount steps more verbosely.
199After -o the following commonly used cifs vfs specific options 191After -o the following commonly used cifs vfs specific options
200are supported: 192are supported:
201 193
202 user=<username> 194 username=<username>
203 pass=<password> 195 password=<password>
204 domain=<domain name> 196 domain=<domain name>
205 197
206Other cifs mount options are described below. Use of TCP names (in addition to 198Other cifs mount options are described below. Use of TCP names (in addition to
@@ -246,13 +238,16 @@ the Server's registry. Samba starting with version 3.10 will allow such
246filenames (ie those which contain valid Linux characters, which normally 238filenames (ie those which contain valid Linux characters, which normally
247would be forbidden for Windows/CIFS semantics) as long as the server is 239would be forbidden for Windows/CIFS semantics) as long as the server is
248configured for Unix Extensions (and the client has not disabled 240configured for Unix Extensions (and the client has not disabled
249/proc/fs/cifs/LinuxExtensionsEnabled). 241/proc/fs/cifs/LinuxExtensionsEnabled). In addition the mount option
250 242"mapposix" can be used on CIFS (vers=1.0) to force the mapping of
243illegal Windows/NTFS/SMB characters to a remap range (this mount parm
244is the default for SMB3). This remap ("mapposix") range is also
245compatible with Mac (and "Services for Mac" on some older Windows).
251 246
252CIFS VFS Mount Options 247CIFS VFS Mount Options
253====================== 248======================
254A partial list of the supported mount options follows: 249A partial list of the supported mount options follows:
255 user The user name to use when trying to establish 250 username The user name to use when trying to establish
256 the CIFS session. 251 the CIFS session.
257 password The user password. If the mount helper is 252 password The user password. If the mount helper is
258 installed, the user will be prompted for password 253 installed, the user will be prompted for password
diff --git a/Documentation/filesystems/cifs/TODO b/Documentation/filesystems/cifs/TODO
index 066ffddc3964..396ecfd6ff4a 100644
--- a/Documentation/filesystems/cifs/TODO
+++ b/Documentation/filesystems/cifs/TODO
@@ -1,4 +1,4 @@
1Version 2.03 August 1, 2014 1Version 2.04 September 13, 2017
2 2
3A Partial List of Missing Features 3A Partial List of Missing Features
4================================== 4==================================
@@ -8,73 +8,69 @@ for visible, important contributions to this module. Here
8is a partial list of the known problems and missing features: 8is a partial list of the known problems and missing features:
9 9
10a) SMB3 (and SMB3.02) missing optional features: 10a) SMB3 (and SMB3.02) missing optional features:
11 - RDMA 11 - RDMA (started)
12 - multichannel (started) 12 - multichannel (started)
13 - directory leases (improved metadata caching) 13 - directory leases (improved metadata caching)
14 - T10 copy offload (copy chunk is only mechanism supported) 14 - T10 copy offload (copy chunk is only mechanism supported)
15 - encrypted shares
16 15
17b) improved sparse file support 16b) improved sparse file support
18 17
19c) Directory entry caching relies on a 1 second timer, rather than 18c) Directory entry caching relies on a 1 second timer, rather than
20using FindNotify or equivalent. - (started) 19using Directory Leases
21 20
22d) quota support (needs minor kernel change since quota calls 21d) quota support (needs minor kernel change since quota calls
23to make it to network filesystems or deviceless filesystems) 22to make it to network filesystems or deviceless filesystems)
24 23
25e) improve support for very old servers (OS/2 and Win9x for example) 24e) Better optimize open to reduce redundant opens (using reference
26Including support for changing the time remotely (utimes command). 25counts more) and to improve use of compounding in SMB3 to reduce
26number of roundtrips.
27 27
28f) hook lower into the sockets api (as NFS/SunRPC does) to avoid the 28f) Finish inotify support so kde and gnome file list windows
29extra copy in/out of the socket buffers in some cases.
30
31g) Better optimize open (and pathbased setfilesize) to reduce the
32oplock breaks coming from windows srv. Piggyback identical file
33opens on top of each other by incrementing reference count rather
34than resending (helps reduce server resource utilization and avoid
35spurious oplock breaks).
36
37h) Add support for storing symlink info to Windows servers
38in the Extended Attribute format their SFU clients would recognize.
39
40i) Finish inotify support so kde and gnome file list windows
41will autorefresh (partially complete by Asser). Needs minor kernel 29will autorefresh (partially complete by Asser). Needs minor kernel
42vfs change to support removing D_NOTIFY on a file. 30vfs change to support removing D_NOTIFY on a file.
43 31
44j) Add GUI tool to configure /proc/fs/cifs settings and for display of 32g) Add GUI tool to configure /proc/fs/cifs settings and for display of
45the CIFS statistics (started) 33the CIFS statistics (started)
46 34
47k) implement support for security and trusted categories of xattrs 35h) implement support for security and trusted categories of xattrs
48(requires minor protocol extension) to enable better support for SELINUX 36(requires minor protocol extension) to enable better support for SELINUX
49 37
50l) Implement O_DIRECT flag on open (already supported on mount) 38i) Implement O_DIRECT flag on open (already supported on mount)
51 39
52m) Create UID mapping facility so server UIDs can be mapped on a per 40j) Create UID mapping facility so server UIDs can be mapped on a per
53mount or a per server basis to client UIDs or nobody if no mapping 41mount or a per server basis to client UIDs or nobody if no mapping
54exists. This is helpful when Unix extensions are negotiated to 42exists. Also better integration with winbind for resolving SID owners
55allow better permission checking when UIDs differ on the server 43
56and client. Add new protocol request to the CIFS protocol 44k) Add tools to take advantage of more smb3 specific ioctls and features
57standard for asking the server for the corresponding name of a 45
58particular uid. 46l) encrypted file support
47
48m) improved stats gathering, tools (perhaps integration with nfsometer?)
59 49
60n) DOS attrs - returned as pseudo-xattr in Samba format (check VFAT and NTFS for this too) 50n) allow setting more NTFS/SMB3 file attributes remotely (currently limited to compressed
51file attribute via chflags) and improve user space tools for managing and
52viewing them.
61 53
62o) mount check for unmatched uids 54o) mount helper GUI (to simplify the various configuration options on mount)
63 55
64p) Add support for new vfs entry point for fallocate 56p) autonegotiation of dialects (offering more than one dialect ie SMB3.02,
57SMB3, SMB2.1 not just SMB3).
65 58
66q) Add tools to take advantage of cifs/smb3 specific ioctls and features 59q) Allow mount.cifs to be more verbose in reporting errors with dialect
67such as "CopyChunk" (fast server side file copy) 60or unsupported feature errors.
68 61
69r) encrypted file support 62r) updating cifs documentation, and user guid.
70 63
71s) improved stats gathering, tools (perhaps integration with nfsometer?) 64s) Addressing bugs found by running a broader set of xfstests in standard
65file system xfstest suite.
72 66
73t) allow setting more NTFS/SMB3 file attributes remotely (currently limited to compressed 67t) split cifs and smb3 support into separate modules so legacy (and less
74file attribute via chflags) 68secure) CIFS dialect can be disabled in environments that don't need it
69and simplify the code.
75 70
76u) mount helper GUI (to simplify the various configuration options on mount) 71u) Finish up SMB3.1.1 dialect support
77 72
73v) POSIX Extensions for SMB3.1.1
78 74
79KNOWN BUGS 75KNOWN BUGS
80==================================== 76====================================
diff --git a/Documentation/filesystems/cifs/cifs.txt b/Documentation/filesystems/cifs/cifs.txt
index 2fac91ac96cf..67756607246e 100644
--- a/Documentation/filesystems/cifs/cifs.txt
+++ b/Documentation/filesystems/cifs/cifs.txt
@@ -1,24 +1,28 @@
1 This is the client VFS module for the Common Internet File System 1 This is the client VFS module for the SMB3 NAS protocol as well
2 (CIFS) protocol which is the successor to the Server Message Block 2 older dialects such as the Common Internet File System (CIFS)
3 protocol which was the successor to the Server Message Block
3 (SMB) protocol, the native file sharing mechanism for most early 4 (SMB) protocol, the native file sharing mechanism for most early
4 PC operating systems. New and improved versions of CIFS are now 5 PC operating systems. New and improved versions of CIFS are now
5 called SMB2 and SMB3. These dialects are also supported by the 6 called SMB2 and SMB3. These dialects are also supported by the
6 CIFS VFS module. CIFS is fully supported by network 7 CIFS VFS module. CIFS is fully supported by network
7 file servers such as Windows 2000, 2003, 2008 and 2012 8 file servers such as Windows 2000, 2003, 2008, 2012 and 2016
8 as well by Samba (which provides excellent CIFS 9 as well by Samba (which provides excellent CIFS
9 server support for Linux and many other operating systems), so 10 server support for Linux and many other operating systems), Apple
11 systems, as well as most Network Attached Storage vendors, so
10 this network filesystem client can mount to a wide variety of 12 this network filesystem client can mount to a wide variety of
11 servers. 13 servers.
12 14
13 The intent of this module is to provide the most advanced network 15 The intent of this module is to provide the most advanced network
14 file system function for CIFS compliant servers, including better 16 file system function for SMB3 compliant servers, including advanced
15 POSIX compliance, secure per-user session establishment, high 17 security features, excellent parallelized high performance i/o, better
16 performance safe distributed caching (oplock), optional packet 18 POSIX compliance, secure per-user session establishment, encryption,
19 high performance safe distributed caching (leases/oplocks), optional packet
17 signing, large files, Unicode support and other internationalization 20 signing, large files, Unicode support and other internationalization
18 improvements. Since both Samba server and this filesystem client support 21 improvements. Since both Samba server and this filesystem client support
19 the CIFS Unix extensions, the combination can provide a reasonable 22 the CIFS Unix extensions (and in the future SMB3 POSIX extensions),
20 alternative to NFSv4 for fileserving in some Linux to Linux environments, 23 the combination can provide a reasonable alternative to other network and
21 not just in Linux to Windows environments. 24 cluster file systems for fileserving in some Linux to Linux environments,
25 not just in Linux to Windows (or Linux to Mac) environments.
22 26
23 This filesystem has an mount utility (mount.cifs) that can be obtained from 27 This filesystem has an mount utility (mount.cifs) that can be obtained from
24 28
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 30bf89b1fd9a..5a10e566f0e6 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -149,5 +149,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
149extern const struct export_operations cifs_export_ops; 149extern const struct export_operations cifs_export_ops;
150#endif /* CONFIG_CIFS_NFSD_EXPORT */ 150#endif /* CONFIG_CIFS_NFSD_EXPORT */
151 151
152#define CIFS_VERSION "2.09" 152#define CIFS_VERSION "2.10"
153#endif /* _CIFSFS_H */ 153#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 808486c29f0d..de5b2e1fcce5 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -188,6 +188,8 @@ enum smb_version {
188#ifdef CONFIG_CIFS_SMB311 188#ifdef CONFIG_CIFS_SMB311
189 Smb_311, 189 Smb_311,
190#endif /* SMB311 */ 190#endif /* SMB311 */
191 Smb_3any,
192 Smb_default,
191 Smb_version_err 193 Smb_version_err
192}; 194};
193 195
@@ -1701,6 +1703,10 @@ extern struct smb_version_values smb20_values;
1701#define SMB21_VERSION_STRING "2.1" 1703#define SMB21_VERSION_STRING "2.1"
1702extern struct smb_version_operations smb21_operations; 1704extern struct smb_version_operations smb21_operations;
1703extern struct smb_version_values smb21_values; 1705extern struct smb_version_values smb21_values;
1706#define SMBDEFAULT_VERSION_STRING "default"
1707extern struct smb_version_values smbdefault_values;
1708#define SMB3ANY_VERSION_STRING "3"
1709extern struct smb_version_values smb3any_values;
1704#define SMB30_VERSION_STRING "3.0" 1710#define SMB30_VERSION_STRING "3.0"
1705extern struct smb_version_operations smb30_operations; 1711extern struct smb_version_operations smb30_operations;
1706extern struct smb_version_values smb30_values; 1712extern struct smb_version_values smb30_values;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 5aa2d278ca84..8d38b22afb2b 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -301,6 +301,8 @@ static const match_table_t cifs_smb_version_tokens = {
301 { Smb_311, SMB311_VERSION_STRING }, 301 { Smb_311, SMB311_VERSION_STRING },
302 { Smb_311, ALT_SMB311_VERSION_STRING }, 302 { Smb_311, ALT_SMB311_VERSION_STRING },
303#endif /* SMB311 */ 303#endif /* SMB311 */
304 { Smb_3any, SMB3ANY_VERSION_STRING },
305 { Smb_default, SMBDEFAULT_VERSION_STRING },
304 { Smb_version_err, NULL } 306 { Smb_version_err, NULL }
305}; 307};
306 308
@@ -1148,6 +1150,14 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
1148 vol->vals = &smb311_values; 1150 vol->vals = &smb311_values;
1149 break; 1151 break;
1150#endif /* SMB311 */ 1152#endif /* SMB311 */
1153 case Smb_3any:
1154 vol->ops = &smb30_operations; /* currently identical with 3.0 */
1155 vol->vals = &smb3any_values;
1156 break;
1157 case Smb_default:
1158 vol->ops = &smb30_operations; /* currently identical with 3.0 */
1159 vol->vals = &smbdefault_values;
1160 break;
1151 default: 1161 default:
1152 cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value); 1162 cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value);
1153 return 1; 1163 return 1;
@@ -1274,9 +1284,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1274 1284
1275 vol->actimeo = CIFS_DEF_ACTIMEO; 1285 vol->actimeo = CIFS_DEF_ACTIMEO;
1276 1286
1277 /* FIXME: add autonegotiation for SMB3 or later rather than just SMB3 */ 1287 /* offer SMB2.1 and later (SMB3 etc). Secure and widely accepted */
1278 vol->ops = &smb30_operations; /* both secure and accepted widely */ 1288 vol->ops = &smb30_operations;
1279 vol->vals = &smb30_values; 1289 vol->vals = &smbdefault_values;
1280 1290
1281 vol->echo_interval = SMB_ECHO_INTERVAL_DEFAULT; 1291 vol->echo_interval = SMB_ECHO_INTERVAL_DEFAULT;
1282 1292
@@ -1988,11 +1998,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1988 1998
1989 if (got_version == false) 1999 if (got_version == false)
1990 pr_warn("No dialect specified on mount. Default has changed to " 2000 pr_warn("No dialect specified on mount. Default has changed to "
1991 "a more secure dialect, SMB3 (vers=3.0), from CIFS " 2001 "a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS "
1992 "(SMB1). To use the less secure SMB1 dialect to access " 2002 "(SMB1). To use the less secure SMB1 dialect to access "
1993 "old servers which do not support SMB3 specify vers=1.0" 2003 "old servers which do not support SMB3 (or SMB2.1) specify vers=1.0"
1994 " on mount. For somewhat newer servers such as Windows " 2004 " on mount.\n");
1995 "7 try vers=2.1.\n");
1996 2005
1997 kfree(mountdata_copy); 2006 kfree(mountdata_copy);
1998 return 0; 2007 return 0;
@@ -2133,6 +2142,7 @@ static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol)
2133 if (vol->nosharesock) 2142 if (vol->nosharesock)
2134 return 0; 2143 return 0;
2135 2144
2145 /* BB update this for smb3any and default case */
2136 if ((server->vals != vol->vals) || (server->ops != vol->ops)) 2146 if ((server->vals != vol->vals) || (server->ops != vol->ops))
2137 return 0; 2147 return 0;
2138 2148
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index fb2934b9b97c..0dafdbae1f8c 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -426,6 +426,7 @@ smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
426 return rc; 426 return rc;
427} 427}
428 428
429#ifdef CONFIG_CIFS_XATTR
429static ssize_t 430static ssize_t
430move_smb2_ea_to_cifs(char *dst, size_t dst_size, 431move_smb2_ea_to_cifs(char *dst, size_t dst_size,
431 struct smb2_file_full_ea_info *src, size_t src_size, 432 struct smb2_file_full_ea_info *src, size_t src_size,
@@ -613,6 +614,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
613 614
614 return rc; 615 return rc;
615} 616}
617#endif
616 618
617static bool 619static bool
618smb2_can_echo(struct TCP_Server_Info *server) 620smb2_can_echo(struct TCP_Server_Info *server)
@@ -3110,6 +3112,46 @@ struct smb_version_values smb21_values = {
3110 .create_lease_size = sizeof(struct create_lease), 3112 .create_lease_size = sizeof(struct create_lease),
3111}; 3113};
3112 3114
3115struct smb_version_values smb3any_values = {
3116 .version_string = SMB3ANY_VERSION_STRING,
3117 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3118 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3119 .large_lock_type = 0,
3120 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3121 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3122 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3123 .header_size = sizeof(struct smb2_hdr),
3124 .max_header_size = MAX_SMB2_HDR_SIZE,
3125 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3126 .lock_cmd = SMB2_LOCK,
3127 .cap_unix = 0,
3128 .cap_nt_find = SMB2_NT_FIND,
3129 .cap_large_files = SMB2_LARGE_FILES,
3130 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3131 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3132 .create_lease_size = sizeof(struct create_lease_v2),
3133};
3134
3135struct smb_version_values smbdefault_values = {
3136 .version_string = SMBDEFAULT_VERSION_STRING,
3137 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3138 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3139 .large_lock_type = 0,
3140 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3141 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3142 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3143 .header_size = sizeof(struct smb2_hdr),
3144 .max_header_size = MAX_SMB2_HDR_SIZE,
3145 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3146 .lock_cmd = SMB2_LOCK,
3147 .cap_unix = 0,
3148 .cap_nt_find = SMB2_NT_FIND,
3149 .cap_large_files = SMB2_LARGE_FILES,
3150 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3151 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3152 .create_lease_size = sizeof(struct create_lease_v2),
3153};
3154
3113struct smb_version_values smb30_values = { 3155struct smb_version_values smb30_values = {
3114 .version_string = SMB30_VERSION_STRING, 3156 .version_string = SMB30_VERSION_STRING,
3115 .protocol_id = SMB30_PROT_ID, 3157 .protocol_id = SMB30_PROT_ID,
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 5531e7ee1210..5c16591a128e 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -491,10 +491,25 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
491 491
492 req->hdr.sync_hdr.SessionId = 0; 492 req->hdr.sync_hdr.SessionId = 0;
493 493
494 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id); 494 if (strcmp(ses->server->vals->version_string,
495 495 SMB3ANY_VERSION_STRING) == 0) {
496 req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */ 496 req->Dialects[0] = cpu_to_le16(SMB30_PROT_ID);
497 inc_rfc1001_len(req, 2); 497 req->Dialects[1] = cpu_to_le16(SMB302_PROT_ID);
498 req->DialectCount = cpu_to_le16(2);
499 inc_rfc1001_len(req, 4);
500 } else if (strcmp(ses->server->vals->version_string,
501 SMBDEFAULT_VERSION_STRING) == 0) {
502 req->Dialects[0] = cpu_to_le16(SMB21_PROT_ID);
503 req->Dialects[1] = cpu_to_le16(SMB30_PROT_ID);
504 req->Dialects[2] = cpu_to_le16(SMB302_PROT_ID);
505 req->DialectCount = cpu_to_le16(3);
506 inc_rfc1001_len(req, 6);
507 } else {
508 /* otherwise send specific dialect */
509 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
510 req->DialectCount = cpu_to_le16(1);
511 inc_rfc1001_len(req, 2);
512 }
498 513
499 /* only one of SMB2 signing flags may be set in SMB2 request */ 514 /* only one of SMB2 signing flags may be set in SMB2 request */
500 if (ses->sign) 515 if (ses->sign)
@@ -528,16 +543,42 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
528 */ 543 */
529 if (rc == -EOPNOTSUPP) { 544 if (rc == -EOPNOTSUPP) {
530 cifs_dbg(VFS, "Dialect not supported by server. Consider " 545 cifs_dbg(VFS, "Dialect not supported by server. Consider "
531 "specifying vers=1.0 or vers=2.1 on mount for accessing" 546 "specifying vers=1.0 or vers=2.0 on mount for accessing"
532 " older servers\n"); 547 " older servers\n");
533 goto neg_exit; 548 goto neg_exit;
534 } else if (rc != 0) 549 } else if (rc != 0)
535 goto neg_exit; 550 goto neg_exit;
536 551
552 if (strcmp(ses->server->vals->version_string,
553 SMB3ANY_VERSION_STRING) == 0) {
554 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) {
555 cifs_dbg(VFS,
556 "SMB2 dialect returned but not requested\n");
557 return -EIO;
558 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) {
559 cifs_dbg(VFS,
560 "SMB2.1 dialect returned but not requested\n");
561 return -EIO;
562 }
563 } else if (strcmp(ses->server->vals->version_string,
564 SMBDEFAULT_VERSION_STRING) == 0) {
565 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) {
566 cifs_dbg(VFS,
567 "SMB2 dialect returned but not requested\n");
568 return -EIO;
569 } else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) {
570 /* ops set to 3.0 by default for default so update */
571 ses->server->ops = &smb21_operations;
572 }
573 } else if (rsp->DialectRevision != ses->server->vals->protocol_id) {
574 /* if requested single dialect ensure returned dialect matched */
575 cifs_dbg(VFS, "Illegal 0x%x dialect returned: not requested\n",
576 cpu_to_le16(rsp->DialectRevision));
577 return -EIO;
578 }
579
537 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode); 580 cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode);
538 581
539 /* BB we may eventually want to match the negotiated vs. requested
540 dialect, even though we are only requesting one at a time */
541 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) 582 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID))
542 cifs_dbg(FYI, "negotiated smb2.0 dialect\n"); 583 cifs_dbg(FYI, "negotiated smb2.0 dialect\n");
543 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) 584 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID))
@@ -558,6 +599,8 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
558 } 599 }
559 server->dialect = le16_to_cpu(rsp->DialectRevision); 600 server->dialect = le16_to_cpu(rsp->DialectRevision);
560 601
602 /* BB: add check that dialect was valid given dialect(s) we asked for */
603
561 /* SMB2 only has an extended negflavor */ 604 /* SMB2 only has an extended negflavor */
562 server->negflavor = CIFS_NEGFLAVOR_EXTENDED; 605 server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
563 /* set it to the maximum buffer size value we can send with 1 credit */ 606 /* set it to the maximum buffer size value we can send with 1 credit */
@@ -606,6 +649,7 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
606 struct validate_negotiate_info_req vneg_inbuf; 649 struct validate_negotiate_info_req vneg_inbuf;
607 struct validate_negotiate_info_rsp *pneg_rsp; 650 struct validate_negotiate_info_rsp *pneg_rsp;
608 u32 rsplen; 651 u32 rsplen;
652 u32 inbuflen; /* max of 4 dialects */
609 653
610 cifs_dbg(FYI, "validate negotiate\n"); 654 cifs_dbg(FYI, "validate negotiate\n");
611 655
@@ -634,9 +678,30 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
634 else 678 else
635 vneg_inbuf.SecurityMode = 0; 679 vneg_inbuf.SecurityMode = 0;
636 680
637 vneg_inbuf.DialectCount = cpu_to_le16(1); 681
638 vneg_inbuf.Dialects[0] = 682 if (strcmp(tcon->ses->server->vals->version_string,
639 cpu_to_le16(tcon->ses->server->vals->protocol_id); 683 SMB3ANY_VERSION_STRING) == 0) {
684 vneg_inbuf.Dialects[0] = cpu_to_le16(SMB30_PROT_ID);
685 vneg_inbuf.Dialects[1] = cpu_to_le16(SMB302_PROT_ID);
686 vneg_inbuf.DialectCount = cpu_to_le16(2);
687 /* structure is big enough for 3 dialects, sending only 2 */
688 inbuflen = sizeof(struct validate_negotiate_info_req) - 2;
689 } else if (strcmp(tcon->ses->server->vals->version_string,
690 SMBDEFAULT_VERSION_STRING) == 0) {
691 vneg_inbuf.Dialects[0] = cpu_to_le16(SMB21_PROT_ID);
692 vneg_inbuf.Dialects[1] = cpu_to_le16(SMB30_PROT_ID);
693 vneg_inbuf.Dialects[2] = cpu_to_le16(SMB302_PROT_ID);
694 vneg_inbuf.DialectCount = cpu_to_le16(3);
695 /* structure is big enough for 3 dialects */
696 inbuflen = sizeof(struct validate_negotiate_info_req);
697 } else {
698 /* otherwise specific dialect was requested */
699 vneg_inbuf.Dialects[0] =
700 cpu_to_le16(tcon->ses->server->vals->protocol_id);
701 vneg_inbuf.DialectCount = cpu_to_le16(1);
702 /* structure is big enough for 3 dialects, sending only 1 */
703 inbuflen = sizeof(struct validate_negotiate_info_req) - 4;
704 }
640 705
641 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, 706 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
642 FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */, 707 FSCTL_VALIDATE_NEGOTIATE_INFO, true /* is_fsctl */,
@@ -1634,7 +1699,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
1634 struct cifs_tcon *tcon = oparms->tcon; 1699 struct cifs_tcon *tcon = oparms->tcon;
1635 struct cifs_ses *ses = tcon->ses; 1700 struct cifs_ses *ses = tcon->ses;
1636 struct kvec iov[4]; 1701 struct kvec iov[4];
1637 struct kvec rsp_iov; 1702 struct kvec rsp_iov = {NULL, 0};
1638 int resp_buftype; 1703 int resp_buftype;
1639 int uni_path_len; 1704 int uni_path_len;
1640 __le16 *copy_path = NULL; 1705 __le16 *copy_path = NULL;
@@ -1763,7 +1828,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
1763 1828
1764 if (rc != 0) { 1829 if (rc != 0) {
1765 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE); 1830 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE);
1766 if (err_buf) 1831 if (err_buf && rsp)
1767 *err_buf = kmemdup(rsp, get_rfc1002_length(rsp) + 4, 1832 *err_buf = kmemdup(rsp, get_rfc1002_length(rsp) + 4,
1768 GFP_KERNEL); 1833 GFP_KERNEL);
1769 goto creat_exit; 1834 goto creat_exit;
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index 393ed5f4e1b6..6c9653a130c8 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -716,7 +716,7 @@ struct validate_negotiate_info_req {
716 __u8 Guid[SMB2_CLIENT_GUID_SIZE]; 716 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
717 __le16 SecurityMode; 717 __le16 SecurityMode;
718 __le16 DialectCount; 718 __le16 DialectCount;
719 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */ 719 __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
720} __packed; 720} __packed;
721 721
722struct validate_negotiate_info_rsp { 722struct validate_negotiate_info_rsp {