Skip to contentSkip to conversation

smb/server: Fix another refcount leak in smb2_open()

PATCH Applied Guenter Roeck 3 participants 3 messages Feb 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smb/server: Fix another refcount leak in smb2_open()

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.

Cc Namjae Jeon <[email protected]>
Cc ChenXiaoSong <[email protected]>
Fixes c8efcc786146a ("ksmbd: add support for durable handles v1/v2")
---
 fs/smb/server/smb2pdu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +2 -1
index 95901a78951c..8b680c96ee44 100644
@@ -3011,13 +3011,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);
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 1/1
#1 lore raw

Looks good. Feel free to add:

Quoted 39 lines · Guenter Roeck

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.

Cc Namjae Jeon <[email protected]>
Cc ChenXiaoSong <[email protected]>
Fixes c8efcc786146a ("ksmbd: add support for durable handles v1/v2")
---
  fs/smb/server/smb2pdu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +2 -1
index 95901a78951c..8b680c96ee44 100644
@@ -3011,13 +3011,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);
maintainer Applied
#2 lore raw
In reply to Guenter Roeck
Quoted 10 lines · Guenter Roeck

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.

Quoted 6 lines

Found by an experimental AI code review agent at Google.

Cc Namjae Jeon <[email protected]>
Cc ChenXiaoSong <[email protected]>
Fixes c8efcc786146a ("ksmbd: add support for durable handles v1/v2")

Applied it with ChenXiaoSong's reviewed-by tag to #ksmbd-for-next-next. Thanks!