Skip to content

Commit

Permalink
fs: Don't allow to create hardlink for deleted file
Browse files Browse the repository at this point in the history
Add inode->i_nlink == 0 check in VFS. Some of the file systems
do this internally. A followup patch will remove those instance.
This is needed to ensure that with link by handle we don't allow
to create hardlink of an unlinked file. The check also prevent a race
between unlink and link

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Aneesh Kumar K.V authored and Al Viro committed Mar 15, 2011
1 parent becfd1f commit aae8a97
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,11 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
return error;

mutex_lock(&inode->i_mutex);
error = dir->i_op->link(old_dentry, dir, new_dentry);
/* Make sure we don't allow creating hardlink to an unlinked file */
if (inode->i_nlink == 0)
error = -ENOENT;
else
error = dir->i_op->link(old_dentry, dir, new_dentry);
mutex_unlock(&inode->i_mutex);
if (!error)
fsnotify_link(dir, inode, new_dentry);
Expand Down

0 comments on commit aae8a97

Please sign in to comment.