Skip to content

Commit cacf02d

Browse files
committed
Merge tag '4.21-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs updates from Steve French: - four fixes for stable - improvements to DFS including allowing failover to alternate targets - some small performance improvements * tag '4.21-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6: (39 commits) cifs: update internal module version number cifs: we can not use small padding iovs together with encryption cifs: Minor Kconfig clarification cifs: Always resolve hostname before reconnecting cifs: Add support for failover in cifs_reconnect_tcon() cifs: Add support for failover in smb2_reconnect() cifs: Only free DFS target list if we actually got one cifs: start DFS cache refresher in cifs_mount() cifs: Use GFP_ATOMIC when a lock is held in cifs_mount() cifs: Add support for failover in cifs_reconnect() cifs: Add support for failover in cifs_mount() cifs: remove set but not used variable 'sep' cifs: Make use of DFS cache to get new DFS referrals cifs: minor updates to documentation cifs: check kzalloc return cifs: remove set but not used variable 'server' cifs: Use kzfree() to free password cifs: Fix to use kmem_cache_free() instead of kfree() cifs: update for current_kernel_time64() removal cifs: Add DFS cache routines ...
2 parents 74673fc + fea1708 commit cacf02d

28 files changed

Lines changed: 2862 additions & 507 deletions

‎Documentation/filesystems/cifs/TODO‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version 2.11 September 13, 2017
1+
Version 2.14 December 21, 2018
22

33
A Partial List of Missing Features
44
==================================
@@ -7,7 +7,7 @@ Contributions are welcome. There are plenty of opportunities
77
for visible, important contributions to this module. Here
88
is a partial list of the known problems and missing features:
99

10-
a) SMB3 (and SMB3.02) missing optional features:
10+
a) SMB3 (and SMB3.1.1) missing optional features:
1111
- multichannel (started), integration with RDMA
1212
- directory leases (improved metadata caching), started (root dir only)
1313
- T10 copy offload ie "ODX" (copy chunk, and "Duplicate Extents" ioctl
@@ -21,8 +21,9 @@ using Directory Leases, currently only the root file handle is cached longer
2121
d) quota support (needs minor kernel change since quota calls
2222
to make it to network filesystems or deviceless filesystems)
2323

24-
e) Compounding (in progress) to reduce number of roundtrips, and also
25-
better optimize open to reduce redundant opens (using reference counts more).
24+
e) Additional use cases where we use "compoounding" (e.g. open/query/close
25+
and open/setinfo/close) to reduce the number of roundtrips, and also
26+
open to reduce redundant opens (using deferred close and reference counts more).
2627

2728
f) Finish inotify support so kde and gnome file list windows
2829
will autorefresh (partially complete by Asser). Needs minor kernel
@@ -43,11 +44,13 @@ exists. Also better integration with winbind for resolving SID owners
4344

4445
k) Add tools to take advantage of more smb3 specific ioctls and features
4546
(passthrough ioctl/fsctl for sending various SMB3 fsctls to the server
46-
is in progress)
47+
is in progress, and a passthrough query_info call is already implemented
48+
in cifs.ko to allow smb3 info levels queries to be sent from userspace)
4749

4850
l) encrypted file support
4951

50-
m) improved stats gathering, tools (perhaps integration with nfsometer?)
52+
m) improved stats gathering tools (perhaps integration with nfsometer?)
53+
to extend and make easier to use what is currently in /proc/fs/cifs/Stats
5154

5255
n) allow setting more NTFS/SMB3 file attributes remotely (currently limited to compressed
5356
file attribute via chflags) and improve user space tools for managing and
@@ -76,6 +79,9 @@ and simplify the code.
7679
v) POSIX Extensions for SMB3.1.1 (started, create and mkdir support added
7780
so far).
7881

82+
w) Add support for additional strong encryption types, and additional spnego
83+
authentication mechanisms (see MS-SMB2)
84+
7985
KNOWN BUGS
8086
====================================
8187
See http://bugzilla.samba.org - search on product "CifsVFS" for
@@ -102,3 +108,11 @@ and when signing is disabled to request larger read sizes (larger than
102108
negotiated size) and send larger write sizes to modern servers.
103109

104110
4) More exhaustively test against less common servers
111+
112+
5) Continue to extend the smb3 "buildbot" which does automated xfstesting
113+
against Windows, Samba and Azure currently - to add additional tests and
114+
to allow the buildbot to execute the tests faster.
115+
116+
6) Address various coverity warnings (most are not bugs per-se, but
117+
the more warnings are addressed, the easier it is to spot real
118+
problems that static analyzers will point out in the future).

