Skip to content

Commit 2b19c1e

Browse files
liu-song-6bwhacks
authored andcommitted
tracing: Fix bad use of igrab in trace_uprobe.c
commit 0c92c7a upstream. As Miklos reported and suggested: This pattern repeats two times in trace_uprobe.c and in kernel/events/core.c as well: ret = kern_path(filename, LOOKUP_FOLLOW, &path); if (ret) goto fail_address_parse; inode = igrab(d_inode(path.dentry)); path_put(&path); And it's wrong. You can only hold a reference to the inode if you have an active ref to the superblock as well (which is normally through path.mnt) or holding s_umount. This way unmounting the containing filesystem while the tracepoint is active will give you the "VFS: Busy inodes after unmount..." message and a crash when the inode is finally put. Solution: store path instead of inode. This patch fixes two instances in trace_uprobe.c. struct path is added to struct trace_uprobe to keep the inode and containing mount point referenced. Link: http://lkml.kernel.org/r/20180423172135.4050588-1-songliubraving@fb.com Fixes: f3f096c ("tracing: Provide trace events interface for uprobes") Fixes: 33ea4b2 ("perf/core: Implement the 'perf_uprobe' PMU") Cc: Ingo Molnar <mingo@redhat.com> Cc: Howard McLauchlan <hmclauchlan@fb.com> Cc: Josef Bacik <jbacik@fb.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Acked-by: Miklos Szeredi <mszeredi@redhat.com> Reported-by: Miklos Szeredi <miklos@szeredi.hu> Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> [bwh: Backported to 3.16: - Open-code d_real_inode(), d_is_reg() - Drop changes in create_local_trace_uprobe()] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 3ebb4e8 commit 2b19c1e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

kernel/trace/trace_uprobe.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct trace_uprobe {
5353
struct list_head list;
5454
struct trace_uprobe_filter filter;
5555
struct uprobe_consumer consumer;
56+
struct path path;
5657
struct inode *inode;
5758
char *filename;
5859
unsigned long offset;
@@ -284,7 +285,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
284285
for (i = 0; i < tu->tp.nr_args; i++)
285286
traceprobe_free_probe_arg(&tu->tp.args[i]);
286287

287-
iput(tu->inode);
288+
path_put(&tu->path);
288289
kfree(tu->tp.call.class->system);
289290
kfree(tu->tp.call.name);
290291
kfree(tu->filename);
@@ -358,15 +359,13 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
358359
static int create_trace_uprobe(int argc, char **argv)
359360
{
360361
struct trace_uprobe *tu;
361-
struct inode *inode;
362362
char *arg, *event, *group, *filename;
363363
char buf[MAX_EVENT_NAME_LEN];
364364
struct path path;
365365
unsigned long offset;
366366
bool is_delete, is_return;
367367
int i, ret;
368368

369-
inode = NULL;
370369
ret = 0;
371370
is_delete = false;
372371
is_return = false;
@@ -432,21 +431,16 @@ static int create_trace_uprobe(int argc, char **argv)
432431
}
433432
/* Find the last occurrence, in case the path contains ':' too. */
434433
arg = strrchr(argv[1], ':');
435-
if (!arg) {
436-
ret = -EINVAL;
437-
goto fail_address_parse;
438-
}
434+
if (!arg)
435+
return -EINVAL;
439436

440437
*arg++ = '\0';
441438
filename = argv[1];
442439
ret = kern_path(filename, LOOKUP_FOLLOW, &path);
443440
if (ret)
444-
goto fail_address_parse;
445-
446-
inode = igrab(path.dentry->d_inode);
447-
path_put(&path);
441+
return ret;
448442

449-
if (!inode || !S_ISREG(inode->i_mode)) {
443+
if (!S_ISREG(path.dentry->d_inode->i_mode)) {
450444
ret = -EINVAL;
451445
goto fail_address_parse;
452446
}
@@ -485,7 +479,7 @@ static int create_trace_uprobe(int argc, char **argv)
485479
goto fail_address_parse;
486480
}
487481
tu->offset = offset;
488-
tu->inode = inode;
482+
tu->path = path;
489483
tu->filename = kstrdup(filename, GFP_KERNEL);
490484

491485
if (!tu->filename) {
@@ -552,7 +546,7 @@ static int create_trace_uprobe(int argc, char **argv)
552546
return ret;
553547

554548
fail_address_parse:
555-
iput(inode);
549+
path_put(&path);
556550

557551
pr_info("Failed to parse address or file.\n");
558552

@@ -919,6 +913,7 @@ probe_event_enable(struct trace_uprobe *tu, struct ftrace_event_file *file,
919913
goto err_flags;
920914

921915
tu->consumer.filter = filter;
916+
tu->inode = tu->path.dentry->d_inode;
922917
ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
923918
if (ret)
924919
goto err_buffer;
@@ -964,6 +959,7 @@ probe_event_disable(struct trace_uprobe *tu, struct ftrace_event_file *file)
964959
WARN_ON(!uprobe_filter_is_empty(&tu->filter));
965960

966961
uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
962+
tu->inode = NULL;
967963
tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
968964

969965
uprobe_buffer_disable();

0 commit comments

Comments
 (0)