since when does linkat() on deleted /proc/$PID/fd/$num return ENOENT ?
It used to be the case (last time I checked was around late 2008 or early 2009) that deleted entries from /proc/$PID/fd/ could be linked back to the filesystem by using linkat(,,,,AT_SYMLINK_FOLLOW).
Now this just returns ENOENT.
I'd like to understand when, how and why this change took place. What commit introduced it and was it a deliberate move (e.g., because the feature was a security issue of itself, or came into conflict with something else) or was it accidental? Does it depend on the /proc filesystem itself or on the target filesystem where the deleted file used to reside?
(There's a Reddit thread, <URL:
http://www.reddit.com/r/programming/comments/7yx6f/how_to_undelete_any_open_deleted_file_in_linux/
Quoted 1 line
, where some people are reporting ENOENT on 2.6.27 or perhaps even
2.6.26, which helps but a bound on the change.)
(See also this thread: <URL:
http://comments.gmane.org/gmane.linux.kernel/1224071
Quoted 1 line
, where the question is not answered, however.)
Signature · 2 lines
David A. Madore ( http://www.madore.org/~david/ )
Quoted 10 lines · David Madore
It used to be the case (last time I checked was around late 2008 or early 2009) that deleted entries from
/proc/$PID/fd/could be linked back to the filesystem by usinglinkat(,,,,AT_SYMLINK_FOLLOW).Now this just returns ENOENT.
I'd like to understand when, how and why this change took place. What commit introduced it and was it a deliberate move (e.g., because the feature was a security issue of itself, or came into conflict with something else) or was it accidental?
It was explicitly prohibited since 2.6.39:
commit aae8a97d3ec30788790d1720b71d76fd8eb44b73
Author: Aneesh Kumar K.V <[email protected]> Date: Sat Jan 29 18:43:27 2011 +0530
fs: Don't allow to create hardlink for deleted file
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
fs/namei.c +5 -1
@@ -2906,7 +2906,11 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dereturn 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);
Quoted 7 lines · Alexey Dobriyan
It was explicitly prohibited since 2.6.39:
commit
aae8a97d3ec30788790d1720b71d76fd8eb44b73Author: Aneesh Kumar K.V <[email protected]> Date: Sat Jan 29 18:43:27 2011 +0530fs: Don't allow to create hardlink for deleted file
<snip>
Thanks for digging this for me!
Signature · 2 lines
David A. Madore ( http://www.madore.org/~david/ )
Quoted 11 lines · David Madore
Quoted 7 lines · Alexey Dobriyan
It was explicitly prohibited since 2.6.39:
commit
aae8a97d3ec30788790d1720b71d76fd8eb44b73Author: Aneesh Kumar K.V <[email protected]> Date: Sat Jan 29 18:43:27 2011 +0530fs: Don't allow to create hardlink for deleted file
<snip>
Thanks for digging this for me!
Well, the question if this counts as userspace-visible change.