smb: client: fix rlist race and missing initialization
Subsystems (3)
Paulo Alcantara
maintainerPATCH 1/1 smb: client: fix rlist race and missing initialization
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/client/connect.c +3 -0
@@ -174,6 +174,8 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -1823,6 +1825,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,spin_lock_init (&tcp_ses->mid_counter_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Signature · 1 line
2.55.0
Paulo Alcantara
maintainerQuoted 8 lines · Paulo Alcantara
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making
list_empty()always return false andlist_add()dereference a NULL ->prev pointer.Also,
cifs_signal_cifsd_for_reconnect()can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
Quoted 8 lines
Fixes df0e03a4fb94 ("smb: client: fix potential deadlock when reconnecting channels")Signed-off-by Paulo Alcantara <[email protected]>Cc Namjae Jeon <[email protected]>Cc Ronnie Sahlberg <[email protected]>Cc Shyam Prasad N <[email protected]>Cc Tom Talpey <[email protected]>Cc Bharath SM <[email protected]>
Please ignore it. Sashiko found out a potential issue with this patch.
I'll rework it and then post v2 soon.