smb: client: fix race with concurrent opens in unlink(2)
authorPaulo Alcantara <pc@manguebit.org>
Fri, 8 Aug 2025 15:20:17 +0000 (12:20 -0300)
committerSteve French <stfrench@microsoft.com>
Sun, 10 Aug 2025 17:39:51 +0000 (12:39 -0500)
commit0af1561b2d60bab2a2b00720a5c7b292ecc549ec
tree31c791918369cd4f603c18941a7d6c75245102e4
parent8f5ae30d69d7543eee0d70083daf4de8fe15d585
smb: client: fix race with concurrent opens in unlink(2)

According to some logs reported by customers, CIFS client might end up
reporting unlinked files as existing in stat(2) due to concurrent
opens racing with unlink(2).

Besides sending the removal request to the server, the unlink process
could involve closing any deferred close as well as marking all
existing open handles as deleted to prevent them from deferring
closes, which increases the race window for potential concurrent
opens.

Fix this by unhashing the dentry in cifs_unlink() to prevent any
subsequent opens.  Any open attempts, while we're still unlinking,
will block on parent's i_rwsem.

Reported-by: Jay Shin <jaeshin@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/inode.c