]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.40/tracing-fix-bad-use-of-igrab-in-trace_uprobe.c.patch
Linux 4.14.95
[thirdparty/kernel/stable-queue.git] / releases / 4.14.40 / tracing-fix-bad-use-of-igrab-in-trace_uprobe.c.patch
1 From 0c92c7a3c5d416f47b32c5f20a611dfeca5d5f2e Mon Sep 17 00:00:00 2001
2 From: Song Liu <songliubraving@fb.com>
3 Date: Mon, 23 Apr 2018 10:21:34 -0700
4 Subject: tracing: Fix bad use of igrab in trace_uprobe.c
5
6 From: Song Liu <songliubraving@fb.com>
7
8 commit 0c92c7a3c5d416f47b32c5f20a611dfeca5d5f2e upstream.
9
10 As Miklos reported and suggested:
11
12 This pattern repeats two times in trace_uprobe.c and in
13 kernel/events/core.c as well:
14
15 ret = kern_path(filename, LOOKUP_FOLLOW, &path);
16 if (ret)
17 goto fail_address_parse;
18
19 inode = igrab(d_inode(path.dentry));
20 path_put(&path);
21
22 And it's wrong. You can only hold a reference to the inode if you
23 have an active ref to the superblock as well (which is normally
24 through path.mnt) or holding s_umount.
25
26 This way unmounting the containing filesystem while the tracepoint is
27 active will give you the "VFS: Busy inodes after unmount..." message
28 and a crash when the inode is finally put.
29
30 Solution: store path instead of inode.
31
32 This patch fixes two instances in trace_uprobe.c. struct path is added to
33 struct trace_uprobe to keep the inode and containing mount point
34 referenced.
35
36 Link: http://lkml.kernel.org/r/20180423172135.4050588-1-songliubraving@fb.com
37
38 Fixes: f3f096cfedf8 ("tracing: Provide trace events interface for uprobes")
39 Fixes: 33ea4b24277b ("perf/core: Implement the 'perf_uprobe' PMU")
40 Cc: stable@vger.kernel.org
41 Cc: Ingo Molnar <mingo@redhat.com>
42 Cc: Howard McLauchlan <hmclauchlan@fb.com>
43 Cc: Josef Bacik <jbacik@fb.com>
44 Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
45 Acked-by: Miklos Szeredi <mszeredi@redhat.com>
46 Reported-by: Miklos Szeredi <miklos@szeredi.hu>
47 Signed-off-by: Song Liu <songliubraving@fb.com>
48 Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
49 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
50
51 ---
52 kernel/trace/trace_uprobe.c | 24 ++++++++++--------------
53 1 file changed, 10 insertions(+), 14 deletions(-)
54
55 --- a/kernel/trace/trace_uprobe.c
56 +++ b/kernel/trace/trace_uprobe.c
57 @@ -55,6 +55,7 @@ struct trace_uprobe {
58 struct list_head list;
59 struct trace_uprobe_filter filter;
60 struct uprobe_consumer consumer;
61 + struct path path;
62 struct inode *inode;
63 char *filename;
64 unsigned long offset;
65 @@ -287,7 +288,7 @@ static void free_trace_uprobe(struct tra
66 for (i = 0; i < tu->tp.nr_args; i++)
67 traceprobe_free_probe_arg(&tu->tp.args[i]);
68
69 - iput(tu->inode);
70 + path_put(&tu->path);
71 kfree(tu->tp.call.class->system);
72 kfree(tu->tp.call.name);
73 kfree(tu->filename);
74 @@ -361,7 +362,6 @@ end:
75 static int create_trace_uprobe(int argc, char **argv)
76 {
77 struct trace_uprobe *tu;
78 - struct inode *inode;
79 char *arg, *event, *group, *filename;
80 char buf[MAX_EVENT_NAME_LEN];
81 struct path path;
82 @@ -369,7 +369,6 @@ static int create_trace_uprobe(int argc,
83 bool is_delete, is_return;
84 int i, ret;
85
86 - inode = NULL;
87 ret = 0;
88 is_delete = false;
89 is_return = false;
90 @@ -435,21 +434,16 @@ static int create_trace_uprobe(int argc,
91 }
92 /* Find the last occurrence, in case the path contains ':' too. */
93 arg = strrchr(argv[1], ':');
94 - if (!arg) {
95 - ret = -EINVAL;
96 - goto fail_address_parse;
97 - }
98 + if (!arg)
99 + return -EINVAL;
100
101 *arg++ = '\0';
102 filename = argv[1];
103 ret = kern_path(filename, LOOKUP_FOLLOW, &path);
104 if (ret)
105 - goto fail_address_parse;
106 -
107 - inode = igrab(d_inode(path.dentry));
108 - path_put(&path);
109 + return ret;
110
111 - if (!inode || !S_ISREG(inode->i_mode)) {
112 + if (!d_is_reg(path.dentry)) {
113 ret = -EINVAL;
114 goto fail_address_parse;
115 }
116 @@ -488,7 +482,7 @@ static int create_trace_uprobe(int argc,
117 goto fail_address_parse;
118 }
119 tu->offset = offset;
120 - tu->inode = inode;
121 + tu->path = path;
122 tu->filename = kstrdup(filename, GFP_KERNEL);
123
124 if (!tu->filename) {
125 @@ -556,7 +550,7 @@ error:
126 return ret;
127
128 fail_address_parse:
129 - iput(inode);
130 + path_put(&path);
131
132 pr_info("Failed to parse address or file.\n");
133
134 @@ -935,6 +929,7 @@ probe_event_enable(struct trace_uprobe *
135 goto err_flags;
136
137 tu->consumer.filter = filter;
138 + tu->inode = d_real_inode(tu->path.dentry);
139 ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
140 if (ret)
141 goto err_buffer;
142 @@ -980,6 +975,7 @@ probe_event_disable(struct trace_uprobe
143 WARN_ON(!uprobe_filter_is_empty(&tu->filter));
144
145 uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
146 + tu->inode = NULL;
147 tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
148
149 uprobe_buffer_disable();