Skip to content

Commit e585e64

Browse files
Divya Indirostedt
authored andcommitted
tracing: Verify if trace array exists before destroying it.
A trace array can be destroyed from userspace or kernel. Verify if the trace array exists before proceeding to destroy/remove it. Link: http://lkml.kernel.org/r/1565805327-579-3-git-send-email-divya.indi@oracle.com Reviewed-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> Signed-off-by: Divya Indi <divya.indi@oracle.com> [ Removed unneeded braces ] Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 2d6425a commit e585e64

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎kernel/module.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,6 @@ static int complete_formation(struct module *mod, struct load_info *info)
37283728

37293729
module_enable_ro(mod, false);
37303730
module_enable_nx(mod);
3731-
module_enable_x(mod);
37323731

37333732
/* Mark state as coming so strong_try_module_get() ignores us,
37343733
* but kallsyms etc. can see us. */
@@ -3751,6 +3750,11 @@ static int prepare_coming_module(struct module *mod)
37513750
if (err)
37523751
return err;
37533752

3753+
/* Make module executable after ftrace is enabled */
3754+
mutex_lock(&module_mutex);
3755+
module_enable_x(mod);
3756+
mutex_unlock(&module_mutex);
3757+
37543758
blocking_notifier_call_chain(&module_notify_list,
37553759
MODULE_STATE_COMING, mod);
37563760
return 0;

‎kernel/trace/trace.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8556,17 +8556,26 @@ static int __remove_instance(struct trace_array *tr)
85568556
return 0;
85578557
}
85588558

8559-
int trace_array_destroy(struct trace_array *tr)
8559+
int trace_array_destroy(struct trace_array *this_tr)
85608560
{
8561+
struct trace_array *tr;
85618562
int ret;
85628563

8563-
if (!tr)
8564+
if (!this_tr)
85648565
return -EINVAL;
85658566

85668567
mutex_lock(&event_mutex);
85678568
mutex_lock(&trace_types_lock);
85688569

8569-
ret = __remove_instance(tr);
8570+
ret = -ENODEV;
8571+
8572+
/* Making sure trace array exists before destroying it. */
8573+
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
8574+
if (tr == this_tr) {
8575+
ret = __remove_instance(tr);
8576+
break;
8577+
}
8578+
}
85708579

85718580
mutex_unlock(&trace_types_lock);
85728581
mutex_unlock(&event_mutex);

0 commit comments

Comments
 (0)