Skip to content

Commit 8e5bb3c

Browse files
Miklos Szeredigregkh
Miklos Szeredi
authored andcommitted
vfs: rename: check backing inode being equal
commit 9409e22 upstream. If a file is renamed to a hardlink of itself POSIX specifies that rename(2) should do nothing and return success. This condition is checked in vfs_rename(). However it won't detect hard links on overlayfs where these are given separate inodes on the overlayfs layer. Overlayfs itself detects this condition and returns success without doing anything, but then vfs_rename() will proceed as if this was a successful rename (detach_mounts(), d_move()). The correct thing to do is to detect this condition before even calling into overlayfs. This patch does this by calling vfs_select_inode() to get the underlying inodes. Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b0dac61 commit 8e5bb3c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/namei.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4195,7 +4195,11 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
41954195
bool new_is_dir = false;
41964196
unsigned max_links = new_dir->i_sb->s_max_links;
41974197

4198-
if (source == target)
4198+
/*
4199+
* Check source == target.
4200+
* On overlayfs need to look at underlying inodes.
4201+
*/
4202+
if (vfs_select_inode(old_dentry, 0) == vfs_select_inode(new_dentry, 0))
41994203
return 0;
42004204

42014205
error = may_delete(old_dir, old_dentry, is_dir);

0 commit comments

Comments
 (0)