Unverified Commit 350278a0 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!11229 tracing: Have format file honor EVENT_FILE_FL_FREED

parents b5ee721d 5a4b232f
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -1563,6 +1563,29 @@ static inline void *event_file_data(struct file *filp)
extern struct mutex event_mutex;
extern struct list_head ftrace_events;

/*
 * When the trace_event_file is the filp->i_private pointer,
 * it must be taken under the event_mutex lock, and then checked
 * if the EVENT_FILE_FL_FREED flag is set. If it is, then the
 * data pointed to by the trace_event_file can not be trusted.
 *
 * Use the event_file_file() to access the trace_event_file from
 * the filp the first time under the event_mutex and check for
 * NULL. If it is needed to be retrieved again and the event_mutex
 * is still held, then the event_file_data() can be used and it
 * is guaranteed to be valid.
 */
static inline struct trace_event_file *event_file_file(struct file *filp)
{
	struct trace_event_file *file;

	lockdep_assert_held(&event_mutex);
	file = READ_ONCE(file_inode(filp)->i_private);
	if (!file || file->flags & EVENT_FILE_FL_FREED)
		return NULL;
	return file;
}

extern const struct file_operations event_trigger_fops;
extern const struct file_operations event_hist_fops;
extern const struct file_operations event_hist_debug_fops;
+20 −13
Original line number Diff line number Diff line
@@ -1386,12 +1386,12 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
	char buf[4] = "0";

	mutex_lock(&event_mutex);
	file = event_file_data(filp);
	file = event_file_file(filp);
	if (likely(file))
		flags = file->flags;
	mutex_unlock(&event_mutex);

	if (!file || flags & EVENT_FILE_FL_FREED)
	if (!file)
		return -ENODEV;

	if (flags & EVENT_FILE_FL_ENABLED &&
@@ -1428,8 +1428,8 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
	case 1:
		ret = -ENODEV;
		mutex_lock(&event_mutex);
		file = event_file_data(filp);
		if (likely(file && !(file->flags & EVENT_FILE_FL_FREED)))
		file = event_file_file(filp);
		if (likely(file))
			ret = ftrace_event_enable_disable(file, val);
		mutex_unlock(&event_mutex);
		break;
@@ -1538,7 +1538,8 @@ enum {

static void *f_next(struct seq_file *m, void *v, loff_t *pos)
{
	struct trace_event_call *call = event_file_data(m->private);
	struct trace_event_file *file = event_file_data(m->private);
	struct trace_event_call *call = file->event_call;
	struct list_head *common_head = &ftrace_common_fields;
	struct list_head *head = trace_get_fields(call);
	struct list_head *node = v;
@@ -1570,7 +1571,8 @@ static void *f_next(struct seq_file *m, void *v, loff_t *pos)

static int f_show(struct seq_file *m, void *v)
{
	struct trace_event_call *call = event_file_data(m->private);
	struct trace_event_file *file = event_file_data(m->private);
	struct trace_event_call *call = file->event_call;
	struct ftrace_event_field *field;
	const char *array_descriptor;

@@ -1625,12 +1627,14 @@ static int f_show(struct seq_file *m, void *v)

static void *f_start(struct seq_file *m, loff_t *pos)
{
	struct trace_event_file *file;
	void *p = (void *)FORMAT_HEADER;
	loff_t l = 0;

	/* ->stop() is called even if ->start() fails */
	mutex_lock(&event_mutex);
	if (!event_file_data(m->private))
	file = event_file_file(m->private);
	if (!file)
		return ERR_PTR(-ENODEV);

	while (l < *pos && p)
@@ -1704,8 +1708,8 @@ event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
	trace_seq_init(s);

	mutex_lock(&event_mutex);
	file = event_file_data(filp);
	if (file && !(file->flags & EVENT_FILE_FL_FREED))
	file = event_file_file(filp);
	if (file)
		print_event_filter(file, s);
	mutex_unlock(&event_mutex);

@@ -1734,9 +1738,13 @@ event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
		return PTR_ERR(buf);

	mutex_lock(&event_mutex);
	file = event_file_data(filp);
	if (file)
	file = event_file_file(filp);
	if (file) {
		if (file->flags & EVENT_FILE_FL_FREED)
			err = -ENODEV;
		else
			err = apply_event_filter(file, buf);
	}
	mutex_unlock(&event_mutex);

	kfree(buf);
@@ -2451,7 +2459,6 @@ static int event_callback(const char *name, umode_t *mode, void **data,
	if (strcmp(name, "format") == 0) {
		*mode = TRACE_MODE_READ;
		*fops = &ftrace_event_format_fops;
		*data = call;
		return 1;
	}

+2 −2
Original line number Diff line number Diff line
@@ -5609,7 +5609,7 @@ static int hist_show(struct seq_file *m, void *v)

	mutex_lock(&event_mutex);

	event_file = event_file_data(m->private);
	event_file = event_file_file(m->private);
	if (unlikely(!event_file)) {
		ret = -ENODEV;
		goto out_unlock;
@@ -5888,7 +5888,7 @@ static int hist_debug_show(struct seq_file *m, void *v)

	mutex_lock(&event_mutex);

	event_file = event_file_data(m->private);
	event_file = event_file_file(m->private);
	if (unlikely(!event_file)) {
		ret = -ENODEV;
		goto out_unlock;
+1 −1
Original line number Diff line number Diff line
@@ -299,7 +299,7 @@ event_inject_write(struct file *filp, const char __user *ubuf, size_t cnt,
	strim(buf);

	mutex_lock(&event_mutex);
	file = event_file_data(filp);
	file = event_file_file(filp);
	if (file) {
		call = file->event_call;
		size = parse_entry(buf, call, &entry);
+3 −3
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ static void *trigger_start(struct seq_file *m, loff_t *pos)

	/* ->stop() is called even if ->start() fails */
	mutex_lock(&event_mutex);
	event_file = event_file_data(m->private);
	event_file = event_file_file(m->private);
	if (unlikely(!event_file))
		return ERR_PTR(-ENODEV);

@@ -213,7 +213,7 @@ static int event_trigger_regex_open(struct inode *inode, struct file *file)

	mutex_lock(&event_mutex);

	if (unlikely(!event_file_data(file))) {
	if (unlikely(!event_file_file(file))) {
		mutex_unlock(&event_mutex);
		return -ENODEV;
	}
@@ -293,7 +293,7 @@ static ssize_t event_trigger_regex_write(struct file *file,
	strim(buf);

	mutex_lock(&event_mutex);
	event_file = event_file_data(file);
	event_file = event_file_file(file);
	if (unlikely(!event_file)) {
		mutex_unlock(&event_mutex);
		kfree(buf);