Skip to content

Commit c0c97d6

Browse files
committed
cifs: Fix reacquisition of volume cookie on still-live connection
jira LE-2157 Rebuild_History Non-Buildable kernel-5.14.0-503.14.1.el9_5 commit-author David Howells <[email protected]> commit dad80c6 During mount, cifs_mount_get_tcon() gets a tcon resource connection record and then attaches an fscache volume cookie to it. However, it does this irrespective of whether or not the tcon returned from cifs_get_tcon() is a new record or one that's already in use. This leads to a warning about a volume cookie collision and a leaked volume cookie because tcon->fscache gets reset. Fix this be adding a mutex and a "we've already tried this" flag and only doing it once for the lifetime of the tcon. [!] Note: Looking at cifs_mount_get_tcon(), a more general solution may actually be required. Reacquiring the volume cookie isn't the only thing that function does: it also partially reinitialises the tcon record without any locking - which may cause live filesystem ops already using the tcon through a previous mount to malfunction. This can be reproduced simply by something like: mount //example.com/test /xfstest.test -o user=shares,pass=xxx,fsc mount //example.com/test /mnt -o user=shares,pass=xxx,fsc Fixes: 70431bf ("cifs: Support fscache indexing rewrite") Signed-off-by: David Howells <[email protected]> Acked-by: Paulo Alcantara (Red Hat) <[email protected]> cc: Shyam Prasad N <[email protected]> cc: [email protected] cc: [email protected] Signed-off-by: Steve French <[email protected]> (cherry picked from commit dad80c6) Signed-off-by: Jonathan Maple <[email protected]>
1 parent bb98273 commit c0c97d6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

fs/smb/client/cifsglob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,9 @@ struct cifs_tcon {
12761276
__u32 max_cached_dirs;
12771277
#ifdef CONFIG_CIFS_FSCACHE
12781278
u64 resource_id; /* server resource id */
1279+
bool fscache_acquired; /* T if we've tried acquiring a cookie */
12791280
struct fscache_volume *fscache; /* cookie for share */
1281+
struct mutex fscache_lock; /* Prevent regetting a cookie */
12801282
#endif
12811283
struct list_head pending_opens; /* list of incomplete opens */
12821284
struct cached_fids *cfids;

fs/smb/client/fscache.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ int cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
4343
char *key;
4444
int ret = -ENOMEM;
4545

46+
if (tcon->fscache_acquired)
47+
return 0;
48+
49+
mutex_lock(&tcon->fscache_lock);
50+
if (tcon->fscache_acquired) {
51+
mutex_unlock(&tcon->fscache_lock);
52+
return 0;
53+
}
54+
tcon->fscache_acquired = true;
55+
4656
tcon->fscache = NULL;
4757
switch (sa->sa_family) {
4858
case AF_INET:
4959
case AF_INET6:
5060
break;
5161
default:
62+
mutex_unlock(&tcon->fscache_lock);
5263
cifs_dbg(VFS, "Unknown network family '%d'\n", sa->sa_family);
5364
return -EINVAL;
5465
}
@@ -57,6 +68,7 @@ int cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
5768

5869
sharename = extract_sharename(tcon->tree_name);
5970
if (IS_ERR(sharename)) {
71+
mutex_unlock(&tcon->fscache_lock);
6072
cifs_dbg(FYI, "%s: couldn't extract sharename\n", __func__);
6173
return PTR_ERR(sharename);
6274
}
@@ -90,6 +102,7 @@ int cifs_fscache_get_super_cookie(struct cifs_tcon *tcon)
90102
kfree(key);
91103
out:
92104
kfree(sharename);
105+
mutex_unlock(&tcon->fscache_lock);
93106
return ret;
94107
}
95108

fs/smb/client/misc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ tcon_info_alloc(bool dir_leases_enabled)
138138
atomic_set(&ret_buf->num_local_opens, 0);
139139
atomic_set(&ret_buf->num_remote_opens, 0);
140140
ret_buf->stats_from_time = ktime_get_real_seconds();
141+
#ifdef CONFIG_CIFS_FSCACHE
142+
mutex_init(&ret_buf->fscache_lock);
143+
#endif
141144

142145
return ret_buf;
143146
}

0 commit comments

Comments
 (0)