summaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2016-05-10 19:16:37 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2016-05-10 23:55:43 -0400
commit9409e22acdfc9153f88d9b1ed2bd2a5b34d2d3ca (patch)
tree94f5f543f75ed4080b99483242ef7622c97d6f54 /fs/namei.c
parent54d5ca871e72f2bb172ec9323497f01cd5091ec7 (diff)
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 <mszeredi@redhat.com> Cc: <stable@vger.kernel.org> # v4.2+
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 1d9ca2d5dff6..3ef87d673bbe 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4213,7 +4213,11 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
4213 bool new_is_dir = false; 4213 bool new_is_dir = false;
4214 unsigned max_links = new_dir->i_sb->s_max_links; 4214 unsigned max_links = new_dir->i_sb->s_max_links;
4215 4215
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))
4217 return 0; 4221 return 0;
4218 4222
4219 error = may_delete(old_dir, old_dentry, is_dir); 4223 error = may_delete(old_dir, old_dentry, is_dir);