]> 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 13:30:19 +0000 (15:30 +0200)
commitbc1427a48371808378ef0c8cc1d21a27352fbeb1
treee6219d7b7fcf3b48998fd6170dbe423ee9c1193c
parent43662b846c7a22ffc368502ab39e8caaaf4d111e
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