aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-06-11 00:34:36 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-06-29 04:57:11 -0400
commitf4e0c30c191f87851c4a53454abb55ee276f4a7e (patch)
tree8bdb4f81dea303f93f1d646034653c8af3fba323
parent60545d0d4610b02e55f65d141c95b18ccf855b6e (diff)
allow the temp files created by open() to be linked to
O_TMPFILE | O_CREAT => linkat() with AT_SYMLINK_FOLLOW and /proc/self/fd/<n> as oldpath (i.e. flink()) will create a link O_TMPFILE | O_CREAT | O_EXCL => ENOENT on attempt to link those guys Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/inode.c4
-rw-r--r--fs/namei.c16
-rw-r--r--include/linux/fs.h1
3 files changed, 18 insertions, 3 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 00d5fc3b86e1..d6dfb09c8280 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -333,8 +333,10 @@ EXPORT_SYMBOL(set_nlink);
333 */ 333 */
334void inc_nlink(struct inode *inode) 334void inc_nlink(struct inode *inode)
335{ 335{
336 if (WARN_ON(inode->i_nlink == 0)) 336 if (unlikely(inode->i_nlink == 0)) {
337 WARN_ON(!(inode->i_state & I_LINKABLE));
337 atomic_long_dec(&inode->i_sb->s_remove_count); 338 atomic_long_dec(&inode->i_sb->s_remove_count);
339 }
338 340
339 inode->__i_nlink++; 341 inode->__i_nlink++;
340} 342}
diff --git a/fs/namei.c b/fs/namei.c
index 778e253e3d48..66998b06d822 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2948,8 +2948,14 @@ static int do_tmpfile(int dfd, struct filename *pathname,
2948 if (error) 2948 if (error)
2949 goto out2; 2949 goto out2;
2950 error = open_check_o_direct(file); 2950 error = open_check_o_direct(file);
2951 if (error) 2951 if (error) {
2952 fput(file); 2952 fput(file);
2953 } else if (!(op->open_flag & O_EXCL)) {
2954 struct inode *inode = file_inode(file);
2955 spin_lock(&inode->i_lock);
2956 inode->i_state |= I_LINKABLE;
2957 spin_unlock(&inode->i_lock);
2958 }
2953out2: 2959out2:
2954 mnt_drop_write(nd->path.mnt); 2960 mnt_drop_write(nd->path.mnt);
2955out: 2961out:
@@ -3628,12 +3634,18 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
3628 3634
3629 mutex_lock(&inode->i_mutex); 3635 mutex_lock(&inode->i_mutex);
3630 /* Make sure we don't allow creating hardlink to an unlinked file */ 3636 /* Make sure we don't allow creating hardlink to an unlinked file */
3631 if (inode->i_nlink == 0) 3637 if (inode->i_nlink == 0 && !(inode->i_state & I_LINKABLE))
3632 error = -ENOENT; 3638 error = -ENOENT;
3633 else if (max_links && inode->i_nlink >= max_links) 3639 else if (max_links && inode->i_nlink >= max_links)
3634 error = -EMLINK; 3640 error = -EMLINK;
3635 else 3641 else
3636 error = dir->i_op->link(old_dentry, dir, new_dentry); 3642 error = dir->i_op->link(old_dentry, dir, new_dentry);
3643
3644 if (!error && (inode->i_state & I_LINKABLE)) {
3645 spin_lock(&inode->i_lock);
3646 inode->i_state &= ~I_LINKABLE;
3647 spin_unlock(&inode->i_lock);
3648 }
3637 mutex_unlock(&inode->i_mutex); 3649 mutex_unlock(&inode->i_mutex);
3638 if (!error) 3650 if (!error)
3639 fsnotify_link(dir, inode, new_dentry); 3651 fsnotify_link(dir, inode, new_dentry);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index dd6615f0fd13..ab11c44b0697 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1744,6 +1744,7 @@ struct super_operations {
1744#define I_REFERENCED (1 << 8) 1744#define I_REFERENCED (1 << 8)
1745#define __I_DIO_WAKEUP 9 1745#define __I_DIO_WAKEUP 9
1746#define I_DIO_WAKEUP (1 << I_DIO_WAKEUP) 1746#define I_DIO_WAKEUP (1 << I_DIO_WAKEUP)
1747#define I_LINKABLE (1 << 10)
1747 1748
1748#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) 1749#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
1749 1750