Skip to content

Commit 27f29db

Browse files
liu-song-6gregkh
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/[email protected] Fixes: f3f096c ("tracing: Provide trace events interface for uprobes") Fixes: 33ea4b2 ("perf/core: Implement the 'perf_uprobe' PMU") Cc: [email protected] Cc: Ingo Molnar <[email protected]> Cc: Howard McLauchlan <[email protected]> Cc: Josef Bacik <[email protected]> Cc: Srikar Dronamraju <[email protected]> Acked-by: Miklos Szeredi <[email protected]> Reported-by: Miklos Szeredi <[email protected]> Signed-off-by: Song Liu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d86aaca commit 27f29db

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
@@ -55,6 +55,7 @@ struct trace_uprobe {
5555
struct list_head list;
5656
struct trace_uprobe_filter filter;
5757
struct uprobe_consumer consumer;
58+
struct path path;
5859
struct inode *inode;
5960
char *filename;
6061
unsigned long offset;
@@ -287,7 +288,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
287288
for (i = 0; i < tu->tp.nr_args; i++)
288289
traceprobe_free_probe_arg(&tu->tp.args[i]);
289290

290-
iput(tu->inode);
291+
path_put(&tu->path);
291292
kfree(tu->tp.call.class->system);
292293
kfree(tu->tp.call.name);
293294
kfree(tu->filename);
@@ -361,15 +362,13 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
361362
static int create_trace_uprobe(int argc, char **argv)
362363
{
363364
struct trace_uprobe *tu;
364-
struct inode *inode;
365365
char *arg, *event, *group, *filename;
366366
char buf[MAX_EVENT_NAME_LEN];
367367
struct path path;
368368
unsigned long offset;
369369
bool is_delete, is_return;
370370
int i, ret;
371371

372-
inode = NULL;
373372
ret = 0;
374373
is_delete = false;
375374
is_return = false;
@@ -435,21 +434,16 @@ static int create_trace_uprobe(int argc, char **argv)
435434
}
436435
/* Find the last occurrence, in case the path contains ':' too. */
437436
arg = strrchr(argv[1], ':');
438-
if (!arg) {
439-
ret = -EINVAL;
440-
goto fail_address_parse;
441-
}
437+
if (!arg)
438+
return -EINVAL;
442439

443440
*arg++ = '\0';
444441
filename = argv[1];
445442
ret = kern_path(filename, LOOKUP_FOLLOW, &path);
446443
if (ret)
447-
goto fail_address_parse;
448-
449-
inode = igrab(d_inode(path.dentry));
450-
path_put(&path);
444+
return ret;
451445

452-
if (!inode || !S_ISREG(inode->i_mode)) {
446+
if (!d_is_reg(path.dentry)) {
453447
ret = -EINVAL;
454448
goto fail_address_parse;
455449
}
@@ -488,7 +482,7 @@ static int create_trace_uprobe(int argc, char **argv)
488482
goto fail_address_parse;
489483
}
490484
tu->offset = offset;
491-
tu->inode = inode;
485+
tu->path = path;
492486
tu->filename = kstrdup(filename, GFP_KERNEL);
493487

494488
if (!tu->filename) {
@@ -556,7 +550,7 @@ static int create_trace_uprobe(int argc, char **argv)
556550
return ret;
557551

558552
fail_address_parse:
559-
iput(inode);
553+
path_put(&path);
560554

561555
pr_info("Failed to parse address or file.\n");
562556

@@ -935,6 +929,7 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
935929
goto err_flags;
936930

937931
tu->consumer.filter = filter;
932+
tu->inode = d_real_inode(tu->path.dentry);
938933
ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
939934
if (ret)
940935
goto err_buffer;
@@ -980,6 +975,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)
980975
WARN_ON(!uprobe_filter_is_empty(&tu->filter));
981976

982977
uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
978+
tu->inode = NULL;
983979
tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
984980

985981
uprobe_buffer_disable();

0 commit comments

Comments
 (0)