cifs: fix potential deadlock in cache_refresh_path()
authorPaulo Alcantara <pc@cjr.nz>
Tue, 17 Jan 2023 22:00:37 +0000 (19:00 -0300)
committerSteve French <stfrench@microsoft.com>
Wed, 18 Jan 2023 16:45:40 +0000 (10:45 -0600)
commit9fb0db40513e27537fde63287aea920b60557a69
treee76129a7dcf2b7f5ecd5515557e9dfd2d6a2cb7a
parent5dc4c995db9eb45f6373a956eb1f69460e69e6d4
cifs: fix potential deadlock in cache_refresh_path()

Avoid getting DFS referral from an exclusive lock in
cache_refresh_path() because the tcon IPC used for getting the
referral could be disconnected and thus causing a deadlock as shown
below:

task A                       task B
======                       ======
cifs_demultiplex_thread()    dfs_cache_find()
 cifs_handle_standard()       cache_refresh_path()
  reconnect_dfs_server()       down_write()
   dfs_cache_noreq_find()       get_dfs_referral()
    down_read() <- deadlock      smb2_get_dfs_refer()
                                  SMB2_ioctl()
   cifs_send_recv()
    compound_send_recv()
     wait_for_response()

where task A cannot wake up task B because it is blocked on
down_read() due to the exclusive lock held in cache_refresh_path() and
therefore not being able to make progress.

Fixes: c9f711039905 ("cifs: keep referral server sessions alive")
Reviewed-by: Aurélien Aptel <aurelien.aptel@gmail.com>
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/dfs_cache.c