Skip to contentSkip to conversation

smb/server: fix some refcount leaks

PATCH Applied [email protected] 2 participants 5 messages Dec 29, 2025

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover smb/server: fix some refcount leaks

From: ChenXiaoSong <[email protected]>

My dear team member, ZhangGuoDong, has caught some refcount leak issues.

Other patches pending review (including those from others) can be found at the following link:
https://chenxiaosong.com/en/smb-patch.html

ZhangGuoDong (2):
smb/server: fix refcount leak in parse_durable_handle_context() smb/server: fix refcount leak in smb2_open()

 fs/smb/server/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 smb/server: fix refcount leak in parse_durable_handle_context()

From: ZhangGuoDong <[email protected]>

When the command is a replay operation and -ENOEXEC is returned, the refcount of ksmbd_file must be released.

---
 fs/smb/server/smb2pdu.c | 1 +
 1 file changed, 1 insertion(+)
fs/smb/server/smb2pdu.c +1 -0
index 469b70757dba..6a966c696f7d 100644
@@ -2809,6 +2809,7 @@ static int parse_durable_handle_context(struct ksmbd_work *work,
 					    SMB2_CLIENT_GUID_SIZE)) {
 					if (!(req->hdr.Flags & SMB2_FLAGS_REPLAY_OPERATION)) {
 						err = -ENOEXEC;
+						ksmbd_put_durable_fd(dh_info->fp);
 						goto out;
 					}
 
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw

Re: [PATCH 1/2] smb/server: fix refcount leak in parse_durable_handle_context()

Quoted 8 lines · On Mon, Dec 29, 2025 at 11:15 AM <[email protected]> wrote:

From: ZhangGuoDong <[email protected]>

When the command is a replay operation and -ENOEXEC is returned, the refcount of ksmbd_file must be released.

Applied it to #ksmbd-for-next-next.
Thanks!

#3 lore raw

PATCH 2/2 smb/server: fix refcount leak in smb2_open()

In reply to [email protected]

From: ZhangGuoDong <[email protected]>

When ksmbd_vfs_getattr() fails, the reference count of ksmbd_file must be released.

---
 fs/smb/server/smb2pdu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +3 -1
index 6a966c696f7d..ed9352753d83 100644
@@ -3007,8 +3007,10 @@ int smb2_open(struct ksmbd_work *work)
 			file_info = FILE_OPENED;
 
 			rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat);
-			if (rc)
+			if (rc) {
+				ksmbd_put_durable_fd(fp);
 				goto err_out2;
+			}
 
 			ksmbd_put_durable_fd(fp);
 			goto reconnected_fp;
Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH 2/2] smb/server: fix refcount leak in smb2_open()

Quoted 17 lines · On Mon, Dec 29, 2025 at 11:15 AM <[email protected]> wrote:

From: ZhangGuoDong <[email protected]>

When ksmbd_vfs_getattr() fails, the reference count of ksmbd_file must be released.

---
 fs/smb/server/smb2pdu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +0 -0
index 6a966c696f7d..ed9352753d83 100644

fs/smb/server/smb2pdu.c int smb2_open(struct ksmbd_work *work) · line 3013

Quoted 8 lines
fs/smb/server/smb2pdu.c +3 -1
@@ -3007,8 +3007,10 @@ int smb2_open(struct ksmbd_work *work)
                        file_info = FILE_OPENED;
 
                        rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat);
-                       if (rc)
+                       if (rc) {
+                               ksmbd_put_durable_fd(fp);
                                goto err_out2;
+                       }

I think that It is simpler to do it like this:

fs/smb/server/smb2pdu.c +1 -2
index 8a7c48adb87e..41626cb7d2f5 100644
@@ -3009,10 +3009,9 @@ int smb2_open(struct ksmbd_work *work)
                        file_info = FILE_OPENED;
 
                        rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat);
+                       ksmbd_put_durable_fd(fp);
                        if (rc)
                                goto err_out2;
-
-                       ksmbd_put_durable_fd(fp);
                        goto reconnected_fp;
                }
        } else if (req_op_level == SMB2_OPLOCK_LEVEL_LEASE)
Quoted 6 lines
fs/smb/server/smb2pdu.c +0 -1
                        ksmbd_put_durable_fd(fp);
                        goto reconnected_fp;
--

2.43.0