Skip to contentSkip to conversation

vfs: Don't rehash the dentry on successfull deletion

PATCH New Aneesh Kumar K.V 1 participant 1 message Feb 16, 2011 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: Don't rehash the dentry on successfull deletion

vfs_rename_dir() doesn't properly account for filesystems with FS_RENAME_DOES_D_MOVE. If new_dentry has a target inode attached, it unhashes the new_dentry prior to the rename() iop and rehashes it after, but doesn't account for the possibility that rename() may have swapped {old,new}_dentry. For FS_RENAME_DOES_D_MOVE filesystems, it rehashes new_dentry (now the old renamed-from name, which d_move() expected to go away), such that a subsequent lookup will find it... and the overwritte target inode.

To correct this call d_rehash only in case of error or in if the file systems doesn't do d_move itself.

Based on the original patch by Sage Weil <[email protected]>
http://kerneltrap.org/mailarchive/linux-fsdevel/2008/4/18/1498534

Cc Zach Brown <[email protected]
Cc Sage Weil <[email protected]>
Cc Miklos Szeredi <[email protected]>
---
 fs/namei.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
fs/namei.c +9 -2
index 7d77f24..5631ccf 100644
@@ -3259,8 +3259,15 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
 			dont_mount(new_dentry);
 		}
 		mutex_unlock(&target->i_mutex);
-		if (d_unhashed(new_dentry))
-			d_rehash(new_dentry);
+		/*
+		 * if rename callback returned success and we have
+		 * FS_RENAME_DOES_D_MOVE set, then don't do the
+		 * rehash.
+		 */
+		if (error ||
+		    !(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
+			if (d_unhashed(new_dentry))
+				d_rehash(new_dentry);
 		dput(new_dentry);
 	}
 	if (!error)
Signature · 1 line
1.7.1