]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Sep 2025 14:55:30 +0000 (16:55 +0200)
commitdddeed19782df4cabccf5791d37d143871456612
treea79675c0adee6a59e628b11c56109f70659695fd
parentb08a26b87b2345b35eb5605446648a774cbb622d
smb: client: fix race with concurrent opens in unlink(2)

[ Upstream commit 0af1561b2d60bab2a2b00720a5c7b292ecc549ec ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/inode.c