From: Miklos Szeredi Date: Tue, 10 May 2016 23:16:37 +0000 (+0200) Subject: vfs: rename: check backing inode being equal X-Git-Tag: firefly_0821_release~176^2~4^2~45^2~16 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=8e5bb3c5417fd98c8966807dc07cc1b687da97c4;p=firefly-linux-kernel-4.4.55.git vfs: rename: check backing inode being equal commit 9409e22acdfc9153f88d9b1ed2bd2a5b34d2d3ca 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/namei.c b/fs/namei.c index d8ee4da93650..0202aebb9813 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4195,7 +4195,11 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, bool new_is_dir = false; unsigned max_links = new_dir->i_sb->s_max_links; - if (source == target) + /* + * Check source == target. + * On overlayfs need to look at underlying inodes. + */ + if (vfs_select_inode(old_dentry, 0) == vfs_select_inode(new_dentry, 0)) return 0; error = may_delete(old_dir, old_dentry, is_dir);