ovl: fix nlink leak in ovl_rename()
authorAmir Goldstein <amir73il@gmail.com>
Mon, 5 Jun 2017 19:44:49 +0000 (22:44 +0300)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 4 Jul 2017 20:03:15 +0000 (22:03 +0200)
This patch fixes an overlay inode nlink leak in the case where
ovl_rename() renames over a non-dir.

This is not so critical, because overlay inode doesn't rely on
nlink dropping to zero for inode deletion.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/dir.c

index a63a71656e9bdaef6ed5cadf8acdb6d8002fe1b6..fcfa7de12ad57299a2dbb45e8eb5ac08f336dc70 100644 (file)
@@ -1046,6 +1046,13 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
        if (cleanup_whiteout)
                ovl_cleanup(old_upperdir->d_inode, newdentry);
 
+       if (overwrite && d_inode(new)) {
+               if (new_is_dir)
+                       clear_nlink(d_inode(new));
+               else
+                       drop_nlink(d_inode(new));
+       }
+
        ovl_dentry_version_inc(old->d_parent);
        ovl_dentry_version_inc(new->d_parent);