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

Serialise cifs_construct_tcon() with cifs_mount_mutex to handle
parallel mounts that may end up reusing the session and tcon created
by it.

Cc: stable@vger.kernel.org # 6.4+
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
fs/smb/client/fs_context.c
fs/smb/client/fs_context.h

index f6434e867b385ae704c1e27648c243a9855fe1fa..087859619a9a950107be0a96f85f3d1121e24a91 100644 (file)
@@ -3989,7 +3989,7 @@ cifs_set_vol_auth(struct smb3_fs_context *ctx, struct cifs_ses *ses)
 }
 
 static struct cifs_tcon *
-cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
+__cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
 {
        int rc;
        struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb);
@@ -4087,6 +4087,17 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
        return tcon;
 }
 
+static struct cifs_tcon *
+cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
+{
+       struct cifs_tcon *ret;
+
+       cifs_mount_lock();
+       ret = __cifs_construct_tcon(cifs_sb, fsuid);
+       cifs_mount_unlock();
+       return ret;
+}
+
 struct cifs_tcon *
 cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb)
 {
index 415e87635d5aab3f217146fa3348b822c37090c8..d9fe17b2ba375c4343ff818b2d8b1a4048adc90e 100644 (file)
@@ -37,7 +37,7 @@
 #include "rfc1002pdu.h"
 #include "fs_context.h"
 
-static DEFINE_MUTEX(cifs_mount_mutex);
+DEFINE_MUTEX(cifs_mount_mutex);
 
 static const match_table_t cifs_smb_version_tokens = {
        { Smb_1, SMB1_VERSION_STRING },
@@ -753,9 +753,9 @@ static int smb3_get_tree(struct fs_context *fc)
 
        if (err)
                return err;
-       mutex_lock(&cifs_mount_mutex);
+       cifs_mount_lock();
        ret = smb3_get_tree_common(fc);
-       mutex_unlock(&cifs_mount_mutex);
+       cifs_mount_unlock();
        return ret;
 }
 
index 182ce11cbe9362eccf73eebadcdcfc2ee7ac7988..b3d51b345eaef5291a51ac368958008b04f0b8d8 100644 (file)
@@ -295,4 +295,16 @@ extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
 #define MAX_CACHED_FIDS 16
 extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
 
+extern struct mutex cifs_mount_mutex;
+
+static inline void cifs_mount_lock(void)
+{
+       mutex_lock(&cifs_mount_mutex);
+}
+
+static inline void cifs_mount_unlock(void)
+{
+       mutex_unlock(&cifs_mount_mutex);
+}
+
 #endif