All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: Fix connections leak when tlink setup failed
@ 2022-11-10  3:00 Zhang Xiaoxu
  2022-11-10 21:29 ` Paulo Alcantara
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Xiaoxu @ 2022-11-10  3:00 UTC (permalink / raw)
  To: linux-cifs, zhangxiaoxu5, sfrench, smfrench, pc, lsahlber,
	sprasad, tom, palcantara

If the tlink setup failed, lost to put the connections, then
the module refcnt leak since the cifsd kthread not exit.

Also leak the fscache info, and for next mount with fsc,it will
print the follow errors:
  CIFS: Cache volume key already in use (cifs,127.0.0.1:445,TEST)

Let's check the result of tlink setup, and put the connection when
error happened.

Fixes: 56c762eb9bee ("cifs: Refactor out cifs_mount()")
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/cifs/connect.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 1cc47dd3b4d6..e699e45e70c4 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3855,14 +3855,19 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 	uuid_copy(&cifs_sb->dfs_mount_id, &mnt_ctx.mount_id);
 
 out:
-	free_xid(mnt_ctx.xid);
 	cifs_try_adding_channels(cifs_sb, mnt_ctx.ses);
-	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	if (rc)
+		goto put_conns;
+
+	free_xid(mnt_ctx.xid);
+	return rc;
 
 error:
 	dfs_cache_put_refsrv_sessions(&mnt_ctx.mount_id);
 	kfree(mnt_ctx.origin_fullpath);
 	kfree(mnt_ctx.leaf_fullpath);
+put_conns:
 	mount_put_conns(&mnt_ctx);
 	return rc;
 }
@@ -3884,8 +3889,12 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 			goto error;
 	}
 
+	rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	if (rc)
+		goto error;
+
 	free_xid(mnt_ctx.xid);
-	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	return rc;
 
 error:
 	mount_put_conns(&mnt_ctx);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cifs: Fix connections leak when tlink setup failed
  2022-11-10  3:00 [PATCH] cifs: Fix connections leak when tlink setup failed Zhang Xiaoxu
@ 2022-11-10 21:29 ` Paulo Alcantara
  2022-11-11  1:11   ` zhangxiaoxu (A)
  0 siblings, 1 reply; 3+ messages in thread
From: Paulo Alcantara @ 2022-11-10 21:29 UTC (permalink / raw)
  To: Zhang Xiaoxu, linux-cifs, zhangxiaoxu5, sfrench, smfrench,
	lsahlber, sprasad, tom

Zhang Xiaoxu <zhangxiaoxu5@huawei.com> writes:

> If the tlink setup failed, lost to put the connections, then
> the module refcnt leak since the cifsd kthread not exit.
>
> Also leak the fscache info, and for next mount with fsc,it will
> print the follow errors:
>   CIFS: Cache volume key already in use (cifs,127.0.0.1:445,TEST)
>
> Let's check the result of tlink setup, and put the connection when
> error happened.
>
> Fixes: 56c762eb9bee ("cifs: Refactor out cifs_mount()")
> Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
> ---
>  fs/cifs/connect.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 1cc47dd3b4d6..e699e45e70c4 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -3855,14 +3855,19 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
>  	uuid_copy(&cifs_sb->dfs_mount_id, &mnt_ctx.mount_id);
>  
>  out:
> -	free_xid(mnt_ctx.xid);
>  	cifs_try_adding_channels(cifs_sb, mnt_ctx.ses);
> -	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
> +	rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
> +	if (rc)
> +		goto put_conns;

Good catch.  However, this would partially fix the leaked connections as
you must still call dfs_cache_put_refsrv_sessions() to put all other
connections that were used for chasing DFS referrals.  For non-DFS
mounts, it wouldn't be a problem, though.

What about something like below

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 1cc47dd3b4d6..083ba70f3c1a 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3855,9 +3855,13 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 	uuid_copy(&cifs_sb->dfs_mount_id, &mnt_ctx.mount_id);
 
 out:
-	free_xid(mnt_ctx.xid);
 	cifs_try_adding_channels(cifs_sb, mnt_ctx.ses);
-	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	rc =  mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
+	if (rc)
+		goto error;
+
+	free_xid(mnt_ctx.xid);
+	return rc;
 
 error:
 	dfs_cache_put_refsrv_sessions(&mnt_ctx.mount_id);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cifs: Fix connections leak when tlink setup failed
  2022-11-10 21:29 ` Paulo Alcantara
@ 2022-11-11  1:11   ` zhangxiaoxu (A)
  0 siblings, 0 replies; 3+ messages in thread
From: zhangxiaoxu (A) @ 2022-11-11  1:11 UTC (permalink / raw)
  To: Paulo Alcantara, linux-cifs, sfrench, smfrench, lsahlber, sprasad, tom



On 2022/11/11 5:29, Paulo Alcantara wrote:
> Zhang Xiaoxu <zhangxiaoxu5@huawei.com> writes:
> 
>> If the tlink setup failed, lost to put the connections, then
>> the module refcnt leak since the cifsd kthread not exit.
>>
>> Also leak the fscache info, and for next mount with fsc,it will
>> print the follow errors:
>>    CIFS: Cache volume key already in use (cifs,127.0.0.1:445,TEST)
>>
>> Let's check the result of tlink setup, and put the connection when
>> error happened.
>>
>> Fixes: 56c762eb9bee ("cifs: Refactor out cifs_mount()")
>> Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
>> ---
>>   fs/cifs/connect.c | 15 ++++++++++++---
>>   1 file changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
>> index 1cc47dd3b4d6..e699e45e70c4 100644
>> --- a/fs/cifs/connect.c
>> +++ b/fs/cifs/connect.c
>> @@ -3855,14 +3855,19 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
>>   	uuid_copy(&cifs_sb->dfs_mount_id, &mnt_ctx.mount_id);
>>   
>>   out:
>> -	free_xid(mnt_ctx.xid);
>>   	cifs_try_adding_channels(cifs_sb, mnt_ctx.ses);
>> -	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
>> +	rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
>> +	if (rc)
>> +		goto put_conns;
> 
> Good catch.  However, this would partially fix the leaked connections as
> you must still call dfs_cache_put_refsrv_sessions() to put all other
> connections that were used for chasing DFS referrals.  For non-DFS
> mounts, it wouldn't be a problem, though.
> 
> What about something like below
> 
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 1cc47dd3b4d6..083ba70f3c1a 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -3855,9 +3855,13 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
>   	uuid_copy(&cifs_sb->dfs_mount_id, &mnt_ctx.mount_id);
>   
>   out:
> -	free_xid(mnt_ctx.xid);
>   	cifs_try_adding_channels(cifs_sb, mnt_ctx.ses);
> -	return mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
> +	rc =  mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
> +	if (rc)
> +		goto error;
> +
> +	free_xid(mnt_ctx.xid);
> +	return rc;
>   
>   error:
>   	dfs_cache_put_refsrv_sessions(&mnt_ctx.mount_id);
Thanks Paulo, I will check this point and send v2.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-11  1:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  3:00 [PATCH] cifs: Fix connections leak when tlink setup failed Zhang Xiaoxu
2022-11-10 21:29 ` Paulo Alcantara
2022-11-11  1:11   ` zhangxiaoxu (A)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.