]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb/server: Fix another refcount leak in smb2_open()
authorGuenter Roeck <linux@roeck-us.net>
Fri, 27 Feb 2026 05:54:21 +0000 (21:54 -0800)
committerSteve French <stfrench@microsoft.com>
Mon, 9 Mar 2026 02:28:38 +0000 (21:28 -0500)
If ksmbd_override_fsids() fails, we jump to err_out2. At that point, fp is
NULL because it hasn't been assigned dh_info.fp yet, so ksmbd_fd_put(work,
fp) will not be called. However, dh_info.fp was already inserted into the
session file table by ksmbd_reopen_durable_fd(), so it will leak in the
session file table until the session is closed.

Move fp = dh_info.fp; ahead of the ksmbd_override_fsids() check to fix the
problem.

Found by an experimental AI code review agent at Google.

Fixes: c8efcc786146a ("ksmbd: add support for durable handles v1/v2")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c

index 743c629fe7ec64c391479d9412fed56e0739ccf8..48836b97951bcf553e1d3ec25f57d8981787c2c8 100644 (file)
@@ -3012,13 +3012,14 @@ int smb2_open(struct ksmbd_work *work)
                                goto err_out2;
                        }
 
+                       fp = dh_info.fp;
+
                        if (ksmbd_override_fsids(work)) {
                                rc = -ENOMEM;
                                ksmbd_put_durable_fd(dh_info.fp);
                                goto err_out2;
                        }
 
-                       fp = dh_info.fp;
                        file_info = FILE_OPENED;
 
                        rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat);