* [PATCH] ksmbd: Fix memory leak in get_file_all_info()
@ 2025-12-24 14:20 Zilin Guan
2025-12-25 1:59 ` Namjae Jeon
2025-12-25 2:00 ` yebin
0 siblings, 2 replies; 3+ messages in thread
From: Zilin Guan @ 2025-12-24 14:20 UTC (permalink / raw)
To: linkinjeon
Cc: smfrench, senozhatsky, tom, linux-cifs, linux-kernel, jianhao.xu,
Zilin Guan
In get_file_all_info(), if vfs_getattr() fails, the function returns
immediately without freeing the allocated filename, leading to a memory
leak.
Fix this by freeing the filename before returning in this error case.
Fixes: 5614c8c487f6a ("ksmbd: replace generic_fillattr with vfs_getattr")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
fs/smb/server/smb2pdu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 8aa483800014..4472638ab11a 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -4923,8 +4923,10 @@ static int get_file_all_info(struct ksmbd_work *work,
ret = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS,
AT_STATX_SYNC_AS_STAT);
- if (ret)
+ if (ret) {
+ kfree(filename);
return ret;
+ }
ksmbd_debug(SMB, "filename = %s\n", filename);
delete_pending = ksmbd_inode_pending_delete(fp);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ksmbd: Fix memory leak in get_file_all_info()
2025-12-24 14:20 [PATCH] ksmbd: Fix memory leak in get_file_all_info() Zilin Guan
@ 2025-12-25 1:59 ` Namjae Jeon
2025-12-25 2:00 ` yebin
1 sibling, 0 replies; 3+ messages in thread
From: Namjae Jeon @ 2025-12-25 1:59 UTC (permalink / raw)
To: Zilin Guan
Cc: smfrench, senozhatsky, tom, linux-cifs, linux-kernel, jianhao.xu
On Wed, Dec 24, 2025 at 11:20 PM Zilin Guan <zilin@seu.edu.cn> wrote:
>
> In get_file_all_info(), if vfs_getattr() fails, the function returns
> immediately without freeing the allocated filename, leading to a memory
> leak.
>
> Fix this by freeing the filename before returning in this error case.
>
> Fixes: 5614c8c487f6a ("ksmbd: replace generic_fillattr with vfs_getattr")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Applied it to #ksmbd-for-next-next.
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ksmbd: Fix memory leak in get_file_all_info()
2025-12-24 14:20 [PATCH] ksmbd: Fix memory leak in get_file_all_info() Zilin Guan
2025-12-25 1:59 ` Namjae Jeon
@ 2025-12-25 2:00 ` yebin
1 sibling, 0 replies; 3+ messages in thread
From: yebin @ 2025-12-25 2:00 UTC (permalink / raw)
To: Zilin Guan, linkinjeon
Cc: smfrench, senozhatsky, tom, linux-cifs, linux-kernel, jianhao.xu
On 2025/12/24 22:20, Zilin Guan wrote:
> In get_file_all_info(), if vfs_getattr() fails, the function returns
> immediately without freeing the allocated filename, leading to a memory
> leak.
>
> Fix this by freeing the filename before returning in this error case.
>
> Fixes: 5614c8c487f6a ("ksmbd: replace generic_fillattr with vfs_getattr")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
> fs/smb/server/smb2pdu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
> index 8aa483800014..4472638ab11a 100644
> --- a/fs/smb/server/smb2pdu.c
> +++ b/fs/smb/server/smb2pdu.c
> @@ -4923,8 +4923,10 @@ static int get_file_all_info(struct ksmbd_work *work,
>
> ret = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS,
> AT_STATX_SYNC_AS_STAT);
> - if (ret)
> + if (ret) {
goto out;
> + kfree(filename);
> return ret;
> + }
>
out:
kfree(filename);
return ret;
Maybe we can add 'out' label.
> ksmbd_debug(SMB, "filename = %s\n", filename);
> delete_pending = ksmbd_inode_pending_delete(fp);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-25 2:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-24 14:20 [PATCH] ksmbd: Fix memory leak in get_file_all_info() Zilin Guan
2025-12-25 1:59 ` Namjae Jeon
2025-12-25 2:00 ` yebin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®