‎fs/cifs/Kconfig‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ config CIFS_DFS_UPCALL
190190
moves to a different server. This feature also enables
191191
an upcall mechanism for CIFS which contacts userspace helper
192192
utilities to provide server name resolution (host names to
193-
IP addresses) which is needed for implicit mounts of DFS junction
194-
points. If unsure, say Y.
193+
IP addresses) which is needed in order to reconnect to
194+
servers if their addresses change or for implicit mounts of
195+
DFS junction points. If unsure, say Y.
195196

196197
config CIFS_NFSD_EXPORT
197198
bool "Allow nfsd to export CIFS file system"

‎fs/cifs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
1717

1818
cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
1919

20-
cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
20+
cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o dfs_cache.o
2121

2222
cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
2323

‎fs/cifs/cifs_debug.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include "cifsproto.h"
3131
#include "cifs_debug.h"
3232
#include "cifsfs.h"
33+
#ifdef CONFIG_CIFS_DFS_UPCALL
34+
#include "dfs_cache.h"
35+
#endif
3336
#ifdef CONFIG_CIFS_SMB_DIRECT
3437
#include "smbdirect.h"
3538
#endif
@@ -629,6 +632,11 @@ cifs_proc_init(void)
629632
&cifs_security_flags_proc_fops);
630633
proc_create("LookupCacheEnabled", 0644, proc_fs_cifs,
631634
&cifs_lookup_cache_proc_fops);
635+
636+
#ifdef CONFIG_CIFS_DFS_UPCALL
637+
proc_create("dfscache", 0644, proc_fs_cifs, &dfscache_proc_fops);
638+
#endif
639+
632640
#ifdef CONFIG_CIFS_SMB_DIRECT
633641
proc_create("rdma_readwrite_threshold", 0644, proc_fs_cifs,
634642
&cifs_rdma_readwrite_threshold_proc_fops);
@@ -663,6 +671,10 @@ cifs_proc_clean(void)
663671
remove_proc_entry("SecurityFlags", proc_fs_cifs);
664672
remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
665673
remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
674+
675+
#ifdef CONFIG_CIFS_DFS_UPCALL
676+
remove_proc_entry("dfscache", proc_fs_cifs);
677+
#endif
666678
#ifdef CONFIG_CIFS_SMB_DIRECT
667679
remove_proc_entry("rdma_readwrite_threshold", proc_fs_cifs);
668680
remove_proc_entry("smbd_max_frmr_depth", proc_fs_cifs);

‎fs/cifs/cifs_dfs_ref.c‎

Lines changed: 86 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "dns_resolve.h"
2626
#include "cifs_debug.h"
2727
#include "cifs_unicode.h"
28+
#include "dfs_cache.h"
2829

2930
static LIST_HEAD(cifs_dfs_automount_list);
3031

@@ -126,7 +127,7 @@ cifs_build_devname(char *nodename, const char *prepath)
126127
* @sb_mountdata: parent/root DFS mount options (template)
127128
* @fullpath: full path in UNC format
128129
* @ref: server's referral
129-
* @devname: pointer for saving device name
130+
* @devname: optional pointer for saving device name
130131
*
131132
* creates mount options for submount based on template options sb_mountdata
132133
* and replacing unc,ip,prefixpath options with ones we've got form ref_unc.
@@ -140,6 +141,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
140141
char **devname)
141142
{
142143
int rc;
144+
char *name;
143145
char *mountdata = NULL;
144146
const char *prepath = NULL;
145147
int md_len;
@@ -158,17 +160,17 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
158160
prepath++;
159161
}
160162

161-
*devname = cifs_build_devname(ref->node_name, prepath);
162-
if (IS_ERR(*devname)) {
163-
rc = PTR_ERR(*devname);
164-
*devname = NULL;
163+
name = cifs_build_devname(ref->node_name, prepath);
164+
if (IS_ERR(name)) {
165+
rc = PTR_ERR(name);
166+
name = NULL;
165167
goto compose_mount_options_err;
166168
}
167169

168-
rc = dns_resolve_server_name_to_ip(*devname, &srvIP);
170+
rc = dns_resolve_server_name_to_ip(name, &srvIP);
169171
if (rc < 0) {
170172
cifs_dbg(FYI, "%s: Failed to resolve server part of %s to IP: %d\n",
171-
__func__, *devname, rc);
173+
__func__, name, rc);
172174
goto compose_mount_options_err;
173175
}
174176

