Commit d8e83d26 authored by Steven Rostedt's avatar Steven Rostedt

tracing: add protection around open use of current_tracer

Impact: fix to possible race conditions

There's some uses of current_tracer that is not protected by the
trace_types_lock. There is a small chance that a sysadmin changes
the tracer while the current_tracer is being referenced.

If the race is hit, it is unlikely to cause any harm since the
tracers are constant and are not freed. But some strang side
effects may occur.
Signed-off-by: default avatarSteven Rostedt <srostedt@redhat.com>
parent 577b785f
...@@ -2024,12 +2024,12 @@ static ssize_t ...@@ -2024,12 +2024,12 @@ static ssize_t
tracing_trace_options_read(struct file *filp, char __user *ubuf, tracing_trace_options_read(struct file *filp, char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
int i; struct tracer_opt *trace_opts;
u32 tracer_flags;
int len = 0;
char *buf; char *buf;
int r = 0; int r = 0;
int len = 0; int i;
u32 tracer_flags = current_trace->flags->val;
struct tracer_opt *trace_opts = current_trace->flags->opts;
/* calculate max size */ /* calculate max size */
...@@ -2038,6 +2038,10 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, ...@@ -2038,6 +2038,10 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
len += 3; /* "no" and space */ len += 3; /* "no" and space */
} }
mutex_lock(&trace_types_lock);
tracer_flags = current_trace->flags->val;
trace_opts = current_trace->flags->opts;
/* /*
* Increase the size with names of options specific * Increase the size with names of options specific
* of the current tracer. * of the current tracer.
...@@ -2049,8 +2053,10 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, ...@@ -2049,8 +2053,10 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
/* +2 for \n and \0 */ /* +2 for \n and \0 */
buf = kmalloc(len + 2, GFP_KERNEL); buf = kmalloc(len + 2, GFP_KERNEL);
if (!buf) if (!buf) {
mutex_unlock(&trace_types_lock);
return -ENOMEM; return -ENOMEM;
}
for (i = 0; trace_options[i]; i++) { for (i = 0; trace_options[i]; i++) {
if (trace_flags & (1 << i)) if (trace_flags & (1 << i))
...@@ -2067,6 +2073,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, ...@@ -2067,6 +2073,7 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
r += sprintf(buf + r, "no%s ", r += sprintf(buf + r, "no%s ",
trace_opts[i].name); trace_opts[i].name);
} }
mutex_unlock(&trace_types_lock);
r += sprintf(buf + r, "\n"); r += sprintf(buf + r, "\n");
WARN_ON(r >= len + 2); WARN_ON(r >= len + 2);
...@@ -2074,7 +2081,6 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf, ...@@ -2074,7 +2081,6 @@ tracing_trace_options_read(struct file *filp, char __user *ubuf,
r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
kfree(buf); kfree(buf);
return r; return r;
} }
...@@ -2149,7 +2155,9 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf, ...@@ -2149,7 +2155,9 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
/* If no option could be set, test the specific tracer options */ /* If no option could be set, test the specific tracer options */
if (!trace_options[i]) { if (!trace_options[i]) {
mutex_lock(&trace_types_lock);
ret = set_tracer_option(current_trace, cmp, neg); ret = set_tracer_option(current_trace, cmp, neg);
mutex_unlock(&trace_types_lock);
if (ret) if (ret)
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment