Skip to content

Commit 69d34da

Browse files
committed
tracing: Protect tracer flags with trace_types_lock
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. Cc: [email protected] Signed-off-by: Steven Rostedt <[email protected]>
1 parent 740466b commit 69d34da

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kernel/trace/trace.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,8 @@ static int trace_set_options(char *option)
29162916
cmp += 2;
29172917
}
29182918

2919+
mutex_lock(&trace_types_lock);
2920+
29192921
for (i = 0; trace_options[i]; i++) {
29202922
if (strcmp(cmp, trace_options[i]) == 0) {
29212923
set_tracer_flags(1 << i, !neg);
@@ -2924,11 +2926,10 @@ static int trace_set_options(char *option)
29242926
}
29252927

29262928
/* If no option could be set, test the specific tracer options */
2927-
if (!trace_options[i]) {
2928-
mutex_lock(&trace_types_lock);
2929+
if (!trace_options[i])
29292930
ret = set_tracer_option(current_trace, cmp, neg);
2930-
mutex_unlock(&trace_types_lock);
2931-
}
2931+
2932+
mutex_unlock(&trace_types_lock);
29322933

29332934
return ret;
29342935
}
@@ -4781,7 +4782,10 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
47814782

47824783
if (val != 0 && val != 1)
47834784
return -EINVAL;
4785+
4786+
mutex_lock(&trace_types_lock);
47844787
set_tracer_flags(1 << index, val);
4788+
mutex_unlock(&trace_types_lock);
47854789

47864790
*ppos += cnt;
47874791

0 commit comments

Comments
 (0)