Skip to content

Commit 9ffad92

Browse files
z00467499smfrench
authored andcommitted
cifs: Fix the target file was deleted when rename failed.
When xfstest generic/035, we found the target file was deleted if the rename return -EACESS. In cifs_rename2, we unlink the positive target dentry if rename failed with EACESS or EEXIST, even if the target dentry is positived before rename. Then the existing file was deleted. We should just delete the target file which created during the rename. Reported-by: Hulk Robot <[email protected]> Signed-off-by: Zhang Xiaoxu <[email protected]> Cc: [email protected] Signed-off-by: Steve French <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]>
1 parent 5391b8e commit 9ffad92

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/cifs/inode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,7 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry,
20442044
FILE_UNIX_BASIC_INFO *info_buf_target;
20452045
unsigned int xid;
20462046
int rc, tmprc;
2047+
bool new_target = d_really_is_negative(target_dentry);
20472048

20482049
if (flags & ~RENAME_NOREPLACE)
20492050
return -EINVAL;
@@ -2120,8 +2121,13 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry,
21202121
*/
21212122

21222123
unlink_target:
2123-
/* Try unlinking the target dentry if it's not negative */
2124-
if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) {
2124+
/*
2125+
* If the target dentry was created during the rename, try
2126+
* unlinking it if it's not negative
2127+
*/
2128+
if (new_target &&
2129+
d_really_is_positive(target_dentry) &&
2130+
(rc == -EACCES || rc == -EEXIST)) {
21252131
if (d_is_dir(target_dentry))
21262132
tmprc = cifs_rmdir(target_dir, target_dentry);
21272133
else

0 commit comments

Comments
 (0)