]> www.infradead.org Git - users/hch/xfs.git/commitdiff
smb3: fix problem unloading module due to leaked refcount on shutdown
authorSteve French <stfrench@microsoft.com>
Fri, 16 Aug 2024 21:47:39 +0000 (16:47 -0500)
committerSteve French <stfrench@microsoft.com>
Thu, 22 Aug 2024 17:36:57 +0000 (12:36 -0500)
The shutdown ioctl can leak a refcount on the tlink which can
prevent rmmod (unloading the cifs.ko) module from working.

Found while debugging xfstest generic/043

Fixes: 69ca1f57555f ("smb3: add dynamic tracepoints for shutdown ioctl")
Reviewed-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/connect.c
fs/smb/client/ioctl.c
fs/smb/client/link.c

index d2307162a2de15ec01462d49b8ce3191a0be9f66..c1c14274930ac6826f422fc18cbaec5dab88293b 100644 (file)
@@ -4194,6 +4194,9 @@ tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink)
  *
  * If one doesn't exist then insert a new tcon_link struct into the tree and
  * try to construct a new one.
+ *
+ * REMEMBER to call cifs_put_tlink() after successful calls to cifs_sb_tlink,
+ * to avoid refcount issues
  */
 struct tcon_link *
 cifs_sb_tlink(struct cifs_sb_info *cifs_sb)
index 44dbaf9929a4e39707630463c6270bb43d1781fd..9bb5c869f4db7e60ad215967e5cf7721543fee21 100644 (file)
@@ -229,9 +229,11 @@ static int cifs_shutdown(struct super_block *sb, unsigned long arg)
 
 shutdown_good:
        trace_smb3_shutdown_done(flags, tcon->tid);
+       cifs_put_tlink(tlink);
        return 0;
 shutdown_out_err:
        trace_smb3_shutdown_err(rc, flags, tcon->tid);
+       cifs_put_tlink(tlink);
        return rc;
 }
 
index d86da949a919056b23b68f400b36933a94e9635f..80099bbb333b0847364161782cd361fe39b9dc91 100644 (file)
@@ -588,6 +588,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
        tlink = cifs_sb_tlink(cifs_sb);
        if (IS_ERR(tlink)) {
                rc = PTR_ERR(tlink);
+               /* BB could be clearer if skipped put_tlink on error here, but harmless */
                goto symlink_exit;
        }
        pTcon = tlink_tcon(tlink);