Skip to content

Commit 476497f

Browse files
committed
smb: client: fix file open check in __cifs_unlink()
JIRA: https://issues.redhat.com/browse/RHEL-108683 commit 251090e Author: Paulo Alcantara <pc@manguebit.org> Date: Thu Sep 18 12:30:32 2025 -0300 smb: client: fix file open check in __cifs_unlink() Fix the file open check to decide whether or not silly-rename the file in SMB2+. Fixes: c5ea306 ("smb: client: fix data loss due to broken rename(2)") Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Cc: Frank Sorenson <sorenson@redhat.com> Reviewed-by: David Howells <dhowells@redhat.com> Cc: linux-cifs@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Paulo Alcantara <paalcant@redhat.com>
1 parent d13eb2f commit 476497f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

fs/smb/client/inode.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,8 +2003,21 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
20032003
goto psx_del_no_retry;
20042004
}
20052005

2006-
if (sillyrename || (server->vals->protocol_id > SMB10_PROT_ID &&
2007-
d_is_positive(dentry) && d_count(dentry) > 2))
2006+
/* For SMB2+, if the file is open, we always perform a silly rename.
2007+
*
2008+
* We check for d_count() right after calling
2009+
* cifs_close_deferred_file_under_dentry() to make sure that the
2010+
* dentry's refcount gets dropped in case the file had any deferred
2011+
* close.
2012+
*/
2013+
if (!sillyrename && server->vals->protocol_id > SMB10_PROT_ID) {
2014+
spin_lock(&dentry->d_lock);
2015+
if (d_count(dentry) > 1)
2016+
sillyrename = true;
2017+
spin_unlock(&dentry->d_lock);
2018+
}
2019+
2020+
if (sillyrename)
20082021
rc = -EBUSY;
20092022
else
20102023
rc = server->ops->unlink(xid, tcon, full_path, cifs_sb, dentry);

0 commit comments

Comments
 (0)