@@ -224,6 +226,9 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
224226
strcat(mountdata, "ip=");
225227
strcat(mountdata, srvIP);
226228

229+
if (devname)
230+
*devname = name;
231+
227232
/*cifs_dbg(FYI, "%s: parent mountdata: %s\n", __func__, sb_mountdata);*/
228233
/*cifs_dbg(FYI, "%s: submount mountdata: %s\n", __func__, mountdata );*/
229234

@@ -234,8 +239,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
234239
compose_mount_options_err:
235240
kfree(mountdata);
236241
mountdata = ERR_PTR(rc);
237-
kfree(*devname);
238-
*devname = NULL;
242+
kfree(name);
239243
goto compose_mount_options_out;
240244
}
241245

@@ -251,20 +255,30 @@ static struct vfsmount *cifs_dfs_do_refmount(struct dentry *mntpt,
251255
{
252256
struct vfsmount *mnt;
253257
char *mountdata;
254-
char *devname = NULL;
258+
char *devname;
259+
260+
/*
261+
* Always pass down the DFS full path to smb3_do_mount() so we
262+
* can use it later for failover.
263+
*/
264+
devname = kstrndup(fullpath, strlen(fullpath), GFP_KERNEL);
265+
if (!devname)
266+
return ERR_PTR(-ENOMEM);
267+
268+
convert_delimiter(devname, '/');
255269

256270
/* strip first '\' from fullpath */
257271
mountdata = cifs_compose_mount_options(cifs_sb->mountdata,
258-
fullpath + 1, ref, &devname);
259-
260-
if (IS_ERR(mountdata))
272+
fullpath + 1, ref, NULL);
273+
if (IS_ERR(mountdata)) {
274+
kfree(devname);
261275
return (struct vfsmount *)mountdata;
276+
}
262277

263278
mnt = vfs_submount(mntpt, &cifs_fs_type, devname, mountdata);
264279
kfree(mountdata);
265280
kfree(devname);
266281
return mnt;
267-
268282
}
269283

270284
static void dump_referral(const struct dfs_info3_param *ref)
@@ -282,16 +296,15 @@ static void dump_referral(const struct dfs_info3_param *ref)
282296
*/
283297
static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
284298
{
285-
struct dfs_info3_param *referrals = NULL;
286-
unsigned int num_referrals = 0;
299+
struct dfs_info3_param referral = {0};
287300
struct cifs_sb_info *cifs_sb;
288301
struct cifs_ses *ses;
289-
char *full_path;
302+
struct cifs_tcon *tcon;
303+
char *full_path, *root_path;
290304
unsigned int xid;
291-
int i;
305+
int len;
292306
int rc;
293307
struct vfsmount *mnt;
294-
struct tcon_link *tlink;
295308

296309
cifs_dbg(FYI, "in %s\n", __func__);
297310
BUG_ON(IS_ROOT(mntpt));
@@ -315,48 +328,69 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
315328
if (full_path == NULL)
316329
goto cdda_exit;
317330

318-
tlink = cifs_sb_tlink(cifs_sb);
319-
if (IS_ERR(tlink)) {
320-
mnt = ERR_CAST(tlink);
331+
cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path);
332+
333+
if (!cifs_sb_master_tlink(cifs_sb)) {
334+
cifs_dbg(FYI, "%s: master tlink is NULL\n", __func__);
321335
goto free_full_path;
322336
}
323-
ses = tlink_tcon(tlink)->ses;
324337

338+
tcon = cifs_sb_master_tcon(cifs_sb);
339+
if (!tcon) {
340+
cifs_dbg(FYI, "%s: master tcon is NULL\n", __func__);
341+
goto free_full_path;
342+
}
343+
344+
root_path = kstrdup(tcon->treeName, GFP_KERNEL);
345+
if (!root_path) {
346+
mnt = ERR_PTR(-ENOMEM);
347+
goto free_full_path;
348+
}
349+
cifs_dbg(FYI, "%s: root path: %s\n", __func__, root_path);
350+
351+
ses = tcon->ses;
325352
xid = get_xid();
326-
rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls,
327-
&num_referrals, &referrals,
328-
cifs_remap(cifs_sb));
329-
free_xid(xid);
330353

