Skip to content

Commit 9617c3e

Browse files
pcacjrgregkh
authored andcommitted
smb: client: fix file open check in __cifs_unlink()
[ Upstream commit 251090e ] 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) <[email protected]> Cc: Frank Sorenson <[email protected]> Reviewed-by: David Howells <[email protected]> Cc: [email protected] Signed-off-by: Steve French <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 5ba113d commit 9617c3e

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)