Skip to contentSkip to conversation

smb: client: cancel reconnect work in clean_demultiplex_info()

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: cancel reconnect work in clean_demultiplex_info()

clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:

cifs_demultiplex_thread()

    cifs_readv_from_socket()
      cifs_reconnect()
        __cifs_reconnect()
          cifs_queue_server_reconn()
            mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
    clean_demultiplex_info()
      cancel_delayed_work_sync(&server->echo)   // echo canceled
                                                 // reconnect NOT canceled
      kfree_sensitive(server)                    // server freed

...later, on cifsiod_wq:

smb2_reconnect_server()

    server->srv_count  // UAF read of freed server

Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.

Reported-by [email protected]
Fixes 53e0e11efe92 ("CIFS: Fix a possible memory corruption during reconnect")
Cc David Howells <[email protected]>
Cc Shyam Prasad N <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Tom Talpey <[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 b6e98eb31673..bef710d9a3c3 100644
@@ -1067,6 +1067,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)
 	spin_unlock(&server->srv_lock);
 
 	cancel_delayed_work_sync(&server->echo);
+	cancel_delayed_work_sync(&server->reconnect);
 
 	spin_lock(&server->srv_lock);
 	server->tcpStatus = CifsExiting;
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Paulo Alcantara

clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:

cifs_demultiplex_thread()

    cifs_readv_from_socket()
      cifs_reconnect()
        __cifs_reconnect()
          cifs_queue_server_reconn()
            mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
    clean_demultiplex_info()
      cancel_delayed_work_sync(&server->echo)   // echo canceled
                                                 // reconnect NOT canceled
      kfree_sensitive(server)                    // server freed

...later, on cifsiod_wq:

smb2_reconnect_server()

    server->srv_count  // UAF read of freed server

Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.

Quoted 11 lines
Reported-by [email protected]
Fixes 53e0e11efe92 ("CIFS: Fix a possible memory corruption during reconnect")
Cc David Howells <[email protected]>
Cc Shyam Prasad N <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Tom Talpey <[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 17 lines · Paulo Alcantara

clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:

cifs_demultiplex_thread()

    cifs_readv_from_socket()
      cifs_reconnect()
        __cifs_reconnect()
          cifs_queue_server_reconn()
            mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
    clean_demultiplex_info()
      cancel_delayed_work_sync(&server->echo)   // echo canceled
                                                 // reconnect NOT canceled
      kfree_sensitive(server)                    // server freed

...later, on cifsiod_wq:

Quoted 7 lines

smb2_reconnect_server()

    server->srv_count  // UAF read of freed server

Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
...

Applied.