Skip to contentSkip to conversation

smb: client: fix refcount leak in smb2_set_path_attr

PATCH In review Shuhao Fu 3 participants 6 messages Nov 4, 2025

Subsystems (2)
lore
Share & tools
lore

Shuhao Fu

author
#0 lore raw

PATCH 1/1 smb: client: fix refcount leak in smb2_set_path_attr

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -0
index 09e3fc81d..69cb81fa0 100644
@@ -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;
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw

There are multiple callers - are there callers that don't call
"set_writeable_path()" ? And so could cause the reverse refcount
issue?

Quoted 32 lines · Shuhao Fu

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -1
index 09e3fc81d..69cb81fa0 100644
@@ -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;
--

2.39.5 (Apple Git-154)

Signature · 3 lines
Thanks,

Steve
#2 lore raw
Quoted 3 lines · Steve French via samba-technical

There are multiple callers - are there callers that don't call
"set_writeable_path()" ? And so could cause the reverse refcount
issue?

Yes... Even if it does not cause an issue today, that fix looks like it belongs inside smb2_rename_path?

Quoted 36 lines · Shuhao Fu
Quoted 32 lines

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -1
index 09e3fc81d..69cb81fa0 100644
@@ -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;
--

2.39.5 (Apple Git-154)

Signature · 2 lines
Henrique
SUSE Labs
author
#5 lore raw
In reply to Steve French
Quoted 3 lines · Steve French

There are multiple callers - are there callers that don't call
"set_writeable_path()" ? And so could cause the reverse refcount
issue?

I found three calls to smb2_set_path_attr. Two in smb2_rename_path and one in smb2_create_hardlink. The one in smb2_create_hardlink passes NULL for cfile. Therefore, it would not cause reverse refcount issue here.

Thanks,
Shuhao

Quoted 40 lines · Shuhao Fu
Quoted 32 lines

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -1
index 09e3fc81d..69cb81fa0 100644
@@ -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;
--

2.39.5 (Apple Git-154)

Signature · 3 lines
Thanks,

Steve
author
#3 lore raw
In reply to Henrique Carvalho
Quoted 9 lines · Henrique Carvalho
Quoted 3 lines · Steve French via samba-technical

There are multiple callers - are there callers that don't call
"set_writeable_path()" ? And so could cause the reverse refcount
issue?

Yes... Even if it does not cause an issue today, that fix looks like it belongs inside smb2_rename_path?

I placed decrement in smb2_set_path_attr since it seems like a wrapper of smb2_compound_op. I figured that this wrapper should handle the failure cases the same way as smb2_compound_op.

Thanks,
Shuhao

Quoted 41 lines
Quoted 37 lines · Shuhao Fu
Quoted 32 lines

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -1
index 09e3fc81d..69cb81fa0 100644
@@ -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;
--

2.39.5 (Apple Git-154)

Signature · 2 lines
Henrique
SUSE Labs
#4 lore raw
Quoted 8 lines · Shuhao Fu
Quoted 7 lines · Henrique Carvalho
Quoted 3 lines · Steve French via samba-technical

There are multiple callers - are there callers that don't call
"set_writeable_path()" ? And so could cause the reverse refcount
issue?

Quoted 6 lines
Quoted 2 lines

Yes... Even if it does not cause an issue today, that fix looks like it belongs inside smb2_rename_path?

I placed decrement in smb2_set_path_attr since it seems like a wrapper of smb2_compound_op. I figured that this wrapper should handle the failure cases the same way as smb2_compound_op.

Makes sense.

Quoted 44 lines

Thanks,
Shuhao

Quoted 41 lines
Quoted 37 lines · Shuhao Fu
Quoted 32 lines

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")
---
 fs/smb/client/smb2inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2inode.c +2 -1
index 09e3fc81d..69cb81fa0 100644
@@ -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;
--

2.39.5 (Apple Git-154)

Signature · 2 lines
Henrique
SUSE Labs
Signature · 2 lines
Henrique
SUSE Labs