Skip to content

Commit 5a5fb3c

Browse files
Paulo Alcantarajohn-cabaj
authored andcommitted
cifs: set DFS root session in cifs_get_smb_ses()
BugLink: https://bugs.launchpad.net/bugs/2036450 Set the DFS root session pointer earlier when creating a new SMB session to prevent racing with smb2_reconnect(), cifs_reconnect_tcon() and DFS cache refresher. Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com> Cc: stable@vger.kernel.org # 6.2 Signed-off-by: Steve French <stfrench@microsoft.com> (cherry picked from commit b56bce5) Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
1 parent e2a9c43 commit 5a5fb3c

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

fs/cifs/cifs_dfs_ref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct path *path)
179179
tmp.source = full_path;
180180
tmp.leaf_fullpath = NULL;
181181
tmp.UNC = tmp.prepath = NULL;
182+
tmp.dfs_root_ses = NULL;
182183

183184
rc = smb3_fs_context_dup(ctx, &tmp);
184185
if (rc) {

fs/cifs/cifsglob.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,6 @@ struct cifs_mount_ctx {
17671767
struct TCP_Server_Info *server;
17681768
struct cifs_ses *ses;
17691769
struct cifs_tcon *tcon;
1770-
struct cifs_ses *root_ses;
17711770
uuid_t mount_id;
17721771
char *origin_fullpath, *leaf_fullpath;
17731772
};

fs/cifs/connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
22402240
* need to lock before changing something in the session.
22412241
*/
22422242
spin_lock(&cifs_tcp_ses_lock);
2243+
ses->dfs_root_ses = ctx->dfs_root_ses;
22432244
list_add(&ses->smb_ses_list, &server->smb_ses_list);
22442245
spin_unlock(&cifs_tcp_ses_lock);
22452246

fs/cifs/dfs.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,22 @@ static int get_session(struct cifs_mount_ctx *mnt_ctx, const char *full_path)
9595
ctx->leaf_fullpath = (char *)full_path;
9696
rc = cifs_mount_get_session(mnt_ctx);
9797
ctx->leaf_fullpath = NULL;
98-
if (!rc) {
99-
struct cifs_ses *ses = mnt_ctx->ses;
10098

101-
mutex_lock(&ses->session_mutex);
102-
ses->dfs_root_ses = mnt_ctx->root_ses;
103-
mutex_unlock(&ses->session_mutex);
104-
}
10599
return rc;
106100
}
107101

108102
static void set_root_ses(struct cifs_mount_ctx *mnt_ctx)
109103
{
110-
if (mnt_ctx->ses) {
104+
struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
105+
struct cifs_ses *ses = mnt_ctx->ses;
106+
107+
if (ses) {
111108
spin_lock(&cifs_tcp_ses_lock);
112-
mnt_ctx->ses->ses_count++;
109+
ses->ses_count++;
113110
spin_unlock(&cifs_tcp_ses_lock);
114-
dfs_cache_add_refsrv_session(&mnt_ctx->mount_id, mnt_ctx->ses);
111+
dfs_cache_add_refsrv_session(&mnt_ctx->mount_id, ses);
115112
}
116-
mnt_ctx->root_ses = mnt_ctx->ses;
113+
ctx->dfs_root_ses = mnt_ctx->ses;
117114
}
118115

119116
static int get_dfs_conn(struct cifs_mount_ctx *mnt_ctx, const char *ref_path, const char *full_path,
@@ -260,7 +257,7 @@ int dfs_mount_share(struct cifs_mount_ctx *mnt_ctx, bool *isdfs)
260257
rc = get_session(mnt_ctx, NULL);
261258
if (rc)
262259
return rc;
263-
mnt_ctx->root_ses = mnt_ctx->ses;
260+
ctx->dfs_root_ses = mnt_ctx->ses;
264261
/*
265262
* If called with 'nodfs' mount option, then skip DFS resolving. Otherwise unconditionally
266263
* try to get an DFS referral (even cached) to determine whether it is an DFS mount.

fs/cifs/dfs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ static inline char *dfs_get_path(struct cifs_sb_info *cifs_sb, const char *path)
2222
static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *path,
2323
struct dfs_info3_param *ref, struct dfs_cache_tgt_list *tl)
2424
{
25+
struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
2526
struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb;
2627

27-
return dfs_cache_find(mnt_ctx->xid, mnt_ctx->root_ses, cifs_sb->local_nls,
28+
return dfs_cache_find(mnt_ctx->xid, ctx->dfs_root_ses, cifs_sb->local_nls,
2829
cifs_remap(cifs_sb), path, ref, tl);
2930
}
3031

fs/cifs/fs_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct smb3_fs_context {
267267
bool rootfs:1; /* if it's a SMB root file system */
268268
bool witness:1; /* use witness protocol */
269269
char *leaf_fullpath;
270+
struct cifs_ses *dfs_root_ses;
270271
};
271272

272273
extern const struct fs_parameter_spec smb3_fs_parameters[];

0 commit comments

Comments
 (0)