]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb: client: Fix refcount leak for cifs_sb_tlink
authorShuhao Fu <sfual@cse.ust.hk>
Thu, 16 Oct 2025 02:52:55 +0000 (02:52 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:04:29 +0000 (14:04 +0100)
commit c2b77f42205ef485a647f62082c442c1cd69d3fc upstream.

Fix three refcount inconsistency issues related to `cifs_sb_tlink`.

Comments for `cifs_sb_tlink` state that `cifs_put_tlink()` needs to be
called after successful calls to `cifs_sb_tlink()`. Three calls fail to
update refcount accordingly, leading to possible resource leaks.

Fixes: 8ceb98437946 ("CIFS: Move rename to ops struct")
Fixes: 2f1afe25997f ("cifs: Use smb 2 - 3 and cifsacl mount options getacl functions")
Fixes: 366ed846df60 ("cifs: Use smb 2 - 3 and cifsacl mount options setacl function")
Cc: stable@vger.kernel.org
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/inode.c
fs/smb/client/smb2ops.c

index f3ed5134ecfa9a11011e01d0d4cefdf8b4a5baed..51d38449ca855f6773b8a5c9c2eb0f3bb5864205 100644 (file)
@@ -2106,8 +2106,10 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
        tcon = tlink_tcon(tlink);
        server = tcon->ses->server;
 
-       if (!server->ops->rename)
-               return -ENOSYS;
+       if (!server->ops->rename) {
+               rc = -ENOSYS;
+               goto do_rename_exit;
+       }
 
        /* try path-based rename first */
        rc = server->ops->rename(xid, tcon, from_path, to_path, cifs_sb);
index 4dd5b2e04886934b57a11f011e8d01f31f65ca23..497417a9839730376244fdd3f59a6c72f62d3c4b 100644 (file)
@@ -3323,8 +3323,7 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
        utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
        if (!utf16_path) {
                rc = -ENOMEM;
-               free_xid(xid);
-               return ERR_PTR(rc);
+               goto put_tlink;
        }
 
        oparms = (struct cifs_open_parms) {
@@ -3356,6 +3355,7 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
                SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
        }
 
+put_tlink:
        cifs_put_tlink(tlink);
        free_xid(xid);
 
@@ -3396,8 +3396,7 @@ set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
        utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
        if (!utf16_path) {
                rc = -ENOMEM;
-               free_xid(xid);
-               return rc;
+               goto put_tlink;
        }
 
        oparms = (struct cifs_open_parms) {
@@ -3418,6 +3417,7 @@ set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
                SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
        }
 
+put_tlink:
        cifs_put_tlink(tlink);
        free_xid(xid);
        return rc;