ftrace: Get a reference counter for the trace_array on filter files
The ftrace set_ftrace_filter and set_ftrace_notrace files are specific for
an instance now. They need to take a reference to the instance otherwise
there could be a race between accessing the files and deleting the instance.
It wasn't until the :mod: caching where these file operations started
referencing the trace_array directly.
Cc: stable@vger.kernel.org
Fixes: 673feb9d76
("ftrace: Add :mod: caching infrastructure to trace_array")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
This commit is contained in:
parent
3ed270b129
commit
9ef16693af
|
@ -3540,21 +3540,22 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
|
||||||
struct ftrace_hash *hash;
|
struct ftrace_hash *hash;
|
||||||
struct list_head *mod_head;
|
struct list_head *mod_head;
|
||||||
struct trace_array *tr = ops->private;
|
struct trace_array *tr = ops->private;
|
||||||
int ret = 0;
|
int ret = -ENOMEM;
|
||||||
|
|
||||||
ftrace_ops_init(ops);
|
ftrace_ops_init(ops);
|
||||||
|
|
||||||
if (unlikely(ftrace_disabled))
|
if (unlikely(ftrace_disabled))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
|
if (tr && trace_array_get(tr) < 0)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
|
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
|
||||||
if (!iter)
|
if (!iter)
|
||||||
return -ENOMEM;
|
goto out;
|
||||||
|
|
||||||
if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) {
|
if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX))
|
||||||
kfree(iter);
|
goto out;
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
iter->ops = ops;
|
iter->ops = ops;
|
||||||
iter->flags = flag;
|
iter->flags = flag;
|
||||||
|
@ -3584,13 +3585,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
|
||||||
|
|
||||||
if (!iter->hash) {
|
if (!iter->hash) {
|
||||||
trace_parser_put(&iter->parser);
|
trace_parser_put(&iter->parser);
|
||||||
kfree(iter);
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
iter->hash = hash;
|
iter->hash = hash;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
if (file->f_mode & FMODE_READ) {
|
if (file->f_mode & FMODE_READ) {
|
||||||
iter->pg = ftrace_pages_start;
|
iter->pg = ftrace_pages_start;
|
||||||
|
|
||||||
|
@ -3602,7 +3603,6 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
|
||||||
/* Failed */
|
/* Failed */
|
||||||
free_ftrace_hash(iter->hash);
|
free_ftrace_hash(iter->hash);
|
||||||
trace_parser_put(&iter->parser);
|
trace_parser_put(&iter->parser);
|
||||||
kfree(iter);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
file->private_data = iter;
|
file->private_data = iter;
|
||||||
|
@ -3610,6 +3610,13 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&ops->func_hash->regex_lock);
|
mutex_unlock(&ops->func_hash->regex_lock);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (ret) {
|
||||||
|
kfree(iter);
|
||||||
|
if (tr)
|
||||||
|
trace_array_put(tr);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5037,6 +5044,8 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
|
||||||
|
|
||||||
mutex_unlock(&iter->ops->func_hash->regex_lock);
|
mutex_unlock(&iter->ops->func_hash->regex_lock);
|
||||||
free_ftrace_hash(iter->hash);
|
free_ftrace_hash(iter->hash);
|
||||||
|
if (iter->tr)
|
||||||
|
trace_array_put(iter->tr);
|
||||||
kfree(iter);
|
kfree(iter);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue