Skip to content

Commit 9409e22

Browse files
Miklos SzerediAl Viro
Miklos Szeredi
authored and
Al Viro
committed
vfs: rename: check backing inode being equal
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]> Cc: <[email protected]> # v4.2+
1 parent 54d5ca8 commit 9409e22

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
@@ -4213,7 +4213,11 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
42134213
bool new_is_dir = false;
42144214
unsigned max_links = new_dir->i_sb->s_max_links;
42154215

4216-
if (source == target)
4216+
/*
4217+
* Check source == target.
4218+
* On overlayfs need to look at underlying inodes.
4219+
*/
4220+
if (vfs_select_inode(old_dentry, 0) == vfs_select_inode(new_dentry, 0))
42174221
return 0;
42184222

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

0 commit comments

Comments
 (0)