cifs: fix lock ordering while disabling multichannel
authorSteve French <stfrench@microsoft.com>
Fri, 26 Jan 2024 16:42:54 +0000 (10:42 -0600)
committerSteve French <stfrench@microsoft.com>
Sat, 27 Jan 2024 06:17:57 +0000 (00:17 -0600)
commit35cdaa1062965d21434e19a933a0d18c3658bf4b
tree017109cf7921b8571f5087de11a70983ce723be7
parent4ff6e88a0441460b3d87e60fb8d771090b421221
cifs: fix lock ordering while disabling multichannel

The code to handle the case of server disabling multichannel
was picking iface_lock with chan_lock held. This goes against
the lock ordering rules, as iface_lock is a higher order lock
(even if it isn't so obvious).

This change fixes the lock ordering by doing the following in
that order for each secondary channel:
1. store iface and server pointers in local variable
2. remove references to iface and server in channels
3. unlock chan_lock
4. lock iface_lock
5. dec ref count for iface
6. unlock iface_lock
7. dec ref count for server
8. lock chan_lock again

Since this function can only be called in smb2_reconnect, and
that cannot be called by two parallel processes, we should not
have races due to dropping chan_lock between steps 3 and 8.

Fixes: ee1d21794e55 ("cifs: handle when server stops supporting multichannel")
Reported-by: Paulo Alcantara <pc@manguebit.com>
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/sess.c