Skip to content

Commit b5e8acc

Browse files
committed
tracing: Add down_write(trace_event_sem) when adding trace event
When a module is loaded, it adds trace events defined by the module. It may also need to modify the modules trace printk formats to replace enum names with their values. If two modules are loaded at the same time, the adding of the event to the ftrace_events list can corrupt the walking of the list in the code that is modifying the printk format strings and crash the kernel. The addition of the event should take the trace_event_sem for write while it adds the new event. Also add a lockdep_assert_held() on that semaphore in __trace_add_event_dirs() as it iterates the list. Cc: [email protected] Cc: Mathieu Desnoyers <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Link: https://lore.kernel.org/[email protected] Reported-by: Fusheng Huang(黄富生) <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: 110bf2b ("tracing: add protection around module events unload") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 85a3bce commit b5e8acc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/trace/trace_events.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,7 +3136,10 @@ __register_event(struct trace_event_call *call, struct module *mod)
31363136
if (ret < 0)
31373137
return ret;
31383138

3139+
down_write(&trace_event_sem);
31393140
list_add(&call->list, &ftrace_events);
3141+
up_write(&trace_event_sem);
3142+
31403143
if (call->flags & TRACE_EVENT_FL_DYNAMIC)
31413144
atomic_set(&call->refcnt, 0);
31423145
else
@@ -3750,6 +3753,8 @@ __trace_add_event_dirs(struct trace_array *tr)
37503753
struct trace_event_call *call;
37513754
int ret;
37523755

3756+
lockdep_assert_held(&trace_event_sem);
3757+
37533758
list_for_each_entry(call, &ftrace_events, list) {
37543759
ret = __trace_add_new_event(call, tr);
37553760
if (ret < 0)

0 commit comments

Comments
 (0)