331-
cifs_put_tlink(tlink);
332-
333-
mnt = ERR_PTR(-ENOENT);
334-
for (i = 0; i < num_referrals; i++) {
335-
int len;
336-
dump_referral(referrals + i);
337-
/* connect to a node */
338-
len = strlen(referrals[i].node_name);
339-
if (len < 2) {
340-
cifs_dbg(VFS, "%s: Net Address path too short: %s\n",
341-
__func__, referrals[i].node_name);
342-
mnt = ERR_PTR(-EINVAL);
343-
break;
344-
}
345-
mnt = cifs_dfs_do_refmount(mntpt, cifs_sb,
346-
full_path, referrals + i);
347-
cifs_dbg(FYI, "%s: cifs_dfs_do_refmount:%s , mnt:%p\n",
348-
__func__, referrals[i].node_name, mnt);
349-
if (!IS_ERR(mnt))
350-
goto success;
354+
/*
355+
* If DFS root has been expired, then unconditionally fetch it again to
356+
* refresh DFS referral cache.
357+
*/
358+
rc = dfs_cache_find(xid, ses, cifs_sb->local_nls, cifs_remap(cifs_sb),
359+
root_path + 1, NULL, NULL);
360+
if (!rc) {
361+
rc = dfs_cache_find(xid, ses, cifs_sb->local_nls,
362+
cifs_remap(cifs_sb), full_path + 1,
363+
&referral, NULL);
351364
}
352365

353-
/* no valid submounts were found; return error from get_dfs_path() by
354-
* preference */
355-
if (rc != 0)
366+
free_xid(xid);
367+
368+
if (rc) {
356369
mnt = ERR_PTR(rc);
370+
goto free_root_path;
371+
}
372+
373+
dump_referral(&referral);
357374

358-
success:
359-
free_dfs_info_array(referrals, num_referrals);
375+
len = strlen(referral.node_name);
376+
if (len < 2) {
377+
cifs_dbg(VFS, "%s: Net Address path too short: %s\n",
378+
__func__, referral.node_name);
379+
mnt = ERR_PTR(-EINVAL);
380+
goto free_dfs_ref;
381+
}
382+
/*
383+
* cifs_mount() will retry every available node server in case
384+
* of failures.
385+
*/
386+
mnt = cifs_dfs_do_refmount(mntpt, cifs_sb, full_path, &referral);
387+
cifs_dbg(FYI, "%s: cifs_dfs_do_refmount:%s , mnt:%p\n", __func__,
388+
referral.node_name, mnt);
389+
390+
free_dfs_ref:
391+
free_dfs_info_param(&referral);
392+
free_root_path:
393+
kfree(root_path);
360394
free_full_path:
361395
kfree(full_path);
362396
cdda_exit:

‎fs/cifs/cifs_fs_sb.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ struct cifs_sb_info {
7272
char *mountdata; /* options received at mount time or via DFS refs */
7373
struct delayed_work prune_tlinks;
7474
struct rcu_head rcu;
75+
76+
/* only used when CIFS_MOUNT_USE_PREFIX_PATH is set */
7577
char *prepath;
78+
79+
/*
80+
* Path initially provided by the mount call. We might connect
81+
* to something different via DFS but we want to keep it to do
82+
* failover properly.
83+
*/
84+
char *origin_fullpath; /* \\HOST\SHARE\[OPTIONAL PATH] */
7685
};
7786
#endif /* _CIFS_FS_SB_H */

‎fs/cifs/cifsencrypt.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int cifs_verify_signature(struct smb_rqst *rqst,
224224
if (cifs_pdu->Command == SMB_COM_LOCKING_ANDX) {
225225
struct smb_com_lock_req *pSMB =
226226
(struct smb_com_lock_req *)cifs_pdu;
227-
if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)
227+
if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)
228228
return 0;
229229
}
230230

@@ -304,12 +304,17 @@ int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp)
304304
int calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
305305
char *lnm_session_key)
306306
{
307-
int i;
307+
int i, len;
308308
int rc;
309309
char password_with_pad[CIFS_ENCPWD_SIZE] = {0};
310310

311-
if (password)
312-
strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE);
311+
if (password) {
312+
for (len = 0; len < CIFS_ENCPWD_SIZE; len++)
313+
if (!password[len])
314+
break;
315+
316+
memcpy(password_with_pad, password, len);
317+
}
313318

314319
if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
315320
memcpy(lnm_session_key, password_with_pad,

0 commit comments

Comments
 (0)