1 From 7e0e953bb0cf649f93277ac8fb67ecbb7f7b04a9 Mon Sep 17 00:00:00 2001
2 From: Al Viro <viro@zeniv.linux.org.uk>
3 Date: Sat, 21 Feb 2015 22:16:11 -0500
4 Subject: procfs: fix race between symlink removals and traversals
6 From: Al Viro <viro@zeniv.linux.org.uk>
8 commit 7e0e953bb0cf649f93277ac8fb67ecbb7f7b04a9 upstream.
10 use_pde()/unuse_pde() in ->follow_link()/->put_link() resp.
12 Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 fs/proc/generic.c | 12 ------------
17 fs/proc/inode.c | 21 +++++++++++++++++++++
18 fs/proc/internal.h | 1 +
19 3 files changed, 22 insertions(+), 12 deletions(-)
21 --- a/fs/proc/generic.c
22 +++ b/fs/proc/generic.c
24 #include <linux/mount.h>
25 #include <linux/init.h>
26 #include <linux/idr.h>
27 -#include <linux/namei.h>
28 #include <linux/bitops.h>
29 #include <linux/spinlock.h>
30 #include <linux/completion.h>
31 @@ -162,17 +161,6 @@ void proc_free_inum(unsigned int inum)
32 spin_unlock_irqrestore(&proc_inum_lock, flags);
35 -static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
37 - nd_set_link(nd, __PDE_DATA(dentry->d_inode));
41 -static const struct inode_operations proc_link_inode_operations = {
42 - .readlink = generic_readlink,
43 - .follow_link = proc_follow_link,
47 * Don't create negative dentries here, return -ENOENT by hand
52 #include <linux/slab.h>
53 #include <linux/mount.h>
54 #include <linux/magic.h>
55 +#include <linux/namei.h>
57 #include <asm/uaccess.h>
59 @@ -401,6 +402,26 @@ static const struct file_operations proc
63 +static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
65 + struct proc_dir_entry *pde = PDE(dentry->d_inode);
66 + if (unlikely(!use_pde(pde)))
67 + return ERR_PTR(-EINVAL);
68 + nd_set_link(nd, pde->data);
72 +static void proc_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
77 +const struct inode_operations proc_link_inode_operations = {
78 + .readlink = generic_readlink,
79 + .follow_link = proc_follow_link,
80 + .put_link = proc_put_link,
83 struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
85 struct inode *inode = new_inode_pseudo(sb);
86 --- a/fs/proc/internal.h
87 +++ b/fs/proc/internal.h
88 @@ -202,6 +202,7 @@ struct pde_opener {
92 +extern const struct inode_operations proc_link_inode_operations;
94 extern const struct inode_operations proc_pid_link_inode_operations;