smb: client: fix smbd_connection leak on cifs_get_tcp_session() error
Subsystems (3)
Paulo Alcantara
maintainerPATCH 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.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -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
Quoted 10 lines · Paulo Alcantara
When an RDMA connection is successfully established via
smbd_get_connection()butcifs_get_tcp_session()later fails (e.g.kthread_create()returns an error), the error path freestcp_seswithout first destroying thesmbd_connection.Fix this by calling
smbd_destroy()in theout_errcleanup path beforekfree(tcp_ses).smbd_destroy()safely handles the case wheresmbd_connis 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]>Signed-off-by Paulo Alcantara <[email protected]>
Thanks!
Quoted 9 lines · Paulo Alcantara
When an RDMA connection is successfully established via
smbd_get_connection()butcifs_get_tcp_session()later fails (e.g.kthread_create()returns an error), the error path freestcp_seswithout first destroying thesmbd_connection.Fix this by calling
smbd_destroy()in theout_errcleanup path beforekfree(tcp_ses).smbd_destroy()safely handles the case wheresmbd_connis NULL, so it can be called unconditionally.
...
Applied.