]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.14.36/procfs-fix-race-between-symlink-removals-and-traversals.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.14.36 / procfs-fix-race-between-symlink-removals-and-traversals.patch
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
5
6 From: Al Viro <viro@zeniv.linux.org.uk>
7
8 commit 7e0e953bb0cf649f93277ac8fb67ecbb7f7b04a9 upstream.
9
10 use_pde()/unuse_pde() in ->follow_link()/->put_link() resp.
11
12 Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14
15 ---
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(-)
20
21 --- a/fs/proc/generic.c
22 +++ b/fs/proc/generic.c
23 @@ -19,7 +19,6 @@
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);
33 }
34
35 -static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
36 -{
37 - nd_set_link(nd, __PDE_DATA(dentry->d_inode));
38 - return NULL;
39 -}
40 -
41 -static const struct inode_operations proc_link_inode_operations = {
42 - .readlink = generic_readlink,
43 - .follow_link = proc_follow_link,
44 -};
45 -
46 /*
47 * Don't create negative dentries here, return -ENOENT by hand
48 * instead.
49 --- a/fs/proc/inode.c
50 +++ b/fs/proc/inode.c
51 @@ -23,6 +23,7 @@
52 #include <linux/slab.h>
53 #include <linux/mount.h>
54 #include <linux/magic.h>
55 +#include <linux/namei.h>
56
57 #include <asm/uaccess.h>
58
59 @@ -401,6 +402,26 @@ static const struct file_operations proc
60 };
61 #endif
62
63 +static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
64 +{
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);
69 + return pde;
70 +}
71 +
72 +static void proc_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
73 +{
74 + unuse_pde(p);
75 +}
76 +
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,
81 +};
82 +
83 struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
84 {
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 {
89 int closing;
90 struct completion *c;
91 };
92 +extern const struct inode_operations proc_link_inode_operations;
93
94 extern const struct inode_operations proc_pid_link_inode_operations;
95