Skip to content

Commit

Permalink
tracing: Protect tracer flags with trace_types_lock
Browse files Browse the repository at this point in the history
commit 69d34da upstream.

Seems that the tracer flags have never been protected from
synchronous writes. Luckily, admins don't usually modify the
tracing flags via two different tasks. But if scripts were to
be used to modify them, then they could get corrupted.

Move the trace_types_lock that protects against tracers changing
to also protect the flags being set.

[Backported for 3.4, 3.0-stable. Moved return to after unlock.]

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Lingzhu Xiang <lxiang@redhat.com>
Reviewed-by: CAI Qian <caiqian@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Steven Rostedt (Red Hat) authored and Greg Kroah-Hartman committed Apr 5, 2013
1 parent 503f4bd commit b9736c0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
char buf[64];
char *cmp;
int neg = 0;
int ret;
int ret = 0;
int i;

if (cnt >= sizeof(buf))
Expand All @@ -2569,6 +2569,8 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
cmp += 2;
}

mutex_lock(&trace_types_lock);

for (i = 0; trace_options[i]; i++) {
if (strcmp(cmp, trace_options[i]) == 0) {
set_tracer_flags(1 << i, !neg);
Expand All @@ -2577,13 +2579,13 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
}

/* If no option could be set, test the specific tracer options */
if (!trace_options[i]) {
mutex_lock(&trace_types_lock);
if (!trace_options[i])
ret = set_tracer_option(current_trace, cmp, neg);
mutex_unlock(&trace_types_lock);
if (ret)
return ret;
}

mutex_unlock(&trace_types_lock);

if (ret)
return ret;

*ppos += cnt;

Expand Down Expand Up @@ -4180,7 +4182,10 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,

if (val != 0 && val != 1)
return -EINVAL;

mutex_lock(&trace_types_lock);
set_tracer_flags(1 << index, val);
mutex_unlock(&trace_types_lock);

*ppos += cnt;

Expand Down

0 comments on commit b9736c0

Please sign in to comment.