Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27f29dbc authored by Song Liu's avatar Song Liu Committed by Greg Kroah-Hartman
Browse files

tracing: Fix bad use of igrab in trace_uprobe.c

commit 0c92c7a3c5d416f47b32c5f20a611dfeca5d5f2e 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: f3f096cf ("tracing: Provide trace events interface for uprobes")
Fixes: 33ea4b24277b ("perf/core: Implement the 'perf_uprobe' PMU")
Cc: stable@vger.kernel.org
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: default avatarMiklos Szeredi <mszeredi@redhat.com>
Reported-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d86aaca9
Loading
Loading
Loading
Loading
+10 −14
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ struct trace_uprobe {
	struct list_head		list;
	struct list_head		list;
	struct trace_uprobe_filter	filter;
	struct trace_uprobe_filter	filter;
	struct uprobe_consumer		consumer;
	struct uprobe_consumer		consumer;
	struct path			path;
	struct inode			*inode;
	struct inode			*inode;
	char				*filename;
	char				*filename;
	unsigned long			offset;
	unsigned long			offset;
@@ -287,7 +288,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
	for (i = 0; i < tu->tp.nr_args; i++)
	for (i = 0; i < tu->tp.nr_args; i++)
		traceprobe_free_probe_arg(&tu->tp.args[i]);
		traceprobe_free_probe_arg(&tu->tp.args[i]);


	iput(tu->inode);
	path_put(&tu->path);
	kfree(tu->tp.call.class->system);
	kfree(tu->tp.call.class->system);
	kfree(tu->tp.call.name);
	kfree(tu->tp.call.name);
	kfree(tu->filename);
	kfree(tu->filename);
@@ -361,7 +362,6 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
static int create_trace_uprobe(int argc, char **argv)
static int create_trace_uprobe(int argc, char **argv)
{
{
	struct trace_uprobe *tu;
	struct trace_uprobe *tu;
	struct inode *inode;
	char *arg, *event, *group, *filename;
	char *arg, *event, *group, *filename;
	char buf[MAX_EVENT_NAME_LEN];
	char buf[MAX_EVENT_NAME_LEN];
	struct path path;
	struct path path;
@@ -369,7 +369,6 @@ static int create_trace_uprobe(int argc, char **argv)
	bool is_delete, is_return;
	bool is_delete, is_return;
	int i, ret;
	int i, ret;


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


	*arg++ = '\0';
	*arg++ = '\0';
	filename = argv[1];
	filename = argv[1];
	ret = kern_path(filename, LOOKUP_FOLLOW, &path);
	ret = kern_path(filename, LOOKUP_FOLLOW, &path);
	if (ret)
	if (ret)
		goto fail_address_parse;
		return ret;

	inode = igrab(d_inode(path.dentry));
	path_put(&path);


	if (!inode || !S_ISREG(inode->i_mode)) {
	if (!d_is_reg(path.dentry)) {
		ret = -EINVAL;
		ret = -EINVAL;
		goto fail_address_parse;
		goto fail_address_parse;
	}
	}
@@ -488,7 +482,7 @@ static int create_trace_uprobe(int argc, char **argv)
		goto fail_address_parse;
		goto fail_address_parse;
	}
	}
	tu->offset = offset;
	tu->offset = offset;
	tu->inode = inode;
	tu->path = path;
	tu->filename = kstrdup(filename, GFP_KERNEL);
	tu->filename = kstrdup(filename, GFP_KERNEL);


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


fail_address_parse:
fail_address_parse:
	iput(inode);
	path_put(&path);


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


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


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


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


	uprobe_buffer_disable();
	uprobe_buffer_disable();