Skip to content

Commit 20b1aa9

Browse files
meetakshi253Steve French
authored andcommitted
smb: client: sync the root session and superblock context passwords before automounting
In some cases, when password2 becomes the working password, the client swaps the two password fields in the root session struct, but not in the smb3_fs_context struct in cifs_sb. DFS automounts inherit fs context from their parent mounts. Therefore, they might end up getting the passwords in the stale order. The automount should succeed, because the mount function will end up retrying with the actual password anyway. But to reduce these unnecessary session setup retries for automounts, we can sync the parent context's passwords with the root session's passwords before duplicating it to the child's fs context. Cc: stable@vger.kernel.org Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 9d89551 commit 20b1aa9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

fs/smb/client/namespace.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,28 @@ static struct vfsmount *cifs_do_automount(struct path *path)
196196
struct smb3_fs_context tmp;
197197
char *full_path;
198198
struct vfsmount *mnt;
199+
struct cifs_sb_info *mntpt_sb;
200+
struct cifs_ses *ses;
199201

200202
if (IS_ROOT(mntpt))
201203
return ERR_PTR(-ESTALE);
202204

203-
cur_ctx = CIFS_SB(mntpt->d_sb)->ctx;
205+
mntpt_sb = CIFS_SB(mntpt->d_sb);
206+
ses = cifs_sb_master_tcon(mntpt_sb)->ses;
207+
cur_ctx = mntpt_sb->ctx;
208+
209+
/*
210+
* At this point, the root session should be in the mntpt sb. We should
211+
* bring the sb context passwords in sync with the root session's
212+
* passwords. This would help prevent unnecessary retries and password
213+
* swaps for automounts.
214+
*/
215+
mutex_lock(&ses->session_mutex);
216+
rc = smb3_sync_session_ctx_passwords(mntpt_sb, ses);
217+
mutex_unlock(&ses->session_mutex);
218+
219+
if (rc)
220+
return ERR_PTR(rc);
204221

205222
fc = fs_context_for_submount(path->mnt->mnt_sb->s_type, mntpt);
206223
if (IS_ERR(fc))

0 commit comments

Comments
 (0)