Skip to contentSkip to conversation

smb: client: fix smbd_connection leak on cifs_get_tcp_session() error

PATCH Applied Paulo Alcantara 2 participants 3 messages Sep 12 – Sep 13

Subsystems (3)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 smb: client: fix smbd_connection leak on cifs_get_tcp_session() error

When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.

Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.

Fixes 2f8946464b11 ("CIFS: SMBD: Upper layer connects to SMBDirect session")
Cc Tom Talpey <[email protected]>
Cc Stefan Metzmacher <[email protected]>
Cc Shyam Prasad N <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Bharath SM <[email protected]>
Cc Namjae Jeon <[email protected]>
---
 fs/smb/client/connect.c | 1 +
 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
index 4bd9f9fb93bb..28e1ddeb6182 100644
@@ -1934,6 +1934,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
 		kfree(tcp_ses->leaf_fullpath);
 		if (tcp_ses->ssocket)
 			sock_release(tcp_ses->ssocket);
+		smbd_destroy(tcp_ses);
 		kfree(tcp_ses);
 	}
 	return ERR_PTR(rc);
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paulo Alcantara

When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.

Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.

Quoted 10 lines
Fixes 2f8946464b11 ("CIFS: SMBD: Upper layer connects to SMBDirect session")
Cc Tom Talpey <[email protected]>
Cc Stefan Metzmacher <[email protected]>
Cc Shyam Prasad N <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Bharath SM <[email protected]>
Cc Namjae Jeon <[email protected]>

Thanks!

author maintainer Applied
#2 lore raw
In reply to Paulo Alcantara
Quoted 9 lines · Paulo Alcantara

When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.

Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.
...

Applied.