From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org,
ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com,
bharathsm@microsoft.com, senozhatsky@chromium.org,
dhowells@redhat.com, linux-cifs@vger.kernel.org,
ZhangGuoDong <zhangguodong@kylinos.cn>,
ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: Re: [PATCH v2 1/1] smb/server: fix refcount leak in smb2_open()
Date: Fri, 27 Feb 2026 12:07:44 +0800 [thread overview]
Message-ID: <f3604a74-3caa-4737-bfc0-d93feb988176@chenxiaosong.com> (raw)
In-Reply-To: <59d5c1a6-7a7f-464a-aa62-e53daff8870d@roeck-us.net>
Hi Guenter,
Sorry for the late reply. I had some family matters to take care of
yesterday.
Please see the following process:
```
smb2_open
smb2_check_durable_oplock
opinfo_get(fp) // inc refcount
ksmbd_reopen_durable_fd
__open_id(&work->sess->file_table, fp,
idr_alloc_cyclic(ft->idr, fp, ...)
__open_id_set(fp, id, type); // insert into file table
ksmbd_override_fsids // fail
ksmbd_put_durable_fd
__ksmbd_close_fd
__ksmbd_remove_fd // remove dh_info.fp from file table
// dh_info.fp has already been removed from the file table
ksmbd_fd_put(..., fp) // fp == NULL
```
Thanks,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>
On 2026/2/26 13:09, Guenter Roeck wrote:
> Hi,
>
> On 2/25/26 20:12, ChenXiaoSong wrote:
>> Hi Guenter,
>>
>> Thank you for taking the time to look into this issue.
>>
>> I reviewed the relevant code in more detail and did not find any leak.
>>
>> Both `ksmbd_put_durable_fd()` and `ksmbd_fd_put()` will eventually
>> call `__ksmbd_remove_fd()` (remove fd from file table).
>>
>
> Sorry for bothering you again. Are you sure ?
>
> ksmbd_put_durable_fd() calls __ksmbd_close_fd() with NULL first parameter.
> __ksmbd_close_fd() only calls __ksmbd_remove_fd() if ft (the first
> parameter)
> is not NULL.
>
> ksmbd_fd_put() does call __ksmbd_remove_fd() with first parameter, but ...
>
>> If my understanding is incorrect, please let me know.
>>
>> Thanks,
>> ChenXiaoSong <chenxiaosong@chenxiaosong.com>
>>
>> 在 2026/2/26 00:49, Guenter Roeck 写道:
>>> Running an experimental AI agent on this patch produced the following
>>> feedback:
>>>
>>> This isn't a bug introduced by your patch, but it looks like there is
>>> still a
>>> resource leak here. 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
>
> the AI is trying to make the point that ksmbd_fd_put() will not be called
> because fp == NULL.
>
> Thanks,
> Guenter
>
>>> 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.
>>> Should fp = dh_info.fp; be moved before the ksmbd_override_fsids()
>>> check?
>>>
>>> PTAL and let me know if it has a point or if it is missing something.
>>
next prev parent reply other threads:[~2026-02-27 4:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-29 3:15 [PATCH v2 0/1] smb/server: fix some refcount leaks chenxiaosong.chenxiaosong
2025-12-29 3:15 ` [PATCH v2 1/1] smb/server: fix refcount leak in smb2_open() chenxiaosong.chenxiaosong
2025-12-29 4:06 ` Namjae Jeon
2026-02-25 16:49 ` Guenter Roeck
2026-02-26 4:12 ` ChenXiaoSong
2026-02-26 4:27 ` Guenter Roeck
2026-02-26 5:09 ` Guenter Roeck
2026-02-27 4:07 ` ChenXiaoSong [this message]
2026-02-27 4:12 ` ChenXiaoSong
2026-02-27 4:43 ` Namjae Jeon
2026-02-27 4:42 ` Guenter Roeck
2026-02-27 4:53 ` ChenXiaoSong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f3604a74-3caa-4737-bfc0-d93feb988176@chenxiaosong.com \
--to=chenxiaosong@chenxiaosong.com \
--cc=bharathsm@microsoft.com \
--cc=chenxiaosong@kylinos.cn \
--cc=dhowells@redhat.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=pc@manguebit.org \
--cc=ronniesahlberg@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=zhangguodong@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox