]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: client: fix refcount leak in smb2_set_path_attr
authorShuhao Fu <sfual@cse.ust.hk>
Tue, 4 Nov 2025 15:13:15 +0000 (23:13 +0800)
committerSteve French <stfrench@microsoft.com>
Tue, 4 Nov 2025 22:03:56 +0000 (16:03 -0600)
Fix refcount leak in `smb2_set_path_attr` when path conversion fails.

Function `cifs_get_writable_path` returns `cfile` with its reference
counter `cfile->count` increased on success. Function `smb2_compound_op`
would decrease the reference counter for `cfile`, as stated in its
comment. By calling `smb2_rename_path`, the reference counter of `cfile`
would leak if `cifs_convert_path_to_utf16` fails in `smb2_set_path_attr`.

Fixes: 8de9e86c67ba ("cifs: create a helper to find a writeable handle by path name")
Acked-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/smb2inode.c

index 09e3fc81d7cbc7f807ddb2cf6ba6c8cf615967b4..69cb81fa0d3ab17a89835305d74180f57d4e38df 100644 (file)
@@ -1294,6 +1294,8 @@ static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
        smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
        if (smb2_to_name == NULL) {
                rc = -ENOMEM;
+               if (cfile)
+                       cifsFileInfo_put(cfile);
                goto smb2_rename_path;
        }
        in_iov.iov_base = smb2_to_name;