From: Alexey Dobriyan <adobriyan@gmail.com>
To: David Madore <david+ml@madore.org>
Cc: linux-kernel@vger.kernel.org, aneesh.kumar@linux.vnet.ibm.com,
viro@zeniv.linux.org.uk
Subject: Re: since when does linkat() on deleted /proc/$PID/fd/$num return ENOENT ?
Date: Sat, 31 Mar 2012 09:53:05 +0300 [thread overview]
Message-ID: <20120331065305.GA3398@p183.telecom.by> (raw)
In-Reply-To: <20120330102121.GA5999@aldebaran.gro-tsen.net>
On Fri, Mar 30, 2012 at 12:21:21PM +0200, David Madore wrote:
> 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?
It was explicitly prohibited since 2.6.39:
commit aae8a97d3ec30788790d1720b71d76fd8eb44b73
Author: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
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
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
diff --git a/fs/namei.c b/fs/namei.c
index 83e92ba..33be51a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -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);
next prev parent reply other threads:[~2012-03-31 6:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-30 10:21 since when does linkat() on deleted /proc/$PID/fd/$num return ENOENT ? David Madore
2012-03-31 6:53 ` Alexey Dobriyan [this message]
2012-03-31 11:06 ` David Madore
2012-03-31 14:45 ` Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120331065305.GA3398@p183.telecom.by \
--to=adobriyan@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=david+ml@madore.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox