]> git.itanic.dy.fi Git - linux-stable/commitdiff
smb: client: handle DFS tcons in cifs_construct_tcon()
authorPaulo Alcantara <pc@manguebit.com>
Tue, 2 Apr 2024 01:44:08 +0000 (22:44 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:38:20 +0000 (16:38 +0200)
commit 4a5ba0e0bfe552ac7451f57e304f6343c3d87f89 upstream.

The tcons created by cifs_construct_tcon() on multiuser mounts must
also be able to failover and refresh DFS referrals, so set the
appropriate fields in order to get a full DFS tcon.  They could be
shared among different superblocks later, too.

Cc: stable@vger.kernel.org # 6.4+
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202404021518.3Xu2VU4s-lkp@intel.com/
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/connect.c

index 2064bf6749ff6cf402ae75a68b2df40d704503cd..f6434e867b385ae704c1e27648c243a9855fe1fa 100644 (file)
@@ -3996,6 +3996,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
        struct cifs_ses *ses;
        struct cifs_tcon *tcon = NULL;
        struct smb3_fs_context *ctx;
+       char *origin_fullpath = NULL;
 
        ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
        if (ctx == NULL)
@@ -4019,6 +4020,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
        ctx->sign = master_tcon->ses->sign;
        ctx->seal = master_tcon->seal;
        ctx->witness = master_tcon->use_witness;
+       ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses;
 
        rc = cifs_set_vol_auth(ctx, master_tcon->ses);
        if (rc) {
@@ -4038,12 +4040,39 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
                goto out;
        }
 
+#ifdef CONFIG_CIFS_DFS_UPCALL
+       spin_lock(&master_tcon->tc_lock);
+       if (master_tcon->origin_fullpath) {
+               spin_unlock(&master_tcon->tc_lock);
+               origin_fullpath = dfs_get_path(cifs_sb, cifs_sb->ctx->source);
+               if (IS_ERR(origin_fullpath)) {
+                       tcon = ERR_CAST(origin_fullpath);
+                       origin_fullpath = NULL;
+                       cifs_put_smb_ses(ses);
+                       goto out;
+               }
+       } else {
+               spin_unlock(&master_tcon->tc_lock);
+       }
+#endif
+
        tcon = cifs_get_tcon(ses, ctx);
        if (IS_ERR(tcon)) {
                cifs_put_smb_ses(ses);
                goto out;
        }
 
+#ifdef CONFIG_CIFS_DFS_UPCALL
+       if (origin_fullpath) {
+               spin_lock(&tcon->tc_lock);
+               tcon->origin_fullpath = origin_fullpath;
+               spin_unlock(&tcon->tc_lock);
+               origin_fullpath = NULL;
+               queue_delayed_work(dfscache_wq, &tcon->dfs_cache_work,
+                                  dfs_cache_get_ttl() * HZ);
+       }
+#endif
+
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
        if (cap_unix(ses))
                reset_cifs_unix_caps(0, tcon, NULL, ctx);
@@ -4052,6 +4081,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
 out:
        kfree(ctx->username);
        kfree_sensitive(ctx->password);
+       kfree(origin_fullpath);
        kfree(ctx);
 
        return tcon;